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

Commit f99cd18

Browse files
committed
Ensure BoundingBoxEvent hooks stay synchronised
Multi-threading issues may have caused the NPEs in getBB.
1 parent 8b5e13c commit f99cd18

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

src/main/java/clientapi/load/mixin/MixinBlock.java

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,19 +55,23 @@ private void canCollideCheck(IBlockState state, boolean hitIfLiquid, CallbackInf
5555

5656
@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",
5757
at = @At("HEAD"))
58-
private void in(IBlockState state, World world, BlockPos pos, AxisAlignedBB entityBox, List<AxisAlignedBB> collidingBoxes, @Nullable Entity entity, boolean isActualState, CallbackInfo ci) {
59-
Block block = (Block) (Object) (this);
60-
bbEvent = new BoundingBoxEvent(block, pos, block.getCollisionBoundingBox(state, world, pos), collidingBoxes, entity);
61-
ClientAPI.EVENT_BUS.post(bbEvent);
58+
private void addCollisionBox(IBlockState state, World world, BlockPos pos, AxisAlignedBB entityBox, List<AxisAlignedBB> collidingBoxes, @Nullable Entity entity, boolean isActualState, CallbackInfo ci) {
59+
synchronized (this) {
60+
Block block = (Block) (Object) (this);
61+
bbEvent = new BoundingBoxEvent(block, pos, block.getCollisionBoundingBox(state, world, pos), collidingBoxes, entity);
62+
ClientAPI.EVENT_BUS.post(bbEvent);
63+
}
6264
}
6365

6466
@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",
6567
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;"))
6668
private AxisAlignedBB getBB(IBlockState state, IBlockAccess world, BlockPos pos) {
67-
AxisAlignedBB bb = (bbEvent == null) ?
68-
state.getCollisionBoundingBox(world, pos):
69-
bbEvent.getBoundingBox();
70-
bbEvent = null;
71-
return bb;
69+
synchronized (this) {
70+
AxisAlignedBB bb = (bbEvent == null) ?
71+
state.getCollisionBoundingBox(world, pos) :
72+
bbEvent.getBoundingBox();
73+
bbEvent = null;
74+
return bb;
75+
}
7276
}
7377
}

0 commit comments

Comments
 (0)