mirror of
https://github.com/ViaVersion/ViaVersion.git
synced 2024-11-22 10:05:12 +01:00
Use mapped identifier getter when converting items in 1.20.3->.5 components (#3869)
This commit is contained in:
parent
d5ccb17951
commit
659bee771b
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user