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

This commit is contained in:
EnZaXD 2024-05-20 19:08:10 +02:00 committed by GitHub
parent d5ccb17951
commit 659bee771b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -234,9 +234,9 @@ public class ComponentRewriter1_20_5<C extends ClientboundPacketType> extends Co
} }
if (structuredItem.identifier() != 0) { if (structuredItem.identifier() != 0) {
final String itemName = Protocol1_20_3To1_20_5.MAPPINGS.getFullItemMappings().mappedIdentifier(structuredItem.identifier()); final String identifier = mappedIdentifier(structuredItem.identifier());
if (itemName != null) { if (identifier != null) {
contentsTag.putString("id", itemName); contentsTag.putString("id", identifier);
} }
} else { } else {
// Cannot be air // 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); 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 // 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) { protected ListTag<StringTag> convertPotDecorations(final PotDecorations value) {
final ListTag<StringTag> tag = new ListTag<>(StringTag.class); final ListTag<StringTag> tag = new ListTag<>(StringTag.class);
for (final int decoration : value.itemIds()) { for (final int decoration : value.itemIds()) {
final String item = Protocol1_20_3To1_20_5.MAPPINGS.getFullItemMappings().identifier(decoration); final String identifier = mappedIdentifier(decoration);
if (item == null) { if (identifier == null) {
throw new IllegalArgumentException("Unknown item: " + decoration); throw new IllegalArgumentException("Unknown item: " + decoration);
} }
tag.add(new StringTag(item)); tag.add(new StringTag(identifier));
} }
return tag; 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) { protected void convertItem(final CompoundTag tag, final Item item) {
final String name = Protocol1_20_3To1_20_5.MAPPINGS.getFullItemMappings().identifier(item.identifier()); final String identifier = mappedIdentifier(item.identifier());
if (name == null) { if (identifier == null) {
throw new IllegalArgumentException("Unknown item: " + item.identifier()); throw new IllegalArgumentException("Unknown item: " + item.identifier());
} }
tag.putString("id", name); tag.putString("id", identifier);
try { try {
tag.put("count", convertPositiveInt(item.amount())); tag.put("count", convertPositiveInt(item.amount()));
} catch (IllegalArgumentException ignored) { // Fallback value } catch (IllegalArgumentException ignored) { // Fallback value