3
0
Mirror von https://github.com/GeyserMC/Geyser.git synchronisiert 2024-12-27 08:30:12 +01:00

Set BlockMapping.AIR (#4135)

* Set BlockMapping.AIR, id is always 0, but this also ensures that the palette always has air

* Rename BlockMapping.AIR to DEFAULT, as it does not have to represent AIR, and statically set it
Dieser Commit ist enthalten in:
Valaphee The Meerkat 2023-09-20 15:52:37 +02:00 committet von GitHub
Ursprung 7a28ef5c5f
Commit dead91b929
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23
8 geänderte Dateien mit 10 neuen und 10 gelöschten Zeilen

Datei anzeigen

@ -118,7 +118,7 @@ public class VillagerEntity extends AbstractMerchantEntity {
// The bed block // The bed block
int blockId = session.getGeyser().getWorldManager().getBlockAt(session, bedPosition); int blockId = session.getGeyser().getWorldManager().getBlockAt(session, bedPosition);
String fullIdentifier = BlockRegistries.JAVA_BLOCKS.getOrDefault(blockId, BlockMapping.AIR).getJavaIdentifier(); String fullIdentifier = BlockRegistries.JAVA_BLOCKS.getOrDefault(blockId, BlockMapping.DEFAULT).getJavaIdentifier();
// Set the correct position offset and rotation when sleeping // Set the correct position offset and rotation when sleeping
int bedRotation = 0; int bedRotation = 0;

Datei anzeigen

@ -80,7 +80,7 @@ public class BlockInventoryHolder extends InventoryHolder {
// and the bedrock block is vanilla // and the bedrock block is vanilla
int javaBlockId = session.getGeyser().getWorldManager().getBlockAt(session, session.getLastInteractionBlockPosition()); int javaBlockId = session.getGeyser().getWorldManager().getBlockAt(session, session.getLastInteractionBlockPosition());
if (!BlockRegistries.CUSTOM_BLOCK_STATE_OVERRIDES.get().containsKey(javaBlockId)) { if (!BlockRegistries.CUSTOM_BLOCK_STATE_OVERRIDES.get().containsKey(javaBlockId)) {
String[] javaBlockString = BlockRegistries.JAVA_BLOCKS.getOrDefault(javaBlockId, BlockMapping.AIR).getJavaIdentifier().split("\\["); String[] javaBlockString = BlockRegistries.JAVA_BLOCKS.getOrDefault(javaBlockId, BlockMapping.DEFAULT).getJavaIdentifier().split("\\[");
if (isValidBlock(javaBlockString)) { if (isValidBlock(javaBlockString)) {
// We can safely use this block // We can safely use this block
inventory.setHolderPosition(session.getLastInteractionBlockPosition()); inventory.setHolderPosition(session.getLastInteractionBlockPosition());

Datei anzeigen

@ -403,7 +403,7 @@ public final class BlockStateValues {
* @return true if a piston can break the block * @return true if a piston can break the block
*/ */
public static boolean canPistonDestroyBlock(int state) { public static boolean canPistonDestroyBlock(int state) {
return BlockRegistries.JAVA_BLOCKS.getOrDefault(state, BlockMapping.AIR).getPistonBehavior() == PistonBehavior.DESTROY; return BlockRegistries.JAVA_BLOCKS.getOrDefault(state, BlockMapping.DEFAULT).getPistonBehavior() == PistonBehavior.DESTROY;
} }
public static boolean canPistonMoveBlock(int javaId, boolean isPushing) { public static boolean canPistonMoveBlock(int javaId, boolean isPushing) {
@ -414,7 +414,7 @@ public final class BlockStateValues {
if (PistonBlockEntityTranslator.isBlock(javaId)) { if (PistonBlockEntityTranslator.isBlock(javaId)) {
return !PISTON_VALUES.get(javaId); return !PISTON_VALUES.get(javaId);
} }
BlockMapping block = BlockRegistries.JAVA_BLOCKS.getOrDefault(javaId, BlockMapping.AIR); BlockMapping block = BlockRegistries.JAVA_BLOCKS.getOrDefault(javaId, BlockMapping.DEFAULT);
// Bedrock, End portal frames, etc. can't be moved // Bedrock, End portal frames, etc. can't be moved
if (block.getHardness() == -1.0d) { if (block.getHardness() == -1.0d) {
return false; return false;
@ -511,7 +511,7 @@ public final class BlockStateValues {
* @return The block's slipperiness * @return The block's slipperiness
*/ */
public static float getSlipperiness(int state) { public static float getSlipperiness(int state) {
String blockIdentifier = BlockRegistries.JAVA_BLOCKS.getOrDefault(state, BlockMapping.AIR).getJavaIdentifier(); String blockIdentifier = BlockRegistries.JAVA_BLOCKS.getOrDefault(state, BlockMapping.DEFAULT).getJavaIdentifier();
return switch (blockIdentifier) { return switch (blockIdentifier) {
case "minecraft:slime_block" -> 0.8f; case "minecraft:slime_block" -> 0.8f;
case "minecraft:ice", "minecraft:packed_ice" -> 0.98f; case "minecraft:ice", "minecraft:packed_ice" -> 0.98f;

Datei anzeigen

@ -36,7 +36,7 @@ import javax.annotation.Nullable;
@Builder @Builder
@Value @Value
public class BlockMapping { public class BlockMapping {
public static BlockMapping AIR; public static BlockMapping DEFAULT = BlockMapping.builder().javaIdentifier("minecraft:air").pistonBehavior(PistonBehavior.NORMAL).build();;
String javaIdentifier; String javaIdentifier;
/** /**

Datei anzeigen

@ -58,7 +58,7 @@ public class DoubleChestInventoryTranslator extends ChestInventoryTranslator {
if (session.getLastInteractionPlayerPosition().equals(session.getPlayerEntity().getPosition())) { if (session.getLastInteractionPlayerPosition().equals(session.getPlayerEntity().getPosition())) {
int javaBlockId = session.getGeyser().getWorldManager().getBlockAt(session, session.getLastInteractionBlockPosition()); int javaBlockId = session.getGeyser().getWorldManager().getBlockAt(session, session.getLastInteractionBlockPosition());
if (!BlockRegistries.CUSTOM_BLOCK_STATE_OVERRIDES.get().containsKey(javaBlockId)) { if (!BlockRegistries.CUSTOM_BLOCK_STATE_OVERRIDES.get().containsKey(javaBlockId)) {
String[] javaBlockString = BlockRegistries.JAVA_BLOCKS.getOrDefault(javaBlockId, BlockMapping.AIR).getJavaIdentifier().split("\\["); String[] javaBlockString = BlockRegistries.JAVA_BLOCKS.getOrDefault(javaBlockId, BlockMapping.DEFAULT).getJavaIdentifier().split("\\[");
if (javaBlockString.length > 1 && (javaBlockString[0].equals("minecraft:chest") || javaBlockString[0].equals("minecraft:trapped_chest")) if (javaBlockString.length > 1 && (javaBlockString[0].equals("minecraft:chest") || javaBlockString[0].equals("minecraft:trapped_chest"))
&& !javaBlockString[1].contains("type=single")) { && !javaBlockString[1].contains("type=single")) {
inventory.setHolderPosition(session.getLastInteractionBlockPosition()); inventory.setHolderPosition(session.getLastInteractionBlockPosition());

Datei anzeigen

@ -67,7 +67,7 @@ public class BedrockBlockPickRequestTranslator extends PacketTranslator<BlockPic
return; return;
} }
BlockMapping blockMapping = BlockRegistries.JAVA_BLOCKS.getOrDefault(blockToPick, BlockMapping.AIR); BlockMapping blockMapping = BlockRegistries.JAVA_BLOCKS.getOrDefault(blockToPick, BlockMapping.DEFAULT);
boolean addNbtData = packet.isAddUserData() && blockMapping.isBlockEntity(); // Holding down CTRL boolean addNbtData = packet.isAddUserData() && blockMapping.isBlockEntity(); // Holding down CTRL
if (BlockStateValues.getBannerColor(blockToPick) != -1 || addNbtData) { if (BlockStateValues.getBannerColor(blockToPick) != -1 || addNbtData) {
session.getGeyser().getWorldManager().getPickItemNbt(session, vector.getX(), vector.getY(), vector.getZ(), addNbtData) session.getGeyser().getWorldManager().getPickItemNbt(session, vector.getX(), vector.getY(), vector.getZ(), addNbtData)

Datei anzeigen

@ -185,7 +185,7 @@ public class BedrockActionTranslator extends PacketTranslator<PlayerActionPacket
// Account for fire - the client likes to hit the block behind. // Account for fire - the client likes to hit the block behind.
Vector3i fireBlockPos = BlockUtils.getBlockPosition(vector, packet.getFace()); Vector3i fireBlockPos = BlockUtils.getBlockPosition(vector, packet.getFace());
int blockUp = session.getGeyser().getWorldManager().getBlockAt(session, fireBlockPos); int blockUp = session.getGeyser().getWorldManager().getBlockAt(session, fireBlockPos);
String identifier = BlockRegistries.JAVA_BLOCKS.getOrDefault(blockUp, BlockMapping.AIR).getJavaIdentifier(); String identifier = BlockRegistries.JAVA_BLOCKS.getOrDefault(blockUp, BlockMapping.DEFAULT).getJavaIdentifier();
if (identifier.startsWith("minecraft:fire") || identifier.startsWith("minecraft:soul_fire")) { if (identifier.startsWith("minecraft:fire") || identifier.startsWith("minecraft:soul_fire")) {
ServerboundPlayerActionPacket startBreakingPacket = new ServerboundPlayerActionPacket(PlayerAction.START_DIGGING, fireBlockPos, ServerboundPlayerActionPacket startBreakingPacket = new ServerboundPlayerActionPacket(PlayerAction.START_DIGGING, fireBlockPos,
Direction.VALUES[packet.getFace()], session.getWorldCache().nextPredictionSequence()); Direction.VALUES[packet.getFace()], session.getWorldCache().nextPredictionSequence());

Datei anzeigen

@ -100,7 +100,7 @@ public class JavaBlockUpdateTranslator extends PacketTranslator<ClientboundBlock
|| lastInteractPos.getZ() != packet.getEntry().getPosition().getZ())) { || lastInteractPos.getZ() != packet.getEntry().getPosition().getZ())) {
return; return;
} }
String identifier = BlockRegistries.JAVA_BLOCKS.getOrDefault(packet.getEntry().getBlock(), BlockMapping.AIR).getJavaIdentifier(); String identifier = BlockRegistries.JAVA_BLOCKS.getOrDefault(packet.getEntry().getBlock(), BlockMapping.DEFAULT).getJavaIdentifier();
session.setInteracting(false); session.setInteracting(false);
BlockSoundInteractionTranslator.handleBlockInteraction(session, lastInteractPos.toFloat(), identifier); BlockSoundInteractionTranslator.handleBlockInteraction(session, lastInteractPos.toFloat(), identifier);
} }