From 4ab26e0717e9f5fba9785da8a3da8e4c3a9d2799 Mon Sep 17 00:00:00 2001 From: davchoo <4722249+davchoo@users.noreply.github.com> Date: Mon, 16 Jan 2023 14:46:20 -0500 Subject: [PATCH 1/3] Fix light_emission and light_dampening components --- .../registry/populator/CustomBlockRegistryPopulator.java | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/core/src/main/java/org/geysermc/geyser/registry/populator/CustomBlockRegistryPopulator.java b/core/src/main/java/org/geysermc/geyser/registry/populator/CustomBlockRegistryPopulator.java index 48a8a8259..fae38cd19 100644 --- a/core/src/main/java/org/geysermc/geyser/registry/populator/CustomBlockRegistryPopulator.java +++ b/core/src/main/java/org/geysermc/geyser/registry/populator/CustomBlockRegistryPopulator.java @@ -254,15 +254,12 @@ public class CustomBlockRegistryPopulator { } if (components.lightEmission() != null) { builder.putCompound("minecraft:light_emission", NbtMap.builder() - .putInt("value", components.lightEmission()) + .putByte("emission", components.lightEmission().byteValue()) .build()); } - // This is supposed to be sent as "light_dampening" since "block_light_filter" is the old value - // However, it seems they forgot to actually update it on the network despite all the documentation changing - // So we'll send this for now if (components.lightDampening() != null) { - builder.putCompound("minecraft:block_light_filter", NbtMap.builder() - .putByte("value", components.lightDampening().byteValue()) + builder.putCompound("minecraft:light_dampening", NbtMap.builder() + .putByte("lightLevel", components.lightDampening().byteValue()) .build()); } if (components.rotation() != null) { From 4d78503b7c193df2d523aab31e4da545151b32ce Mon Sep 17 00:00:00 2001 From: davchoo <4722249+davchoo@users.noreply.github.com> Date: Mon, 16 Jan 2023 14:48:48 -0500 Subject: [PATCH 2/3] Remove redundant populate method and remove BLOCKS_JSON after last use --- .../geysermc/geyser/registry/BlockRegistries.java | 2 +- .../registry/populator/BlockRegistryPopulator.java | 12 +++--------- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/core/src/main/java/org/geysermc/geyser/registry/BlockRegistries.java b/core/src/main/java/org/geysermc/geyser/registry/BlockRegistries.java index 4beeff34f..67963ce26 100644 --- a/core/src/main/java/org/geysermc/geyser/registry/BlockRegistries.java +++ b/core/src/main/java/org/geysermc/geyser/registry/BlockRegistries.java @@ -118,7 +118,7 @@ public class BlockRegistries { static { CustomSkullRegistryPopulator.populate(); - BlockRegistryPopulator.populate(); + BlockRegistryPopulator.registerJavaBlocks(); COLLISIONS = IntMappedRegistry.create(Pair.of("org.geysermc.geyser.translator.collision.CollisionRemapper", "mappings/collision.json"), CollisionRegistryLoader::new); CustomBlockRegistryPopulator.registerCustomBedrockBlocks(); BlockRegistryPopulator.registerBedrockBlocks(); diff --git a/core/src/main/java/org/geysermc/geyser/registry/populator/BlockRegistryPopulator.java b/core/src/main/java/org/geysermc/geyser/registry/populator/BlockRegistryPopulator.java index da8511a7f..c7e751904 100644 --- a/core/src/main/java/org/geysermc/geyser/registry/populator/BlockRegistryPopulator.java +++ b/core/src/main/java/org/geysermc/geyser/registry/populator/BlockRegistryPopulator.java @@ -74,14 +74,6 @@ public final class BlockRegistryPopulator { */ private static JsonNode BLOCKS_JSON; - public static void populate() { - registerJavaBlocks(); - // CustomBlockRegistryPopulator.registerCustomBedrockBlocks() and registerBedrockBlocks() moved to BlockRegistries to ensure correct load order - - // Needs to be placed somewhere at some point - //BLOCKS_JSON = null; - } - public static void registerBedrockBlocks() { BiFunction emptyMapper = (bedrockIdentifier, statesBuilder) -> null; ImmutableMap, BiFunction> blockMappers = ImmutableMap., BiFunction>builder() @@ -262,9 +254,11 @@ public final class BlockRegistryPopulator { .customBlockStateIds(customBlockStateIds) .build()); } + + BLOCKS_JSON = null; } - private static void registerJavaBlocks() { + public static void registerJavaBlocks() { JsonNode blocksJson; try (InputStream stream = GeyserImpl.getInstance().getBootstrap().getResource("mappings/blocks.json")) { blocksJson = GeyserImpl.JSON_MAPPER.readTree(stream); From 0f0308b6ef17209c8f82f2e362f175424b2d87e1 Mon Sep 17 00:00:00 2001 From: davchoo <4722249+davchoo@users.noreply.github.com> Date: Mon, 16 Jan 2023 15:22:05 -0500 Subject: [PATCH 3/3] Fix inventories with block state overrides not opening --- .../holder/BlockInventoryHolder.java | 19 ++++---- .../chest/DoubleChestInventoryTranslator.java | 44 ++++++++++--------- 2 files changed, 34 insertions(+), 29 deletions(-) diff --git a/core/src/main/java/org/geysermc/geyser/inventory/holder/BlockInventoryHolder.java b/core/src/main/java/org/geysermc/geyser/inventory/holder/BlockInventoryHolder.java index 3e0892be4..4d5ad375d 100644 --- a/core/src/main/java/org/geysermc/geyser/inventory/holder/BlockInventoryHolder.java +++ b/core/src/main/java/org/geysermc/geyser/inventory/holder/BlockInventoryHolder.java @@ -76,15 +76,18 @@ public class BlockInventoryHolder extends InventoryHolder { // (This could be a virtual inventory that the player is opening) if (checkInteractionPosition(session)) { // Then, check to see if the interacted block is valid for this inventory by ensuring the block state identifier is valid + // and the bedrock block is vanilla int javaBlockId = session.getGeyser().getWorldManager().getBlockAt(session, session.getLastInteractionBlockPosition()); - String[] javaBlockString = BlockRegistries.JAVA_IDENTIFIERS.get().getOrDefault(javaBlockId, "minecraft:air").split("\\["); - if (isValidBlock(javaBlockString)) { - // We can safely use this block - inventory.setHolderPosition(session.getLastInteractionBlockPosition()); - ((Container) inventory).setUsingRealBlock(true, javaBlockString[0]); - setCustomName(session, session.getLastInteractionBlockPosition(), inventory, javaBlockId); + if (!BlockRegistries.CUSTOM_BLOCK_STATE_OVERRIDES.get().containsKey(javaBlockId)) { + String[] javaBlockString = BlockRegistries.JAVA_IDENTIFIERS.get().getOrDefault(javaBlockId, "minecraft:air").split("\\["); + if (isValidBlock(javaBlockString)) { + // We can safely use this block + inventory.setHolderPosition(session.getLastInteractionBlockPosition()); + ((Container) inventory).setUsingRealBlock(true, javaBlockString[0]); + setCustomName(session, session.getLastInteractionBlockPosition(), inventory, javaBlockId); - return true; + return true; + } } } @@ -96,7 +99,7 @@ public class BlockInventoryHolder extends InventoryHolder { UpdateBlockPacket blockPacket = new UpdateBlockPacket(); blockPacket.setDataLayer(0); blockPacket.setBlockPosition(position); - blockPacket.setRuntimeId(session.getBlockMappings().getBedrockBlockId(defaultJavaBlockState)); + blockPacket.setRuntimeId(session.getBlockMappings().getVanillaBedrockBlockId(defaultJavaBlockState)); blockPacket.getFlags().addAll(UpdateBlockPacket.FLAG_ALL_PRIORITY); session.sendUpstreamPacket(blockPacket); inventory.setHolderPosition(position); diff --git a/core/src/main/java/org/geysermc/geyser/translator/inventory/chest/DoubleChestInventoryTranslator.java b/core/src/main/java/org/geysermc/geyser/translator/inventory/chest/DoubleChestInventoryTranslator.java index fa20e6dbb..48fde47af 100644 --- a/core/src/main/java/org/geysermc/geyser/translator/inventory/chest/DoubleChestInventoryTranslator.java +++ b/core/src/main/java/org/geysermc/geyser/translator/inventory/chest/DoubleChestInventoryTranslator.java @@ -55,30 +55,32 @@ public class DoubleChestInventoryTranslator extends ChestInventoryTranslator { // See BlockInventoryHolder - same concept there except we're also dealing with a specific block state if (session.getLastInteractionPlayerPosition().equals(session.getPlayerEntity().getPosition())) { int javaBlockId = session.getGeyser().getWorldManager().getBlockAt(session, session.getLastInteractionBlockPosition()); - String[] javaBlockString = BlockRegistries.JAVA_IDENTIFIERS.get().getOrDefault(javaBlockId, "minecraft:air").split("\\["); - if (javaBlockString.length > 1 && (javaBlockString[0].equals("minecraft:chest") || javaBlockString[0].equals("minecraft:trapped_chest")) - && !javaBlockString[1].contains("type=single")) { - inventory.setHolderPosition(session.getLastInteractionBlockPosition()); - ((Container) inventory).setUsingRealBlock(true, javaBlockString[0]); + if (!BlockRegistries.CUSTOM_BLOCK_STATE_OVERRIDES.get().containsKey(javaBlockId)) { + String[] javaBlockString = BlockRegistries.JAVA_IDENTIFIERS.get().getOrDefault(javaBlockId, "minecraft:air").split("\\["); + if (javaBlockString.length > 1 && (javaBlockString[0].equals("minecraft:chest") || javaBlockString[0].equals("minecraft:trapped_chest")) + && !javaBlockString[1].contains("type=single")) { + inventory.setHolderPosition(session.getLastInteractionBlockPosition()); + ((Container) inventory).setUsingRealBlock(true, javaBlockString[0]); - NbtMapBuilder tag = NbtMap.builder() - .putString("id", "Chest") - .putInt("x", session.getLastInteractionBlockPosition().getX()) - .putInt("y", session.getLastInteractionBlockPosition().getY()) - .putInt("z", session.getLastInteractionBlockPosition().getZ()) - .putString("CustomName", inventory.getTitle()) - .putString("id", "Chest"); + NbtMapBuilder tag = NbtMap.builder() + .putString("id", "Chest") + .putInt("x", session.getLastInteractionBlockPosition().getX()) + .putInt("y", session.getLastInteractionBlockPosition().getY()) + .putInt("z", session.getLastInteractionBlockPosition().getZ()) + .putString("CustomName", inventory.getTitle()) + .putString("id", "Chest"); - DoubleChestValue chestValue = BlockStateValues.getDoubleChestValues().get(javaBlockId); - DoubleChestBlockEntityTranslator.translateChestValue(tag, chestValue, - session.getLastInteractionBlockPosition().getX(), session.getLastInteractionBlockPosition().getZ()); + DoubleChestValue chestValue = BlockStateValues.getDoubleChestValues().get(javaBlockId); + DoubleChestBlockEntityTranslator.translateChestValue(tag, chestValue, + session.getLastInteractionBlockPosition().getX(), session.getLastInteractionBlockPosition().getZ()); - BlockEntityDataPacket dataPacket = new BlockEntityDataPacket(); - dataPacket.setData(tag.build()); - dataPacket.setBlockPosition(session.getLastInteractionBlockPosition()); - session.sendUpstreamPacket(dataPacket); + BlockEntityDataPacket dataPacket = new BlockEntityDataPacket(); + dataPacket.setData(tag.build()); + dataPacket.setBlockPosition(session.getLastInteractionBlockPosition()); + session.sendUpstreamPacket(dataPacket); - return true; + return true; + } } } @@ -88,7 +90,7 @@ public class DoubleChestInventoryTranslator extends ChestInventoryTranslator { } Vector3i pairPosition = position.add(Vector3i.UNIT_X); - int bedrockBlockId = session.getBlockMappings().getBedrockBlockId(defaultJavaBlockState); + int bedrockBlockId = session.getBlockMappings().getVanillaBedrockBlockId(defaultJavaBlockState); UpdateBlockPacket blockPacket = new UpdateBlockPacket(); blockPacket.setDataLayer(0);