Skip to content

Commit

Permalink
Fixed item retrieval error
Browse files Browse the repository at this point in the history
  • Loading branch information
UselessBullets committed Dec 27, 2023
1 parent 3750798 commit 215511d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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

Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -20,7 +21,23 @@ public class ItemStackJsonAdapterMixin {
protected void deserializeKey(JsonElement json, Type typeOfT, JsonDeserializationContext context, CallbackInfoReturnable<ItemStack> 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);
}
}
Expand Down

0 comments on commit 215511d

Please sign in to comment.