3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-11-19 14:30:16 +01:00
Dieser Commit ist enthalten in:
FlorianMichael 2024-03-15 16:23:20 +01:00 committet von Nassim Jahnke
Ursprung c2567115d8
Commit 5899886b42
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: EF6771C01F6EF02F
2 geänderte Dateien mit 42 neuen und 35 gelöschten Zeilen

Datei anzeigen

@ -279,6 +279,10 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter<Clientboun
// Goat horn // Goat horn
// (check more) // (check more)
if (tag == null) { if (tag == null) {
if (old.identifier() == 1191) {
// I'm unsure if this is intended or an issue, see https://bugs.mojang.com/browse/MC-269503
data.set(StructuredDataKey.INSTRUMENT, Holder.of(Instruments1_20_3.keyToId("minecraft:ponder_goat_horn")));
}
return item; return item;
} }
@ -438,6 +442,11 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter<Clientboun
return item; return item;
} }
private int toItemId(final String name) {
final int unmappedId = protocol.getMappingData().itemId(name);
return unmappedId != -1 ? protocol.getMappingData().getNewItemId(unmappedId) : -1;
}
private AdventureModePredicate updateBlockPredicates(final ListTag<StringTag> tag, final boolean showInTooltip) { private AdventureModePredicate updateBlockPredicates(final ListTag<StringTag> tag, final boolean showInTooltip) {
final BlockPredicate[] predicates = tag.stream() final BlockPredicate[] predicates = tag.stream()
.map(StringTag::getValue) .map(StringTag::getValue)
@ -817,11 +826,6 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter<Clientboun
data.set(dataKey, items); data.set(dataKey, items);
} }
private int toItemId(final String name) {
final int unmappedId = protocol.getMappingData().itemId(name);
return unmappedId != -1 ? protocol.getMappingData().getNewItemId(unmappedId) : -1;
}
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");
if (id == null) { if (id == null) {

Datei anzeigen

@ -255,8 +255,7 @@ final class StructuredDataConverter {
register(StructuredDataKey.POT_DECORATIONS, (data, tag) -> { register(StructuredDataKey.POT_DECORATIONS, (data, tag) -> {
final ListTag<StringTag> sherds = new ListTag<>(StringTag.class); final ListTag<StringTag> sherds = new ListTag<>(StringTag.class);
for (final int id : data.itemIds()) { for (final int id : data.itemIds()) {
final int oldId = Protocol1_20_5To1_20_3.MAPPINGS.getOldItemId(id); sherds.add(new StringTag(toItemName(id)));
sherds.add(new StringTag(Protocol1_20_5To1_20_3.MAPPINGS.itemName(oldId)));
} }
getBlockEntityTag(tag).put("sherds", sherds); getBlockEntityTag(tag).put("sherds", sherds);
}); });
@ -280,7 +279,18 @@ final class StructuredDataConverter {
tag.put("LootTableSeed", data.get("loot_table_seed")); tag.put("LootTableSeed", data.get("loot_table_seed"));
}); });
register(StructuredDataKey.ENCHANTMENT_GLINT_OVERRIDE, (data, tag) -> { register(StructuredDataKey.ENCHANTMENT_GLINT_OVERRIDE, (data, tag) -> {
final ListTag<CompoundTag> enchantmentsTag = getOrCreateListTag(tag, "Enchantments"); if (!data) {
// There is no way to remove the glint without removing the enchantments
// which would lead to broken data, so we just don't do anything
return;
}
// If the glint is overridden, we just add an invalid enchantment to the existing list
ListTag<CompoundTag> enchantmentsTag = tag.getListTag("Enchantments", CompoundTag.class);
if (enchantmentsTag == null) {
enchantmentsTag = new ListTag<>(CompoundTag.class);
tag.put("Enchantments", enchantmentsTag);
}
final CompoundTag invalidEnchantment = new CompoundTag(); final CompoundTag invalidEnchantment = new CompoundTag();
invalidEnchantment.putString("id", ""); invalidEnchantment.putString("id", "");
// Skipping the level tag, causing the enchantment to be invalid // Skipping the level tag, causing the enchantment to be invalid
@ -317,7 +327,7 @@ final class StructuredDataConverter {
tag.put("custom_potion_effects", customPotionEffectsTag); tag.put("custom_potion_effects", customPotionEffectsTag);
}); });
register(StructuredDataKey.SUSPICIOUS_STEW_EFFECTS, (data, tag) -> { register(StructuredDataKey.SUSPICIOUS_STEW_EFFECTS, (data, tag) -> {
final ListTag<CompoundTag> effectsTag = getOrCreateListTag(tag, "effects"); final ListTag<CompoundTag> effectsTag = new ListTag<>(CompoundTag.class);
for (final SuspiciousStewEffect effect : data) { for (final SuspiciousStewEffect effect : data) {
final CompoundTag effectTag = new CompoundTag(); final CompoundTag effectTag = new CompoundTag();
final String id = PotionEffects.idToKey(effect.mobEffect() + 1); final String id = PotionEffects.idToKey(effect.mobEffect() + 1);
@ -328,9 +338,10 @@ final class StructuredDataConverter {
effectsTag.add(effectTag); effectsTag.add(effectTag);
} }
tag.put("effects", effectsTag);
}); });
register(StructuredDataKey.BANNER_PATTERNS, (data, tag) -> { register(StructuredDataKey.BANNER_PATTERNS, (data, tag) -> {
final ListTag<CompoundTag> patternsTag = getOrCreateListTag(tag, "Patterns"); final ListTag<CompoundTag> patternsTag = new ListTag<>(CompoundTag.class);
for (final BannerPatternLayer layer : data) { for (final BannerPatternLayer layer : data) {
final String pattern = BannerPatterns1_20_5.fullIdToCompact(BannerPatterns1_20_5.idToKey(layer.pattern().id())); final String pattern = BannerPatterns1_20_5.fullIdToCompact(BannerPatterns1_20_5.idToKey(layer.pattern().id()));
if (pattern == null) { if (pattern == null) {
@ -341,6 +352,7 @@ final class StructuredDataConverter {
patternTag.putInt("Color", layer.dyeColor()); patternTag.putInt("Color", layer.dyeColor());
patternsTag.add(patternTag); patternsTag.add(patternTag);
} }
tag.put("Patterns", patternsTag);
}); });
register(StructuredDataKey.CONTAINER, (data, tag) -> convertItemList(data, tag, "Items")); register(StructuredDataKey.CONTAINER, (data, tag) -> convertItemList(data, tag, "Items"));
register(StructuredDataKey.CAN_PLACE_ON, (data, tag) -> convertBlockPredicates(tag, data, "CanPlaceOn", HIDE_CAN_PLACE_ON)); register(StructuredDataKey.CAN_PLACE_ON, (data, tag) -> convertBlockPredicates(tag, data, "CanPlaceOn", HIDE_CAN_PLACE_ON));
@ -356,9 +368,9 @@ final class StructuredDataConverter {
} }
}); });
register(StructuredDataKey.TRIM, (data, tag) -> { register(StructuredDataKey.TRIM, (data, tag) -> {
final CompoundTag trimTag = getOrCreateTag(tag, "Trim"); final CompoundTag trimTag = new CompoundTag();
if (data.material().isDirect()) { if (data.material().isDirect()) {
final CompoundTag materialTag = getOrCreateTag(trimTag, "material"); final CompoundTag materialTag = new CompoundTag();
final ArmorTrimMaterial material = data.material().value(); final ArmorTrimMaterial material = data.material().value();
materialTag.putString("asset_name", material.assetName()); materialTag.putString("asset_name", material.assetName());
@ -376,6 +388,7 @@ final class StructuredDataConverter {
} }
materialTag.put("override_armor_materials", overrideArmorMaterials); materialTag.put("override_armor_materials", overrideArmorMaterials);
} }
trimTag.put("material", materialTag);
} else { } else {
final String oldKey = TrimMaterials1_20_3.idToKey(data.material().id()); final String oldKey = TrimMaterials1_20_3.idToKey(data.material().id());
if (oldKey != null) { if (oldKey != null) {
@ -383,7 +396,7 @@ final class StructuredDataConverter {
} }
} }
if (data.pattern().isDirect()) { if (data.pattern().isDirect()) {
final CompoundTag patternTag = getOrCreateTag(trimTag, "pattern"); final CompoundTag patternTag = new CompoundTag();
final ArmorTrimPattern pattern = data.pattern().value(); final ArmorTrimPattern pattern = data.pattern().value();
patternTag.putString("assetId", pattern.assetName()); patternTag.putString("assetId", pattern.assetName());
@ -394,12 +407,14 @@ final class StructuredDataConverter {
patternTag.putString("templateItem", itemName); patternTag.putString("templateItem", itemName);
patternTag.put("description", pattern.description()); patternTag.put("description", pattern.description());
patternTag.putBoolean("decal", pattern.decal()); patternTag.putBoolean("decal", pattern.decal());
trimTag.put("pattern", patternTag);
} else { } else {
final String oldKey = TrimMaterials1_20_3.idToKey(data.pattern().id()); final String oldKey = TrimMaterials1_20_3.idToKey(data.pattern().id());
if (oldKey != null) { if (oldKey != null) {
trimTag.putString("pattern", oldKey); trimTag.putString("pattern", oldKey);
} }
} }
tag.put("Trim", trimTag);
if (!data.showInTooltip()) { if (!data.showInTooltip()) {
putHideFlag(tag, HIDE_ARMOR_TRIM); putHideFlag(tag, HIDE_ARMOR_TRIM);
} }
@ -421,6 +436,16 @@ final class StructuredDataConverter {
return mappedId != -1 ? Protocol1_20_5To1_20_3.MAPPINGS.itemName(mappedId) : ""; return mappedId != -1 ? Protocol1_20_5To1_20_3.MAPPINGS.itemName(mappedId) : "";
} }
// If multiple item components which previously were stored in BlockEntityTag are present, we need to merge them
private static CompoundTag getBlockEntityTag(final CompoundTag tag) {
CompoundTag subTag = tag.getCompoundTag("BlockEntityTag");
if (subTag == null) {
subTag = new CompoundTag();
tag.put("BlockEntityTag", subTag);
}
return subTag;
}
private static void convertBlockPredicates(final CompoundTag tag, final AdventureModePredicate data, final String key, final int hideFlag) { private static void convertBlockPredicates(final CompoundTag tag, final AdventureModePredicate data, final String key, final int hideFlag) {
final ListTag<StringTag> predicatedListTag = new ListTag<>(StringTag.class); final ListTag<StringTag> predicatedListTag = new ListTag<>(StringTag.class);
for (final BlockPredicate predicate : data.predicates()) { for (final BlockPredicate predicate : data.predicates()) {
@ -462,28 +487,6 @@ final class StructuredDataConverter {
return new StringTag(builder.toString()); return new StringTag(builder.toString());
} }
private static CompoundTag getBlockEntityTag(final CompoundTag tag) {
return getOrCreateTag(tag, "BlockEntityTag");
}
private static CompoundTag getOrCreateTag(final CompoundTag tag, final String name) {
CompoundTag subTag = tag.getCompoundTag(name);
if (subTag == null) {
subTag = new CompoundTag();
tag.put(name, subTag);
}
return subTag;
}
private static ListTag<CompoundTag> getOrCreateListTag(final CompoundTag tag, final String name) {
ListTag<CompoundTag> subTag = tag.getListTag(name, CompoundTag.class);
if (subTag == null) {
subTag = new ListTag<>(CompoundTag.class);
tag.put(name, subTag);
}
return subTag;
}
private static CompoundTag convertExplosion(final FireworkExplosion explosion) { private static CompoundTag convertExplosion(final FireworkExplosion explosion) {
final CompoundTag explosionTag = new CompoundTag(); final CompoundTag explosionTag = new CompoundTag();
explosionTag.putInt("Type", explosion.shape()); explosionTag.putInt("Type", explosion.shape());