Skip to content

Commit

Permalink
Create recipes using a RecipeBuilder in more situations (#202)
Browse files Browse the repository at this point in the history
* add more ability to add aspects to infusion and crucible

* add lens to Atomic Reconstructor Recipe Builder

* convert complex add methods to use builder

* make Crucible Recipe Builder register method create recipe

* adjust Elven Trade add shorthand methods
  • Loading branch information
WaitingIdly authored Jul 24, 2024
1 parent e8a7443 commit 8911f99
Show file tree
Hide file tree
Showing 36 changed files with 148 additions and 311 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import de.ellpeck.actuallyadditions.api.lens.Lens;
import de.ellpeck.actuallyadditions.api.recipe.LensConversionRecipe;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.Ingredient;
import org.jetbrains.annotations.Nullable;

@RegistryDescription
Expand All @@ -35,10 +34,13 @@ public void onReload() {
ActuallyAdditionsAPI.RECONSTRUCTOR_LENS_CONVERSION_RECIPES.addAll(restoreFromBackup());
}

public LensConversionRecipe add(Ingredient input, ItemStack output, int energy, Lens type) {
LensConversionRecipe recipe = new LensConversionRecipe(input, output, energy, type);
add(recipe);
return recipe;
public LensConversionRecipe add(IIngredient input, ItemStack output, int energy, Lens type) {
return recipeBuilder()
.type(type)
.energy(energy)
.input(input)
.output(output)
.register();
}

public void add(LensConversionRecipe recipe) {
Expand Down Expand Up @@ -94,6 +96,8 @@ public static class RecipeBuilder extends AbstractRecipeBuilder<LensConversionRe

@Property(defaultValue = "1", valid = @Comp(type = Comp.Type.GT, value = "0"))
private int energyUse = 1;
@Property(defaultValue = "ActuallyAdditionsAPI.lensDefaultConversion", valid = @Comp(value = "null", type = Comp.Type.NOT))
private Lens type = ActuallyAdditionsAPI.lensDefaultConversion;

@RecipeBuilderMethodDescription
public RecipeBuilder energyUse(int energyUse) {
Expand All @@ -107,6 +111,12 @@ public RecipeBuilder energy(int energy) {
return this;
}

@RecipeBuilderMethodDescription
public RecipeBuilder type(Lens type) {
this.type = type;
return this;
}

@Override
public String getErrorMsg() {
return "Error adding Actually Additions Atomic Reconstructor recipe";
Expand All @@ -117,13 +127,14 @@ public void validate(GroovyLog.Msg msg) {
validateItems(msg, 1, 1, 1, 1);
validateFluids(msg);
msg.add(energyUse <= 0, "energyUse must be an integer greater than 0, yet it was {}", energyUse);
msg.add(type == null, "type must not be null!");
}

@Override
@RecipeBuilderRegistrationMethod
public @Nullable LensConversionRecipe register() {
if (!validate()) return null;
LensConversionRecipe recipe = new LensConversionRecipe(input.get(0).toMcIngredient(), output.get(0), energyUse, ActuallyAdditionsAPI.lensDefaultConversion);
LensConversionRecipe recipe = new LensConversionRecipe(input.get(0).toMcIngredient(), output.get(0), energyUse, type);
ModSupport.ACTUALLY_ADDITIONS.get().atomicReconstructor.add(recipe);
return recipe;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public RecipeBuilder recipeBuilder() {

@MethodDescription(type = MethodDescription.Type.ADDITION)
public AtomizerRecipe add(FluidStack input, ItemStack output) {
return new RecipeBuilder().fluidInput(input).output(output).register();
return recipeBuilder().fluidInput(input).output(output).register();
}

public AtomizerRecipe add(AtomizerRecipe recipe) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public RecipeBuilder recipeBuilder() {

@MethodDescription(type = MethodDescription.Type.ADDITION)
public EvaporatorRecipe add(FluidStack input, ItemStack output) {
return new RecipeBuilder().fluidInput(input).output(output).register();
return recipeBuilder().fluidInput(input).output(output).register();
}

public EvaporatorRecipe add(EvaporatorRecipe recipe) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public RecipeBuilder recipeBuilder() {

@MethodDescription(type = MethodDescription.Type.ADDITION)
public LiquifierRecipe add(IIngredient input, FluidStack output) {
return new RecipeBuilder().input(input).fluidOutput(output).register();
return recipeBuilder().input(input).fluidOutput(output).register();
}

public LiquifierRecipe add(LiquifierRecipe recipe) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import com.cleanroommc.groovyscript.helper.recipe.AbstractRecipeBuilder;
import com.cleanroommc.groovyscript.registry.VirtualizedRegistry;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.Ingredient;
import net.minecraft.util.ResourceLocation;
import org.jetbrains.annotations.Nullable;

Expand All @@ -36,22 +35,27 @@ public void onReload() {
}

@MethodDescription(description = "groovyscript.wiki.bloodmagic.alchemy_array.add0", type = MethodDescription.Type.ADDITION)
public RecipeAlchemyArray add(Ingredient input, Ingredient catalyst, ItemStack output) {
RecipeAlchemyArray recipe = new RecipeAlchemyArray(input, catalyst, output, null);
add(recipe);
return recipe;
public RecipeAlchemyArray add(IIngredient input, IIngredient catalyst, ItemStack output) {
return recipeBuilder()
.catalyst(catalyst)
.input(input)
.output(output)
.register();
}

@MethodDescription(description = "groovyscript.wiki.bloodmagic.alchemy_array.add1", type = MethodDescription.Type.ADDITION)
public RecipeAlchemyArray add(Ingredient input, Ingredient catalyst, ItemStack output, String circleTexture) {
public RecipeAlchemyArray add(IIngredient input, IIngredient catalyst, ItemStack output, String circleTexture) {
return add(input, catalyst, output, new ResourceLocation(circleTexture));
}

@MethodDescription(description = "groovyscript.wiki.bloodmagic.alchemy_array.add1", type = MethodDescription.Type.ADDITION)
public RecipeAlchemyArray add(Ingredient input, Ingredient catalyst, ItemStack output, ResourceLocation circleTexture) {
RecipeAlchemyArray recipe = new RecipeAlchemyArray(input, catalyst, output, circleTexture);
add(recipe);
return recipe;
public RecipeAlchemyArray add(IIngredient input, IIngredient catalyst, ItemStack output, ResourceLocation circleTexture) {
return recipeBuilder()
.catalyst(catalyst)
.texture(circleTexture)
.input(input)
.output(output)
.register();
}

public void add(RecipeAlchemyArray recipe) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import com.cleanroommc.groovyscript.helper.recipe.AbstractRecipeBuilder;
import com.cleanroommc.groovyscript.registry.VirtualizedRegistry;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.Ingredient;
import org.jetbrains.annotations.Nullable;

@RegistryDescription(
Expand Down Expand Up @@ -44,10 +43,14 @@ public void onReload() {
}

@MethodDescription(type = MethodDescription.Type.ADDITION)
public RecipeBloodAltar add(Ingredient input, ItemStack output, int minimumTier, int syphon, int consumeRate, int drainRate) {
RecipeBloodAltar recipe = new RecipeBloodAltar(input, output, minimumTier, syphon, consumeRate, drainRate);
add(recipe);
return recipe;
public RecipeBloodAltar add(IIngredient input, ItemStack output, int minimumTier, int syphon, int consumeRate, int drainRate) {
return recipeBuilder()
.minimumTier(minimumTier)
.consumeRate(consumeRate)
.drainRate(drainRate)
.input(input)
.output(output)
.register();
}

public void add(RecipeBloodAltar recipe) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import net.minecraft.util.NonNullList;
import org.jetbrains.annotations.Nullable;

import java.util.Collection;
import java.util.Collections;

@RegistryDescription
Expand All @@ -38,21 +39,13 @@ public void onReload() {
}

@MethodDescription(type = MethodDescription.Type.ADDITION)
public RecipeTartaricForge add(NonNullList<Ingredient> input, ItemStack output, double minimumSouls, double soulDrain) {
double minimum;
if (minimumSouls < soulDrain) {
GroovyLog.msg("Warning creating Blood Magic Tartaric Forge recipe")
.add("minimumSouls should be greater than soulDrain, yet minimumSouls was {} and soulDrain was {}", minimumSouls, soulDrain)
.add("set minimumSouls equal to soulDrain")
.warn()
.post();
minimum = soulDrain;
} else {
minimum = minimumSouls;
}
RecipeTartaricForge recipe = new RecipeTartaricForge(input, output, minimum, soulDrain);
add(recipe);
return recipe;
public RecipeTartaricForge add(Collection<IIngredient> input, ItemStack output, double minimumSouls, double soulDrain) {
return recipeBuilder()
.soulDrain(soulDrain)
.minimumSouls(minimumSouls)
.output(output)
.input(input)
.register();
}

public void add(RecipeTartaricForge recipe) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ public void onReload() {

@MethodDescription(type = MethodDescription.Type.ADDITION)
public RecipePetals add(ItemStack output, IIngredient... inputs) {
RecipePetals recipe = new RecipePetals(output, Arrays.stream(inputs).map(i -> i instanceof OreDictIngredient ? ((OreDictIngredient) i).getOreDict()
: i.getMatchingStacks()[0]).toArray());
add(recipe);
return recipe;
return recipeBuilder()
.output(output)
.input(inputs)
.register();
}

public void add(RecipePetals recipe) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import vazkii.botania.api.recipe.RecipeElvenTrade;

import java.util.Arrays;
import java.util.Collection;
import java.util.List;

@RegistryDescription
Expand All @@ -37,15 +38,23 @@ protected Object[] convertIngredients(IIngredient[] inputs) {
}

@MethodDescription(type = MethodDescription.Type.ADDITION)
public RecipeElvenTrade add(ItemStack[] outputs, IIngredient[] inputs) {
RecipeElvenTrade recipe = new RecipeElvenTrade(outputs, convertIngredients(inputs));
add(recipe);
return recipe;
public RecipeElvenTrade add(ItemStack[] outputs, IIngredient... inputs) {
return recipeBuilder().input(inputs).output(outputs).register();
}

@MethodDescription(type = MethodDescription.Type.ADDITION)
public RecipeElvenTrade add(ItemStack output, IIngredient[] inputs) {
return add(new ItemStack[]{output}, inputs);
public RecipeElvenTrade add(Collection<ItemStack> outputs, Collection<IIngredient> inputs) {
return recipeBuilder().input(inputs).output(outputs).register();
}

@MethodDescription(type = MethodDescription.Type.ADDITION)
public RecipeElvenTrade add(ItemStack output, IIngredient... inputs) {
return recipeBuilder().input(inputs).output(output).register();
}

@MethodDescription(type = MethodDescription.Type.ADDITION)
public RecipeElvenTrade add(ItemStack output, Collection<IIngredient> inputs) {
return recipeBuilder().input(inputs).output(output).register();
}

public void add(RecipeElvenTrade recipe) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,14 +251,12 @@ public void onReload() {

@MethodDescription(type = MethodDescription.Type.ADDITION)
public LexiconEntry add(String name, LexiconCategory category) {
LexiconEntry entry = new LexiconEntry(name, category);
add(entry);
return entry;
return entryBuilder().name(name).category(category).register();
}

@MethodDescription(type = MethodDescription.Type.ADDITION)
public LexiconEntry add(String name, String category) {
return add(name, Botania.getCategory(category));
return entryBuilder().name(name).category(category).register();
}

public void add(LexiconEntry entry) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,7 @@ public void onReload() {

@MethodDescription(type = MethodDescription.Type.ADDITION)
public RecipeManaInfusion add(ItemStack output, IIngredient input, int mana) {
RecipeManaInfusion recipe = new RecipeManaInfusion(output, input instanceof OreDictIngredient ? ((OreDictIngredient) input).getOreDict()
: input.getMatchingStacks()[0], mana);
add(recipe);
return recipe;
return recipeBuilder().mana(mana).output(output).input(input).register();
}

public void add(RecipeManaInfusion recipe) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,12 @@ public void onReload() {

@MethodDescription(description = "groovyscript.wiki.botania.pure_daisy.add0", type = MethodDescription.Type.ADDITION)
public RecipePureDaisy add(IBlockState output, IBlockState input, int time) {
RecipePureDaisy recipe = new RecipePureDaisy(input, output, time);
add(recipe);
return recipe;
return recipeBuilder().time(time).output(output).input(input).register();
}

@MethodDescription(description = "groovyscript.wiki.botania.pure_daisy.add1", type = MethodDescription.Type.ADDITION)
public RecipePureDaisy add(IBlockState output, IBlockState input) {
return add(output, input, RecipePureDaisy.DEFAULT_TIME);
return recipeBuilder().output(output).input(input).register();
}

public void add(RecipePureDaisy recipe) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,7 @@ public void onReload() {

@MethodDescription(type = MethodDescription.Type.ADDITION)
public RecipeRuneAltar add(ItemStack output, int mana, IIngredient... inputs) {
RecipeRuneAltar recipe = new RecipeRuneAltar(output, mana, Arrays.stream(inputs).map(i -> i instanceof OreDictIngredient
? ((OreDictIngredient) i).getOreDict()
: i.getMatchingStacks()[0]).toArray());
add(recipe);
return recipe;
return recipeBuilder().mana(mana).output(output).input(inputs).register();
}

public void add(RecipeRuneAltar recipe) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ public void onReload() {
}

public IMoistenerRecipe add(ItemStack output, IIngredient input, int time) {
IMoistenerRecipe recipe = new MoistenerRecipe(input.getMatchingStacks()[0], output, time);
add(recipe);
return recipe;
return recipeBuilder().time(time).output(output).input(input).register();
}

public void add(IMoistenerRecipe recipe) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,8 @@ public void onReload() {
restoreFromBackup().forEach(SqueezerRecipeManagerAccessor.getRecipes()::add);
}

public ISqueezerRecipe add(FluidStack output, IIngredient remnant, int time, int remnantChance, IIngredient... inputs) {
ISqueezerRecipe recipe = new SqueezerRecipe(time, NonNullList.from(ItemStack.EMPTY, Arrays.stream(inputs).map(i -> i.getMatchingStacks()[0]).toArray(ItemStack[]::new)), output, remnant.getMatchingStacks()[0], remnantChance);
add(recipe);
return recipe;
public ISqueezerRecipe add(FluidStack output, ItemStack remnant, int time, int remnantChance, IIngredient... inputs) {
return recipeBuilder().chance(remnantChance).time(time).output(remnant).fluidOutput(output).input(inputs).register();
}

public void add(ISqueezerRecipe recipe) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ public void onReload() {
}

public IStillRecipe add(FluidStack output, int time, FluidStack input) {
IStillRecipe recipe = new StillRecipe(time, input, output);
add(recipe);
return recipe;
return recipeBuilder().time(time).fluidOutput(output).fluidInput(input).register();
}

public void add(IStillRecipe recipe) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,7 @@ public RecipeBuilder recipeBuilder() {

@MethodDescription(type = MethodDescription.Type.ADDITION, example = @Example(value = "gas('copper') * 10, gas('iron'), gas('gold') * 15", commented = true))
public ChemicalInfuserRecipe add(GasStack leftInput, GasStack rightInput, GasStack output) {
GroovyLog.Msg msg = GroovyLog.msg("Error adding Mekanism Chemical Infuser recipe").error();
msg.add(Mekanism.isEmpty(leftInput), () -> "left gas input must not be empty");
msg.add(Mekanism.isEmpty(rightInput), () -> "right gas input must not be empty");
msg.add(Mekanism.isEmpty(output), () -> "gas output must not be empty");
if (msg.postIfNotEmpty()) return null;

ChemicalInfuserRecipe recipe = new ChemicalInfuserRecipe(leftInput, rightInput, output);
addScripted(recipe);
recipeRegistry.put(recipe);
return recipe;
return recipeBuilder().gasInput(leftInput, rightInput).gasOutput(output).register();
}

@MethodDescription(example = @Example("gas('hydrogen'), gas('chlorine')"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,7 @@ public RecipeBuilder recipeBuilder() {

@MethodDescription(type = MethodDescription.Type.ADDITION, example = @Example(value = "ore('dustGold'), gas('gold')", commented = true))
public OxidationRecipe add(IIngredient ingredient, GasStack output) {
GroovyLog.Msg msg = GroovyLog.msg("Error adding Mekanism Oxidizer recipe").error();
msg.add(IngredientHelper.isEmpty(ingredient), () -> "input must not be empty");
msg.add(Mekanism.isEmpty(output), () -> "output must not be empty");
if (msg.postIfNotEmpty()) return null;

OxidationRecipe recipe1 = null;
for (ItemStack itemStack : ingredient.getMatchingStacks()) {
OxidationRecipe recipe = new OxidationRecipe(itemStack, output);
if (recipe1 == null) recipe1 = recipe;
recipeRegistry.put(recipe);
addScripted(recipe);
}
return recipe1;
return recipeBuilder().gasOutput(output).input(ingredient).register();
}

@MethodDescription(example = @Example("ore('dustSulfur')"))
Expand Down
Loading

0 comments on commit 8911f99

Please sign in to comment.