diff --git a/patches/net/minecraft/world/level/chunk/LevelChunkSection.java.patch b/patches/net/minecraft/world/level/chunk/LevelChunkSection.java.patch new file mode 100644 index 0000000000..382d1bc347 --- /dev/null +++ b/patches/net/minecraft/world/level/chunk/LevelChunkSection.java.patch @@ -0,0 +1,29 @@ +--- a/net/minecraft/world/level/chunk/LevelChunkSection.java ++++ b/net/minecraft/world/level/chunk/LevelChunkSection.java +@@ -65,7 +_,7 @@ + + FluidState fluidstate = blockstate.getFluidState(); + FluidState fluidstate1 = p_62995_.getFluidState(); +- if (!blockstate.isAir()) { ++ if (!blockstate.isEmpty()) { // Neo: Fix MC-232360 for modded blocks (Makes modded isAir blocks not be replaced with Blocks.AIR in all-air chunk sections) + --this.nonEmptyBlockCount; + if (blockstate.isRandomlyTicking()) { + --this.tickingBlockCount; +@@ -76,7 +_,7 @@ + --this.tickingFluidCount; + } + +- if (!p_62995_.isAir()) { ++ if (!p_62995_.isEmpty()) { // Neo: Fix MC-232360 for modded blocks (Makes modded isAir blocks not be replaced with Blocks.AIR in all-air chunk sections) + ++this.nonEmptyBlockCount; + if (p_62995_.isRandomlyTicking()) { + ++this.tickingBlockCount; +@@ -114,7 +_,7 @@ + + public void accept(BlockState p_204444_, int p_204445_) { + FluidState fluidstate = p_204444_.getFluidState(); +- if (!p_204444_.isAir()) { ++ if (!p_204444_.isEmpty()) { // Neo: Fix MC-232360 for modded blocks (Makes modded isAir blocks not be replaced with Blocks.AIR in all-air chunk sections) + this.nonEmptyBlockCount += p_204445_; + if (p_204444_.isRandomlyTicking()) { + this.tickingBlockCount += p_204445_; diff --git a/src/main/java/net/neoforged/neoforge/common/extensions/IBlockExtension.java b/src/main/java/net/neoforged/neoforge/common/extensions/IBlockExtension.java index 1925c00a7c..723eb43383 100644 --- a/src/main/java/net/neoforged/neoforge/common/extensions/IBlockExtension.java +++ b/src/main/java/net/neoforged/neoforge/common/extensions/IBlockExtension.java @@ -947,4 +947,14 @@ default BlockState getAppearance(BlockState state, BlockAndTintGetter level, Blo default PushReaction getPistonPushReaction(BlockState state) { return null; } + + /** + * Return true if the state is able to be replaced with Blocks.AIR in chunk sections that is entirely made of blocks that return true for isEmpty + * + * @param state The current state + * @return True if the block should be allowed to be optimized away into Blocks.AIR + */ + default boolean isEmpty(BlockState state) { + return state.is(Blocks.AIR) || state.is(Blocks.CAVE_AIR) || state.is(Blocks.VOID_AIR); + } } diff --git a/src/main/java/net/neoforged/neoforge/common/extensions/IBlockStateExtension.java b/src/main/java/net/neoforged/neoforge/common/extensions/IBlockStateExtension.java index b6860119e0..c137c40677 100644 --- a/src/main/java/net/neoforged/neoforge/common/extensions/IBlockStateExtension.java +++ b/src/main/java/net/neoforged/neoforge/common/extensions/IBlockStateExtension.java @@ -721,4 +721,13 @@ default boolean canBeHydrated(BlockGetter getter, BlockPos pos, FluidState fluid default BlockState getAppearance(BlockAndTintGetter level, BlockPos pos, Direction side, @Nullable BlockState queryState, @Nullable BlockPos queryPos) { return self().getBlock().getAppearance(self(), level, pos, side, queryState, queryPos); } + + /** + * Return true if the state is able to be replaced with Blocks.AIR in chunk sections that is entirely made of blocks that return true for isEmpty + * + * @return True if the block should be allowed to be optimized away into Blocks.AIR + */ + default boolean isEmpty() { + return self().getBlock().isEmpty(self()); + } }