From 750c77477aab4abe2a83e058100077f71d585150 Mon Sep 17 00:00:00 2001 From: Juuz <6596629+Juuxel@users.noreply.github.com> Date: Wed, 23 Oct 2024 15:52:37 +0300 Subject: [PATCH] Remove deprecated item stack serde methods This includes serialising and deserialising item stacks with the default Jankson instance from JanksonFactory. These were deprecated in 8.0.0 as they didn't include item components. Components can't be included in JanksonFactory.builder() since they need registry access, so devs should use the vanilla item stack codecs instead. --- .../jankson/BlockAndItemSerializers.java | 73 ------------------- .../cottonmc/jankson/JanksonFactory.java | 6 -- 2 files changed, 79 deletions(-) diff --git a/src/main/java/io/github/cottonmc/jankson/BlockAndItemSerializers.java b/src/main/java/io/github/cottonmc/jankson/BlockAndItemSerializers.java index 6b5d5a9..60ec455 100644 --- a/src/main/java/io/github/cottonmc/jankson/BlockAndItemSerializers.java +++ b/src/main/java/io/github/cottonmc/jankson/BlockAndItemSerializers.java @@ -9,84 +9,11 @@ import blue.endless.jankson.api.Marshaller; import net.minecraft.block.Block; import net.minecraft.block.BlockState; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.item.Items; import net.minecraft.registry.Registries; import net.minecraft.state.property.Property; import net.minecraft.util.Identifier; public class BlockAndItemSerializers { - /** - * @deprecated This method doesn't support item stack components. - * You can use {@link ItemStack#CODEC} with a {@link net.minecraft.registry.RegistryOps} - * wrapping a {@link JanksonOps}. - */ - @Deprecated(forRemoval = true) - public static ItemStack getItemStack(JsonObject json, Marshaller m) { - String itemIdString = json.get(String.class, "item"); - Item item = Registries.ITEM.getOptionalValue(Identifier.of(itemIdString)).orElse(Items.AIR); - ItemStack stack = new ItemStack(item); - if (json.containsKey("count")) { - Integer count = json.get(Integer.class, "count"); - if (count!=null) { - stack.setCount(count); - } - } - return stack; - } - - /** - * @deprecated This method doesn't support item stack components. - * You can use {@link ItemStack#CODEC} with a {@link net.minecraft.registry.RegistryOps} - * wrapping a {@link JanksonOps}. For supporting the inline/primitive format, you can use - * {@link com.mojang.serialization.Codec#withAlternative(com.mojang.serialization.Codec, com.mojang.serialization.Codec, java.util.function.Function) - * Codec.withAlternative} - * where the secondary codec is an {@link Item} codec. - */ - @Deprecated(forRemoval = true) - public static ItemStack getItemStackPrimitive(String s, Marshaller m) { - Item item = Registries.ITEM.getOptionalValue(Identifier.of(s)).orElse(Items.AIR); - ItemStack stack = new ItemStack(item); - return stack; - } - - /** - * @deprecated This method doesn't support item stack components. - * You can use {@link ItemStack#CODEC} with a {@link net.minecraft.registry.RegistryOps} - * wrapping a {@link JanksonOps}. - */ - @Deprecated(forRemoval = true) - public static JsonElement saveItemStack(ItemStack stack, Marshaller m) { - JsonPrimitive id = new JsonPrimitive(Registries.ITEM.getId(stack.getItem()).toString()); - if (stack.getCount()==1) return id; - - JsonObject result = new JsonObject(); - result.put("item", new JsonPrimitive(Registries.ITEM.getId(stack.getItem()).toString())); - result.put("count", new JsonPrimitive(stack.getCount())); - return result; - } - - /** - * @deprecated The {@link blue.endless.jankson.Jankson} instance created - * by {@link JanksonFactory} already supports {@link Block} with this format. - */ - @Deprecated(forRemoval = true) - public static Block getBlockPrimitive(String blockIdString, Marshaller m) { - Optional blockOpt = Registries.BLOCK.getOptionalValue(Identifier.of(blockIdString)); - return blockOpt.orElse(null); - } - - /** - * @deprecated The {@link blue.endless.jankson.Jankson} instance created - * by {@link JanksonFactory} already supports {@link Block} with this format. - */ - @Deprecated(forRemoval = true) - public static JsonElement saveBlock(Block block, Marshaller m) { - return new JsonPrimitive(Registries.BLOCK.getId(block).toString()); - } - - public static BlockState getBlockStatePrimitive(String blockIdString, Marshaller m) { Optional blockOpt = Registries.BLOCK.getOptionalValue(Identifier.of(blockIdString)); if (blockOpt.isPresent()) { diff --git a/src/main/java/io/github/cottonmc/jankson/JanksonFactory.java b/src/main/java/io/github/cottonmc/jankson/JanksonFactory.java index 43f3db6..59368e5 100644 --- a/src/main/java/io/github/cottonmc/jankson/JanksonFactory.java +++ b/src/main/java/io/github/cottonmc/jankson/JanksonFactory.java @@ -17,7 +17,6 @@ import net.minecraft.fluid.Fluid; import net.minecraft.item.Item; import net.minecraft.item.ItemGroup; -import net.minecraft.item.ItemStack; import net.minecraft.item.consume.ConsumeEffect; import net.minecraft.item.map.MapDecorationType; import net.minecraft.loot.condition.LootConditionType; @@ -78,11 +77,6 @@ public class JanksonFactory { public static Jankson.Builder builder() { Jankson.Builder builder = Jankson.builder(); - - builder - .registerDeserializer(String.class, ItemStack.class, BlockAndItemSerializers::getItemStackPrimitive) - .registerDeserializer(JsonObject.class, ItemStack.class, BlockAndItemSerializers::getItemStack) - .registerSerializer(ItemStack.class, BlockAndItemSerializers::saveItemStack); builder .registerDeserializer(String.class, BlockState.class, BlockAndItemSerializers::getBlockStatePrimitive)