diff --git a/patches/server/API-to-get-a-BlockState-without-a-snapshot.patch b/patches/server/API-to-get-a-BlockState-without-a-snapshot.patch index 1f7ce3722..f69c6885b 100644 --- a/patches/server/API-to-get-a-BlockState-without-a-snapshot.patch +++ b/patches/server/API-to-get-a-BlockState-without-a-snapshot.patch @@ -55,36 +55,24 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 --- a/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java +++ b/src/main/java/org/bukkit/craftbukkit/block/CraftBlock.java @@ -0,0 +0,0 @@ public class CraftBlock implements Block { - - @Override - public BlockState getState() { -+ // Paper start -+ return this.getState(true); -+ } -+ -+ @Override -+ public BlockState getState(boolean useSnapshot) { -+ boolean prev = CraftBlockEntityState.DISABLE_SNAPSHOT; -+ CraftBlockEntityState.DISABLE_SNAPSHOT = !useSnapshot; -+ try { return CraftBlockStates.getBlockState(this); -+ } finally { -+ CraftBlockEntityState.DISABLE_SNAPSHOT = prev; -+ } -+ // Paper end } ++ // Paper start ++ @Override ++ public BlockState getState(boolean useSnapshot) { ++ return CraftBlockStates.getBlockState(this, useSnapshot); ++ } ++ // Paper end ++ @Override + public Biome getBiome() { + return this.getWorld().getBiome(this.getX(), this.getY(), this.getZ()); diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftBlockEntityState.java b/src/main/java/org/bukkit/craftbukkit/block/CraftBlockEntityState.java index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/org/bukkit/craftbukkit/block/CraftBlockEntityState.java +++ b/src/main/java/org/bukkit/craftbukkit/block/CraftBlockEntityState.java -@@ -0,0 +0,0 @@ import org.bukkit.World; - import org.bukkit.block.TileState; - import org.bukkit.persistence.PersistentDataContainer; - --public class CraftBlockEntityState extends CraftBlockState implements TileState { -+public abstract class CraftBlockEntityState extends CraftBlockState implements TileState { // Paper - revert revert +@@ -0,0 +0,0 @@ public class CraftBlockEntityState extends CraftBlockStat private final T tileEntity; private final T snapshot; @@ -118,22 +106,36 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 --- a/src/main/java/org/bukkit/craftbukkit/block/CraftBlockStates.java +++ b/src/main/java/org/bukkit/craftbukkit/block/CraftBlockStates.java @@ -0,0 +0,0 @@ public final class CraftBlockStates { - private static final BlockStateFactory DEFAULT_FACTORY = new BlockStateFactory(CraftBlockState.class) { - @Override - public CraftBlockState createBlockState(World world, BlockPos blockPosition, net.minecraft.world.level.block.state.BlockState blockData, BlockEntity tileEntity) { -- // SPIGOT-6754, SPIGOT-6817: Restore previous behaviour for tile entities with removed blocks (loot generation post-destroy) -- if (tileEntity != null) { -- // block with unhandled TileEntity: -- return new CraftBlockEntityState<>(world, tileEntity); -- } -- Preconditions.checkState(tileEntity == null, "Unexpected BlockState for %s", CraftMagicNumbers.getMaterial(blockData.getBlock())); -+ // Paper start - revert revert -+ // 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. -+ Preconditions.checkState(tileEntity == null || CraftMagicNumbers.getMaterial(blockData.getBlock()) == Material.AIR, "Unexpected BlockState for %s", CraftMagicNumbers.getMaterial(blockData.getBlock())); -+ // Paper end - return new CraftBlockState(world, blockPosition, blockData); - } - }; + } + + public static BlockState getBlockState(Block block) { ++ // Paper start ++ return CraftBlockStates.getBlockState(block, true); ++ } ++ public static BlockState getBlockState(Block block, boolean useSnapshot) { ++ // Paper end + Preconditions.checkNotNull(block, "block is null"); + CraftBlock craftBlock = (CraftBlock) block; + CraftWorld world = (CraftWorld) block.getWorld(); + BlockPos blockPosition = craftBlock.getPosition(); + net.minecraft.world.level.block.state.BlockState blockData = craftBlock.getNMS(); + BlockEntity tileEntity = craftBlock.getHandle().getBlockEntity(blockPosition); ++ // Paper start - block state snapshots ++ boolean prev = CraftBlockEntityState.DISABLE_SNAPSHOT; ++ CraftBlockEntityState.DISABLE_SNAPSHOT = !useSnapshot; ++ try { ++ // Paper end + CraftBlockState blockState = CraftBlockStates.getBlockState(world, blockPosition, blockData, tileEntity); + blockState.setWorldHandle(craftBlock.getHandle()); // Inject the block's generator access + return blockState; ++ // Paper start ++ } finally { ++ CraftBlockEntityState.DISABLE_SNAPSHOT = prev; ++ } ++ // Paper end + } + + public static BlockState getBlockState(Material material, @Nullable CompoundTag blockEntityTag) { diff --git a/src/main/java/org/bukkit/craftbukkit/persistence/CraftPersistentDataContainer.java b/src/main/java/org/bukkit/craftbukkit/persistence/CraftPersistentDataContainer.java index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/org/bukkit/craftbukkit/persistence/CraftPersistentDataContainer.java diff --git a/patches/server/Fix-upstreams-block-state-factories.patch b/patches/server/Fix-upstreams-block-state-factories.patch index 825647574..b41389509 100644 --- a/patches/server/Fix-upstreams-block-state-factories.patch +++ b/patches/server/Fix-upstreams-block-state-factories.patch @@ -22,6 +22,19 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 org.bukkit.block.BlockState state = block.getState(useSnapshot); // Paper if (state instanceof InventoryHolder) return (InventoryHolder) state; return null; +diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftBlockEntityState.java b/src/main/java/org/bukkit/craftbukkit/block/CraftBlockEntityState.java +index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 +--- a/src/main/java/org/bukkit/craftbukkit/block/CraftBlockEntityState.java ++++ b/src/main/java/org/bukkit/craftbukkit/block/CraftBlockEntityState.java +@@ -0,0 +0,0 @@ import org.bukkit.World; + import org.bukkit.block.TileState; + import org.bukkit.persistence.PersistentDataContainer; + +-public class CraftBlockEntityState extends CraftBlockState implements TileState { ++public abstract class CraftBlockEntityState extends CraftBlockState implements TileState { // Paper - revert upstream's revert of the block state changes + + private final T tileEntity; + private final T snapshot; diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftBlockStates.java b/src/main/java/org/bukkit/craftbukkit/block/CraftBlockStates.java index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/org/bukkit/craftbukkit/block/CraftBlockStates.java @@ -35,12 +48,16 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 import net.minecraft.world.level.block.entity.CampfireBlockEntity; import net.minecraft.world.level.block.entity.ChestBlockEntity; @@ -0,0 +0,0 @@ public final class CraftBlockStates { + private static final BlockStateFactory DEFAULT_FACTORY = new BlockStateFactory(CraftBlockState.class) { + @Override public CraftBlockState createBlockState(World world, BlockPos blockPosition, net.minecraft.world.level.block.state.BlockState blockData, BlockEntity tileEntity) { - // Paper start - revert revert - // 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. -- Preconditions.checkState(tileEntity == null || CraftMagicNumbers.getMaterial(blockData.getBlock()) == Material.AIR, "Unexpected BlockState for %s", CraftMagicNumbers.getMaterial(blockData.getBlock())); -+ Preconditions.checkState(tileEntity == null/* || CraftMagicNumbers.getMaterial(blockData.getBlock()) == Material.AIR*/, "Unexpected BlockState for %s", CraftMagicNumbers.getMaterial(blockData.getBlock())); // Paper - don't ignore the TileEntity while its still valid - // Paper end +- // SPIGOT-6754, SPIGOT-6817: Restore previous behaviour for tile entities with removed blocks (loot generation post-destroy) +- if (tileEntity != null) { +- // block with unhandled TileEntity: +- return new CraftBlockEntityState<>(world, tileEntity); +- } ++ // Paper - revert upstream's revert of the block state changes. Block entities that have already had the block type set to AIR are still valid, upstream decided to ignore them + Preconditions.checkState(tileEntity == null, "Unexpected BlockState for %s", CraftMagicNumbers.getMaterial(blockData.getBlock())); return new CraftBlockState(world, blockPosition, blockData); } }; @@ -321,8 +338,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + // Paper end + public static BlockState getBlockState(Block block) { - Preconditions.checkNotNull(block, "block is null"); - CraftBlock craftBlock = (CraftBlock) block; + // Paper start + return CraftBlockStates.getBlockState(block, true); @@ -0,0 +0,0 @@ public final class CraftBlockStates { if (world != null && tileEntity == null && CraftBlockStates.isTileEntityOptional(material)) { factory = CraftBlockStates.DEFAULT_FACTORY; diff --git a/patches/server/Show-blockstate-location-if-we-failed-to-read-it.patch b/patches/server/Show-blockstate-location-if-we-failed-to-read-it.patch index 7003b3ec4..63022048e 100644 --- a/patches/server/Show-blockstate-location-if-we-failed-to-read-it.patch +++ b/patches/server/Show-blockstate-location-if-we-failed-to-read-it.patch @@ -8,7 +8,7 @@ diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftBlockEntityState.ja index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/src/main/java/org/bukkit/craftbukkit/block/CraftBlockEntityState.java +++ b/src/main/java/org/bukkit/craftbukkit/block/CraftBlockEntityState.java -@@ -0,0 +0,0 @@ public abstract class CraftBlockEntityState extends Craft +@@ -0,0 +0,0 @@ public class CraftBlockEntityState extends CraftBlockStat this.tileEntity = tileEntity; @@ -16,7 +16,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 // Paper start this.snapshotDisabled = DISABLE_SNAPSHOT; if (DISABLE_SNAPSHOT) { -@@ -0,0 +0,0 @@ public abstract class CraftBlockEntityState extends Craft +@@ -0,0 +0,0 @@ public class CraftBlockEntityState extends CraftBlockStat this.load(this.snapshot); } // Paper end