3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-11-19 14:30:16 +01:00

Fix display tag setting and doubled item id rewriting

Dieser Commit ist enthalten in:
Nassim Jahnke 2024-03-19 12:05:37 +01:00
Ursprung 3fef71db2e
Commit 60b782455d
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: EF6771C01F6EF02F
3 geänderte Dateien mit 46 neuen und 18 gelöschten Zeilen

Datei anzeigen

@ -98,4 +98,13 @@ public class StructuredItem implements Item {
result = 31 * result + amount; result = 31 * result + amount;
return result; return result;
} }
@Override
public String toString() {
return "StructuredItem{" +
"data=" + data +
", identifier=" + identifier +
", amount=" + amount +
'}';
}
} }

Datei anzeigen

@ -442,8 +442,12 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter<Clientboun
return item; return item;
} }
private int toItemId(final String name) { private int unmappedItemId(final String name) {
final int unmappedId = protocol.getMappingData().itemId(name); return protocol.getMappingData().itemId(name);
}
private int toMappedItemId(final String name) {
final int unmappedId = unmappedItemId(name);
return unmappedId != -1 ? protocol.getMappingData().getNewItemId(unmappedId) : -1; return unmappedId != -1 ? protocol.getMappingData().getNewItemId(unmappedId) : -1;
} }
@ -616,10 +620,12 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter<Clientboun
if (assetNameTag == null || ingredientTag == null) { if (assetNameTag == null || ingredientTag == null) {
return; return;
} }
final int ingredientId = toItemId(ingredientTag.getValue());
final int ingredientId = toMappedItemId(ingredientTag.getValue());
if (ingredientId == -1) { if (ingredientId == -1) {
return; return;
} }
final NumberTag itemModelIndexTag = materialCompoundTag.getNumberTag("item_model_index"); final NumberTag itemModelIndexTag = materialCompoundTag.getNumberTag("item_model_index");
final CompoundTag overrideArmorMaterialsTag = materialCompoundTag.get("override_armor_materials"); final CompoundTag overrideArmorMaterialsTag = materialCompoundTag.get("override_armor_materials");
final Tag descriptionTag = materialCompoundTag.get("description"); final Tag descriptionTag = materialCompoundTag.get("description");
@ -663,10 +669,12 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter<Clientboun
if (assetId == null || templateItem == null) { if (assetId == null || templateItem == null) {
return; return;
} }
final int templateItemId = toItemId(templateItem);
final int templateItemId = toMappedItemId(templateItem);
if (templateItemId == -1) { if (templateItemId == -1) {
return; return;
} }
final Tag descriptionTag = patternCompoundTag.get("description"); final Tag descriptionTag = patternCompoundTag.get("description");
final boolean decal = patternCompoundTag.getBoolean("decal"); final boolean decal = patternCompoundTag.getBoolean("decal");
patternHolder = Holder.of(new ArmorTrimPattern( patternHolder = Holder.of(new ArmorTrimPattern(
@ -817,14 +825,12 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter<Clientboun
} }
private void updateItemList(final StructuredDataContainer data, final CompoundTag tag, final String key, final StructuredDataKey<Item[]> dataKey) { private void updateItemList(final StructuredDataContainer data, final CompoundTag tag, final String key, final StructuredDataKey<Item[]> dataKey) {
final ListTag<CompoundTag> chargedProjectiles = tag.getListTag(key, CompoundTag.class); final ListTag<CompoundTag> itemsTag = tag.getListTag(key, CompoundTag.class);
if (chargedProjectiles == null) { if (itemsTag != null) {
return; final Item[] items = itemsTag.stream().map(this::itemFromTag).filter(Objects::nonNull).toArray(Item[]::new);
}
final Item[] items = chargedProjectiles.stream().map(this::itemFromTag).filter(Objects::nonNull).toArray(Item[]::new);
data.set(dataKey, items); data.set(dataKey, items);
} }
}
private @Nullable Item itemFromTag(final CompoundTag item) { private @Nullable Item itemFromTag(final CompoundTag item) {
final String id = item.getString("id"); final String id = item.getString("id");
@ -832,7 +838,7 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter<Clientboun
return null; return null;
} }
final int itemId = toItemId(id); final int itemId = unmappedItemId(id);
if (itemId == -1) { if (itemId == -1) {
return null; return null;
} }
@ -1000,7 +1006,12 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter<Clientboun
final String rightSherd = sherdsTag.get(2).getValue(); final String rightSherd = sherdsTag.get(2).getValue();
final String frontSherd = sherdsTag.get(3).getValue(); final String frontSherd = sherdsTag.get(3).getValue();
data.set(StructuredDataKey.POT_DECORATIONS, new PotDecorations(toItemId(backSherd), toItemId(leftSherd), toItemId(rightSherd), toItemId(frontSherd))); data.set(StructuredDataKey.POT_DECORATIONS, new PotDecorations(
toMappedItemId(backSherd),
toMappedItemId(leftSherd),
toMappedItemId(rightSherd),
toMappedItemId(frontSherd)
));
} }
final StringTag noteBlockSoundTag = tag.getStringTag("note_block_sound"); final StringTag noteBlockSoundTag = tag.getStringTag("note_block_sound");

Datei anzeigen

@ -84,13 +84,13 @@ final class StructuredDataConverter {
putHideFlag(tag, HIDE_UNBREAKABLE); putHideFlag(tag, HIDE_UNBREAKABLE);
} }
}); });
register(StructuredDataKey.CUSTOM_NAME, (data, tag) -> tag.putString("CustomName", ComponentUtil.tagToJsonString(data))); register(StructuredDataKey.CUSTOM_NAME, (data, tag) -> getDisplayTag(tag).putString("Name", ComponentUtil.tagToJsonString(data)));
register(StructuredDataKey.LORE, (data, tag) -> { register(StructuredDataKey.LORE, (data, tag) -> {
final ListTag<StringTag> lore = new ListTag<>(StringTag.class); final ListTag<StringTag> lore = new ListTag<>(StringTag.class);
for (final Tag loreEntry : data) { for (final Tag loreEntry : data) {
lore.add(new StringTag(ComponentUtil.tagToJsonString(loreEntry))); lore.add(new StringTag(ComponentUtil.tagToJsonString(loreEntry)));
} }
tag.put("Lore", lore); getDisplayTag(tag).put("Lore", lore);
}); });
register(StructuredDataKey.ENCHANTMENTS, (data, tag) -> convertEnchantments(data, tag, false)); register(StructuredDataKey.ENCHANTMENTS, (data, tag) -> convertEnchantments(data, tag, false));
register(StructuredDataKey.STORED_ENCHANTMENTS, (data, tag) -> convertEnchantments(data, tag, true)); register(StructuredDataKey.STORED_ENCHANTMENTS, (data, tag) -> convertEnchantments(data, tag, true));
@ -120,12 +120,12 @@ final class StructuredDataConverter {
register(StructuredDataKey.HIDE_ADDITIONAL_TOOLTIP, (data, tag) -> putHideFlag(tag, 0x20)); register(StructuredDataKey.HIDE_ADDITIONAL_TOOLTIP, (data, tag) -> putHideFlag(tag, 0x20));
register(StructuredDataKey.REPAIR_COST, (data, tag) -> tag.putInt("RepairCost", data)); register(StructuredDataKey.REPAIR_COST, (data, tag) -> tag.putInt("RepairCost", data));
register(StructuredDataKey.DYED_COLOR, (data, tag) -> { register(StructuredDataKey.DYED_COLOR, (data, tag) -> {
tag.putInt("color", data.rgb()); getDisplayTag(tag).putInt("color", data.rgb());
if (!data.showInTooltip()) { if (!data.showInTooltip()) {
putHideFlag(tag, HIDE_DYE_COLOR); putHideFlag(tag, HIDE_DYE_COLOR);
} }
}); });
register(StructuredDataKey.MAP_COLOR, (data, tag) -> tag.putInt("MapColor", data)); register(StructuredDataKey.MAP_COLOR, (data, tag) -> getDisplayTag(tag).putInt("MapColor", data));
register(StructuredDataKey.MAP_ID, (data, tag) -> tag.putInt("map", data)); register(StructuredDataKey.MAP_ID, (data, tag) -> tag.putInt("map", data));
register(StructuredDataKey.MAP_DECORATIONS, (data, tag) -> { register(StructuredDataKey.MAP_DECORATIONS, (data, tag) -> {
final ListTag<CompoundTag> decorations = new ListTag<>(CompoundTag.class); final ListTag<CompoundTag> decorations = new ListTag<>(CompoundTag.class);
@ -447,10 +447,18 @@ final class StructuredDataConverter {
// If multiple item components which previously were stored in BlockEntityTag are present, we need to merge them // If multiple item components which previously were stored in BlockEntityTag are present, we need to merge them
private static CompoundTag getBlockEntityTag(final CompoundTag tag) { private static CompoundTag getBlockEntityTag(final CompoundTag tag) {
CompoundTag subTag = tag.getCompoundTag("BlockEntityTag"); return getOrCreate(tag, "BlockEntityTag");
}
private static CompoundTag getDisplayTag(final CompoundTag tag) {
return getOrCreate(tag, "display");
}
private static CompoundTag getOrCreate(final CompoundTag tag, final String key) {
CompoundTag subTag = tag.getCompoundTag(key);
if (subTag == null) { if (subTag == null) {
subTag = new CompoundTag(); subTag = new CompoundTag();
tag.put("BlockEntityTag", subTag); tag.put(key, subTag);
} }
return subTag; return subTag;
} }