Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add hasBlockEntity to IBlockExtension for per-BlockState BlockEntities #1409

Open
wants to merge 6 commits into
base: 1.21.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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();
Expand Down Expand Up @@ -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_);
}
Expand Down
10 changes: 9 additions & 1 deletion patches/net/minecraft/world/level/chunk/LevelChunk.java.patch
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}