From 9d9f8a38133e36fead79373413989b0014270648 Mon Sep 17 00:00:00 2001 From: Ruben Taelman Date: Sat, 19 Oct 2024 10:18:52 +0200 Subject: [PATCH] Fix recipe caching not considering different rotations Closes CyclopsMC/IntegratedTerminals#129 --- .../helper/CraftingHelpersCommon.java | 20 +++++++++++++++---- .../cyclopscore/helper/CraftingHelpers.java | 20 +++++++++++++++---- 2 files changed, 32 insertions(+), 8 deletions(-) diff --git a/loader-common/src/main/java/org/cyclops/cyclopscore/helper/CraftingHelpersCommon.java b/loader-common/src/main/java/org/cyclops/cyclopscore/helper/CraftingHelpersCommon.java index cb01f6799f..916bf03cb0 100644 --- a/loader-common/src/main/java/org/cyclops/cyclopscore/helper/CraftingHelpersCommon.java +++ b/loader-common/src/main/java/org/cyclops/cyclopscore/helper/CraftingHelpersCommon.java @@ -141,8 +141,18 @@ public boolean equals(Object obj) { return false; } RecipeInput otherInput = ((CacheableCraftingInventory) obj).getInventoryCrafting(); - if (getInventoryCrafting().size() != otherInput.size()) { - return false; + if (getInventoryCrafting() instanceof CraftingInput craftingInputThis) { + if (otherInput instanceof CraftingInput craftingInputOther) { + if (craftingInputThis.width() != craftingInputOther.width() || craftingInputThis.height() != craftingInputOther.height()) { + return false; + } + } else { + return false; + } + } else { + if (getInventoryCrafting().size() != otherInput.size()) { + return false; + } } for (int i = 0; i < getInventoryCrafting().size(); i++) { if (!ItemStack.isSameItemSameComponents(getInventoryCrafting().getItem(i), otherInput.getItem(i))) { @@ -155,9 +165,11 @@ public boolean equals(Object obj) { @Override public int hashCode() { int hash = 11 + getInventoryCrafting().size(); + if (getInventoryCrafting() instanceof CraftingInput craftingInput) { + hash = 23 + 3 * craftingInput.width() + 5 * craftingInput.height(); + } for (int i = 0; i < getInventoryCrafting().size(); i++) { - hash = hash << 1; - hash |= modHelpers.getItemStackHelpers().getItemStackHashCode(getInventoryCrafting().getItem(i)); + hash |= modHelpers.getItemStackHelpers().getItemStackHashCode(getInventoryCrafting().getItem(i)) * i; } return hash; } diff --git a/loader-neoforge/src/main/java/org/cyclops/cyclopscore/helper/CraftingHelpers.java b/loader-neoforge/src/main/java/org/cyclops/cyclopscore/helper/CraftingHelpers.java index 2d29c8fdef..089841c260 100644 --- a/loader-neoforge/src/main/java/org/cyclops/cyclopscore/helper/CraftingHelpers.java +++ b/loader-neoforge/src/main/java/org/cyclops/cyclopscore/helper/CraftingHelpers.java @@ -159,8 +159,18 @@ public boolean equals(Object obj) { return false; } RecipeInput otherInput = ((CacheableCraftingInventory) obj).getInventoryCrafting(); - if (getInventoryCrafting().size() != otherInput.size()) { - return false; + if (getInventoryCrafting() instanceof CraftingInput craftingInputThis) { + if (otherInput instanceof CraftingInput craftingInputOther) { + if (craftingInputThis.width() != craftingInputOther.width() || craftingInputThis.height() != craftingInputOther.height()) { + return false; + } + } else { + return false; + } + } else { + if (getInventoryCrafting().size() != otherInput.size()) { + return false; + } } for (int i = 0; i < getInventoryCrafting().size(); i++) { if (!ItemStack.isSameItemSameComponents(getInventoryCrafting().getItem(i), otherInput.getItem(i))) { @@ -173,9 +183,11 @@ public boolean equals(Object obj) { @Override public int hashCode() { int hash = 11 + getInventoryCrafting().size(); + if (getInventoryCrafting() instanceof CraftingInput craftingInput) { + hash = 23 + 3 * craftingInput.width() + 5 * craftingInput.height(); + } for (int i = 0; i < getInventoryCrafting().size(); i++) { - hash = hash << 1; - hash |= ItemStackHelpers.getItemStackHashCode(getInventoryCrafting().getItem(i)); + hash |= ItemStackHelpers.getItemStackHashCode(getInventoryCrafting().getItem(i)) * i; } return hash; }