@@ -51,40 +51,28 @@ index 1e416b23a38458f16add472cea09b0ac5ac91869..6f61fd8224fb4094f38a851300ab55f9
5151 return null;
5252 }
5353diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java b/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java
54- index d8b9a8276204ad8a2f045af9fe94185dbf150bc6..3250559589eb4db7b3df828144cee81a19651842 100644
54+ index c0af4b05b5d77aad99487fa7f8d840e797b6554c..40fc3268e7b662cdd45b569224ccd2abfad0a595 100644
5555--- a/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java
5656+++ b/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java
57- @@ -317,7 +317,20 @@ public class CraftBlock implements Block {
58-
59- @Override
60- public BlockState getState() {
61- + // Paper start
62- + return this.getState(true);
63- + }
64- +
65- + @Override
66- + public BlockState getState(boolean useSnapshot) {
67- + boolean prev = CraftBlockEntityState.DISABLE_SNAPSHOT;
68- + CraftBlockEntityState.DISABLE_SNAPSHOT = !useSnapshot;
69- + try {
57+ @@ -320,6 +320,13 @@ public class CraftBlock implements Block {
7058 return CraftBlockStates.getBlockState(this);
71- + } finally {
72- + CraftBlockEntityState.DISABLE_SNAPSHOT = prev;
73- + }
74- + // Paper end
7559 }
7660
61+ + // Paper start
62+ + @Override
63+ + public BlockState getState(boolean useSnapshot) {
64+ + return CraftBlockStates.getBlockState(this, useSnapshot);
65+ + }
66+ + // Paper end
67+ +
7768 @Override
69+ public Biome getBiome() {
70+ return this.getWorld().getBiome(this.getX(), this.getY(), this.getZ());
7871diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftBlockEntityState.java b/src/main/java/org/bukkit/craftbukkit/block/CraftBlockEntityState.java
79- index 7629a51ec284cab0db7e9238027d6acfa4f3083c..27f38af1eb71dda5dd175dcabc7a467ed772757a 100644
72+ index 7629a51ec284cab0db7e9238027d6acfa4f3083c..c2c0b4bfab64394e55f2832e37e49bccb7e955ab 100644
8073--- a/src/main/java/org/bukkit/craftbukkit/block/CraftBlockEntityState.java
8174+++ b/src/main/java/org/bukkit/craftbukkit/block/CraftBlockEntityState.java
82- @@ -6,19 +6,30 @@ import org.bukkit.World;
83- import org.bukkit.block.TileState;
84- import org.bukkit.persistence.PersistentDataContainer;
85-
86- - public class CraftBlockEntityState<T extends BlockEntity> extends CraftBlockState implements TileState {
87- + public abstract class CraftBlockEntityState<T extends BlockEntity> extends CraftBlockState implements TileState { // Paper - revert revert
75+ @@ -10,15 +10,26 @@ public class CraftBlockEntityState<T extends BlockEntity> extends CraftBlockStat
8876
8977 private final T tileEntity;
9078 private final T snapshot;
@@ -114,26 +102,40 @@ index 7629a51ec284cab0db7e9238027d6acfa4f3083c..27f38af1eb71dda5dd175dcabc7a467e
114102
115103 public void refreshSnapshot() {
116104diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftBlockStates.java b/src/main/java/org/bukkit/craftbukkit/block/CraftBlockStates.java
117- index 51ea68c433c4d530f8404d3174c5a121ce808a96..9d0934656bbd27df4b47b816540d02cfbfc80636 100644
105+ index 51ea68c433c4d530f8404d3174c5a121ce808a96..93a8aeb5545c794ac425c35f8af52a443cd060ca 100644
118106--- a/src/main/java/org/bukkit/craftbukkit/block/CraftBlockStates.java
119107+++ b/src/main/java/org/bukkit/craftbukkit/block/CraftBlockStates.java
120- @@ -105,12 +105,10 @@ public final class CraftBlockStates {
121- private static final BlockStateFactory<?> DEFAULT_FACTORY = new BlockStateFactory<CraftBlockState>(CraftBlockState.class) {
122- @Override
123- public CraftBlockState createBlockState(World world, BlockPos blockPosition, net.minecraft.world.level.block.state.BlockState blockData, BlockEntity tileEntity) {
124- - // SPIGOT-6754, SPIGOT-6817: Restore previous behaviour for tile entities with removed blocks (loot generation post-destroy)
125- - if (tileEntity != null) {
126- - // block with unhandled TileEntity:
127- - return new CraftBlockEntityState<>(world, tileEntity);
128- - }
129- - Preconditions.checkState(tileEntity == null, "Unexpected BlockState for %s", CraftMagicNumbers.getMaterial(blockData.getBlock()));
130- + // Paper start - revert revert
131- + // When a block is being destroyed, the TileEntity may temporarily still exist while the block's type has already been set to AIR. We ignore the TileEntity in this case.
132- + Preconditions.checkState(tileEntity == null || CraftMagicNumbers.getMaterial(blockData.getBlock()) == Material.AIR, "Unexpected BlockState for %s", CraftMagicNumbers.getMaterial(blockData.getBlock()));
133- + // Paper end
134- return new CraftBlockState(world, blockPosition, blockData);
135- }
136- };
108+ @@ -324,15 +324,30 @@ public final class CraftBlockStates {
109+ }
110+
111+ public static BlockState getBlockState(Block block) {
112+ + // Paper start
113+ + return CraftBlockStates.getBlockState(block, true);
114+ + }
115+ + public static BlockState getBlockState(Block block, boolean useSnapshot) {
116+ + // Paper end
117+ Preconditions.checkNotNull(block, "block is null");
118+ CraftBlock craftBlock = (CraftBlock) block;
119+ CraftWorld world = (CraftWorld) block.getWorld();
120+ BlockPos blockPosition = craftBlock.getPosition();
121+ net.minecraft.world.level.block.state.BlockState blockData = craftBlock.getNMS();
122+ BlockEntity tileEntity = craftBlock.getHandle().getBlockEntity(blockPosition);
123+ + // Paper start - block state snapshots
124+ + boolean prev = CraftBlockEntityState.DISABLE_SNAPSHOT;
125+ + CraftBlockEntityState.DISABLE_SNAPSHOT = !useSnapshot;
126+ + try {
127+ + // Paper end
128+ CraftBlockState blockState = CraftBlockStates.getBlockState(world, blockPosition, blockData, tileEntity);
129+ blockState.setWorldHandle(craftBlock.getHandle()); // Inject the block's generator access
130+ return blockState;
131+ + // Paper start
132+ + } finally {
133+ + CraftBlockEntityState.DISABLE_SNAPSHOT = prev;
134+ + }
135+ + // Paper end
136+ }
137+
138+ public static BlockState getBlockState(Material material, @Nullable CompoundTag blockEntityTag) {
137139diff --git a/src/main/java/org/bukkit/craftbukkit/persistence/CraftPersistentDataContainer.java b/src/main/java/org/bukkit/craftbukkit/persistence/CraftPersistentDataContainer.java
138140index 3fc3907172f12ee24ea70bd6a1ffbbc6084ed971..2c59f09a9261a1690951161fd856a5848d9885b7 100644
139141--- a/src/main/java/org/bukkit/craftbukkit/persistence/CraftPersistentDataContainer.java
0 commit comments