Merge branch 'master' of https://github.com/GeyserMC/Geyser into feature/1.18

This commit is contained in:
Camotoy 2021-11-14 13:38:22 -05:00
commit 6249292903
No known key found for this signature in database
GPG key ID: 7EEFB66FE798081F
3 changed files with 29 additions and 26 deletions

View file

@ -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;
} }

View file

@ -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 final 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.

View file

@ -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
* *