3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-10-03 08:41:05 +02:00

Use mapped identifier getter when converting items in 1.20.3->.5 components (#3869)

Dieser Commit ist enthalten in:
EnZaXD 2024-05-20 19:08:10 +02:00 committet von GitHub
Ursprung d5ccb17951
Commit 659bee771b
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: B5690EEEBB952194

Datei anzeigen

@ -234,9 +234,9 @@ public class ComponentRewriter1_20_5<C extends ClientboundPacketType> extends Co
}
if (structuredItem.identifier() != 0) {
final String itemName = Protocol1_20_3To1_20_5.MAPPINGS.getFullItemMappings().mappedIdentifier(structuredItem.identifier());
if (itemName != null) {
contentsTag.putString("id", itemName);
final String identifier = mappedIdentifier(structuredItem.identifier());
if (identifier != null) {
contentsTag.putString("id", identifier);
}
} else {
// Cannot be air
@ -334,6 +334,10 @@ public class ComponentRewriter1_20_5<C extends ClientboundPacketType> extends Co
return StructuredData.of(key, converter.convert(tag), id);
}
private String mappedIdentifier(final int id) {
return Protocol1_20_3To1_20_5.MAPPINGS.getFullItemMappings().mappedIdentifier(id);
}
// ---------------------------------------------------------------------------------------
// Conversion methods, can be overridden in future protocols to handle new changes
@ -849,11 +853,11 @@ public class ComponentRewriter1_20_5<C extends ClientboundPacketType> extends Co
protected ListTag<StringTag> convertPotDecorations(final PotDecorations value) {
final ListTag<StringTag> tag = new ListTag<>(StringTag.class);
for (final int decoration : value.itemIds()) {
final String item = Protocol1_20_3To1_20_5.MAPPINGS.getFullItemMappings().identifier(decoration);
if (item == null) {
final String identifier = mappedIdentifier(decoration);
if (identifier == null) {
throw new IllegalArgumentException("Unknown item: " + decoration);
}
tag.add(new StringTag(item));
tag.add(new StringTag(identifier));
}
return tag;
}
@ -957,11 +961,11 @@ public class ComponentRewriter1_20_5<C extends ClientboundPacketType> extends Co
}
protected void convertItem(final CompoundTag tag, final Item item) {
final String name = Protocol1_20_3To1_20_5.MAPPINGS.getFullItemMappings().identifier(item.identifier());
if (name == null) {
final String identifier = mappedIdentifier(item.identifier());
if (identifier == null) {
throw new IllegalArgumentException("Unknown item: " + item.identifier());
}
tag.putString("id", name);
tag.putString("id", identifier);
try {
tag.put("count", convertPositiveInt(item.amount()));
} catch (IllegalArgumentException ignored) { // Fallback value