3
0
Mirror von https://github.com/GeyserMC/Geyser.git synchronisiert 2024-11-19 14:30:17 +01:00

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

* Fix discarding of custom trim patterns/materials

* Rename `stripNamespace` method to reflect its behaviour
Dieser Commit ist enthalten in:
Eclipse 2024-05-07 07:16:21 +01:00 committet von GitHub
Ursprung 0a261f1d9d
Commit cda7a19a08
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: B5690EEEBB952194
2 geänderte Dateien mit 23 neuen und 9 gelöschten Zeilen

Datei anzeigen

@ -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;
} }

Datei anzeigen

@ -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";
}
} }