forked from Chicken-Bones/NotEnoughItems
-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
slprime
committed
Dec 31, 2024
1 parent
8581394
commit d9a7beb
Showing
2 changed files
with
40 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package codechicken.nei.util; | ||
|
||
import net.minecraft.item.Item; | ||
import net.minecraft.item.ItemStack; | ||
|
||
public class ItemStackKey { | ||
|
||
public final ItemStack stack; | ||
private int hashCode = 1; | ||
|
||
public ItemStackKey(ItemStack stack) { | ||
this.stack = stack; | ||
|
||
if (this.stack != null) { | ||
this.hashCode = 31 * this.hashCode + stack.stackSize; | ||
this.hashCode = 31 * this.hashCode + Item.getIdFromItem(stack.getItem()); | ||
this.hashCode = 31 * this.hashCode + stack.getItemDamage(); | ||
this.hashCode = 31 * this.hashCode + (!stack.hasTagCompound() ? 0 : stack.getTagCompound().hashCode()); | ||
} | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return this.hashCode; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (o == this) return true; | ||
if (!(o instanceof ItemStackKey)) return false; | ||
return ItemStack.areItemStacksEqual(this.stack, ((ItemStackKey) o).stack); | ||
} | ||
} |