Fix discarding of custom trim patterns/materials (#4642)

* Fix discarding of custom trim patterns/materials

* Rename `stripNamespace` method to reflect its behaviour
This commit is contained in:
Eclipse 2024-05-07 07:16:21 +01:00 committed by GitHub
parent 0a261f1d9d
commit cda7a19a08
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 23 additions and 9 deletions

View file

@ -47,7 +47,7 @@ public final class TrimRecipe {
public static final ItemDescriptorWithCount TEMPLATE = tagDescriptor("minecraft:trim_templates"); public static final ItemDescriptorWithCount TEMPLATE = tagDescriptor("minecraft:trim_templates");
public static TrimMaterial readTrimMaterial(GeyserSession session, RegistryEntry entry) { 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 // Color is used when hovering over the item
// Find the nearest legacy color from the RGB Java gives us to work with // 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) { 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"); String itemIdentifier = entry.getData().getString("template_item");
ItemMapping itemMapping = session.getItemMappings().getMapping(itemIdentifier); ItemMapping itemMapping = session.getItemMappings().getMapping(itemIdentifier);
@ -79,10 +79,14 @@ public final class TrimRecipe {
} }
// TODO find a good place for a stripNamespace util method // 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(':'); int i = identifier.indexOf(':');
if (i >= 0) { 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; return identifier;
} }

View file

@ -51,14 +51,15 @@ public class ArmorItem extends Item {
ArmorTrim trim = components.get(DataComponentType.TRIM); ArmorTrim trim = components.get(DataComponentType.TRIM);
if (trim != null) { 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()); TrimMaterial material = session.getRegistryCache().trimMaterials().byId(trim.material().id());
TrimPattern pattern = session.getRegistryCache().trimPatterns().byId(trim.pattern().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(); NbtMapBuilder trimBuilder = NbtMap.builder();
// bedrock has an uppercase first letter key, and the value is not namespaced // bedrock has an uppercase first letter key, and the value is not namespaced
trimBuilder.put("Material", material.getMaterialId()); trimBuilder.put("Material", material.getMaterialId());
@ -71,4 +72,13 @@ public class ArmorItem extends Item {
public boolean isValidRepairItem(Item other) { public boolean isValidRepairItem(Item other) {
return material.getRepairIngredient() == 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";
}
} }