From c2567115d82d837b391629f0f21f7695aca84ab5 Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Fri, 15 Mar 2024 19:01:26 +0100 Subject: [PATCH] Fix various issues --- .../data/StructuredDataContainer.java | 7 +++ .../api/minecraft/data/StructuredDataKey.java | 8 ++++ .../api/minecraft/item/data/Filterable.java | 4 +- .../item/data/FilterableComponent.java | 4 +- .../minecraft/item/data/FilterableString.java | 2 +- ...butes1_20_3.java => Attributes1_20_5.java} | 20 +++++++-- .../data/TrimMaterials1_20_3.java | 14 +++--- ...rns1_20_5.java => TrimPatterns1_20_3.java} | 28 ++++++------ .../BlockItemPacketRewriter1_20_5.java | 45 +++++++++---------- .../rewriter/EntityPacketRewriter1_20_5.java | 28 ++++++------ .../rewriter/StructuredDataConverter.java | 6 +-- .../rewriter/EntityPacketRewriter1_99.java | 1 + 12 files changed, 96 insertions(+), 71 deletions(-) rename common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_5to1_20_3/data/{Attributes1_20_3.java => Attributes1_20_5.java} (71%) rename common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_5to1_20_3/data/{TrimPatterns1_20_5.java => TrimPatterns1_20_3.java} (91%) diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/data/StructuredDataContainer.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/data/StructuredDataContainer.java index ed13054b3..75cc0d7af 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/minecraft/data/StructuredDataContainer.java +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/data/StructuredDataContainer.java @@ -130,4 +130,11 @@ public final class StructuredDataContainer { public Map, StructuredData> data() { return data; } + + @Override + public String toString() { + return "StructuredDataContainer{" + + "data=" + data + + '}'; + } } diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/data/StructuredDataKey.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/data/StructuredDataKey.java index 5b158bdaf..15037e5b4 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/minecraft/data/StructuredDataKey.java +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/data/StructuredDataKey.java @@ -114,4 +114,12 @@ public final class StructuredDataKey { public String identifier() { return identifier; } + + @Override + public String toString() { + return "StructuredDataKey{" + + "identifier='" + identifier + '\'' + + ", type=" + type + + '}'; + } } diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/Filterable.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/Filterable.java index 3a608e276..04cf554d5 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/Filterable.java +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/Filterable.java @@ -55,8 +55,8 @@ public abstract class Filterable { private final Type elementType; private final Type optionalElementType; - protected FilterableType(final Type elementType, final Type optionalElementType) { - super(Filterable.class); + protected FilterableType(final Type elementType, final Type optionalElementType, final Class outputClass) { + super(outputClass); this.elementType = elementType; this.optionalElementType = optionalElementType; } diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/FilterableComponent.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/FilterableComponent.java index 799ad8015..144ea76fe 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/FilterableComponent.java +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/FilterableComponent.java @@ -29,13 +29,13 @@ import org.checkerframework.checker.nullness.qual.Nullable; public final class FilterableComponent extends Filterable { - public static final Type TYPE = new FilterableType(Type.TAG, Type.OPTIONAL_TAG) { + public static final Type TYPE = new FilterableType(Type.TAG, Type.OPTIONAL_TAG, FilterableComponent.class) { @Override protected FilterableComponent create(final Tag raw, final Tag filtered) { return new FilterableComponent(raw, filtered); } }; - public static final Type ARRAY_TYPE = new ArrayType<>(TYPE); + public static final Type ARRAY_TYPE = new ArrayType<>(FilterableComponent.TYPE); public FilterableComponent(final Tag raw, @Nullable final Tag filtered) { super(raw, filtered); diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/FilterableString.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/FilterableString.java index 200892b34..ec11dfd29 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/FilterableString.java +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/FilterableString.java @@ -28,7 +28,7 @@ import org.checkerframework.checker.nullness.qual.Nullable; public final class FilterableString extends Filterable { - public static final Type TYPE = new FilterableType(Type.STRING, Type.OPTIONAL_STRING) { + public static final Type TYPE = new FilterableType(Type.STRING, Type.OPTIONAL_STRING, FilterableString.class) { @Override protected FilterableString create(final String raw, final String filtered) { return new FilterableString(raw, filtered); diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_5to1_20_3/data/Attributes1_20_3.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_5to1_20_3/data/Attributes1_20_5.java similarity index 71% rename from common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_5to1_20_3/data/Attributes1_20_3.java rename to common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_5to1_20_3/data/Attributes1_20_5.java index d80fd99a0..3c883a421 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_5to1_20_3/data/Attributes1_20_3.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_5to1_20_3/data/Attributes1_20_5.java @@ -17,10 +17,11 @@ */ package com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.data; +import com.viaversion.viaversion.util.Key; import com.viaversion.viaversion.util.KeyMappings; import org.checkerframework.checker.nullness.qual.Nullable; -public final class Attributes1_20_3 { +public final class Attributes1_20_5 { private static final KeyMappings ATTRIBUTES = new KeyMappings( "generic.armor", @@ -28,22 +29,33 @@ public final class Attributes1_20_3 { "generic.attack_damage", "generic.attack_knockback", "generic.attack_speed", + "player.block_break_speed", + "player.block_interaction_range", + "player.entity_interaction_range", + "generic.fall_damage_multiplier", "generic.flying_speed", "generic.follow_range", - "horse.jump_strength", + "generic.gravity", + "generic.jump_strength", "generic.knockback_resistance", "generic.luck", "generic.max_absorption", "generic.max_health", "generic.movement_speed", - "zombie.spawn_reinforcements" + "generic.safe_fall_distance", + "generic.scale", + "zombie.spawn_reinforcements", + "generic.step_height" ); public static @Nullable String idToKey(final int id) { return ATTRIBUTES.idToKey(id); } - public static int keyToId(final String attribute) { + public static int keyToId(String attribute) { + if (Key.stripMinecraftNamespace(attribute).equals("horse.jump_strength")) { + attribute = "generic.jump_strength"; + } return ATTRIBUTES.keyToId(attribute); } } diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_5to1_20_3/data/TrimMaterials1_20_3.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_5to1_20_3/data/TrimMaterials1_20_3.java index 50451449b..6f102a8ad 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_5to1_20_3/data/TrimMaterials1_20_3.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_5to1_20_3/data/TrimMaterials1_20_3.java @@ -23,16 +23,16 @@ import org.checkerframework.checker.nullness.qual.Nullable; public final class TrimMaterials1_20_3 { private static final KeyMappings MATERIALS = new KeyMappings( - "quartz", - "iron", - "netherite", - "redstone", + "amethyst", "copper", - "gold", - "emerald", "diamond", + "emerald", + "quartz", + "gold", + "iron", "lapis", - "amethyst" + "netherite", + "redstone" ); public static @Nullable String idToKey(final int id) { diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_5to1_20_3/data/TrimPatterns1_20_5.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_5to1_20_3/data/TrimPatterns1_20_3.java similarity index 91% rename from common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_5to1_20_3/data/TrimPatterns1_20_5.java rename to common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_5to1_20_3/data/TrimPatterns1_20_3.java index 6e1729134..db77f49c1 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_5to1_20_3/data/TrimPatterns1_20_5.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_5to1_20_3/data/TrimPatterns1_20_3.java @@ -1,6 +1,6 @@ /* * This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion - * Copyright (C) 2023 ViaVersion and contributors + * Copyright (C) 2016-2024 ViaVersion and contributors * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -20,27 +20,25 @@ package com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.data; import com.viaversion.viaversion.util.KeyMappings; import org.checkerframework.checker.nullness.qual.Nullable; -public final class TrimPatterns1_20_5 { +public final class TrimPatterns1_20_3 { private static final KeyMappings PATTERNS = new KeyMappings( - "sentry", - "dune", "coast", - "wild", - "ward", + "dune", "eye", - "vex", - "tide", - "snout", + "host", + "raiser", "rib", - "spire", - "wayfinder", + "sentry", "shaper", "silence", - "raiser", - "host", - "flow", - "bolt" + "snout", + "spire", + "tide", + "vex", + "ward", + "wayfinder", + "wild" ); public static @Nullable String idToKey(final int id) { diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_5to1_20_3/rewriter/BlockItemPacketRewriter1_20_5.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_5to1_20_3/rewriter/BlockItemPacketRewriter1_20_5.java index 580df740d..dbd64d518 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_5to1_20_3/rewriter/BlockItemPacketRewriter1_20_5.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_5to1_20_3/rewriter/BlockItemPacketRewriter1_20_5.java @@ -73,7 +73,7 @@ import com.viaversion.viaversion.protocols.protocol1_20_3to1_20_2.packet.Clientb import com.viaversion.viaversion.protocols.protocol1_20_3to1_20_2.packet.ClientboundPackets1_20_3; import com.viaversion.viaversion.protocols.protocol1_20_3to1_20_2.rewriter.RecipeRewriter1_20_3; import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.Protocol1_20_5To1_20_3; -import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.data.Attributes1_20_3; +import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.data.Attributes1_20_5; import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.data.BannerPatterns1_20_5; import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.data.DyeColors; import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.data.Enchantments1_20_3; @@ -81,7 +81,7 @@ import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.data.Instrumen import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.data.MapDecorations1_20_3; import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.data.Potions1_20_3; import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.data.TrimMaterials1_20_3; -import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.data.TrimPatterns1_20_5; +import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.data.TrimPatterns1_20_3; import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.packet.ServerboundPacket1_20_5; import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.packet.ServerboundPackets1_20_5; import com.viaversion.viaversion.rewriter.BlockRewriter; @@ -233,14 +233,14 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter + //TODO add default data if needed, e.g. when getting an item via /give without extra data + // Goat horn + // (check more) if (tag == null) { return item; } @@ -464,7 +466,7 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter 2) { return null; } - final int attributeId = Attributes1_20_3.keyToId(attributeName); + final int attributeId = Attributes1_20_5.keyToId(attributeName); if (attributeId == -1) { return null; } @@ -592,6 +594,7 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter materialHolder; if (materialTag instanceof StringTag) { + // Would technically have to be stored and retreived from registry data, but that'd mean a lot of work final int id = TrimMaterials1_20_3.keyToId(((StringTag) materialTag).getValue()); if (id == -1) { return; @@ -638,7 +641,8 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter patternHolder; if (patternTag instanceof StringTag) { - final int id = TrimPatterns1_20_5.keyToId(((StringTag) patternTag).getValue()); + // Would technically have to be stored and retreived from registry data, but that'd mean a lot of work + final int id = TrimPatterns1_20_3.keyToId(((StringTag) patternTag).getValue()); if (id == -1) { return; } @@ -841,8 +845,6 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter patternsTag = tag.getListTag("Patterns", CompoundTag.class); if (patternsTag != null) { final BannerPatternLayer[] layers = patternsTag.stream().map(patternTag -> { @@ -1055,8 +1056,6 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter entry : registryData.entrySet()) { final CompoundTag entryTag = (CompoundTag) entry.getValue(); - final StringTag typeTag = entryTag.getStringTag("type"); + final String type = entryTag.getString("type"); final ListTag valueTag = entryTag.getListTag("value", CompoundTag.class); RegistryEntry[] registryEntries = new RegistryEntry[valueTag.size()]; boolean requiresDummyValues = false; int entriesLength = registryEntries.length; for (final CompoundTag tag : valueTag) { - final StringTag nameTag = tag.getStringTag("name"); - final int id = tag.getNumberTag("id").asInt(); + final String name = tag.getString("name"); + final int id = tag.getInt("id"); entriesLength = Math.max(entriesLength, id + 1); if (id >= registryEntries.length) { // It was previously possible to have arbitrary ids @@ -82,7 +81,7 @@ public final class EntityPacketRewriter1_20_5 extends EntityRewriter { int id = typeId; - if (typeId >= Types1_20_5.META_TYPES.particlesType.typeId()) { + if (id >= Types1_20_5.META_TYPES.particlesType.typeId()) { id++; } - if (typeId >= Types1_20_5.META_TYPES.armadilloState.typeId()) { + if (id >= Types1_20_5.META_TYPES.wolfVariantType.typeId()) { id++; } - if (typeId >= Types1_20_5.META_TYPES.wolfVariantType.typeId()) { + if (id >= Types1_20_5.META_TYPES.armadilloState.typeId()) { id++; } return Types1_20_5.META_TYPES.byId(id); @@ -259,7 +259,7 @@ public final class EntityPacketRewriter1_20_5 extends EntityRewriter { final ListTag modifiers = new ListTag<>(CompoundTag.class); for (final AttributeModifier modifier : data.modifiers()) { - final String identifier = Attributes1_20_3.idToKey(modifier.attribute()); + final String identifier = Attributes1_20_5.idToKey(modifier.attribute()); if (identifier == null) { continue; } final CompoundTag modifierTag = new CompoundTag(); - modifierTag.putString("AttributeName", identifier); + modifierTag.putString("AttributeName", identifier.equals("generic.jump_strength") ? "horse.jump_strength" : identifier); modifierTag.putString("Name", modifier.modifier().name()); modifierTag.putDouble("Amount", modifier.modifier().amount()); modifierTag.putInt("Slot", modifier.slotType()); diff --git a/template/src/main/java/com/viaversion/viaversion/template/protocols/rewriter/EntityPacketRewriter1_99.java b/template/src/main/java/com/viaversion/viaversion/template/protocols/rewriter/EntityPacketRewriter1_99.java index a1208da68..85fef94e9 100644 --- a/template/src/main/java/com/viaversion/viaversion/template/protocols/rewriter/EntityPacketRewriter1_99.java +++ b/template/src/main/java/com/viaversion/viaversion/template/protocols/rewriter/EntityPacketRewriter1_99.java @@ -68,6 +68,7 @@ public final class EntityPacketRewriter1_99 extends EntityRewriter