3
0
Mirror von https://github.com/GeyserMC/Geyser.git synchronisiert 2024-12-25 15:50:14 +01:00

Prevent blocks destroyed by pistons from moving on Geyser-Spigot (#2627)

Dieser Commit ist enthalten in:
David Choo 2021-11-12 20:36:01 -05:00 committet von GitHub
Ursprung 09e3793fb2
Commit adbadbbba4
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23
3 geänderte Dateien mit 29 neuen und 26 gelöschten Zeilen

Datei anzeigen

@ -110,8 +110,12 @@ public class GeyserPistonListener implements Listener {
List<Block> blocks = isExtend ? ((BlockPistonExtendEvent) event).getBlocks() : ((BlockPistonRetractEvent) event).getBlocks(); List<Block> blocks = isExtend ? ((BlockPistonExtendEvent) event).getBlocks() : ((BlockPistonRetractEvent) event).getBlocks();
for (Block block : blocks) { for (Block block : blocks) {
Location attachedLocation = block.getLocation(); Location attachedLocation = block.getLocation();
attachedBlocks.put(getVector(attachedLocation), worldManager.getBlockNetworkId(player, block, int blockId = worldManager.getBlockNetworkId(player, block,
attachedLocation.getBlockX(), attachedLocation.getBlockY(), attachedLocation.getBlockZ())); attachedLocation.getBlockX(), attachedLocation.getBlockY(), attachedLocation.getBlockZ());
// Ignore blocks that will be destroyed
if (BlockStateValues.canPistonMoveBlock(blockId, isExtend)) {
attachedBlocks.put(getVector(attachedLocation), blockId);
}
} }
blocksFilled = true; blocksFilled = true;
} }

Datei anzeigen

@ -29,6 +29,7 @@ import com.fasterxml.jackson.databind.JsonNode;
import it.unimi.dsi.fastutil.ints.*; import it.unimi.dsi.fastutil.ints.*;
import it.unimi.dsi.fastutil.objects.Object2IntMap; import it.unimi.dsi.fastutil.objects.Object2IntMap;
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap; 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.BlockRegistries;
import org.geysermc.connector.registry.type.BlockMapping; import org.geysermc.connector.registry.type.BlockMapping;
import org.geysermc.connector.utils.Direction; import org.geysermc.connector.utils.Direction;
@ -335,6 +336,26 @@ public class BlockStateValues {
return BlockRegistries.JAVA_BLOCKS.getOrDefault(state, BlockMapping.AIR).getPistonBehavior() == PistonBehavior.DESTROY; 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. * 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. * This gives a byte variant ID that Bedrock can use.

Datei anzeigen

@ -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.CollisionManager;
import org.geysermc.connector.network.translators.collision.translators.BlockCollision; import org.geysermc.connector.network.translators.collision.translators.BlockCollision;
import org.geysermc.connector.network.translators.world.block.BlockStateValues; 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.Registries;
import org.geysermc.connector.registry.type.BlockMapping;
import org.geysermc.connector.utils.*; import org.geysermc.connector.utils.*;
import java.util.LinkedList; import java.util.LinkedList;
@ -256,7 +254,7 @@ public class PistonBlockEntity {
if (blockId == BlockStateValues.JAVA_AIR_ID) { if (blockId == BlockStateValues.JAVA_AIR_ID) {
continue; continue;
} }
if (canMoveBlock(blockId, action == PistonValueType.PUSHING)) { if (BlockStateValues.canPistonMoveBlock(blockId, action == PistonValueType.PUSHING)) {
attachedBlocks.put(blockPos, blockId); attachedBlocks.put(blockPos, blockId);
if (BlockStateValues.isBlockSticky(blockId)) { if (BlockStateValues.isBlockSticky(blockId)) {
// For honey blocks and slime blocks check the blocks adjacent to it // For honey blocks and slime blocks check the blocks adjacent to it
@ -276,7 +274,7 @@ public class PistonBlockEntity {
continue; continue;
} }
int adjacentBlockId = session.getConnector().getWorldManager().getBlockAt(session, adjacentPos); 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 it is another slime/honey block we need to check its adjacent blocks
if (BlockStateValues.isBlockSticky(adjacentBlockId)) { if (BlockStateValues.isBlockSticky(adjacentBlockId)) {
blocksToCheck.add(adjacentPos); 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 * Get the unit vector for the direction of movement
* *