From 215511d597da0debb57a404ee74c6beeb4b6a931 Mon Sep 17 00:00:00 2001 From: UselessBullets <80850784+UselessBullets@users.noreply.github.com> Date: Wed, 27 Dec 2023 17:33:47 -0600 Subject: [PATCH] Fixed item retrieval error --- gradle.properties | 2 +- .../mixins/ItemStackJsonAdapterMixin.java | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/gradle.properties b/gradle.properties index 1f81b02..f21b43f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -7,7 +7,7 @@ bta_version=7.1-pre1a loader_version=0.14.19-babric.3-bta # Mod -mod_version=3.0.4 +mod_version=3.1.0 mod_group=turniplabs mod_name=halplibe diff --git a/src/main/java/turniplabs/halplibe/mixin/mixins/ItemStackJsonAdapterMixin.java b/src/main/java/turniplabs/halplibe/mixin/mixins/ItemStackJsonAdapterMixin.java index d5f4154..f5946aa 100644 --- a/src/main/java/turniplabs/halplibe/mixin/mixins/ItemStackJsonAdapterMixin.java +++ b/src/main/java/turniplabs/halplibe/mixin/mixins/ItemStackJsonAdapterMixin.java @@ -3,6 +3,7 @@ import com.google.gson.JsonDeserializationContext; import com.google.gson.JsonElement; import com.google.gson.JsonObject; +import net.minecraft.core.block.Block; import net.minecraft.core.data.registry.recipe.adapter.ItemStackJsonAdapter; import net.minecraft.core.item.Item; import net.minecraft.core.item.ItemStack; @@ -20,7 +21,23 @@ public class ItemStackJsonAdapterMixin { protected void deserializeKey(JsonElement json, Type typeOfT, JsonDeserializationContext context, CallbackInfoReturnable cir) { JsonObject obj = json.getAsJsonObject(); if (obj.has("key")) { - ItemStack stack = obj.has("amount") ? new ItemStack(Item.nameToIdMap.get(obj.get("key").getAsString()), obj.get("amount").getAsInt(), obj.get("meta").getAsInt()) : new ItemStack(Item.nameToIdMap.get(obj.get("key").getAsString()), 1, obj.get("meta").getAsInt()); + String key = obj.get("key").getAsString(); + Integer itemId; + if (key.startsWith("tile")){ + itemId = Block.keyToIdMap.get(key); + if (itemId == null) { + throw new IllegalArgumentException("Null return when trying to located block from key '" + obj.get("key") + "'"); + } + } else if (key.startsWith("item")) { + itemId = Item.nameToIdMap.get(key); + if (itemId == null) { + throw new IllegalArgumentException("Null return when trying to located item from key '" + obj.get("key") + "'"); + } + } else { + throw new IllegalArgumentException("Key '" + key + "' does not start with a valid predicate of 'item' or 'tile'"); + } + + ItemStack stack = obj.has("amount") ? new ItemStack(itemId, obj.get("amount").getAsInt(), obj.get("meta").getAsInt()) : new ItemStack(itemId, 1, obj.get("meta").getAsInt()); cir.setReturnValue(stack); } }