Alchemy arrays should mostly function now (#1202)

Rewrites the crafting recipe portion of alchemy arrays. Currently the rewritten
portion is wrapped in the old stuff. Ideally the remaining old stuff will
be rewritten as well.

Mods who wish to do custom array effects still need to depend on internal
classes and I think this is fine.
This commit is contained in:
Nicholas Ignoffo 2018-02-11 11:40:13 -08:00
parent 4b5f8a9685
commit 123b06c288
10 changed files with 239 additions and 34 deletions

View file

@ -2,9 +2,11 @@ package WayofTime.bloodmagic.api;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.Ingredient;
import net.minecraft.util.ResourceLocation;
import javax.annotation.Nonnegative;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
/**
* Allows recipe addition and removal.
@ -44,7 +46,7 @@ public interface IBloodMagicRecipeRegistrar {
void addAlchemyTable(@Nonnull ItemStack output, @Nonnegative int syphon, @Nonnegative int ticks, @Nonnegative int minimumTier, @Nonnull Ingredient... input);
/**
* Removes an Alchemy Table recipe based on an input {@link Ingredient} array.
* Removes an Alchemy Table recipe based on an input {@link ItemStack} array.
*
* @param input The input items to remove the recipe of.
*
@ -63,11 +65,31 @@ public interface IBloodMagicRecipeRegistrar {
void addTartaricForge(@Nonnull ItemStack output, @Nonnegative double minimumSouls, @Nonnegative double soulDrain, @Nonnull Ingredient... input);
/**
* Removes a Soul/Tartaric Forge recipe based on an input {@link Ingredient} array.
* Removes a Soul/Tartaric Forge recipe based on an input {@link ItemStack} array.
*
* @param input The input items to remove the recipe of.
*
* @return Whether or not a recipe was removed.
*/
boolean removeTartaricForge(@Nonnull ItemStack... input);
/**
* Adds a new recipe to the Alchemy Array.
*
* @param input An input {@link Ingredient}. First item put into the Alchemy Array.
* @param catalyst A catalyst {@link Ingredient}. Second item put into the Alchemy Array.
* @param output An output {@link ItemStack}.
* @param circleTexture The texture to render for the Alchemy Array circle.
*/
void addAlchemyArray(@Nonnull Ingredient input, @Nonnull Ingredient catalyst, @Nonnull ItemStack output, @Nullable ResourceLocation circleTexture);
/**
* Removes an Alchemy Array recipe based on an input {@link ItemStack} and it's catalyst {@link ItemStack}.
*
* @param input The input item to remove the recipe of.
* @param catalyst The catalyst item to remove the recipe of.
*
* @return Whether or not a recipe was removed.
*/
boolean removeAlchemyArray(@Nonnull ItemStack input, @Nonnull ItemStack catalyst);
}

View file

@ -82,6 +82,7 @@ public class BloodMagicCorePlugin implements IBloodMagicPlugin {
RegistrarBloodMagicRecipes.registerAltarRecipes(api.getRecipeRegistrar());
RegistrarBloodMagicRecipes.registerAlchemyTableRecipes(api.getRecipeRegistrar());
RegistrarBloodMagicRecipes.registerTartaricForgeRecipes(api.getRecipeRegistrar());
RegistrarBloodMagicRecipes.registerAlchemyArrayRecipes(api.getRecipeRegistrar());
}
private static void handleConfigValues(BloodMagicAPI api) {

View file

@ -1,6 +1,7 @@
package WayofTime.bloodmagic.api.impl;
import WayofTime.bloodmagic.api.IBloodMagicRecipeRegistrar;
import WayofTime.bloodmagic.api.impl.recipe.RecipeAlchemyArray;
import WayofTime.bloodmagic.api.impl.recipe.RecipeAlchemyTable;
import WayofTime.bloodmagic.api.impl.recipe.RecipeBloodAltar;
import WayofTime.bloodmagic.api.impl.recipe.RecipeTartaricForge;
@ -13,6 +14,7 @@ import com.google.common.collect.Sets;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.Ingredient;
import net.minecraft.util.NonNullList;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.common.crafting.CraftingHelper;
import javax.annotation.Nonnegative;
@ -26,11 +28,13 @@ public class BloodMagicRecipeRegistrar implements IBloodMagicRecipeRegistrar {
private final Set<RecipeBloodAltar> altarRecipes;
private final Set<RecipeAlchemyTable> alchemyRecipes;
private final Set<RecipeTartaricForge> tartaricForgeRecipes;
private final Set<RecipeAlchemyArray> alchemyArrayRecipes;
public BloodMagicRecipeRegistrar() {
this.altarRecipes = Sets.newHashSet();
this.alchemyRecipes = Sets.newHashSet();
this.tartaricForgeRecipes = Sets.newHashSet();
this.alchemyArrayRecipes = Sets.newHashSet();
}
@Override
@ -138,6 +142,31 @@ public class BloodMagicRecipeRegistrar implements IBloodMagicRecipeRegistrar {
addTartaricForge(output, minimumSouls, soulDrain, ingredients.toArray(new Ingredient[0]));
}
@Override
public void addAlchemyArray(@Nonnull Ingredient input, @Nonnull Ingredient catalyst, @Nonnull ItemStack output, @Nullable ResourceLocation circleTexture) {
Preconditions.checkNotNull(input, "input cannot be null.");
Preconditions.checkNotNull(catalyst, "catalyst cannot be null.");
Preconditions.checkNotNull(output, "output cannot be null.");
alchemyArrayRecipes.add(new RecipeAlchemyArray(input, catalyst, output, circleTexture));
}
@Override
public boolean removeAlchemyArray(@Nonnull ItemStack input, @Nonnull ItemStack catalyst) {
Preconditions.checkNotNull(input, "input cannot be null.");
Preconditions.checkNotNull(catalyst, "catalyst cannot be null.");
return alchemyArrayRecipes.remove(getAlchemyArray(input, catalyst));
}
public void addAlchemyArray(@Nonnull ItemStack input, @Nonnull ItemStack catalyst, @Nonnull ItemStack output, @Nullable ResourceLocation circleTexture) {
Preconditions.checkNotNull(input, "input cannot be null.");
Preconditions.checkNotNull(catalyst, "catalyst cannot be null.");
Preconditions.checkNotNull(output, "output cannot be null.");
addAlchemyArray(Ingredient.fromStacks(input), Ingredient.fromStacks(catalyst), output, circleTexture);
}
@Nullable
public RecipeBloodAltar getBloodAltar(@Nonnull ItemStack input) {
Preconditions.checkNotNull(input, "input cannot be null.");
@ -201,6 +230,19 @@ public class BloodMagicRecipeRegistrar implements IBloodMagicRecipeRegistrar {
return null;
}
@Nullable
public RecipeAlchemyArray getAlchemyArray(@Nonnull ItemStack input, @Nonnull ItemStack catalyst) {
Preconditions.checkNotNull(input, "input cannot be null.");
if (input.isEmpty())
return null;
for (RecipeAlchemyArray recipe : alchemyArrayRecipes)
if (recipe.getInput().test(input) && recipe.getCatalyst().test(catalyst))
return recipe;
return null;
}
public Set<RecipeBloodAltar> getAltarRecipes() {
return ImmutableSet.copyOf(altarRecipes);
}
@ -212,4 +254,8 @@ public class BloodMagicRecipeRegistrar implements IBloodMagicRecipeRegistrar {
public Set<RecipeTartaricForge> getTartaricForgeRecipes() {
return ImmutableSet.copyOf(tartaricForgeRecipes);
}
public Set<RecipeAlchemyArray> getAlchemyArrayRecipes() {
return ImmutableSet.copyOf(alchemyArrayRecipes);
}
}

View file

@ -0,0 +1,53 @@
package WayofTime.bloodmagic.api.impl.recipe;
import WayofTime.bloodmagic.BloodMagic;
import com.google.common.base.Preconditions;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.Ingredient;
import net.minecraft.util.ResourceLocation;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
public class RecipeAlchemyArray {
@Nonnull
private final Ingredient input;
@Nonnull
private final Ingredient catalyst;
@Nonnull
private final ItemStack output;
@Nonnull
private final ResourceLocation circleTexture;
public RecipeAlchemyArray(@Nonnull Ingredient input, @Nonnull Ingredient catalyst, @Nonnull ItemStack output, @Nullable ResourceLocation circleTexture) {
Preconditions.checkNotNull(input, "input cannot be null.");
Preconditions.checkNotNull(catalyst, "catalyst cannot be null.");
Preconditions.checkNotNull(output, "output cannot be null.");
this.input = input;
this.catalyst = catalyst;
this.output = output;
this.circleTexture = circleTexture == null ? new ResourceLocation(BloodMagic.MODID, "textures/models/AlchemyArrays/WIPArray.png") : circleTexture;
}
@Nonnull
public Ingredient getInput() {
return input;
}
@Nonnull
public Ingredient getCatalyst() {
return catalyst;
}
@Nonnull
public ItemStack getOutput() {
return output;
}
@Nonnull
public ResourceLocation getCircleTexture() {
return circleTexture;
}
}