From cda7a19a08f5b9d62ce492f6fdd87af3bc461e8b Mon Sep 17 00:00:00 2001 From: Eclipse <116838833+eclipseisoffline@users.noreply.github.com> Date: Tue, 7 May 2024 07:16:21 +0100 Subject: [PATCH] Fix discarding of custom trim patterns/materials (#4642) * Fix discarding of custom trim patterns/materials * Rename `stripNamespace` method to reflect its behaviour --- .../geyser/inventory/recipe/TrimRecipe.java | 12 +++++++---- .../geysermc/geyser/item/type/ArmorItem.java | 20 ++++++++++++++----- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/core/src/main/java/org/geysermc/geyser/inventory/recipe/TrimRecipe.java b/core/src/main/java/org/geysermc/geyser/inventory/recipe/TrimRecipe.java index 37eb905a4..9d9dbe0db 100644 --- a/core/src/main/java/org/geysermc/geyser/inventory/recipe/TrimRecipe.java +++ b/core/src/main/java/org/geysermc/geyser/inventory/recipe/TrimRecipe.java @@ -47,7 +47,7 @@ public final class TrimRecipe { public static final ItemDescriptorWithCount TEMPLATE = tagDescriptor("minecraft:trim_templates"); public static TrimMaterial readTrimMaterial(GeyserSession session, RegistryEntry entry) { - String key = stripNamespace(entry.getId()); + String key = stripMinecraftNamespace(entry.getId()); // Color is used when hovering over the item // Find the nearest legacy color from the RGB Java gives us to work with @@ -67,7 +67,7 @@ public final class TrimRecipe { } public static TrimPattern readTrimPattern(GeyserSession session, RegistryEntry entry) { - String key = stripNamespace(entry.getId()); + String key = stripMinecraftNamespace(entry.getId()); String itemIdentifier = entry.getData().getString("template_item"); ItemMapping itemMapping = session.getItemMappings().getMapping(itemIdentifier); @@ -79,10 +79,14 @@ public final class TrimRecipe { } // TODO find a good place for a stripNamespace util method - private static String stripNamespace(String identifier) { + private static String stripMinecraftNamespace(String identifier) { int i = identifier.indexOf(':'); if (i >= 0) { - return identifier.substring(i + 1); + String namespace = identifier.substring(0, i); + // Only strip minecraft namespace + if (namespace.equals("minecraft")) { + return identifier.substring(i + 1); + } } return identifier; } diff --git a/core/src/main/java/org/geysermc/geyser/item/type/ArmorItem.java b/core/src/main/java/org/geysermc/geyser/item/type/ArmorItem.java index fc0dd3ba4..0a25a8d4f 100644 --- a/core/src/main/java/org/geysermc/geyser/item/type/ArmorItem.java +++ b/core/src/main/java/org/geysermc/geyser/item/type/ArmorItem.java @@ -51,14 +51,15 @@ public class ArmorItem extends Item { ArmorTrim trim = components.get(DataComponentType.TRIM); if (trim != null) { - // discard custom trim patterns/materials to prevent visual glitches on bedrock - if (trim.material().isCustom() || trim.pattern().isCustom()) { - return; - } - TrimMaterial material = session.getRegistryCache().trimMaterials().byId(trim.material().id()); TrimPattern pattern = session.getRegistryCache().trimPatterns().byId(trim.pattern().id()); + // discard custom trim patterns/materials to prevent visual glitches on bedrock + if (!getNamespace(material.getMaterialId()).equals("minecraft") + || !getNamespace(pattern.getPatternId()).equals("minecraft")) { + return; + } + NbtMapBuilder trimBuilder = NbtMap.builder(); // bedrock has an uppercase first letter key, and the value is not namespaced trimBuilder.put("Material", material.getMaterialId()); @@ -71,4 +72,13 @@ public class ArmorItem extends Item { public boolean isValidRepairItem(Item other) { return material.getRepairIngredient() == other; } + + // TODO maybe some kind of namespace util? + private static String getNamespace(String identifier) { + int i = identifier.indexOf(':'); + if (i >= 0) { + return identifier.substring(0, i); + } + return "minecraft"; + } }