Skip to content

Commit

Permalink
Make chunk sections only resolve Blocks.AIR for vanilla air blocks, p…
Browse files Browse the repository at this point in the history
…reserving modded air (neoforged#471)
  • Loading branch information
TelepathicGrunt authored Jan 15, 2024
1 parent da756fd commit 42077b9
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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_;
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}

0 comments on commit 42077b9

Please sign in to comment.