Skip to content
This repository has been archived by the owner on Feb 19, 2019. It is now read-only.

Commit

Permalink
Ensure BoundingBoxEvent hooks stay synchronised
Browse files Browse the repository at this point in the history
Multi-threading issues may have caused the NPEs in getBB.
  • Loading branch information
LeafHacker committed Jun 24, 2018
1 parent 8b5e13c commit f99cd18
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions src/main/java/clientapi/load/mixin/MixinBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,23 @@ private void canCollideCheck(IBlockState state, boolean hitIfLiquid, CallbackInf

@Inject(method = "addCollisionBoxToList(Lnet/minecraft/block/state/IBlockState;Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/util/math/AxisAlignedBB;Ljava/util/List;Lnet/minecraft/entity/Entity;Z)V",
at = @At("HEAD"))
private void in(IBlockState state, World world, BlockPos pos, AxisAlignedBB entityBox, List<AxisAlignedBB> collidingBoxes, @Nullable Entity entity, boolean isActualState, CallbackInfo ci) {
Block block = (Block) (Object) (this);
bbEvent = new BoundingBoxEvent(block, pos, block.getCollisionBoundingBox(state, world, pos), collidingBoxes, entity);
ClientAPI.EVENT_BUS.post(bbEvent);
private void addCollisionBox(IBlockState state, World world, BlockPos pos, AxisAlignedBB entityBox, List<AxisAlignedBB> collidingBoxes, @Nullable Entity entity, boolean isActualState, CallbackInfo ci) {
synchronized (this) {
Block block = (Block) (Object) (this);
bbEvent = new BoundingBoxEvent(block, pos, block.getCollisionBoundingBox(state, world, pos), collidingBoxes, entity);
ClientAPI.EVENT_BUS.post(bbEvent);
}
}

@Redirect(method = "addCollisionBoxToList(Lnet/minecraft/block/state/IBlockState;Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/util/math/AxisAlignedBB;Ljava/util/List;Lnet/minecraft/entity/Entity;Z)V",
at = @At(value = "INVOKE", target = "Lnet/minecraft/block/state/IBlockState;getCollisionBoundingBox(Lnet/minecraft/world/IBlockAccess;Lnet/minecraft/util/math/BlockPos;)Lnet/minecraft/util/math/AxisAlignedBB;"))
private AxisAlignedBB getBB(IBlockState state, IBlockAccess world, BlockPos pos) {
AxisAlignedBB bb = (bbEvent == null) ?
state.getCollisionBoundingBox(world, pos):
bbEvent.getBoundingBox();
bbEvent = null;
return bb;
synchronized (this) {
AxisAlignedBB bb = (bbEvent == null) ?
state.getCollisionBoundingBox(world, pos) :
bbEvent.getBoundingBox();
bbEvent = null;
return bb;
}
}
}

0 comments on commit f99cd18

Please sign in to comment.