Skip to content

Commit

Permalink
Fix discarding of custom trim patterns/materials (GeyserMC#4642)
Browse files Browse the repository at this point in the history
* Fix discarding of custom trim patterns/materials

* Rename `stripNamespace` method to reflect its behaviour
eclipseisoffline authored May 7, 2024
1 parent 0a261f1 commit cda7a19
Showing 2 changed files with 22 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -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 static TrimMaterial readTrimMaterial(GeyserSession session, RegistryEntry
}

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 static TrimPattern readTrimPattern(GeyserSession session, RegistryEntry e
}

// 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;
}
18 changes: 14 additions & 4 deletions core/src/main/java/org/geysermc/geyser/item/type/ArmorItem.java
Original file line number Diff line number Diff line change
@@ -51,14 +51,15 @@ public void translateComponentsToBedrock(@NonNull GeyserSession session, @NonNul

ArmorTrim trim = components.get(DataComponentType.TRIM);
if (trim != null) {
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 (trim.material().isCustom() || trim.pattern().isCustom()) {
if (!getNamespace(material.getMaterialId()).equals("minecraft")
|| !getNamespace(pattern.getPatternId()).equals("minecraft")) {
return;
}

TrimMaterial material = session.getRegistryCache().trimMaterials().byId(trim.material().id());
TrimPattern pattern = session.getRegistryCache().trimPatterns().byId(trim.pattern().id());

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 void translateComponentsToBedrock(@NonNull GeyserSession session, @NonNul
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";
}
}

0 comments on commit cda7a19

Please sign in to comment.