diff --git a/bootstrap/spigot/src/main/java/org/geysermc/platform/spigot/world/GeyserPistonListener.java b/bootstrap/spigot/src/main/java/org/geysermc/platform/spigot/world/GeyserPistonListener.java index 9810334f6..31f7585bb 100644 --- a/bootstrap/spigot/src/main/java/org/geysermc/platform/spigot/world/GeyserPistonListener.java +++ b/bootstrap/spigot/src/main/java/org/geysermc/platform/spigot/world/GeyserPistonListener.java @@ -110,8 +110,12 @@ public class GeyserPistonListener implements Listener { List blocks = isExtend ? ((BlockPistonExtendEvent) event).getBlocks() : ((BlockPistonRetractEvent) event).getBlocks(); for (Block block : blocks) { Location attachedLocation = block.getLocation(); - attachedBlocks.put(getVector(attachedLocation), worldManager.getBlockNetworkId(player, block, - attachedLocation.getBlockX(), attachedLocation.getBlockY(), attachedLocation.getBlockZ())); + int blockId = worldManager.getBlockNetworkId(player, block, + attachedLocation.getBlockX(), attachedLocation.getBlockY(), attachedLocation.getBlockZ()); + // Ignore blocks that will be destroyed + if (BlockStateValues.canPistonMoveBlock(blockId, isExtend)) { + attachedBlocks.put(getVector(attachedLocation), blockId); + } } blocksFilled = true; } diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/world/block/BlockStateValues.java b/connector/src/main/java/org/geysermc/connector/network/translators/world/block/BlockStateValues.java index 448b17197..a1c47c2b6 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/world/block/BlockStateValues.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/world/block/BlockStateValues.java @@ -29,6 +29,7 @@ import com.fasterxml.jackson.databind.JsonNode; import it.unimi.dsi.fastutil.ints.*; import it.unimi.dsi.fastutil.objects.Object2IntMap; import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap; +import org.geysermc.connector.network.translators.world.block.entity.PistonBlockEntityTranslator; import org.geysermc.connector.registry.BlockRegistries; import org.geysermc.connector.registry.type.BlockMapping; import org.geysermc.connector.utils.Direction; @@ -335,6 +336,26 @@ public final class BlockStateValues { return BlockRegistries.JAVA_BLOCKS.getOrDefault(state, BlockMapping.AIR).getPistonBehavior() == PistonBehavior.DESTROY; } + public static boolean canPistonMoveBlock(int javaId, boolean isPushing) { + if (javaId == JAVA_AIR_ID) { + return true; + } + // Pistons can only be moved if they aren't extended + if (PistonBlockEntityTranslator.isBlock(javaId)) { + return !PISTON_VALUES.get(javaId); + } + BlockMapping block = BlockRegistries.JAVA_BLOCKS.getOrDefault(javaId, BlockMapping.AIR); + // Bedrock, End portal frames, etc. can't be moved + if (block.getHardness() == -1.0d) { + return false; + } + return switch (block.getPistonBehavior()) { + case BLOCK, DESTROY -> false; + case PUSH_ONLY -> isPushing; // Glazed terracotta can only be pushed + default -> !block.isBlockEntity(); // Pistons can't move block entities + }; + } + /** * Skull variations are part of the namespaced ID in Java Edition, but part of the block entity tag in Bedrock. * This gives a byte variant ID that Bedrock can use. diff --git a/connector/src/main/java/org/geysermc/connector/network/translators/world/block/entity/PistonBlockEntity.java b/connector/src/main/java/org/geysermc/connector/network/translators/world/block/entity/PistonBlockEntity.java index f698d43f2..3cd4b94c0 100644 --- a/connector/src/main/java/org/geysermc/connector/network/translators/world/block/entity/PistonBlockEntity.java +++ b/connector/src/main/java/org/geysermc/connector/network/translators/world/block/entity/PistonBlockEntity.java @@ -43,9 +43,7 @@ import org.geysermc.connector.network.translators.collision.BoundingBox; import org.geysermc.connector.network.translators.collision.CollisionManager; import org.geysermc.connector.network.translators.collision.translators.BlockCollision; import org.geysermc.connector.network.translators.world.block.BlockStateValues; -import org.geysermc.connector.registry.BlockRegistries; import org.geysermc.connector.registry.Registries; -import org.geysermc.connector.registry.type.BlockMapping; import org.geysermc.connector.utils.*; import java.util.LinkedList; @@ -256,7 +254,7 @@ public class PistonBlockEntity { if (blockId == BlockStateValues.JAVA_AIR_ID) { continue; } - if (canMoveBlock(blockId, action == PistonValueType.PUSHING)) { + if (BlockStateValues.canPistonMoveBlock(blockId, action == PistonValueType.PUSHING)) { attachedBlocks.put(blockPos, blockId); if (BlockStateValues.isBlockSticky(blockId)) { // For honey blocks and slime blocks check the blocks adjacent to it @@ -276,7 +274,7 @@ public class PistonBlockEntity { continue; } int adjacentBlockId = session.getConnector().getWorldManager().getBlockAt(session, adjacentPos); - if (adjacentBlockId != BlockStateValues.JAVA_AIR_ID && BlockStateValues.isBlockAttached(blockId, adjacentBlockId) && canMoveBlock(adjacentBlockId, false)) { + if (adjacentBlockId != BlockStateValues.JAVA_AIR_ID && BlockStateValues.isBlockAttached(blockId, adjacentBlockId) && BlockStateValues.canPistonMoveBlock(adjacentBlockId, false)) { // If it is another slime/honey block we need to check its adjacent blocks if (BlockStateValues.isBlockSticky(adjacentBlockId)) { blocksToCheck.add(adjacentPos); @@ -303,26 +301,6 @@ public class PistonBlockEntity { } } - private boolean canMoveBlock(int javaId, boolean isPushing) { - if (javaId == BlockStateValues.JAVA_AIR_ID) { - return true; - } - // Pistons can only be moved if they aren't extended - if (PistonBlockEntityTranslator.isBlock(javaId)) { - return !BlockStateValues.getPistonValues().get(javaId); - } - BlockMapping block = BlockRegistries.JAVA_BLOCKS.getOrDefault(javaId, BlockMapping.AIR); - // Bedrock, End portal frames, etc. can't be moved - if (block.getHardness() == -1.0d) { - return false; - } - return switch (block.getPistonBehavior()) { - case BLOCK, DESTROY -> false; - case PUSH_ONLY -> isPushing; // Glazed terracotta can only be pushed - default -> !block.isBlockEntity(); // Pistons can't move block entities - }; - } - /** * Get the unit vector for the direction of movement *