diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/v1_20_3to1_20_5/Protocol1_20_3To1_20_5.java b/common/src/main/java/com/viaversion/viaversion/protocols/v1_20_3to1_20_5/Protocol1_20_3To1_20_5.java
index 2b9fb8291..75e4c4ccd 100644
--- a/common/src/main/java/com/viaversion/viaversion/protocols/v1_20_3to1_20_5/Protocol1_20_3To1_20_5.java
+++ b/common/src/main/java/com/viaversion/viaversion/protocols/v1_20_3to1_20_5/Protocol1_20_3To1_20_5.java
@@ -50,6 +50,7 @@ import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.rewriter.BlockItemPac
import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.rewriter.ComponentRewriter1_20_5;
import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.rewriter.EntityPacketRewriter1_20_5;
import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.storage.AcknowledgedMessagesStorage;
+import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.storage.ArmorTrimStorage;
import com.viaversion.viaversion.protocols.v1_20to1_20_2.packet.ServerboundConfigurationPackets1_20_2;
import com.viaversion.viaversion.rewriter.ComponentRewriter;
import com.viaversion.viaversion.rewriter.SoundRewriter;
@@ -292,6 +293,7 @@ public final class Protocol1_20_3To1_20_5 extends AbstractProtocol.
- */
-package com.viaversion.viaversion.protocols.v1_20_3to1_20_5.data;
-
-import com.viaversion.viaversion.util.KeyMappings;
-import org.checkerframework.checker.nullness.qual.Nullable;
-
-public final class TrimMaterials1_20_3 {
-
- private static final KeyMappings MATERIALS = new KeyMappings(
- "amethyst",
- "copper",
- "diamond",
- "emerald",
- "gold",
- "iron",
- "lapis",
- "netherite",
- "quartz",
- "redstone"
- );
-
- public static @Nullable String idToKey(final int id) {
- return MATERIALS.idToKey(id);
- }
-
- public static int keyToId(final String material) {
- return MATERIALS.keyToId(material);
- }
-}
diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/v1_20_3to1_20_5/rewriter/BlockItemPacketRewriter1_20_5.java b/common/src/main/java/com/viaversion/viaversion/protocols/v1_20_3to1_20_5/rewriter/BlockItemPacketRewriter1_20_5.java
index cef85579f..3dbab46c6 100644
--- a/common/src/main/java/com/viaversion/viaversion/protocols/v1_20_3to1_20_5/rewriter/BlockItemPacketRewriter1_20_5.java
+++ b/common/src/main/java/com/viaversion/viaversion/protocols/v1_20_3to1_20_5/rewriter/BlockItemPacketRewriter1_20_5.java
@@ -93,10 +93,9 @@ import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.data.MapDecorations1_
import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.data.MaxStackSize1_20_3;
import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.data.PotionEffects1_20_5;
import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.data.Potions1_20_5;
-import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.data.TrimMaterials1_20_3;
-import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.data.TrimPatterns1_20_3;
import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ServerboundPacket1_20_5;
import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ServerboundPackets1_20_5;
+import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.storage.ArmorTrimStorage;
import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.storage.BannerPatternStorage;
import com.viaversion.viaversion.rewriter.BlockRewriter;
import com.viaversion.viaversion.rewriter.ItemRewriter;
@@ -499,7 +498,7 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter materialHolder;
+ final ArmorTrimStorage trimStorage = connection.get(ArmorTrimStorage.class);
if (materialTag instanceof StringTag materialStringTag) {
- // Would technically have to be stored and retrieved from registry data, but that'd mean a lot of work
- final int id = TrimMaterials1_20_3.keyToId(materialStringTag.getValue());
+ final int id = trimStorage.trimMaterials().keyToId(materialStringTag.getValue());
if (id == -1) {
return;
}
@@ -1020,11 +1019,11 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter patternHolder;
if (patternTag instanceof StringTag patternStringTag) {
- // Would technically have to be stored and retrieved from registry data, but that'd mean a lot of work
- final int id = TrimPatterns1_20_3.keyToId(patternStringTag.getValue());
+ final int id = trimStorage.trimPatterns().keyToId(patternStringTag.getValue());
if (id == -1) {
return;
}
+
patternHolder = Holder.of(id);
} else if (patternTag instanceof CompoundTag patternCompoundTag) {
final String assetId = patternCompoundTag.getString("assetId");
diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/v1_20_3to1_20_5/rewriter/ComponentRewriter1_20_5.java b/common/src/main/java/com/viaversion/viaversion/protocols/v1_20_3to1_20_5/rewriter/ComponentRewriter1_20_5.java
index c079df632..aaec676c0 100644
--- a/common/src/main/java/com/viaversion/viaversion/protocols/v1_20_3to1_20_5/rewriter/ComponentRewriter1_20_5.java
+++ b/common/src/main/java/com/viaversion/viaversion/protocols/v1_20_3to1_20_5/rewriter/ComponentRewriter1_20_5.java
@@ -17,6 +17,7 @@
*/
package com.viaversion.viaversion.protocols.v1_20_3to1_20_5.rewriter;
+import com.google.common.base.Preconditions;
import com.viaversion.nbt.tag.ByteTag;
import com.viaversion.nbt.tag.CompoundTag;
import com.viaversion.nbt.tag.FloatTag;
@@ -25,7 +26,6 @@ import com.viaversion.nbt.tag.IntTag;
import com.viaversion.nbt.tag.ListTag;
import com.viaversion.nbt.tag.StringTag;
import com.viaversion.nbt.tag.Tag;
-import com.google.common.base.Preconditions;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.GameProfile;
@@ -83,8 +83,7 @@ import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.data.EquipmentSlots1_
import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.data.Instruments1_20_3;
import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.data.PotionEffects1_20_5;
import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.data.Potions1_20_5;
-import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.data.TrimMaterials1_20_3;
-import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.data.TrimPatterns1_20_3;
+import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.storage.ArmorTrimStorage;
import com.viaversion.viaversion.rewriter.ComponentRewriter;
import com.viaversion.viaversion.util.ComponentUtil;
import com.viaversion.viaversion.util.Either;
@@ -132,7 +131,7 @@ public class ComponentRewriter1_20_5 extends Co
register(StructuredDataKey.HIDE_TOOLTIP, this::convertHideTooltip);
register(StructuredDataKey.REPAIR_COST, this::convertRepairCost);
register(StructuredDataKey.ENCHANTMENT_GLINT_OVERRIDE, this::convertEnchantmentGlintOverride);
- register(StructuredDataKey.CREATIVE_SLOT_LOCK, null);
+ registerEmpty(StructuredDataKey.CREATIVE_SLOT_LOCK);
register(StructuredDataKey.INTANGIBLE_PROJECTILE, this::convertIntangibleProjectile);
register(StructuredDataKey.FOOD1_20_5, this::convertFood);
register(StructuredDataKey.FIRE_RESISTANT, this::convertFireResistant);
@@ -142,7 +141,7 @@ public class ComponentRewriter1_20_5 extends Co
register(StructuredDataKey.MAP_COLOR, this::convertMapColor);
register(StructuredDataKey.MAP_ID, this::convertMapId);
register(StructuredDataKey.MAP_DECORATIONS, this::convertMapDecorations);
- register(StructuredDataKey.MAP_POST_PROCESSING, null);
+ registerEmpty(StructuredDataKey.MAP_POST_PROCESSING);
register(StructuredDataKey.CHARGED_PROJECTILES1_20_5, this::convertChargedProjectiles);
register(StructuredDataKey.BUNDLE_CONTENTS1_20_5, this::convertBundleContents);
register(StructuredDataKey.POTION_CONTENTS, this::convertPotionContents);
@@ -247,7 +246,7 @@ public class ComponentRewriter1_20_5 extends Co
if (!data.isEmpty()) {
final CompoundTag components;
try {
- components = toTag(data, false);
+ components = toTag(connection, data, false);
} catch (final Exception e) {
if (!Via.getConfig().isSuppressConversionWarnings()) {
protocol.getLogger().log(Level.WARNING, "Error writing components in show_item!", e);
@@ -278,7 +277,7 @@ public class ComponentRewriter1_20_5 extends Co
}
}
- public CompoundTag toTag(final Map, StructuredData>> data, final boolean empty) {
+ public CompoundTag toTag(final UserConnection connection, final Map, StructuredData>> data, final boolean empty) {
final CompoundTag tag = new CompoundTag();
for (final Map.Entry, StructuredData>> entry : data.entrySet()) {
final StructuredDataKey> key = entry.getKey();
@@ -302,7 +301,7 @@ public class ComponentRewriter1_20_5 extends Co
}
//noinspection unchecked
- final Tag valueTag = converter.dataConverter.convert(value.value());
+ final Tag valueTag = converter.dataConverter.convert(connection, value.value());
if (valueTag == null) {
continue;
}
@@ -578,12 +577,12 @@ public class ComponentRewriter1_20_5 extends Co
return value; // String<->id conversion is already done by the item rewriter
}
- protected ListTag convertChargedProjectiles(final Item[] value) {
- return convertItemArray(value);
+ protected ListTag convertChargedProjectiles(final UserConnection connection, final Item[] value) {
+ return convertItemArray(connection, value);
}
- protected ListTag convertBundleContents(final Item[] value) {
- return convertItemArray(value);
+ protected ListTag convertBundleContents(final UserConnection connection, final Item[] value) {
+ return convertItemArray(connection, value);
}
protected CompoundTag convertPotionContents(final PotionContents value) {
@@ -668,11 +667,12 @@ public class ComponentRewriter1_20_5 extends Co
return tag;
}
- protected CompoundTag convertTrim(final ArmorTrim value) {
+ protected CompoundTag convertTrim(final UserConnection connection, final ArmorTrim value) {
final CompoundTag tag = new CompoundTag();
final Holder material = value.material();
+ final ArmorTrimStorage trimStorage = connection.get(ArmorTrimStorage.class);
if (material.hasId()) {
- final String trimMaterial = TrimMaterials1_20_3.idToKey(material.id());
+ final String trimMaterial = trimStorage.trimMaterials().idToKey(material.id());
tag.putString("material", trimMaterial);
} else {
final ArmorTrimMaterial armorTrimMaterial = material.value();
@@ -700,7 +700,7 @@ public class ComponentRewriter1_20_5 extends Co
final Holder pattern = value.pattern();
if (pattern.hasId()) {
- tag.putString("pattern", TrimPatterns1_20_3.idToKey(pattern.id()));
+ tag.putString("pattern", trimStorage.trimPatterns().idToKey(pattern.id()));
} else {
final ArmorTrimPattern armorTrimPattern = pattern.value();
final CompoundTag patternTag = new CompoundTag();
@@ -862,9 +862,9 @@ public class ComponentRewriter1_20_5 extends Co
return tag;
}
- protected ListTag convertContainer(final Item[] value) {
+ protected ListTag convertContainer(final UserConnection connection, final Item[] value) {
final ListTag tag = new ListTag<>(CompoundTag.class);
- final ListTag items = convertItemArray(value);
+ final ListTag items = convertItemArray(connection, value);
for (int i = 0; i < items.size(); i++) {
final CompoundTag itemTag = new CompoundTag();
itemTag.putInt("slot", i);
@@ -950,17 +950,17 @@ public class ComponentRewriter1_20_5 extends Co
}
}
- protected ListTag convertItemArray(final Item[] value) {
+ protected ListTag convertItemArray(final UserConnection connection, final Item[] value) {
final ListTag tag = new ListTag<>(CompoundTag.class);
for (final Item item : value) {
final CompoundTag itemTag = new CompoundTag();
- convertItem(itemTag, item);
+ convertItem(connection, itemTag, item);
tag.add(itemTag);
}
return tag;
}
- protected void convertItem(final CompoundTag tag, final Item item) {
+ protected void convertItem(final UserConnection connection, final CompoundTag tag, final Item item) {
final String identifier = mappedIdentifier(item.identifier());
if (identifier == null) {
throw new IllegalArgumentException("Unknown item: " + item.identifier());
@@ -972,7 +972,7 @@ public class ComponentRewriter1_20_5 extends Co
tag.putInt("count", 1);
}
final Map, StructuredData>> components = item.dataContainer().data();
- tag.put("components", toTag(components, true));
+ tag.put("components", toTag(connection, components, true));
}
protected void convertFilterableString(final CompoundTag tag, final FilterableString string, final int max) {
@@ -1126,10 +1126,19 @@ public class ComponentRewriter1_20_5 extends Co
// ---------------------------------------------------------------------------------------
+ protected void registerEmpty(final StructuredDataKey key) {
+ converters.put(key, new ConverterPair<>(null, null));
+ }
+
protected void register(final StructuredDataKey key, final DataConverter dataConverter) { // TODO Remove this method
converters.put(key, new ConverterPair<>(dataConverter, null));
}
+ protected void register(final StructuredDataKey key, final SimpleDataConverter dataConverter) {
+ final DataConverter converter = ($, value) -> dataConverter.convert(value);
+ converters.put(key, new ConverterPair<>(converter, null));
+ }
+
protected void register(final StructuredDataKey key, final DataConverter dataConverter, final TagConverter tagConverter) {
converters.put(key, new ConverterPair<>(dataConverter, tagConverter));
}
@@ -1151,11 +1160,17 @@ public class ComponentRewriter1_20_5 extends Co
}
@FunctionalInterface
- protected interface DataConverter {
+ protected interface SimpleDataConverter {
Tag convert(T value);
}
+ @FunctionalInterface
+ protected interface DataConverter {
+
+ Tag convert(UserConnection connection, T value);
+ }
+
@FunctionalInterface
protected interface TagConverter {
@@ -1164,4 +1179,4 @@ public class ComponentRewriter1_20_5 extends Co
private record ConverterPair(DataConverter dataConverter, TagConverter tagConverter) {
}
-}
\ No newline at end of file
+}
diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/v1_20_3to1_20_5/rewriter/EntityPacketRewriter1_20_5.java b/common/src/main/java/com/viaversion/viaversion/protocols/v1_20_3to1_20_5/rewriter/EntityPacketRewriter1_20_5.java
index 063e79aa3..ca6d2ebb1 100644
--- a/common/src/main/java/com/viaversion/viaversion/protocols/v1_20_3to1_20_5/rewriter/EntityPacketRewriter1_20_5.java
+++ b/common/src/main/java/com/viaversion/viaversion/protocols/v1_20_3to1_20_5/rewriter/EntityPacketRewriter1_20_5.java
@@ -46,8 +46,10 @@ import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.data.BannerPatterns1_
import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ClientboundConfigurationPackets1_20_5;
import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ClientboundPackets1_20_5;
import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.storage.AcknowledgedMessagesStorage;
+import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.storage.ArmorTrimStorage;
import com.viaversion.viaversion.rewriter.EntityRewriter;
import com.viaversion.viaversion.util.Key;
+import com.viaversion.viaversion.util.KeyMappings;
import com.viaversion.viaversion.util.TagUtil;
import it.unimi.dsi.fastutil.ints.IntArraySet;
import it.unimi.dsi.fastutil.ints.IntSet;
@@ -156,7 +158,8 @@ public final class EntityPacketRewriter1_20_5 extends EntityRewriter {
+ register(StructuredDataKey.TRIM, (connection, data, tag) -> {
final CompoundTag trimTag = new CompoundTag();
+ final ArmorTrimStorage trimStorage = connection.get(ArmorTrimStorage.class);
if (data.material().isDirect()) {
final CompoundTag materialTag = new CompoundTag();
final ArmorTrimMaterial material = data.material().value();
@@ -540,7 +539,7 @@ public final class StructuredDataConverter {
materialTag.put("description", material.description());
trimTag.put("material", materialTag);
} else {
- final String oldKey = TrimMaterials1_20_3.idToKey(data.material().id());
+ final String oldKey = trimStorage.trimMaterials().idToKey(data.material().id());
if (oldKey != null) {
trimTag.putString("material", oldKey);
}
@@ -559,7 +558,7 @@ public final class StructuredDataConverter {
patternTag.putBoolean("decal", pattern.decal());
trimTag.put("pattern", patternTag);
} else {
- final String oldKey = TrimPatterns1_20_3.idToKey(data.pattern().id());
+ final String oldKey = trimStorage.trimPatterns().idToKey(data.pattern().id());
if (oldKey != null) {
trimTag.putString("pattern", oldKey);
}
diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/v1_20_3to1_20_5/data/TrimPatterns1_20_3.java b/common/src/main/java/com/viaversion/viaversion/protocols/v1_20_3to1_20_5/storage/ArmorTrimStorage.java
similarity index 55%
rename from common/src/main/java/com/viaversion/viaversion/protocols/v1_20_3to1_20_5/data/TrimPatterns1_20_3.java
rename to common/src/main/java/com/viaversion/viaversion/protocols/v1_20_3to1_20_5/storage/ArmorTrimStorage.java
index 944b56619..095539be3 100644
--- a/common/src/main/java/com/viaversion/viaversion/protocols/v1_20_3to1_20_5/data/TrimPatterns1_20_3.java
+++ b/common/src/main/java/com/viaversion/viaversion/protocols/v1_20_3to1_20_5/storage/ArmorTrimStorage.java
@@ -15,13 +15,26 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see .
*/
-package com.viaversion.viaversion.protocols.v1_20_3to1_20_5.data;
+package com.viaversion.viaversion.protocols.v1_20_3to1_20_5.storage;
+import com.viaversion.viaversion.api.connection.StorableObject;
import com.viaversion.viaversion.util.KeyMappings;
-import org.checkerframework.checker.nullness.qual.Nullable;
-public final class TrimPatterns1_20_3 {
+public final class ArmorTrimStorage implements StorableObject {
+ // Default 1.20.3 registries
+ private static final KeyMappings MATERIALS = new KeyMappings(
+ "amethyst",
+ "copper",
+ "diamond",
+ "emerald",
+ "gold",
+ "iron",
+ "lapis",
+ "netherite",
+ "quartz",
+ "redstone"
+ );
private static final KeyMappings PATTERNS = new KeyMappings(
"coast",
"dune",
@@ -41,11 +54,22 @@ public final class TrimPatterns1_20_3 {
"wild"
);
- public static @Nullable String idToKey(final int id) {
- return PATTERNS.idToKey(id);
+ private KeyMappings trimPatterns = PATTERNS;
+ private KeyMappings trimMaterials = MATERIALS;
+
+ public KeyMappings trimPatterns() {
+ return trimPatterns;
}
- public static int keyToId(final String pattern) {
- return PATTERNS.keyToId(pattern);
+ public KeyMappings trimMaterials() {
+ return trimMaterials;
+ }
+
+ public void setTrimPatterns(final KeyMappings trimPatterns) {
+ this.trimPatterns = trimPatterns;
+ }
+
+ public void setTrimMaterials(final KeyMappings trimMaterials) {
+ this.trimMaterials = trimMaterials;
}
}