diff --git a/patches/net/minecraft/world/level/block/state/BlockBehaviour.java.patch b/patches/net/minecraft/world/level/block/state/BlockBehaviour.java.patch index 9fdd0acefe..6f1997eee2 100644 --- a/patches/net/minecraft/world/level/block/state/BlockBehaviour.java.patch +++ b/patches/net/minecraft/world/level/block/state/BlockBehaviour.java.patch @@ -1,5 +1,14 @@ --- a/net/minecraft/world/level/block/state/BlockBehaviour.java +++ b/net/minecraft/world/level/block/state/BlockBehaviour.java +@@ -171,7 +_,7 @@ + } + + protected void onRemove(BlockState p_60515_, Level p_60516_, BlockPos p_60517_, BlockState p_60518_, boolean p_60519_) { +- if (p_60515_.hasBlockEntity() && !p_60515_.is(p_60518_.getBlock())) { ++ if (p_60515_.hasBlockEntity() && (!p_60515_.is(p_60518_.getBlock()) || !p_60518_.hasBlockEntity())) { + p_60516_.removeBlockEntity(p_60517_); + } + } @@ -182,7 +_,7 @@ if (!p_311951_.isAir() && p_312925_.getBlockInteraction() != Explosion.BlockInteraction.TRIGGER_BLOCK) { Block block = p_311951_.getBlock(); @@ -97,6 +106,15 @@ return this.getBlock().useItemOn(p_316374_, this.asState(), p_316651_, p_316877_.getBlockPos(), p_316623_, p_316469_, p_316877_); } +@@ -843,7 +_,7 @@ + } + + public boolean hasBlockEntity() { +- return this.getBlock() instanceof EntityBlock; ++ return this.getBlock().hasBlockEntity(this.asState()); + } + + @Nullable @@ -871,6 +_,7 @@ return this.getBlock().getSeed(this.asState(), p_60727_); } diff --git a/patches/net/minecraft/world/level/chunk/LevelChunk.java.patch b/patches/net/minecraft/world/level/chunk/LevelChunk.java.patch index dfa6a02fdf..1088d2a017 100644 --- a/patches/net/minecraft/world/level/chunk/LevelChunk.java.patch +++ b/patches/net/minecraft/world/level/chunk/LevelChunk.java.patch @@ -26,7 +26,15 @@ ProfilerFiller profilerfiller = Profiler.get(); profilerfiller.push("updateSkyLightSources"); this.skyLightSources.update(this, j, i, l); -@@ -298,7 +_,7 @@ +@@ -291,14 +_,14 @@ + boolean flag2 = blockstate.hasBlockEntity(); + if (!this.level.isClientSide) { + blockstate.onRemove(this.level, p_62865_, p_62866_, p_62867_); +- } else if (!blockstate.is(block) && flag2) { ++ } else if ((!blockstate.is(block) || !p_62866_.hasBlockEntity()) && flag2) { + this.removeBlockEntity(p_62865_); + } + if (!levelchunksection.getBlockState(j, k, l).is(block)) { return null; } else { 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 813b8a398f..5159885d23 100644 --- a/src/main/java/net/neoforged/neoforge/common/extensions/IBlockExtension.java +++ b/src/main/java/net/neoforged/neoforge/common/extensions/IBlockExtension.java @@ -47,6 +47,7 @@ import net.minecraft.world.level.block.CampfireBlock; import net.minecraft.world.level.block.CandleBlock; import net.minecraft.world.level.block.CandleCakeBlock; +import net.minecraft.world.level.block.EntityBlock; import net.minecraft.world.level.block.FarmBlock; import net.minecraft.world.level.block.FenceGateBlock; import net.minecraft.world.level.block.FireBlock; @@ -1019,4 +1020,15 @@ default BubbleColumnDirection getBubbleColumnDirection(BlockState state) { return BubbleColumnDirection.NONE; } } + + /** + * Specifies if the incoming state has a BlockEntity or not. Override this method in your block if only certain BlockStates + * are to have BlockEntities. If you override this method, be sure to also change {@link EntityBlock#newBlockEntity} result + * as well to return null for BlockStates that do not have BlockEntities for your block. + * + * @return Whether this BlockState is intended to have a BlockEntity attached to it + */ + default boolean hasBlockEntity(BlockState state) { + return state.getBlock() instanceof EntityBlock; + } }