diff options
author | Alkalus <3060479+draknyte1@users.noreply.github.com> | 2021-11-17 15:59:38 +0000 |
---|---|---|
committer | Alkalus <3060479+draknyte1@users.noreply.github.com> | 2021-11-17 15:59:38 +0000 |
commit | 25d664c62e4b658f1bc3c41706488ab351fec2db (patch) | |
tree | 90ed93c079ca6b4112b13334b4913d57b6664891 /src/main | |
parent | a40b1e3b79709baa60ae2ced9ab57279c065cb7d (diff) | |
download | GT5-Unofficial-25d664c62e4b658f1bc3c41706488ab351fec2db.tar.gz GT5-Unofficial-25d664c62e4b658f1bc3c41706488ab351fec2db.tar.bz2 GT5-Unofficial-25d664c62e4b658f1bc3c41706488ab351fec2db.zip |
Added hashCode and equals overrides to GT_Recipe_AssemblyLine.
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/java/gregtech/api/util/GT_Recipe.java | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/src/main/java/gregtech/api/util/GT_Recipe.java b/src/main/java/gregtech/api/util/GT_Recipe.java index 1f13ff7b82..ec5a062a11 100644 --- a/src/main/java/gregtech/api/util/GT_Recipe.java +++ b/src/main/java/gregtech/api/util/GT_Recipe.java @@ -564,6 +564,77 @@ public class GT_Recipe implements Comparable<GT_Recipe> { mEUt = aEUt; mOreDictAlt = aAlt; } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + GT_ItemStack[] thisInputs = new GT_ItemStack[this.mInputs.length]; + int inputHash = Arrays.deepHashCode(thisInputs); + int inputFluidHash = Arrays.deepHashCode(this.mFluidInputs); + GT_ItemStack thisOutput = new GT_ItemStack(mOutput); + GT_ItemStack thisResearch = new GT_ItemStack(mResearchItem); + result = prime * result + inputFluidHash; + result = prime * result + inputHash; + result = prime * result + Objects.hash( + mDuration, mEUt, + thisOutput, + thisResearch, + mResearchTime + ); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (!(obj instanceof GT_Recipe_AssemblyLine)) { + return false; + } + GT_Recipe_AssemblyLine other = (GT_Recipe_AssemblyLine) obj; + if (this.mInputs.length != other.mInputs.length) { + return false; + } + if (this.mFluidInputs.length != other.mFluidInputs.length) { + return false; + } + // Check Outputs Match + GT_ItemStack output1 = new GT_ItemStack(this.mOutput); + GT_ItemStack output2 = new GT_ItemStack(other.mOutput); + if (!output1.equals(output2)) { + return false; + } + // Check Scanned Item Match + GT_ItemStack scan1 = new GT_ItemStack(this.mResearchItem); + GT_ItemStack scan2 = new GT_ItemStack(other.mResearchItem); + if (!scan1.equals(scan2)) { + return false; + } + // Check Items Match + GT_ItemStack[] thisInputs = new GT_ItemStack[this.mInputs.length]; + GT_ItemStack[] otherInputs = new GT_ItemStack[other.mInputs.length]; + for (int i=0;i<thisInputs.length;i++) { + thisInputs[i] = new GT_ItemStack(this.mInputs[i]); + otherInputs[i] = new GT_ItemStack(other.mInputs[i]); + } + for (int i=0;i<thisInputs.length;i++) { + if (!thisInputs[i].equals(otherInputs[i]) || thisInputs[i].mStackSize != otherInputs[i].mStackSize) { + return false; + } + } + // Check Fluids Match + for (int i=0;i<this.mFluidInputs.length;i++) { + if (!this.mFluidInputs[i].isFluidStackIdentical(other.mFluidInputs[i])) { + return false; + } + } + + return this.mDuration == other.mDuration + && this.mEUt == other.mEUt + && this.mResearchTime == other.mResearchTime; + } } |