Skip to content

Commit

Permalink
Implement equals and hashcode for the basic recipe implementations, a…
Browse files Browse the repository at this point in the history
…nd add support for various newer JEI features
  • Loading branch information
pupnewfster committed Feb 23, 2025
1 parent bfdd3b5 commit 3762b51
Show file tree
Hide file tree
Showing 53 changed files with 756 additions and 130 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ wthit_version=12.5.1
framedblocks_mod_id=6127891

#Mod dependency min version ranges
jei_version_range=[19.10.0.126,)
jei_version_range=[19.19.0.219,)

#Mod dependency min version ranges until next MC version. For deps that we need a min version of but otherwise don't have to force ourselves loading after

Expand Down
Empty file modified gradlew
100755 → 100644
Empty file.
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package mekanism.api.recipes;

import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import java.util.List;
import java.util.Objects;
import java.util.function.Predicate;
import mekanism.api.SerializationConstants;
import mekanism.api.annotations.NothingNullByDefault;
import mekanism.api.recipes.ingredients.ItemStackIngredient;
import net.minecraft.world.item.ItemStack;
Expand All @@ -23,7 +26,6 @@
* <ul>
* <li>Nutritional Liquification: These cannot currently be created, but are processed in the Nutritional Liquifier.</li>
* </ul>
*
* @since 10.6.3
*/
@NothingNullByDefault
Expand Down Expand Up @@ -74,6 +76,11 @@ public boolean isIncomplete() {
*/
public record FluidOptionalItemOutput(FluidStack fluid, ItemStack optionalItem) {

public static final Codec<FluidOptionalItemOutput> CODEC = RecordCodecBuilder.create(instance -> instance.group(
FluidStack.CODEC.fieldOf(SerializationConstants.FLUID).forGetter(FluidOptionalItemOutput::fluid),
ItemStack.CODEC.optionalFieldOf(SerializationConstants.ITEM, ItemStack.EMPTY).forGetter(FluidOptionalItemOutput::optionalItem)
).apply(instance, FluidOptionalItemOutput::new));

public FluidOptionalItemOutput {
Objects.requireNonNull(fluid, "Fluid output cannot be null.");
Objects.requireNonNull(optionalItem, "Item output cannot be null.");
Expand All @@ -88,5 +95,27 @@ public record FluidOptionalItemOutput(FluidStack fluid, ItemStack optionalItem)
public FluidOptionalItemOutput copy() {
return new FluidOptionalItemOutput(fluid.copy(), optionalItem.copy());
}

@Override
public boolean equals(Object o) {
if (o == this) {
return true;
} else if (o == null || getClass() != o.getClass()) {
return false;
}
FluidOptionalItemOutput other = (FluidOptionalItemOutput) o;
return FluidStack.matches(fluid, other.fluid) && ItemStack.matches(optionalItem, other.optionalItem);
}

@Override
public int hashCode() {
int hash = FluidStack.hashFluidAndComponents(fluid);
hash = 31 * hash + fluid.getAmount();
if (!optionalItem.isEmpty()) {
hash = 31 * hash + ItemStack.hashItemAndComponents(optionalItem);
hash = 31 * hash + optionalItem.getCount();
}
return hash;
}
}
}
21 changes: 21 additions & 0 deletions src/api/java/mekanism/api/recipes/PressurizedReactionRecipe.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,5 +131,26 @@ public record PressurizedReactionRecipeOutput(@NotNull ItemStack item, @NotNull
throw new IllegalArgumentException("At least one output must be present.");
}
}

@Override
public boolean equals(Object o) {
if (o == this) {
return true;
} else if (o == null || getClass() != o.getClass()) {
return false;
}
PressurizedReactionRecipeOutput other = (PressurizedReactionRecipeOutput) o;
return ItemStack.matches(item, other.item) && chemical.equals(other.chemical);
}

@Override
public int hashCode() {
int hash = chemical.hashCode();
if (!item.isEmpty()) {
hash = 31 * hash + ItemStack.hashItemAndComponents(item);
hash = 31 * hash + item.getCount();
}
return hash;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,21 @@ public List<ChemicalStack> getOutputDefinition() {
public ChemicalStack getOutputRaw() {
return output;
}

@Override
public boolean equals(Object o) {
if (o == this) {
return true;
} else if (o == null || getClass() != o.getClass()) {
return false;
}
BasicChemicalChemicalToChemicalRecipe other = (BasicChemicalChemicalToChemicalRecipe) o;
//Note: We don't need to compare the recipe type as that gets covered by the explicit class type check above
return leftInput.equals(other.leftInput) && rightInput.equals(other.rightInput) && output.equals(other.output);
}

@Override
public int hashCode() {
return Objects.hash(leftInput, rightInput, output);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,23 @@ public ItemStack getOutputRaw() {
public RecipeSerializer<BasicChemicalCrystallizerRecipe> getSerializer() {
return MekanismRecipeSerializers.CRYSTALLIZING.get();
}

@Override
public boolean equals(Object o) {
if (o == this) {
return true;
} else if (o == null || getClass() != o.getClass()) {
return false;
}
BasicChemicalCrystallizerRecipe other = (BasicChemicalCrystallizerRecipe) o;
return input.equals(other.input) && ItemStack.matches(output, other.output);
}

@Override
public int hashCode() {
int hash = input.hashCode();
hash = 31 * hash + ItemStack.hashItemAndComponents(output);
hash = 31 * hash + output.getCount();
return hash;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,20 @@ public ChemicalStack getOutputRaw() {
public RecipeSerializer<BasicChemicalDissolutionRecipe> getSerializer() {
return MekanismRecipeSerializers.DISSOLUTION.get();
}

@Override
public boolean equals(Object o) {
if (o == this) {
return true;
} else if (o == null || getClass() != o.getClass()) {
return false;
}
BasicChemicalDissolutionRecipe other = (BasicChemicalDissolutionRecipe) o;
return perTickUsage == other.perTickUsage && itemInput.equals(other.itemInput) && chemicalInput.equals(other.chemicalInput) && output.equals(other.output);
}

@Override
public int hashCode() {
return Objects.hash(itemInput, chemicalInput, output, perTickUsage);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,21 @@ public ChemicalStack getOutput(ChemicalStack input) {
public ChemicalStack getOutputRaw() {
return output;
}

@Override
public boolean equals(Object o) {
if (o == this) {
return true;
} else if (o == null || getClass() != o.getClass()) {
return false;
}
BasicChemicalToChemicalRecipe other = (BasicChemicalToChemicalRecipe) o;
//Note: We don't need to compare the recipe type as that gets covered by the explicit class type check above
return output.equals(other.output) && input.equals(other.input);
}

@Override
public int hashCode() {
return Objects.hash(output, input);
}
}
19 changes: 19 additions & 0 deletions src/api/java/mekanism/api/recipes/basic/BasicCombinerRecipe.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,23 @@ public ItemStack getOutputRaw() {
public RecipeSerializer<BasicCombinerRecipe> getSerializer() {
return MekanismRecipeSerializers.COMBINING.get();
}

@Override
public boolean equals(Object o) {
if (o == this) {
return true;
} else if (o == null || getClass() != o.getClass()) {
return false;
}
BasicCombinerRecipe other = (BasicCombinerRecipe) o;
return mainInput.equals(other.mainInput) && extraInput.equals(other.extraInput) && ItemStack.matches(output, other.output);
}

@Override
public int hashCode() {
int hash = Objects.hash(mainInput, extraInput);
hash = 31 * hash + ItemStack.hashItemAndComponents(output);
hash = 31 * hash + output.getCount();
return hash;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,21 @@ public ChemicalStack getRightChemicalOutput() {
public RecipeSerializer<BasicElectrolysisRecipe> getSerializer() {
return MekanismRecipeSerializers.SEPARATING.get();
}

@Override
public boolean equals(Object o) {
if (o == this) {
return true;
} else if (o == null || getClass() != o.getClass()) {
return false;
}
BasicElectrolysisRecipe other = (BasicElectrolysisRecipe) o;
return energyMultiplier == other.energyMultiplier && input.equals(other.input) && leftChemicalOutput.equals(other.leftChemicalOutput) &&
rightChemicalOutput.equals(other.rightChemicalOutput);
}

@Override
public int hashCode() {
return Objects.hash(input, leftChemicalOutput, rightChemicalOutput, energyMultiplier);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,23 @@ public FluidStack getOutputRaw() {
public RecipeSerializer<BasicFluidToFluidRecipe> getSerializer() {
return MekanismRecipeSerializers.EVAPORATING.get();
}

@Override
public boolean equals(Object o) {
if (o == this) {
return true;
} else if (o == null || getClass() != o.getClass()) {
return false;
}
BasicFluidToFluidRecipe other = (BasicFluidToFluidRecipe) o;
return input.equals(other.input) && FluidStack.matches(output, other.output);
}

@Override
public int hashCode() {
int hash = input.hashCode();
hash = 31 * hash + FluidStack.hashFluidAndComponents(output);
hash = 31 * hash + output.getAmount();
return hash;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,24 @@ public boolean test(ItemStack itemStack, ChemicalStack chemicalStack) {
public ItemStack getOutputRaw() {
return output;
}

@Override
public boolean equals(Object o) {
if (o == this) {
return true;
} else if (o == null || getClass() != o.getClass()) {
return false;
}
BasicItemStackChemicalToItemStackRecipe other = (BasicItemStackChemicalToItemStackRecipe) o;
//Note: We don't need to compare the recipe type as that gets covered by the explicit class type check above
return perTickUsage == other.perTickUsage && itemInput.equals(other.itemInput) && chemicalInput.equals(other.chemicalInput) && ItemStack.matches(output, other.output);
}

@Override
public int hashCode() {
int hash = Objects.hash(itemInput, chemicalInput, perTickUsage);
hash = 31 * hash + ItemStack.hashItemAndComponents(output);
hash = 31 * hash + output.getCount();
return hash;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,21 @@ public ChemicalStack getOutputRaw() {
public final RecipeType<ItemStackToChemicalRecipe> getType() {
return recipeType;
}

@Override
public boolean equals(Object o) {
if (o == this) {
return true;
} else if (o == null || getClass() != o.getClass()) {
return false;
}
BasicItemStackToChemicalRecipe other = (BasicItemStackToChemicalRecipe) o;
//Note: We don't need to compare the recipe type as that gets covered by the explicit class type check above
return input.equals(other.input) && output.equals(other.output);
}

@Override
public int hashCode() {
return Objects.hash(input, output);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package mekanism.api.recipes.basic;

import java.util.Collections;
import java.util.Objects;
import mekanism.api.annotations.NothingNullByDefault;
import mekanism.api.recipes.ItemStackToEnergyRecipe;
Expand Down Expand Up @@ -62,4 +61,20 @@ public long[] getOutputDefinition() {
public RecipeSerializer<BasicItemStackToEnergyRecipe> getSerializer() {
return MekanismRecipeSerializers.ENERGY_CONVERSION.get();
}

@Override
public boolean equals(Object o) {
if (o == this) {
return true;
} else if (o == null || getClass() != o.getClass()) {
return false;
}
BasicItemStackToEnergyRecipe other = (BasicItemStackToEnergyRecipe) o;
return output == other.output && input.equals(other.input);
}

@Override
public int hashCode() {
return Objects.hash(input, output);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,28 @@ public FluidOptionalItemOutput getOutput(ItemStack input) {
return output.copy();
}

public FluidOptionalItemOutput getOutputRaw() {
return output;
}

@Override
public List<FluidOptionalItemOutput> getOutputDefinition() {
return Collections.singletonList(output);
}

@Override
public boolean equals(Object o) {
if (o == this) {
return true;
} else if (o == null || getClass() != o.getClass()) {
return false;
}
BasicItemStackToFluidOptionalItemRecipe other = (BasicItemStackToFluidOptionalItemRecipe) o;
return input.equals(other.input) && output.equals(other.output);
}

@Override
public int hashCode() {
return Objects.hash(input, output);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,22 @@ public List<FluidStack> getOutputDefinition() {
return Collections.singletonList(output);
}

@Override
public boolean equals(Object o) {
if (o == this) {
return true;
} else if (o == null || getClass() != o.getClass()) {
return false;
}
BasicItemStackToFluidRecipe other = (BasicItemStackToFluidRecipe) o;
return input.equals(other.input) && FluidStack.matches(output, other.output);
}

@Override
public int hashCode() {
int hash = input.hashCode();
hash = 31 * hash + FluidStack.hashFluidAndComponents(output);
hash = 31 * hash + output.getAmount();
return hash;
}
}
Loading

0 comments on commit 3762b51

Please sign in to comment.