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 0944c5d55..7f40096ce 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 @@ -52,6 +52,7 @@ import com.viaversion.viaversion.api.minecraft.item.data.WrittenBook; import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Types; import com.viaversion.viaversion.api.type.types.version.Types1_20_5; +import com.viaversion.viaversion.api.type.types.version.Types1_21; import com.viaversion.viaversion.util.Unit; public record StructuredDataKey(String identifier, Type type) { @@ -87,8 +88,10 @@ public record StructuredDataKey(String identifier, Type type) { public static final StructuredDataKey MAP_ID = new StructuredDataKey<>("map_id", Types.VAR_INT); public static final StructuredDataKey MAP_DECORATIONS = new StructuredDataKey<>("map_decorations", Types.COMPOUND_TAG); public static final StructuredDataKey MAP_POST_PROCESSING = new StructuredDataKey<>("map_post_processing", Types.VAR_INT); - public static final StructuredDataKey CHARGED_PROJECTILES = new StructuredDataKey<>("charged_projectiles", Types1_20_5.ITEM_ARRAY); - public static final StructuredDataKey BUNDLE_CONTENTS = new StructuredDataKey<>("bundle_contents", Types1_20_5.ITEM_ARRAY); + public static final StructuredDataKey CHARGED_PROJECTILES1_20_5 = new StructuredDataKey<>("charged_projectiles", Types1_20_5.ITEM_ARRAY); + public static final StructuredDataKey CHARGED_PROJECTILES1_21 = new StructuredDataKey<>("charged_projectiles", Types1_21.ITEM_ARRAY); + public static final StructuredDataKey BUNDLE_CONTENTS1_20_5 = new StructuredDataKey<>("bundle_contents", Types1_20_5.ITEM_ARRAY); + public static final StructuredDataKey BUNDLE_CONTENTS1_21 = new StructuredDataKey<>("bundle_contents", Types1_21.ITEM_ARRAY); public static final StructuredDataKey POTION_CONTENTS = new StructuredDataKey<>("potion_contents", PotionContents.TYPE); public static final StructuredDataKey SUSPICIOUS_STEW_EFFECTS = new StructuredDataKey<>("suspicious_stew_effects", SuspiciousStewEffect.ARRAY_TYPE); public static final StructuredDataKey WRITABLE_BOOK_CONTENT = new StructuredDataKey<>("writable_book_content", FilterableString.ARRAY_TYPE); @@ -110,7 +113,8 @@ public record StructuredDataKey(String identifier, Type type) { public static final StructuredDataKey BANNER_PATTERNS = new StructuredDataKey<>("banner_patterns", BannerPatternLayer.ARRAY_TYPE); public static final StructuredDataKey BASE_COLOR = new StructuredDataKey<>("base_color", Types.VAR_INT); public static final StructuredDataKey POT_DECORATIONS = new StructuredDataKey<>("pot_decorations", PotDecorations.TYPE); - public static final StructuredDataKey CONTAINER = new StructuredDataKey<>("container", Types1_20_5.ITEM_ARRAY); + public static final StructuredDataKey CONTAINER1_20_5 = new StructuredDataKey<>("container", Types1_20_5.ITEM_ARRAY); + public static final StructuredDataKey CONTAINER1_21 = new StructuredDataKey<>("container", Types1_21.ITEM_ARRAY); public static final StructuredDataKey BLOCK_STATE = new StructuredDataKey<>("block_state", BlockStateProperties.TYPE); public static final StructuredDataKey BEES = new StructuredDataKey<>("bees", Bee.ARRAY_TYPE); public static final StructuredDataKey LOCK = new StructuredDataKey<>("lock", Types.TAG); diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/item/StructuredDataType.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/item/StructuredDataType.java index 8b51ff967..28e35ba8c 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/item/StructuredDataType.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/item/StructuredDataType.java @@ -83,6 +83,7 @@ public class StructuredDataType extends Type> { public DataFiller add(final StructuredDataKey key) { final int id = mappings.mappedId(key.identifier()); Preconditions.checkArgument(id != -1, "No mapped id found for %s", key.identifier()); + Preconditions.checkArgument(types[id] == null, "Data component serializer already exists for id %s", id); types[id] = key; return this; } 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 5c9ba7a74..8a7c3a56d 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 @@ -268,14 +268,14 @@ public final class Protocol1_20_3To1_20_5 extends AbstractProtocol extends Co register(StructuredDataKey.MAP_ID, this::convertMapId); register(StructuredDataKey.MAP_DECORATIONS, this::convertMapDecorations); register(StructuredDataKey.MAP_POST_PROCESSING, null); - register(StructuredDataKey.CHARGED_PROJECTILES, this::convertChargedProjectiles); - register(StructuredDataKey.BUNDLE_CONTENTS, this::convertBundleContents); + register(StructuredDataKey.CHARGED_PROJECTILES1_20_5, this::convertChargedProjectiles); + register(StructuredDataKey.BUNDLE_CONTENTS1_20_5, this::convertBundleContents); register(StructuredDataKey.POTION_CONTENTS, this::convertPotionContents); register(StructuredDataKey.SUSPICIOUS_STEW_EFFECTS, this::convertSuspiciousStewEffects); register(StructuredDataKey.WRITABLE_BOOK_CONTENT, this::convertWritableBookContent); @@ -165,7 +165,7 @@ public class ComponentRewriter1_20_5 extends Co register(StructuredDataKey.BANNER_PATTERNS, this::convertBannerPatterns); register(StructuredDataKey.BASE_COLOR, this::convertBaseColor); register(StructuredDataKey.POT_DECORATIONS, this::convertPotDecorations); - register(StructuredDataKey.CONTAINER, this::convertContainer); + register(StructuredDataKey.CONTAINER1_20_5, this::convertContainer); register(StructuredDataKey.BLOCK_STATE, this::convertBlockState); register(StructuredDataKey.BEES, this::convertBees); register(StructuredDataKey.LOCK, this::convertLock); diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/v1_20_3to1_20_5/rewriter/StructuredDataConverter.java b/common/src/main/java/com/viaversion/viaversion/protocols/v1_20_3to1_20_5/rewriter/StructuredDataConverter.java index 00bb7d4bd..5fe8adb56 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/v1_20_3to1_20_5/rewriter/StructuredDataConverter.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/v1_20_3to1_20_5/rewriter/StructuredDataConverter.java @@ -218,8 +218,8 @@ public final class StructuredDataConverter { } }); register(StructuredDataKey.BASE_COLOR, (data, tag) -> getBlockEntityTag(tag).putInt("Base", data)); - register(StructuredDataKey.CHARGED_PROJECTILES, (connection, data, tag) -> convertItemList(connection, data, tag, "ChargedProjectiles")); - register(StructuredDataKey.BUNDLE_CONTENTS, (connection, data, tag) -> convertItemList(connection, data, tag, "Items")); + register(StructuredDataKey.CHARGED_PROJECTILES1_20_5, (connection, data, tag) -> convertItemList(connection, data, tag, "ChargedProjectiles")); + register(StructuredDataKey.BUNDLE_CONTENTS1_20_5, (connection, data, tag) -> convertItemList(connection, data, tag, "Items")); register(StructuredDataKey.LODESTONE_TRACKER, (data, tag) -> { tag.putBoolean("LodestoneTracked", data.tracked()); if (data.position() != null) { @@ -494,7 +494,7 @@ public final class StructuredDataConverter { } getBlockEntityTag(tag, "banner").put("Patterns", patternsTag); }); - register(StructuredDataKey.CONTAINER, (connection, data, tag) -> convertItemList(connection, data, getBlockEntityTag(tag), "Items")); + register(StructuredDataKey.CONTAINER1_20_5, (connection, data, tag) -> convertItemList(connection, data, getBlockEntityTag(tag), "Items")); register(StructuredDataKey.CAN_PLACE_ON, (data, tag) -> convertBlockPredicates(tag, data, "CanPlaceOn", HIDE_CAN_PLACE_ON)); register(StructuredDataKey.CAN_BREAK, (data, tag) -> convertBlockPredicates(tag, data, "CanDestroy", HIDE_CAN_DESTROY)); register(StructuredDataKey.MAP_POST_PROCESSING, (data, tag) -> { diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/v1_20_5to1_21/Protocol1_20_5To1_21.java b/common/src/main/java/com/viaversion/viaversion/protocols/v1_20_5to1_21/Protocol1_20_5To1_21.java index 85ef81a71..7bb46567d 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/v1_20_5to1_21/Protocol1_20_5To1_21.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/v1_20_5to1_21/Protocol1_20_5To1_21.java @@ -199,14 +199,14 @@ public final class Protocol1_20_5To1_21 extends AbstractProtocol { final AttributeModifiers1_21.AttributeModifier[] modifiers = Arrays.stream(attributeModifiers.modifiers()).map(modifier -> { final AttributeModifiers1_20_5.ModifierData modData = modifier.modifier(); @@ -144,6 +147,9 @@ public final class BlockItemPacketRewriter1_21 extends StructuredItemRewriter { final AttributeModifiers1_20_5.AttributeModifier[] modifiers = Arrays.stream(attributeModifiers.modifiers()).map(modifier -> {