diff --git a/examples/postInit/immersiveengineering.groovy b/examples/postInit/immersiveengineering.groovy index ad9895b28..10dbf4a68 100644 --- a/examples/postInit/immersiveengineering.groovy +++ b/examples/postInit/immersiveengineering.groovy @@ -116,7 +116,7 @@ mods.immersiveengineering.coke_oven.recipeBuilder() // Crusher: -// Converts an input itemstack into an output itemstack, consuming energy. +// Converts an input itemstack into an output itemstack with optional additional chanced item outputs, consuming energy. mods.immersiveengineering.crusher.removeByInput(item('immersiveengineering:material:7')) mods.immersiveengineering.crusher.removeByOutput(item('minecraft:sand')) @@ -128,6 +128,14 @@ mods.immersiveengineering.crusher.recipeBuilder() .energy(100) .register() +mods.immersiveengineering.crusher.recipeBuilder() + .input(item('minecraft:diamond_block')) + .output(item('minecraft:diamond')) + .secondaryOutput(item('minecraft:gold_ingot')) + .secondaryOutput(item('minecraft:gold_ingot'), 0.3) + .energy(100) + .register() + // Excavator: diff --git a/src/main/java/com/cleanroommc/groovyscript/compat/mods/immersiveengineering/Crusher.java b/src/main/java/com/cleanroommc/groovyscript/compat/mods/immersiveengineering/Crusher.java index 56ad2ccac..fe6e97058 100644 --- a/src/main/java/com/cleanroommc/groovyscript/compat/mods/immersiveengineering/Crusher.java +++ b/src/main/java/com/cleanroommc/groovyscript/compat/mods/immersiveengineering/Crusher.java @@ -10,14 +10,19 @@ import com.cleanroommc.groovyscript.helper.recipe.AbstractRecipeBuilder; import com.cleanroommc.groovyscript.registry.VirtualizedRegistry; import net.minecraft.item.ItemStack; +import org.apache.commons.lang3.ArrayUtils; import org.jetbrains.annotations.Nullable; +import java.util.ArrayList; import java.util.List; @RegistryDescription public class Crusher extends VirtualizedRegistry { - @RecipeBuilderDescription(example = @Example(".input(item('minecraft:diamond')).output(item('minecraft:clay')).energy(100)")) + @RecipeBuilderDescription(example = { + @Example(".input(item('minecraft:diamond')).output(item('minecraft:clay')).energy(100)"), + @Example(".input(item('minecraft:diamond_block')).output(item('minecraft:diamond')).secondaryOutput(item('minecraft:gold_ingot')).secondaryOutput(item('minecraft:gold_ingot'), 0.3).energy(100)") + }) public static RecipeBuilder recipeBuilder() { return new RecipeBuilder(); } @@ -103,9 +108,25 @@ public void removeAll() { @Property(property = "output", valid = @Comp("1")) public static class RecipeBuilder extends AbstractRecipeBuilder { + @Property(valid = @Comp("secondaryOutputChances")) + private final List secondaryOutputItems = new ArrayList<>(); + @Property(valid = @Comp("secondaryOutputItems")) + private final List secondaryOutputChances = new ArrayList<>(); @Property(valid = @Comp(value = "0", type = Comp.Type.GTE)) private int energy; + @RecipeBuilderMethodDescription(field = {"secondaryOutputItems", "secondaryOutputChances"}) + public RecipeBuilder secondaryOutput(ItemStack item) { + return this.secondaryOutput(item, 1); + } + + @RecipeBuilderMethodDescription(field = {"secondaryOutputItems", "secondaryOutputChances"}) + public RecipeBuilder secondaryOutput(ItemStack item, float chance) { + this.secondaryOutputItems.add(item); + this.secondaryOutputChances.add(chance); + return this; + } + @RecipeBuilderMethodDescription public RecipeBuilder energy(int energy) { this.energy = energy; @@ -121,6 +142,7 @@ public String getErrorMsg() { public void validate(GroovyLog.Msg msg) { validateItems(msg, 1, 1, 1, 1); validateFluids(msg); + msg.add(secondaryOutputItems.size() != secondaryOutputChances.size(), "secondaryOutputItems and secondaryOutputChances must be of equal length, yet secondaryOutputItems was {} and secondaryOutputChances was {}", secondaryOutputItems.size(), secondaryOutputChances.size()); if (energy < 0) energy = 200; } @@ -129,6 +151,11 @@ public void validate(GroovyLog.Msg msg) { public @Nullable CrusherRecipe register() { if (!validate()) return null; CrusherRecipe recipe = new CrusherRecipe(output.get(0), input.get(0), energy); + if (!secondaryOutputItems.isEmpty()) { + recipe.secondaryOutput = secondaryOutputItems.toArray(new ItemStack[0]); + recipe.secondaryChance = ArrayUtils.toPrimitive(secondaryOutputChances.toArray(new Float[0])); + recipe.getItemOutputs().addAll(secondaryOutputItems); + } ModSupport.IMMERSIVE_ENGINEERING.get().crusher.add(recipe); return recipe; } diff --git a/src/main/resources/assets/groovyscript/lang/en_us.lang b/src/main/resources/assets/groovyscript/lang/en_us.lang index 6dddea30a..704556cc0 100644 --- a/src/main/resources/assets/groovyscript/lang/en_us.lang +++ b/src/main/resources/assets/groovyscript/lang/en_us.lang @@ -932,9 +932,11 @@ groovyscript.wiki.immersiveengineering.coke_oven.creosote.value=Sets the amount groovyscript.wiki.immersiveengineering.coke_oven.time.value=Sets the time in ticks the recipe takes to process groovyscript.wiki.immersiveengineering.crusher.title=Crusher -groovyscript.wiki.immersiveengineering.crusher.description=Converts an input itemstack into an output itemstack, consuming energy. +groovyscript.wiki.immersiveengineering.crusher.description=Converts an input itemstack into an output itemstack with optional additional chanced item outputs, consuming energy. groovyscript.wiki.immersiveengineering.crusher.add=Adds recipes in the format `output`, `input`, `energy` groovyscript.wiki.immersiveengineering.crusher.energy.value=Sets the amount of power consumed to complete the recipe +groovyscript.wiki.immersiveengineering.crusher.secondaryOutputItems.value=Sets the additional items output by the recipe, if any +groovyscript.wiki.immersiveengineering.crusher.secondaryOutputChances.value=Sets the chance of the respective additional items output by the recipe groovyscript.wiki.immersiveengineering.excavator.title=Excavator groovyscript.wiki.immersiveengineering.excavator.description=Adds a Mineral Mix with the given name, weight, fail chance, ores, and allowed dimensions. A Mineral Mix can be mined by an Excavator Multiblock and scanned via a Core Sample Drill.