3
0
Mirror von https://github.com/GeyserMC/Geyser.git synchronisiert 2024-12-27 08:30:12 +01:00

Translate armour trims on items (#3837)

Dieser Commit ist enthalten in:
Konicai 2023-06-08 23:32:04 -04:00 committet von GitHub
Ursprung d6e095424c
Commit ab577f66ac
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23
2 geänderte Dateien mit 40 neuen und 1 gelöschten Zeilen

Datei anzeigen

@ -25,7 +25,12 @@
package org.geysermc.geyser.item.type; package org.geysermc.geyser.item.type;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import com.github.steveice10.opennbt.tag.builtin.StringTag;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.geysermc.geyser.item.ArmorMaterial; import org.geysermc.geyser.item.ArmorMaterial;
import org.geysermc.geyser.registry.type.ItemMapping;
import org.geysermc.geyser.session.GeyserSession;
public class ArmorItem extends Item { public class ArmorItem extends Item {
private final ArmorMaterial material; private final ArmorMaterial material;
@ -35,8 +40,42 @@ public class ArmorItem extends Item {
this.material = material; this.material = material;
} }
@Override
public void translateNbtToBedrock(@NonNull GeyserSession session, @NonNull CompoundTag tag) {
super.translateNbtToBedrock(session, tag);
if (tag.get("Trim") instanceof CompoundTag trim) {
StringTag material = trim.remove("material");
StringTag pattern = trim.remove("pattern");
// bedrock has an uppercase first letter key, and the value is not namespaced
trim.put(new StringTag("Material", stripNamespace(material.getValue())));
trim.put(new StringTag("Pattern", stripNamespace(pattern.getValue())));
}
}
@Override
public void translateNbtToJava(@NonNull CompoundTag tag, @NonNull ItemMapping mapping) {
super.translateNbtToJava(tag, mapping);
if (tag.get("Trim") instanceof CompoundTag trim) {
StringTag material = trim.remove("Material");
StringTag pattern = trim.remove("Pattern");
// java has a lowercase key, and namespaced value
trim.put(new StringTag("material", "minecraft:" + material.getValue()));
trim.put(new StringTag("pattern", "minecraft:" + pattern.getValue()));
}
}
@Override @Override
public boolean isValidRepairItem(Item other) { public boolean isValidRepairItem(Item other) {
return material.getRepairIngredient() == other; return material.getRepairIngredient() == other;
} }
private static String stripNamespace(String identifier) {
int i = identifier.indexOf(':');
if (i >= 0) {
return identifier.substring(i + 1);
}
return identifier;
}
} }

Datei anzeigen

@ -144,7 +144,7 @@ public class Item {
} }
/** /**
* Takes NBT from Java Edition and converts any value that Bedrock parses differently. <br> * Takes NBT from Bedrock Edition and converts any value that Java parses differently. <br>
* Do note that this method is, these days, only called in three places (as of 2023/~1.19): * Do note that this method is, these days, only called in three places (as of 2023/~1.19):
* <ul> * <ul>
* <li>Extra recipe loading</li> * <li>Extra recipe loading</li>