Skip to content

Commit

Permalink
Fix recipe caching not considering different rotations
Browse files Browse the repository at this point in the history
  • Loading branch information
rubensworks committed Oct 19, 2024
1 parent f57ce14 commit 9d9f8a3
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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))) {
Expand All @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))) {
Expand All @@ -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;
}
Expand Down

0 comments on commit 9d9f8a3

Please sign in to comment.