Better recipe removal
No more weird Ingredient comparison
This commit is contained in:
parent
dd1dafe3dc
commit
c58e29eeea
|
@ -41,8 +41,8 @@ public class BloodMagic {
|
|||
public static final String NAME = "Blood Magic: Alchemical Wizardry";
|
||||
public static final String VERSION = "@VERSION@";
|
||||
public static final String DEPEND = "required-after:guideapi;";
|
||||
public static final Logger LOGGER = LogManager.getLogger(NAME.substring(0, NAME.indexOf(":")));
|
||||
public static final boolean IS_DEV = (Boolean) Launch.blackboard.get("fml.deobfuscatedEnvironment");
|
||||
public static final Logger LOGGER = LogManager.getLogger(NAME.substring(0, NAME.indexOf(":")));
|
||||
public static final List<Pair<IBloodMagicPlugin, BloodMagicPlugin>> PLUGINS = Lists.newArrayList();
|
||||
public static final CreativeTabs TAB_BM = new CreativeTabs(MODID + ".creativeTab") {
|
||||
@Override
|
||||
|
|
|
@ -17,7 +17,6 @@ import javax.annotation.Nonnegative;
|
|||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class BloodMagicRecipeRegistrar implements IBloodMagicRecipeRegistrar {
|
||||
|
@ -44,6 +43,13 @@ public class BloodMagicRecipeRegistrar implements IBloodMagicRecipeRegistrar {
|
|||
altarRecipes.add(new RecipeBloodAltar(input, output, minimumTier, syphon, consumeRate, drainRate));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeBloodAltar(@Nonnull ItemStack input) {
|
||||
Preconditions.checkNotNull(input, "input cannot be null.");
|
||||
|
||||
return altarRecipes.remove(getBloodAltar(input));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addAlchemyTable(@Nonnull ItemStack output, @Nonnegative int syphon, @Nonnegative int ticks, @Nonnegative int minimumTier, @Nonnull Ingredient... input) {
|
||||
Preconditions.checkNotNull(output, "output cannot be null.");
|
||||
|
@ -56,6 +62,16 @@ public class BloodMagicRecipeRegistrar implements IBloodMagicRecipeRegistrar {
|
|||
alchemyRecipes.add(new RecipeAlchemyTable(inputs, output, syphon, ticks, minimumTier));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeAlchemyTable(@Nonnull ItemStack... input) {
|
||||
Preconditions.checkNotNull(input, "inputs cannot be null.");
|
||||
|
||||
for (ItemStack stack : input)
|
||||
Preconditions.checkNotNull(stack, "input cannot be null.");
|
||||
|
||||
return alchemyRecipes.remove(getAlchemyTable(Lists.newArrayList(input)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addTartaricForge(@Nonnull ItemStack output, @Nonnegative double minimumSouls, @Nonnegative double soulDrain, @Nonnull Ingredient... input) {
|
||||
Preconditions.checkNotNull(output, "output cannot be null.");
|
||||
|
@ -67,6 +83,16 @@ public class BloodMagicRecipeRegistrar implements IBloodMagicRecipeRegistrar {
|
|||
tartaricForgeRecipes.add(new RecipeTartaricForge(inputs, output, minimumSouls, soulDrain));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean removeTartaricForge(@Nonnull ItemStack... input) {
|
||||
Preconditions.checkNotNull(input, "inputs cannot be null.");
|
||||
|
||||
for (ItemStack stack : input)
|
||||
Preconditions.checkNotNull(stack, "input cannot be null.");
|
||||
|
||||
return tartaricForgeRecipes.remove(getTartaricForge(Lists.newArrayList(input)));
|
||||
}
|
||||
|
||||
public void addTartaricForge(@Nonnull ItemStack output, @Nonnegative double minimumSouls, @Nonnegative double soulDrain, @Nonnull Object... input) {
|
||||
Preconditions.checkNotNull(output, "output cannot be null.");
|
||||
Preconditions.checkArgument(minimumSouls >= 0, "minimumSouls cannot be negative.");
|
||||
|
@ -86,24 +112,6 @@ public class BloodMagicRecipeRegistrar implements IBloodMagicRecipeRegistrar {
|
|||
addTartaricForge(output, minimumSouls, soulDrain, ingredients.toArray(new Ingredient[0]));
|
||||
}
|
||||
|
||||
public boolean removeBloodAltar(@Nonnull RecipeBloodAltar recipe) {
|
||||
Preconditions.checkNotNull(recipe, "recipe cannot be null.");
|
||||
|
||||
return altarRecipes.remove(recipe);
|
||||
}
|
||||
|
||||
public boolean removeAlchemyTable(@Nonnull RecipeAlchemyTable recipe) {
|
||||
Preconditions.checkNotNull(recipe, "recipe cannot be null.");
|
||||
|
||||
return alchemyRecipes.remove(recipe);
|
||||
}
|
||||
|
||||
public boolean removeTartaricForge(@Nonnull RecipeTartaricForge recipe) {
|
||||
Preconditions.checkNotNull(recipe, "recipe cannot be null.");
|
||||
|
||||
return tartaricForgeRecipes.remove(recipe);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public RecipeBloodAltar getBloodAltar(@Nonnull ItemStack input) {
|
||||
Preconditions.checkNotNull(input, "input cannot be null.");
|
||||
|
|
|
@ -1,34 +0,0 @@
|
|||
package WayofTime.bloodmagic.api_impl.recipe;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.Ingredient;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class IngredientTester {
|
||||
|
||||
public static boolean compareIngredients(Ingredient ingredient1, Ingredient ingredient2) {
|
||||
ItemStack[] stacks1 = ingredient1.getMatchingStacks();
|
||||
ItemStack[] stacks2 = ingredient2.getMatchingStacks();
|
||||
|
||||
if (stacks1.length != stacks2.length)
|
||||
return false;
|
||||
|
||||
for (int i = 0; i < stacks1.length; i++)
|
||||
if (!ItemStack.areItemStacksEqualUsingNBTShareTag(stacks1[i], stacks2[i]))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean compareIngredients(List<Ingredient> ingredients1, List<Ingredient> ingredients2) {
|
||||
if (ingredients1.size() != ingredients2.size())
|
||||
return false;
|
||||
|
||||
for (int i = 0; i < ingredients1.size(); i++)
|
||||
if (!compareIngredients(ingredients1.get(i), ingredients2.get(i)))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -56,28 +56,4 @@ public class RecipeAlchemyTable {
|
|||
public final int getMinimumTier() {
|
||||
return minimumTier;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof RecipeAlchemyTable)) return false;
|
||||
|
||||
RecipeAlchemyTable that = (RecipeAlchemyTable) o;
|
||||
|
||||
if (syphon != that.syphon) return false;
|
||||
if (ticks != that.ticks) return false;
|
||||
if (minimumTier != that.minimumTier) return false;
|
||||
if (!IngredientTester.compareIngredients(input, that.input)) return false;
|
||||
return ItemStack.areItemStacksEqualUsingNBTShareTag(output, that.output);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = input.hashCode();
|
||||
result = 31 * result + output.hashCode();
|
||||
result = 31 * result + syphon;
|
||||
result = 31 * result + ticks;
|
||||
result = 31 * result + minimumTier;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ public class RecipeBloodAltar {
|
|||
public RecipeBloodAltar(@Nonnull Ingredient input, @Nonnull ItemStack output, @Nonnegative int minimumTier, @Nonnegative int syphon, @Nonnegative int consumeRate, @Nonnegative int drainRate) {
|
||||
Preconditions.checkNotNull(input, "input cannot be null.");
|
||||
Preconditions.checkNotNull(output, "output cannot be null.");
|
||||
Preconditions.checkNotNull(minimumTier, "minimumTier cannot be negative.");
|
||||
Preconditions.checkArgument(minimumTier >= 0, "minimumTier cannot be negative.");
|
||||
Preconditions.checkArgument(minimumTier <= EnumAltarTier.MAXTIERS, "minimumTier cannot be higher than max tier");
|
||||
Preconditions.checkArgument(syphon >= 0, "syphon cannot be negative.");
|
||||
Preconditions.checkArgument(consumeRate >= 0, "consumeRate cannot be negative.");
|
||||
|
@ -69,28 +69,4 @@ public class RecipeBloodAltar {
|
|||
public final int getDrainRate() {
|
||||
return drainRate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof RecipeBloodAltar)) return false;
|
||||
|
||||
RecipeBloodAltar that = (RecipeBloodAltar) o;
|
||||
|
||||
if (minimumTier != that.minimumTier) return false;
|
||||
if (syphon != that.syphon) return false;
|
||||
if (drainRate != that.drainRate) return false;
|
||||
if (!IngredientTester.compareIngredients(input, that.input)) return false;
|
||||
return ItemStack.areItemStacksEqualUsingNBTShareTag(output, that.output);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = input.hashCode();
|
||||
result = 31 * result + output.hashCode();
|
||||
result = 31 * result + minimumTier.ordinal();
|
||||
result = 31 * result + syphon;
|
||||
result = 31 * result + drainRate;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -50,30 +50,4 @@ public class RecipeTartaricForge {
|
|||
public final double getSoulDrain() {
|
||||
return soulDrain;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof RecipeTartaricForge)) return false;
|
||||
|
||||
RecipeTartaricForge that = (RecipeTartaricForge) o;
|
||||
|
||||
if (minimumSouls != that.minimumSouls) return false;
|
||||
if (soulDrain != that.soulDrain) return false;
|
||||
if (!IngredientTester.compareIngredients(input, that.input)) return false;
|
||||
return ItemStack.areItemStacksEqualUsingNBTShareTag(output, that.output);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result;
|
||||
long temp;
|
||||
result = input.hashCode();
|
||||
result = 31 * result + output.hashCode();
|
||||
temp = Double.doubleToLongBits(minimumSouls);
|
||||
result = 31 * result + (int) (temp ^ (temp >>> 32));
|
||||
temp = Double.doubleToLongBits(soulDrain);
|
||||
result = 31 * result + (int) (temp ^ (temp >>> 32));
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,7 +10,13 @@ public interface IBloodMagicRecipeRegistrar {
|
|||
|
||||
void addBloodAltar(@Nonnull Ingredient input, @Nonnull ItemStack output, @Nonnegative int minimumTier, @Nonnegative int syphon, @Nonnegative int consumeRate, @Nonnegative int drainRate);
|
||||
|
||||
boolean removeBloodAltar(@Nonnull ItemStack input);
|
||||
|
||||
void addAlchemyTable(@Nonnull ItemStack output, @Nonnegative int syphon, @Nonnegative int ticks, @Nonnegative int minimumTier, @Nonnull Ingredient... input);
|
||||
|
||||
boolean removeAlchemyTable(@Nonnull ItemStack... input);
|
||||
|
||||
void addTartaricForge(@Nonnull ItemStack output, @Nonnegative double minimumSouls, @Nonnegative double soulDrain, @Nonnull Ingredient... input);
|
||||
|
||||
boolean removeTartaricForge(@Nonnull ItemStack... input);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue