From b1f04a9012e9c64c9931a86f7045aa4cebb769c4 Mon Sep 17 00:00:00 2001 From: chris Date: Mon, 7 Aug 2023 02:22:05 +0200 Subject: [PATCH] Allow custom unusable-space blocker item (#4038) * Allow the "unusable-space-block" to be a custom item (specified by bedrock identifier) * add space for log error * don't use ugly atomic reference --- .../geysermc/geyser/util/InventoryUtils.java | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/core/src/main/java/org/geysermc/geyser/util/InventoryUtils.java b/core/src/main/java/org/geysermc/geyser/util/InventoryUtils.java index 55af9eb11..728f03def 100644 --- a/core/src/main/java/org/geysermc/geyser/util/InventoryUtils.java +++ b/core/src/main/java/org/geysermc/geyser/util/InventoryUtils.java @@ -208,12 +208,21 @@ public class InventoryUtils { private static ItemDefinition getUnusableSpaceBlockDefinition(int protocolVersion) { String unusableSpaceBlock = GeyserImpl.getInstance().getConfig().getUnusableSpaceBlock(); - ItemMapping unusableSpaceBlockID = Registries.ITEMS.forVersion(protocolVersion).getMapping(unusableSpaceBlock); - if (unusableSpaceBlockID != null) { - return unusableSpaceBlockID.getBedrockDefinition(); - } else { - GeyserImpl.getInstance().getLogger().error("Invalid value" + unusableSpaceBlock + ". Resorting to barrier block."); + ItemDefinition itemDefinition = null; + + // looping through all the items to find the one with the specified Bedrock identifier + for (ItemDefinition definition : Registries.ITEMS.forVersion(protocolVersion).getItemDefinitions().values()) { + if (definition.getIdentifier().equals(unusableSpaceBlock)) { + itemDefinition = definition; + break; + } + } + + if (itemDefinition == null) { + GeyserImpl.getInstance().getLogger().error("Invalid value " + unusableSpaceBlock + ". Resorting to barrier block."); return Registries.ITEMS.forVersion(protocolVersion).getStoredItems().barrier().getBedrockDefinition(); + } else { + return itemDefinition; } }