Fix legacy solid property not being set correctly when blockstate cache is invalid

Related: #244
This commit is contained in:
embeddedt 2023-09-27 17:48:07 -04:00
parent 3011e40972
commit c0815b787e
2 changed files with 15 additions and 0 deletions

View File

@ -30,6 +30,7 @@ public abstract class BlockStateBaseMixin extends StateHolder<Block, BlockState>
@Shadow private BlockBehaviour.BlockStateBase.Cache cache;
@Shadow private FluidState fluidState;
@Shadow private boolean isRandomlyTicking;
@Shadow @Deprecated private boolean legacySolid;
@Shadow protected abstract BlockState asState();
@ -114,4 +115,15 @@ public abstract class BlockStateBaseMixin extends StateHolder<Block, BlockState>
return this.owner.isRandomlyTicking(this.asState());
return this.isRandomlyTicking;
}
@Redirect(method = "*", at = @At(
value = "FIELD",
opcode = Opcodes.GETFIELD,
target = "Lnet/minecraft/world/level/block/state/BlockBehaviour$BlockStateBase;legacySolid:Z",
ordinal = 0
))
private boolean genCacheBeforeCheckingSolid(BlockBehaviour.BlockStateBase base) {
mfix$generateCache();
return this.legacySolid;
}
}

View File

@ -28,6 +28,9 @@ public class BlockStateCacheTest {
BlockState stoneBlock = Blocks.STONE.defaultBlockState();
assertTrue(((IBlockState)stoneBlock).isCacheInvalid());
assertNull(stoneBlock.cache);
// make sure lazy cache correctly handles solid
assertTrue(stoneBlock.isSolid());
}
/**