From 96e611fd139e0061b00441d32d83920aeb7736ca Mon Sep 17 00:00:00 2001 From: Timo Ley Date: Thu, 19 Jan 2023 21:38:32 +0100 Subject: [PATCH] fix: aspect calculation exceptions fixes #2 --- build.gradle | 2 +- .../auracore/crafting/AspectCalculation.java | 115 ++++++++++++++---- 2 files changed, 90 insertions(+), 27 deletions(-) diff --git a/build.gradle b/build.gradle index 66333ca..3b9e125 100644 --- a/build.gradle +++ b/build.gradle @@ -24,7 +24,7 @@ apply from: './gradle/scripts/mixins.gradle' sourceCompatibility = JavaVersion.VERSION_1_8 targetCompatibility = JavaVersion.VERSION_1_8 -version = "1.7.1" +version = "1.7.2" group= "dev.tilera" archivesBaseName = "auracore" diff --git a/src/main/java/dev/tilera/auracore/crafting/AspectCalculation.java b/src/main/java/dev/tilera/auracore/crafting/AspectCalculation.java index 6ad413f..77cb9db 100644 --- a/src/main/java/dev/tilera/auracore/crafting/AspectCalculation.java +++ b/src/main/java/dev/tilera/auracore/crafting/AspectCalculation.java @@ -33,7 +33,7 @@ public class AspectCalculation { int idR = recipe.getRecipeOutput().getItemDamage() < 0 ? 0 : recipe.getRecipeOutput().getItemDamage(); int n = idS = meta < 0 ? 0 : meta; if (recipe.getRecipeOutput().getItem() != item || idR != idS) continue; - HashMap, ItemStack> ingredients = new HashMap, ItemStack>(); + HashMap ingredients = new HashMap<>(); AspectList ph = new AspectList(); int cval = 0; try { @@ -45,13 +45,13 @@ public class AspectCalculation { for (int j = 0; j < height && j < 3; ++j) { if (items[i + j * width] == null) continue; items[i + j * width].stackSize = 1; - if (ingredients.containsKey(Arrays.asList(Item.getIdFromItem(items[i + j * width].getItem()), items[i + j * width].getItemDamage()))) { - ItemStack is = (ItemStack)ingredients.get(Arrays.asList(items[i + j * width].getItem(), items[i + j * width].getItemDamage())); + if (ingredients.containsKey(new ItemSignature(items[i + j * width]))) { + ItemStack is = (ItemStack)ingredients.get(new ItemSignature(items[i + j * width])); ++is.stackSize; - ingredients.put(Arrays.asList(Item.getIdFromItem(items[i + j * width].getItem()), items[i + j * width].getItemDamage()), is); + ingredients.put(new ItemSignature(items[i + j * width]), is); continue; } - ingredients.put(Arrays.asList(Item.getIdFromItem(items[i + j * width].getItem()), items[i + j * width].getItemDamage()), items[i + j * width]); + ingredients.put(new ItemSignature(items[i + j * width]), items[i + j * width]); } } } else { @@ -59,13 +59,13 @@ public class AspectCalculation { for (int i = 0; i < items.size() && i < 9; ++i) { if (items.get(i) == null) continue; ((ItemStack)items.get((int)i)).stackSize = 1; - if (ingredients.containsKey(Arrays.asList(((ItemStack)items.get((int)i)).getItem(), ((ItemStack)items.get(i)).getItemDamage()))) { - ItemStack is = (ItemStack)ingredients.get(Arrays.asList(Item.getIdFromItem(((ItemStack)items.get((int)i)).getItem()), ((ItemStack)items.get(i)).getItemDamage())); + if (ingredients.containsKey(new ItemSignature(items.get((int)i)))) { + ItemStack is = (ItemStack)ingredients.get(new ItemSignature(items.get((int)i))); ++is.stackSize; - ingredients.put(Arrays.asList(Item.getIdFromItem(((ItemStack)items.get((int)i)).getItem()), ((ItemStack)items.get(i)).getItemDamage()), is); + ingredients.put(new ItemSignature(items.get((int)i)), is); continue; } - ingredients.put(Arrays.asList(Item.getIdFromItem(((ItemStack)items.get((int)i)).getItem()), ((ItemStack)items.get(i)).getItemDamage()), items.get(i)); + ingredients.put(new ItemSignature(items.get((int)i)), items.get(i)); } } Collection ings = ingredients.values(); @@ -127,39 +127,62 @@ public class AspectCalculation { int idR = recipe.getRecipeOutput().getItemDamage() < 0 ? 0 : recipe.getRecipeOutput().getItemDamage(); int n = idS = meta < 0 ? 0 : meta; if (recipe.getRecipeOutput().getItem() != item || idR != idS) continue; - HashMap, ItemStack> ingredients = new HashMap, ItemStack>(); + HashMap ingredients = new HashMap<>(); AspectList ph = new AspectList(); int cval = 0; try { if (recipe instanceof ShapedArcaneRecipe) { int width = ((ShapedArcaneRecipe)recipe).width; int height = ((ShapedArcaneRecipe)recipe).width; - ItemStack[] items = (ItemStack[]) ((ShapedArcaneRecipe)recipe).input; + Object[] items = ((ShapedArcaneRecipe)recipe).input; for (int i = 0; i < width && i < 3; ++i) { for (int j = 0; j < height && j < 3; ++j) { if (items[i + j * width] == null) continue; - items[i + j * width].stackSize = 1; - if (ingredients.containsKey(Arrays.asList(Item.getIdFromItem(items[i + j * width].getItem()), items[i + j * width].getItemDamage()))) { - ItemStack is = (ItemStack)ingredients.get(Arrays.asList(Item.getIdFromItem(items[i + j * width].getItem()), items[i + j * width].getItemDamage())); - ++is.stackSize; - ingredients.put(Arrays.asList(Item.getIdFromItem(items[i + j * width].getItem()), items[i + j * width].getItemDamage()), is); - continue; + ItemStack stack = null; + if (items[i + j * width] instanceof ItemStack) { + stack = (ItemStack) items[i + j * width]; + + } else if (items[i + j * width] instanceof ArrayList) { + ArrayList l = (ArrayList) items[i + j * width]; + if (l.size() > 0) { + stack = l.get(0); + } + } + if (stack != null) { + stack.stackSize = 1; + if (ingredients.containsKey(new ItemSignature(stack))) { + ItemStack is = (ItemStack)ingredients.get(new ItemSignature(stack)); + ++is.stackSize; + ingredients.put(new ItemSignature(stack), is); + continue; + } + ingredients.put(new ItemSignature(stack), stack); } - ingredients.put(Arrays.asList(Item.getIdFromItem(items[i + j * width].getItem()), items[i + j * width].getItemDamage()), items[i + j * width]); } } } else { - List items = ((ShapelessArcaneRecipe)recipe).getInput(); + List items = ((ShapelessArcaneRecipe)recipe).getInput(); for (int i = 0; i < items.size() && i < 9; ++i) { if (items.get(i) == null) continue; - ((ItemStack)items.get((int)i)).stackSize = 1; - if (ingredients.containsKey(Arrays.asList(Item.getIdFromItem(((ItemStack)items.get((int)i)).getItem()), ((ItemStack)items.get(i)).getItemDamage()))) { - ItemStack is = (ItemStack)ingredients.get(Arrays.asList(Item.getIdFromItem(((ItemStack)items.get((int)i)).getItem()), ((ItemStack)items.get(i)).getItemDamage())); - ++is.stackSize; - ingredients.put(Arrays.asList(Item.getIdFromItem(((ItemStack)items.get((int)i)).getItem()), ((ItemStack)items.get(i)).getItemDamage()), is); - continue; + ItemStack stack = null; + if (items.get(i) instanceof ItemStack) { + stack = (ItemStack) items.get(i); + } else if (items.get(i) instanceof ArrayList) { + ArrayList l = (ArrayList) items.get(i); + if (l.size() > 0){ + stack = l.get(0); + } + } + if (stack != null) { + stack.stackSize = 1; + if (ingredients.containsKey(new ItemSignature(stack))) { + ItemStack is = (ItemStack)ingredients.get(new ItemSignature(stack)); + ++is.stackSize; + ingredients.put(new ItemSignature(stack), is); + continue; + } + ingredients.put(new ItemSignature(stack), stack); } - ingredients.put(Arrays.asList(Item.getIdFromItem(((ItemStack)items.get((int)i)).getItem()), ((ItemStack)items.get(i)).getItemDamage()), items.get(i)); } } Collection ings = ingredients.values(); @@ -191,4 +214,44 @@ public class AspectCalculation { return ret; } + public static class ItemSignature { + + Item item; + int metadata; + + public ItemSignature(ItemStack stack) { + this.item = stack.getItem(); + this.metadata = stack.getItemDamage(); + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((item == null) ? 0 : item.hashCode()); + result = prime * result + metadata; + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + ItemSignature other = (ItemSignature) obj; + if (item == null) { + if (other.item != null) + return false; + } else if (!item.equals(other.item)) + return false; + if (metadata != other.metadata) + return false; + return true; + } + + } + }