From 9065eb255bed6628508e1f397e5f5c5657d20004 Mon Sep 17 00:00:00 2001 From: Waiting Idly <25394029+WaitingIdly@users.noreply.github.com> Date: Sun, 6 Oct 2024 10:02:55 -0700 Subject: [PATCH] add Magneticraft compat (#255) * Magneticraft compat * add shorthand methods for the Hydraulic Press Mode * adjust chance methods * remove unused files * remove oreDict and defer to OreDictIngredient * apply chances to sieve --- dependencies.gradle | 4 +- examples/postInit/magneticraft.groovy | 215 ++++++++++++++++++ gradle.properties | 1 + .../groovyscript/compat/mods/ModSupport.java | 2 + .../mods/magneticraft/CrushingTable.java | 83 +++++++ .../mods/magneticraft/GasificationUnit.java | 103 +++++++++ .../compat/mods/magneticraft/Grinder.java | 95 ++++++++ .../mods/magneticraft/HydraulicPress.java | 129 +++++++++++ .../mods/magneticraft/Magneticraft.java | 17 ++ .../compat/mods/magneticraft/OilHeater.java | 85 +++++++ .../compat/mods/magneticraft/Refinery.java | 77 +++++++ .../compat/mods/magneticraft/Sieve.java | 112 +++++++++ .../compat/mods/magneticraft/SluiceBox.java | 101 ++++++++ .../compat/mods/magneticraft/Thermopile.java | 93 ++++++++ .../groovyscript/core/LateMixin.java | 3 +- .../CrushingTableRecipeManagerAccessor.java | 18 ++ ...GasificationUnitRecipeManagerAccessor.java | 18 ++ .../HydraulicPressRecipeManagerAccessor.java | 18 ++ .../ThermopileRecipeManagerAccessor.java | 18 ++ .../assets/groovyscript/lang/en_us.lang | 48 ++++ .../mixin.groovyscript.magneticraft.json | 13 ++ 21 files changed, 1251 insertions(+), 2 deletions(-) create mode 100644 examples/postInit/magneticraft.groovy create mode 100644 src/main/java/com/cleanroommc/groovyscript/compat/mods/magneticraft/CrushingTable.java create mode 100644 src/main/java/com/cleanroommc/groovyscript/compat/mods/magneticraft/GasificationUnit.java create mode 100644 src/main/java/com/cleanroommc/groovyscript/compat/mods/magneticraft/Grinder.java create mode 100644 src/main/java/com/cleanroommc/groovyscript/compat/mods/magneticraft/HydraulicPress.java create mode 100644 src/main/java/com/cleanroommc/groovyscript/compat/mods/magneticraft/Magneticraft.java create mode 100644 src/main/java/com/cleanroommc/groovyscript/compat/mods/magneticraft/OilHeater.java create mode 100644 src/main/java/com/cleanroommc/groovyscript/compat/mods/magneticraft/Refinery.java create mode 100644 src/main/java/com/cleanroommc/groovyscript/compat/mods/magneticraft/Sieve.java create mode 100644 src/main/java/com/cleanroommc/groovyscript/compat/mods/magneticraft/SluiceBox.java create mode 100644 src/main/java/com/cleanroommc/groovyscript/compat/mods/magneticraft/Thermopile.java create mode 100644 src/main/java/com/cleanroommc/groovyscript/core/mixin/magneticraft/CrushingTableRecipeManagerAccessor.java create mode 100644 src/main/java/com/cleanroommc/groovyscript/core/mixin/magneticraft/GasificationUnitRecipeManagerAccessor.java create mode 100644 src/main/java/com/cleanroommc/groovyscript/core/mixin/magneticraft/HydraulicPressRecipeManagerAccessor.java create mode 100644 src/main/java/com/cleanroommc/groovyscript/core/mixin/magneticraft/ThermopileRecipeManagerAccessor.java create mode 100644 src/main/resources/mixin.groovyscript.magneticraft.json diff --git a/dependencies.gradle b/dependencies.gradle index bd8eeadd1..2cafb98a0 100644 --- a/dependencies.gradle +++ b/dependencies.gradle @@ -34,7 +34,7 @@ final def mod_dependencies = [ 'aether-255308:3280119' : [project.debug_aether], 'alchemistry-293425:3186612' : [project.debug_alchemistry], 'alchemylib-293426:2761706' : [project.debug_alchemistry], - 'shadowfacts-forgelin-248453:2785465' : [project.debug_alchemistry, project.debug_future_mc, project.debug_industrial_foregoing], + 'shadowfacts-forgelin-248453:2785465' : [project.debug_alchemistry, project.debug_future_mc, project.debug_industrial_foregoing, project.debug_magneticraft], 'ae2-extended-life-570458:4553942' : [project.debug_applied_energistics_2, project.debug_lazy_ae2], 'arcane-archives-311357:3057332' : [project.debug_arcane_archives], 'guidebook-253874:2989594' : [project.debug_arcane_archives], @@ -85,6 +85,8 @@ final def mod_dependencies = [ 'integrated-dynamics-236307:3159505' : [project.debug_integrated_dynamics], 'lazy-ae2-322347:3254160' : [project.debug_lazy_ae2], 'libnine-322344:3509087' : [project.debug_lazy_ae2], + 'magneticraft-224808:3791484' : [project.debug_magneticraft], + 'modelloader-277663:2744735' : [project.debug_magneticraft], 'mekanism-268560:2835175' : [project.debug_mekanism], 'mystical_agriculture-246640:2704562' : [project.debug_mystical_agriculture], 'natures-aura-306626:2882138' : [project.debug_natures_aura], diff --git a/examples/postInit/magneticraft.groovy b/examples/postInit/magneticraft.groovy new file mode 100644 index 000000000..c1eea6898 --- /dev/null +++ b/examples/postInit/magneticraft.groovy @@ -0,0 +1,215 @@ + +// Auto generated groovyscript example file +// MODS_LOADED: magneticraft + +import com.cout970.magneticraft.api.registries.machines.hydraulicpress.HydraulicPressMode + +log.info 'mod \'magneticraft\' detected, running script' + +// Crushing Table: +// Converts an input itemstack into an output itemstack when placed on top of the Crushing Table and interacted with by a +// Hammer which has. + +mods.magneticraft.crushing_table.removeByInput(item('minecraft:iron_ore')) +mods.magneticraft.crushing_table.removeByOutput(item('minecraft:gunpowder')) +// mods.magneticraft.crushing_table.removeAll() + +mods.magneticraft.crushing_table.recipeBuilder() + .input(item('minecraft:clay')) + .output(item('minecraft:diamond')) + .register() + +mods.magneticraft.crushing_table.recipeBuilder() + .input(item('minecraft:diamond')) + .output(item('minecraft:clay')) + .register() + + +// Gasification Unit: +// Converts an input itemstack into either an output itemstack, an output fluidstack, or both in a Gasification Unit block. + +// mods.magneticraft.gasification_unit.removeAll() + +mods.magneticraft.gasification_unit.recipeBuilder() + .input(item('minecraft:clay')) + .output(item('minecraft:diamond')) + .duration(50) + .minTemperature(700) + .register() + +mods.magneticraft.gasification_unit.recipeBuilder() + .input(item('minecraft:diamond')) + .fluidOutput(fluid('lava')) + .duration(100) + .minTemperature(500) + .register() + + +// Grinder: +// Converts an input itemstack into an output itemstack with a chance at a second itemstack in a Grinder Multiblock. + +mods.magneticraft.grinder.removeByInput(item('minecraft:iron_ore')) +mods.magneticraft.grinder.removeByOutput(item('minecraft:gravel')) +// mods.magneticraft.grinder.removeAll() + +mods.magneticraft.grinder.recipeBuilder() + .input(item('minecraft:clay')) + .output(item('minecraft:diamond')) + .ticks(50) + .register() + +mods.magneticraft.grinder.recipeBuilder() + .input(item('minecraft:diamond')) + .output(item('minecraft:clay'), item('minecraft:gold_ingot')) + .chance(10) + .ticks(50) + .register() + + +// Hydraulic Press: +// Converts an input itemstack into an output itemstack when set to a given mode in a Hydraulic Press Multiblock. + +mods.magneticraft.hydraulic_press.removeByInput(item('minecraft:iron_ingot')) +mods.magneticraft.hydraulic_press.removeByMode(HydraulicPressMode.MEDIUM) +mods.magneticraft.hydraulic_press.removeByOutput(item('minecraft:cobblestone')) +// mods.magneticraft.hydraulic_press.removeAll() + +mods.magneticraft.hydraulic_press.recipeBuilder() + .input(item('minecraft:clay')) + .output(item('minecraft:diamond')) + .ticks(50) + .register() + +mods.magneticraft.hydraulic_press.recipeBuilder() + .input(item('minecraft:gold_ingot')) + .output(item('minecraft:diamond')) + .ticks(50) + .medium() + .register() + +mods.magneticraft.hydraulic_press.recipeBuilder() + .input(item('minecraft:diamond')) + .output(item('minecraft:clay')) + .ticks(100) + .mode(HydraulicPressMode.HEAVY) + .register() + + +// Oil Heater: +// Converts an input fluidstack into an output fluidstack in a Oil Heater Multiblock. + +mods.magneticraft.oil_heater.removeByInput(fluid('oil')) +mods.magneticraft.oil_heater.removeByOutput(fluid('steam')) +// mods.magneticraft.oil_heater.removeAll() + +mods.magneticraft.oil_heater.recipeBuilder() + .fluidInput(fluid('water')) + .fluidOutput(fluid('lava')) + .duration(50) + .minTemperature(200) + .register() + +mods.magneticraft.oil_heater.recipeBuilder() + .fluidInput(fluid('lava')) + .fluidOutput(fluid('water')) + .duration(100) + .minTemperature(50) + .register() + + +// Refinery: +// Converts an input fluidstack into up to three output fluidstacks in a Refinery Multiblock. + +mods.magneticraft.refinery.removeByInput(fluid('steam')) +mods.magneticraft.refinery.removeByOutput(fluid('fuel')) +// mods.magneticraft.refinery.removeAll() + +mods.magneticraft.refinery.recipeBuilder() + .fluidInput(fluid('water')) + .fluidOutput(fluid('lava')) + .duration(50) + .register() + +mods.magneticraft.refinery.recipeBuilder() + .fluidInput(fluid('lava')) + .fluidOutput(fluid('water')) + .duration(100) + .register() + + +// Sieve: +// Converts an input itemstack into up to three output itemstacks, each with a separate chance in a Sieve Multiblock. + +mods.magneticraft.sieve.removeByInput(item('minecraft:sand')) +mods.magneticraft.sieve.removeByOutput(item('minecraft:quartz')) +// mods.magneticraft.sieve.removeAll() + +mods.magneticraft.sieve.recipeBuilder() + .input(item('minecraft:clay')) + .output(item('minecraft:diamond'), 0.5) + .duration(50) + .register() + +mods.magneticraft.sieve.recipeBuilder() + .input(item('minecraft:gold_ingot')) + .output(item('minecraft:diamond'), 0.05) + .output(item('minecraft:clay')) + .duration(50) + .register() + +mods.magneticraft.sieve.recipeBuilder() + .input(item('minecraft:diamond')) + .output(item('minecraft:clay'), 0.5) + .output(item('minecraft:clay'), 0.5) + .output(item('minecraft:clay'), 0.5) + .duration(1) + .register() + + +// Sluice Box: +// Converts an input itemstack into any number of output itemstacks each with a given chance. Consumes a bucket of water +// per batch, and can be crafted 10 at a time in a Sluice Box. + +mods.magneticraft.sluice_box.removeByInput(item('minecraft:sand')) +mods.magneticraft.sluice_box.removeByOutput(item('minecraft:cobblestone')) +// mods.magneticraft.sluice_box.removeAll() + +mods.magneticraft.sluice_box.recipeBuilder() + .input(item('minecraft:gold_ingot')) + .output(item('minecraft:clay')) + .register() + +mods.magneticraft.sluice_box.recipeBuilder() + .input(item('minecraft:clay')) + .output(item('minecraft:diamond'), 0.5) + .register() + +mods.magneticraft.sluice_box.recipeBuilder() + .input(item('minecraft:diamond')) + .output(item('minecraft:clay'), 0.5) + .output(item('minecraft:clay'), 0.3) + .output(item('minecraft:clay'), 0.2) + .output(item('minecraft:clay'), 0.1) + .register() + + +// Thermopile: +// The Thermopile generates energy from temperature differences modified by the thermal resistances of the block. This lets +// you generate energy when placed on either side of a Thermopile. + +mods.magneticraft.thermopile.removeByInput(blockstate('minecraft:ice')) +// mods.magneticraft.thermopile.removeAll() + +mods.magneticraft.thermopile.recipeBuilder() + .state(blockstate('minecraft:clay')) + .conductivity(10) + .temperature(500) + .register() + +mods.magneticraft.thermopile.recipeBuilder() + .state(blockstate('minecraft:diamond_block')) + .conductivity(70) + .temperature(700) + .register() + + diff --git a/gradle.properties b/gradle.properties index 0c06dc95f..d4ccb8e7b 100644 --- a/gradle.properties +++ b/gradle.properties @@ -58,6 +58,7 @@ debug_integrated_dynamics = false debug_lazy_ae2 = false +debug_magneticraft = false debug_mekanism = false debug_mystical_agriculture = false diff --git a/src/main/java/com/cleanroommc/groovyscript/compat/mods/ModSupport.java b/src/main/java/com/cleanroommc/groovyscript/compat/mods/ModSupport.java index 4e650c953..38c1ab3ca 100644 --- a/src/main/java/com/cleanroommc/groovyscript/compat/mods/ModSupport.java +++ b/src/main/java/com/cleanroommc/groovyscript/compat/mods/ModSupport.java @@ -40,6 +40,7 @@ import com.cleanroommc.groovyscript.compat.mods.integrateddynamics.IntegratedDynamics; import com.cleanroommc.groovyscript.compat.mods.jei.JustEnoughItems; import com.cleanroommc.groovyscript.compat.mods.lazyae2.LazyAE2; +import com.cleanroommc.groovyscript.compat.mods.magneticraft.Magneticraft; import com.cleanroommc.groovyscript.compat.mods.mekanism.Mekanism; import com.cleanroommc.groovyscript.compat.mods.mysticalagriculture.MysticalAgriculture; import com.cleanroommc.groovyscript.compat.mods.naturesaura.NaturesAura; @@ -113,6 +114,7 @@ public class ModSupport { public static final GroovyContainer INSPIRATIONS = new InternalModContainer<>("inspirations", "Inspirations", Inspirations::new); public static final GroovyContainer INTEGRATED_DYNAMICS = new InternalModContainer<>("integrateddynamics", "Integrated Dynamics", IntegratedDynamics::new, "id"); public static final GroovyContainer JEI = new InternalModContainer<>("jei", "Just Enough Items", JustEnoughItems::new, "hei"); + public static final GroovyContainer MAGNETICRAFT = new InternalModContainer<>("magneticraft", "Magneticraft", Magneticraft::new); public static final GroovyContainer MEKANISM = new InternalModContainer<>("mekanism", "Mekanism", Mekanism::new); public static final GroovyContainer MYSTICAL_AGRICULTURE = new InternalModContainer<>("mysticalagriculture", "Mystical Agriculture", MysticalAgriculture::new); public static final GroovyContainer LAZYAE2 = new InternalModContainer<>("threng", "LazyAE2", LazyAE2::new, "lazyae2"); diff --git a/src/main/java/com/cleanroommc/groovyscript/compat/mods/magneticraft/CrushingTable.java b/src/main/java/com/cleanroommc/groovyscript/compat/mods/magneticraft/CrushingTable.java new file mode 100644 index 000000000..bb233ce3d --- /dev/null +++ b/src/main/java/com/cleanroommc/groovyscript/compat/mods/magneticraft/CrushingTable.java @@ -0,0 +1,83 @@ +package com.cleanroommc.groovyscript.compat.mods.magneticraft; + +import com.cleanroommc.groovyscript.api.GroovyLog; +import com.cleanroommc.groovyscript.api.IIngredient; +import com.cleanroommc.groovyscript.api.documentation.annotations.*; +import com.cleanroommc.groovyscript.compat.mods.ModSupport; +import com.cleanroommc.groovyscript.core.mixin.magneticraft.CrushingTableRecipeManagerAccessor; +import com.cleanroommc.groovyscript.helper.ingredient.OreDictIngredient; +import com.cleanroommc.groovyscript.helper.recipe.AbstractRecipeBuilder; +import com.cleanroommc.groovyscript.registry.StandardListRegistry; +import com.cout970.magneticraft.api.MagneticraftApi; +import com.cout970.magneticraft.api.registries.machines.crushingtable.ICrushingTableRecipe; +import org.jetbrains.annotations.Nullable; + +import java.util.Collection; + +@RegistryDescription +public class CrushingTable extends StandardListRegistry { + + @RecipeBuilderDescription(example = { + @Example(".input(item('minecraft:clay')).output(item('minecraft:diamond'))"), + @Example(".input(item('minecraft:diamond')).output(item('minecraft:clay'))") + }) + public RecipeBuilder recipeBuilder() { + return new RecipeBuilder(); + } + + /** + * Internally, the API method uses {@link java.util.Collections#unmodifiableList}, + * so a mixin is required to access the actual list and avoid {@link UnsupportedOperationException}s. + * + * @see com.cout970.magneticraft.api.internal.registries.machines.crushingtable.CrushingTableRecipeManager#getRecipes() MagneticraftApi.getCrushingTableRecipeManager().getRecipes() + */ + @Override + public Collection getRecipes() { + return CrushingTableRecipeManagerAccessor.getRecipes(); + } + + @MethodDescription(example = @Example("item('minecraft:iron_ore')")) + public boolean removeByInput(IIngredient input) { + return getRecipes().removeIf(r -> input.test(r.getInput()) && addBackup(r)); + } + + @MethodDescription(example = @Example("item('minecraft:gunpowder')")) + public boolean removeByOutput(IIngredient output) { + return getRecipes().removeIf(r -> output.test(r.getOutput()) && addBackup(r)); + } + + @Property(property = "input", comp = @Comp(eq = 1)) + @Property(property = "output", comp = @Comp(eq = 1)) + public static class RecipeBuilder extends AbstractRecipeBuilder { + + @Override + public String getErrorMsg() { + return "Error adding Magneticraft Crushing Table recipe"; + } + + @Override + public void validate(GroovyLog.Msg msg) { + validateItems(msg, 1, 1, 1, 1); + validateFluids(msg); + } + + @Override + @RecipeBuilderRegistrationMethod + public @Nullable ICrushingTableRecipe register() { + if (!validate()) return null; + ICrushingTableRecipe recipe = null; + if (input.get(0) instanceof OreDictIngredient ore) { + recipe = MagneticraftApi.getCrushingTableRecipeManager().createRecipe(ore.getMatchingStacks()[0], output.get(0), true); + ModSupport.MAGNETICRAFT.get().crushingTable.add(recipe); + } else { + for (var stack : input.get(0).getMatchingStacks()) { + recipe = MagneticraftApi.getCrushingTableRecipeManager().createRecipe(stack, output.get(0), false); + ModSupport.MAGNETICRAFT.get().crushingTable.add(recipe); + } + } + return recipe; + } + + } + +} diff --git a/src/main/java/com/cleanroommc/groovyscript/compat/mods/magneticraft/GasificationUnit.java b/src/main/java/com/cleanroommc/groovyscript/compat/mods/magneticraft/GasificationUnit.java new file mode 100644 index 000000000..5fc206218 --- /dev/null +++ b/src/main/java/com/cleanroommc/groovyscript/compat/mods/magneticraft/GasificationUnit.java @@ -0,0 +1,103 @@ +package com.cleanroommc.groovyscript.compat.mods.magneticraft; + +import com.cleanroommc.groovyscript.api.GroovyLog; +import com.cleanroommc.groovyscript.api.IIngredient; +import com.cleanroommc.groovyscript.api.documentation.annotations.*; +import com.cleanroommc.groovyscript.compat.mods.ModSupport; +import com.cleanroommc.groovyscript.core.mixin.magneticraft.GasificationUnitRecipeManagerAccessor; +import com.cleanroommc.groovyscript.helper.ingredient.OreDictIngredient; +import com.cleanroommc.groovyscript.helper.recipe.AbstractRecipeBuilder; +import com.cleanroommc.groovyscript.registry.StandardListRegistry; +import com.cout970.magneticraft.api.MagneticraftApi; +import com.cout970.magneticraft.api.registries.machines.gasificationunit.IGasificationUnitRecipe; +import org.jetbrains.annotations.Nullable; + +import java.util.Collection; + +@RegistryDescription +public class GasificationUnit extends StandardListRegistry { + + @RecipeBuilderDescription(example = { + @Example(".input(item('minecraft:clay')).output(item('minecraft:diamond')).duration(50).minTemperature(700)"), + @Example(".input(item('minecraft:diamond')).fluidOutput(fluid('lava')).duration(100).minTemperature(500)") + }) + public RecipeBuilder recipeBuilder() { + return new RecipeBuilder(); + } + + /** + * Internally, the API method uses {@link kotlin.collections.CollectionsKt#toMutableList}, + * so a mixin is required to access the actual list. + * + * @see com.cout970.magneticraft.api.internal.registries.machines.gasificationunit.GasificationUnitRecipeManager#getRecipes() MagneticraftApi.getGasificationUnitRecipeManager().getRecipes() + */ + @Override + public Collection getRecipes() { + return GasificationUnitRecipeManagerAccessor.getRecipes(); + } + + @MethodDescription + public boolean removeByInput(IIngredient input) { + return getRecipes().removeIf(r -> input.test(r.getInput()) && addBackup(r)); + } + + @MethodDescription + public boolean removeByOutput(IIngredient output) { + return getRecipes().removeIf(r -> (output.test(r.getItemOutput()) || output.test(r.getFluidOutput())) && addBackup(r)); + } + + @Property(property = "input", comp = @Comp(eq = 1)) + @Property(property = "output", comp = @Comp(gte = 0, lte = 1)) + @Property(property = "fluidOutput", comp = @Comp(gte = 0, lte = 1)) + public static class RecipeBuilder extends AbstractRecipeBuilder { + + @Property(comp = @Comp(gt = 0)) + private float duration; + @Property + private float minTemperature; + + @RecipeBuilderMethodDescription + public RecipeBuilder duration(float duration) { + this.duration = duration; + return this; + } + + @RecipeBuilderMethodDescription + public RecipeBuilder minTemperature(float minTemperature) { + this.minTemperature = minTemperature; + return this; + } + + @Override + public String getErrorMsg() { + return "Error adding Magneticraft Gasification Unit recipe"; + } + + @Override + public void validate(GroovyLog.Msg msg) { + validateItems(msg, 1, 1, 0, 1); + validateFluids(msg, 0, 0, 0, 1); + msg.add(output.isEmpty() && fluidOutput.isEmpty(), "either output or fluidOutput must have an entry, yet both were empty"); + msg.add(duration <= 0, "duration must be a float greater than 0, yet it was {}", duration); + } + + @Override + @RecipeBuilderRegistrationMethod + public @Nullable IGasificationUnitRecipe register() { + if (!validate()) return null; + IGasificationUnitRecipe recipe = null; + if (input.get(0) instanceof OreDictIngredient ore) { + recipe = MagneticraftApi.getGasificationUnitRecipeManager().createRecipe(ore.getMatchingStacks()[0], output.getOrEmpty(0), fluidOutput.getOrEmpty(0), duration, minTemperature, true); + ModSupport.MAGNETICRAFT.get().gasificationUnit.add(recipe); + } else { + for (var stack : input.get(0).getMatchingStacks()) { + recipe = MagneticraftApi.getGasificationUnitRecipeManager().createRecipe(stack, output.getOrEmpty(0), fluidOutput.getOrEmpty(0), duration, minTemperature, false); + ModSupport.MAGNETICRAFT.get().gasificationUnit.add(recipe); + } + } + return recipe; + } + + } + +} diff --git a/src/main/java/com/cleanroommc/groovyscript/compat/mods/magneticraft/Grinder.java b/src/main/java/com/cleanroommc/groovyscript/compat/mods/magneticraft/Grinder.java new file mode 100644 index 000000000..36aeac47e --- /dev/null +++ b/src/main/java/com/cleanroommc/groovyscript/compat/mods/magneticraft/Grinder.java @@ -0,0 +1,95 @@ +package com.cleanroommc.groovyscript.compat.mods.magneticraft; + +import com.cleanroommc.groovyscript.api.GroovyLog; +import com.cleanroommc.groovyscript.api.IIngredient; +import com.cleanroommc.groovyscript.api.documentation.annotations.*; +import com.cleanroommc.groovyscript.compat.mods.ModSupport; +import com.cleanroommc.groovyscript.helper.ingredient.OreDictIngredient; +import com.cleanroommc.groovyscript.helper.recipe.AbstractRecipeBuilder; +import com.cleanroommc.groovyscript.registry.StandardListRegistry; +import com.cout970.magneticraft.api.MagneticraftApi; +import com.cout970.magneticraft.api.registries.machines.grinder.IGrinderRecipe; +import org.jetbrains.annotations.Nullable; + +import java.util.Collection; + +@RegistryDescription +public class Grinder extends StandardListRegistry { + + @RecipeBuilderDescription(example = { + @Example(".input(item('minecraft:clay')).output(item('minecraft:diamond')).ticks(50)"), + @Example(".input(item('minecraft:diamond')).output(item('minecraft:clay'), item('minecraft:gold_ingot')).chance(10).ticks(50)") + }) + public RecipeBuilder recipeBuilder() { + return new RecipeBuilder(); + } + + @Override + public Collection getRecipes() { + return MagneticraftApi.getGrinderRecipeManager().getRecipes(); + } + + @MethodDescription(example = @Example("item('minecraft:iron_ore')")) + public boolean removeByInput(IIngredient input) { + return getRecipes().removeIf(r -> input.test(r.getInput()) && addBackup(r)); + } + + @MethodDescription(example = @Example("item('minecraft:gravel')")) + public boolean removeByOutput(IIngredient output) { + return getRecipes().removeIf(r -> (output.test(r.getPrimaryOutput()) || output.test(r.getSecondaryOutput())) && addBackup(r)); + } + + @Property(property = "input", comp = @Comp(eq = 1)) + @Property(property = "output", comp = @Comp(gte = 1, lte = 2)) + public static class RecipeBuilder extends AbstractRecipeBuilder { + + @Property(comp = @Comp(gt = 0, lte = 1)) + private float chance; + @Property(comp = @Comp(gt = 0)) + private float ticks; + + @RecipeBuilderMethodDescription + public RecipeBuilder chance(float chance) { + this.chance = chance; + return this; + } + + @RecipeBuilderMethodDescription + public RecipeBuilder ticks(float ticks) { + this.ticks = ticks; + return this; + } + + @Override + public String getErrorMsg() { + return "Error adding Magneticraft Grinder recipe"; + } + + @Override + public void validate(GroovyLog.Msg msg) { + validateItems(msg, 1, 1, 1, 2); + validateFluids(msg); + msg.add(output.size() == 2 && chance <= 0 && chance > 1, "chance must be a float greater than 0 and less than or equal to 1, yet it was {}", chance); + msg.add(ticks <= 0, "ticks must be a float greater than 0, yet it was {}", ticks); + } + + @Override + @RecipeBuilderRegistrationMethod + public @Nullable IGrinderRecipe register() { + if (!validate()) return null; + IGrinderRecipe recipe = null; + if (input.get(0) instanceof OreDictIngredient ore) { + recipe = MagneticraftApi.getGrinderRecipeManager().createRecipe(ore.getMatchingStacks()[0], output.get(0), output.getOrEmpty(1), chance, ticks, true); + ModSupport.MAGNETICRAFT.get().grinder.add(recipe); + } else { + for (var stack : input.get(0).getMatchingStacks()) { + recipe = MagneticraftApi.getGrinderRecipeManager().createRecipe(stack, output.get(0), output.getOrEmpty(1), chance, ticks, false); + ModSupport.MAGNETICRAFT.get().grinder.add(recipe); + } + } + return recipe; + } + + } + +} diff --git a/src/main/java/com/cleanroommc/groovyscript/compat/mods/magneticraft/HydraulicPress.java b/src/main/java/com/cleanroommc/groovyscript/compat/mods/magneticraft/HydraulicPress.java new file mode 100644 index 000000000..13266dbff --- /dev/null +++ b/src/main/java/com/cleanroommc/groovyscript/compat/mods/magneticraft/HydraulicPress.java @@ -0,0 +1,129 @@ +package com.cleanroommc.groovyscript.compat.mods.magneticraft; + +import com.cleanroommc.groovyscript.api.GroovyLog; +import com.cleanroommc.groovyscript.api.IIngredient; +import com.cleanroommc.groovyscript.api.documentation.annotations.*; +import com.cleanroommc.groovyscript.compat.mods.ModSupport; +import com.cleanroommc.groovyscript.core.mixin.magneticraft.HydraulicPressRecipeManagerAccessor; +import com.cleanroommc.groovyscript.helper.ingredient.OreDictIngredient; +import com.cleanroommc.groovyscript.helper.recipe.AbstractRecipeBuilder; +import com.cleanroommc.groovyscript.registry.StandardListRegistry; +import com.cout970.magneticraft.api.MagneticraftApi; +import com.cout970.magneticraft.api.registries.machines.hydraulicpress.HydraulicPressMode; +import com.cout970.magneticraft.api.registries.machines.hydraulicpress.IHydraulicPressRecipe; +import org.jetbrains.annotations.Nullable; + +import java.util.Collection; + + +@RegistryDescription +public class HydraulicPress extends StandardListRegistry { + + @RecipeBuilderDescription(example = { + @Example(".input(item('minecraft:clay')).output(item('minecraft:diamond')).ticks(50)"), + @Example(".input(item('minecraft:gold_ingot')).output(item('minecraft:diamond')).ticks(50).medium()"), + @Example(value = ".input(item('minecraft:diamond')).output(item('minecraft:clay')).ticks(100).mode(HydraulicPressMode.HEAVY)", imports = "com.cout970.magneticraft.api.registries.machines.hydraulicpress.HydraulicPressMode") + }) + public RecipeBuilder recipeBuilder() { + return new RecipeBuilder(); + } + + /** + * Internally, the API method uses {@link kotlin.collections.CollectionsKt#toList} and then {@link java.util.Collections#synchronizedList}, + * meaning that you get a synchronized copy of the list instead of the actual list. + * Thus, a mixin is required to access the actual list. + * + * @see com.cout970.magneticraft.api.internal.registries.machines.hydraulicpress.HydraulicPressRecipeManager#getRecipes() MagneticraftApi.getHydraulicPressRecipeManager().getRecipes() + */ + @Override + public Collection getRecipes() { + return HydraulicPressRecipeManagerAccessor.getRecipes(); + } + + @MethodDescription(example = @Example("item('minecraft:iron_ingot')")) + public boolean removeByInput(IIngredient input) { + return getRecipes().removeIf(r -> input.test(r.getInput()) && addBackup(r)); + } + + @MethodDescription(example = @Example("item('minecraft:cobblestone')")) + public boolean removeByOutput(IIngredient output) { + return getRecipes().removeIf(r -> output.test(r.getOutput()) && addBackup(r)); + } + + @MethodDescription(example = @Example(value = "HydraulicPressMode.MEDIUM", imports = "com.cout970.magneticraft.api.registries.machines.hydraulicpress.HydraulicPressMode")) + public boolean removeByMode(HydraulicPressMode mode) { + return getRecipes().removeIf(r -> mode == r.getMode() && addBackup(r)); + } + + @Property(property = "input", comp = @Comp(eq = 1)) + @Property(property = "output", comp = @Comp(eq = 1)) + public static class RecipeBuilder extends AbstractRecipeBuilder { + + @Property(comp = @Comp(gt = 0)) + private float ticks; + @Property(comp = @Comp(not = "null")) + private HydraulicPressMode mode = HydraulicPressMode.LIGHT; + + @RecipeBuilderMethodDescription + public RecipeBuilder ticks(float ticks) { + this.ticks = ticks; + return this; + } + + @RecipeBuilderMethodDescription + public RecipeBuilder mode(HydraulicPressMode mode) { + this.mode = mode; + return this; + } + + @RecipeBuilderMethodDescription(field = "mode") + public RecipeBuilder light() { + this.mode = HydraulicPressMode.LIGHT; + return this; + } + + @RecipeBuilderMethodDescription(field = "mode") + public RecipeBuilder medium() { + this.mode = HydraulicPressMode.MEDIUM; + return this; + } + + @RecipeBuilderMethodDescription(field = "mode") + public RecipeBuilder heavy() { + this.mode = HydraulicPressMode.HEAVY; + return this; + } + + @Override + public String getErrorMsg() { + return "Error adding Magneticraft Hydraulic Press recipe"; + } + + @Override + public void validate(GroovyLog.Msg msg) { + validateItems(msg, 1, 1, 1, 1); + validateFluids(msg); + msg.add(mode == null, "mode must be defined"); + msg.add(ticks <= 0, "ticks must be a float greater than 0, yet it was {}", ticks); + } + + @Override + @RecipeBuilderRegistrationMethod + public @Nullable IHydraulicPressRecipe register() { + if (!validate()) return null; + IHydraulicPressRecipe recipe = null; + if (input.get(0) instanceof OreDictIngredient ore) { + recipe = MagneticraftApi.getHydraulicPressRecipeManager().createRecipe(ore.getMatchingStacks()[0], output.get(0), ticks, mode, true); + ModSupport.MAGNETICRAFT.get().hydraulicPress.add(recipe); + } else { + for (var stack : input.get(0).getMatchingStacks()) { + recipe = MagneticraftApi.getHydraulicPressRecipeManager().createRecipe(stack, output.get(0), ticks, mode, false); + ModSupport.MAGNETICRAFT.get().hydraulicPress.add(recipe); + } + } + return recipe; + } + + } + +} diff --git a/src/main/java/com/cleanroommc/groovyscript/compat/mods/magneticraft/Magneticraft.java b/src/main/java/com/cleanroommc/groovyscript/compat/mods/magneticraft/Magneticraft.java new file mode 100644 index 000000000..8b9f6a29b --- /dev/null +++ b/src/main/java/com/cleanroommc/groovyscript/compat/mods/magneticraft/Magneticraft.java @@ -0,0 +1,17 @@ +package com.cleanroommc.groovyscript.compat.mods.magneticraft; + +import com.cleanroommc.groovyscript.compat.mods.GroovyPropertyContainer; + +public class Magneticraft extends GroovyPropertyContainer { + + public final CrushingTable crushingTable = new CrushingTable(); + public final GasificationUnit gasificationUnit = new GasificationUnit(); + public final Grinder grinder = new Grinder(); + public final HydraulicPress hydraulicPress = new HydraulicPress(); + public final OilHeater oilHeater = new OilHeater(); + public final Refinery refinery = new Refinery(); + public final Sieve sieve = new Sieve(); + public final SluiceBox sluiceBox = new SluiceBox(); + public final Thermopile thermopile = new Thermopile(); + +} diff --git a/src/main/java/com/cleanroommc/groovyscript/compat/mods/magneticraft/OilHeater.java b/src/main/java/com/cleanroommc/groovyscript/compat/mods/magneticraft/OilHeater.java new file mode 100644 index 000000000..662fdab40 --- /dev/null +++ b/src/main/java/com/cleanroommc/groovyscript/compat/mods/magneticraft/OilHeater.java @@ -0,0 +1,85 @@ +package com.cleanroommc.groovyscript.compat.mods.magneticraft; + +import com.cleanroommc.groovyscript.api.GroovyLog; +import com.cleanroommc.groovyscript.api.IIngredient; +import com.cleanroommc.groovyscript.api.documentation.annotations.*; +import com.cleanroommc.groovyscript.compat.mods.ModSupport; +import com.cleanroommc.groovyscript.helper.recipe.AbstractRecipeBuilder; +import com.cleanroommc.groovyscript.registry.StandardListRegistry; +import com.cout970.magneticraft.api.MagneticraftApi; +import com.cout970.magneticraft.api.registries.machines.oilheater.IOilHeaterRecipe; +import org.jetbrains.annotations.Nullable; + +import java.util.Collection; + +@RegistryDescription +public class OilHeater extends StandardListRegistry { + + @RecipeBuilderDescription(example = { + @Example(".fluidInput(fluid('water')).fluidOutput(fluid('lava')).duration(50).minTemperature(200)"), + @Example(".fluidInput(fluid('lava')).fluidOutput(fluid('water')).duration(100).minTemperature(50)") + }) + public RecipeBuilder recipeBuilder() { + return new RecipeBuilder(); + } + + @Override + public Collection getRecipes() { + return MagneticraftApi.getOilHeaterRecipeManager().getRecipes(); + } + + @MethodDescription(example = @Example("fluid('oil')")) + public boolean removeByInput(IIngredient input) { + return getRecipes().removeIf(r -> input.test(r.getInput()) && addBackup(r)); + } + + @MethodDescription(example = @Example("fluid('steam')")) + public boolean removeByOutput(IIngredient output) { + return getRecipes().removeIf(r -> output.test(r.getOutput()) && addBackup(r)); + } + + @Property(property = "fluidInput", comp = @Comp(eq = 1)) + @Property(property = "fluidOutput", comp = @Comp(eq = 1)) + public static class RecipeBuilder extends AbstractRecipeBuilder { + + @Property(comp = @Comp(gt = 0)) + private float duration; + @Property + private float minTemperature; + + @RecipeBuilderMethodDescription + public RecipeBuilder duration(float duration) { + this.duration = duration; + return this; + } + + @RecipeBuilderMethodDescription + public RecipeBuilder minTemperature(float minTemperature) { + this.minTemperature = minTemperature; + return this; + } + + @Override + public String getErrorMsg() { + return "Error adding Magneticraft Oil Heater recipe"; + } + + @Override + public void validate(GroovyLog.Msg msg) { + validateItems(msg); + validateFluids(msg, 1, 1, 1, 1); + msg.add(duration <= 0, "duration must be a float greater than 0, yet it was {}", duration); + } + + @Override + @RecipeBuilderRegistrationMethod + public @Nullable IOilHeaterRecipe register() { + if (!validate()) return null; + IOilHeaterRecipe recipe = MagneticraftApi.getOilHeaterRecipeManager().createRecipe(fluidInput.get(0), fluidOutput.get(0), duration, minTemperature); + ModSupport.MAGNETICRAFT.get().oilHeater.add(recipe); + return recipe; + } + + } + +} diff --git a/src/main/java/com/cleanroommc/groovyscript/compat/mods/magneticraft/Refinery.java b/src/main/java/com/cleanroommc/groovyscript/compat/mods/magneticraft/Refinery.java new file mode 100644 index 000000000..5e6f0d644 --- /dev/null +++ b/src/main/java/com/cleanroommc/groovyscript/compat/mods/magneticraft/Refinery.java @@ -0,0 +1,77 @@ +package com.cleanroommc.groovyscript.compat.mods.magneticraft; + +import com.cleanroommc.groovyscript.api.GroovyLog; +import com.cleanroommc.groovyscript.api.IIngredient; +import com.cleanroommc.groovyscript.api.documentation.annotations.*; +import com.cleanroommc.groovyscript.compat.mods.ModSupport; +import com.cleanroommc.groovyscript.helper.recipe.AbstractRecipeBuilder; +import com.cleanroommc.groovyscript.registry.StandardListRegistry; +import com.cout970.magneticraft.api.MagneticraftApi; +import com.cout970.magneticraft.api.registries.machines.refinery.IRefineryRecipe; +import org.jetbrains.annotations.Nullable; + +import java.util.Collection; + +@RegistryDescription +public class Refinery extends StandardListRegistry { + + @RecipeBuilderDescription(example = { + @Example(".fluidInput(fluid('water')).fluidOutput(fluid('lava')).duration(50)"), + @Example(".fluidInput(fluid('lava')).fluidOutput(fluid('water')).duration(100)") + }) + public RecipeBuilder recipeBuilder() { + return new RecipeBuilder(); + } + + @Override + public Collection getRecipes() { + return MagneticraftApi.getRefineryRecipeManager().getRecipes(); + } + + @MethodDescription(example = @Example("fluid('steam')")) + public boolean removeByInput(IIngredient input) { + return getRecipes().removeIf(r -> input.test(r.getInput()) && addBackup(r)); + } + + @MethodDescription(example = @Example("fluid('fuel')")) + public boolean removeByOutput(IIngredient output) { + return getRecipes().removeIf(r -> (output.test(r.getOutput0()) || output.test(r.getOutput1()) || output.test(r.getOutput2())) && addBackup(r)); + } + + @Property(property = "fluidInput", comp = @Comp(eq = 1)) + @Property(property = "fluidOutput", comp = @Comp(gte = 1, lte = 3)) + public static class RecipeBuilder extends AbstractRecipeBuilder { + + @Property(comp = @Comp(gt = 0)) + private float duration; + + @RecipeBuilderMethodDescription + public RecipeBuilder duration(float duration) { + this.duration = duration; + return this; + } + + @Override + public String getErrorMsg() { + return "Error adding Magneticraft Refinery recipe"; + } + + @Override + public void validate(GroovyLog.Msg msg) { + validateItems(msg); + validateFluids(msg, 1, 1, 1, 3); + msg.add(duration <= 0, "duration must be a float greater than 0, yet it was {}", duration); + } + + @Override + @RecipeBuilderRegistrationMethod + public @Nullable IRefineryRecipe register() { + if (!validate()) return null; + IRefineryRecipe recipe = MagneticraftApi.getRefineryRecipeManager().createRecipe(fluidInput.get(0), fluidOutput.get(0), fluidOutput.getOrEmpty(1), fluidOutput.getOrEmpty(2), duration); + ModSupport.MAGNETICRAFT.get().refinery.add(recipe); + return recipe; + } + + } + +} diff --git a/src/main/java/com/cleanroommc/groovyscript/compat/mods/magneticraft/Sieve.java b/src/main/java/com/cleanroommc/groovyscript/compat/mods/magneticraft/Sieve.java new file mode 100644 index 000000000..15e1abb63 --- /dev/null +++ b/src/main/java/com/cleanroommc/groovyscript/compat/mods/magneticraft/Sieve.java @@ -0,0 +1,112 @@ +package com.cleanroommc.groovyscript.compat.mods.magneticraft; + +import com.cleanroommc.groovyscript.api.GroovyLog; +import com.cleanroommc.groovyscript.api.IIngredient; +import com.cleanroommc.groovyscript.api.documentation.annotations.*; +import com.cleanroommc.groovyscript.compat.mods.ModSupport; +import com.cleanroommc.groovyscript.helper.ingredient.OreDictIngredient; +import com.cleanroommc.groovyscript.helper.recipe.AbstractRecipeBuilder; +import com.cleanroommc.groovyscript.registry.StandardListRegistry; +import com.cout970.magneticraft.api.MagneticraftApi; +import com.cout970.magneticraft.api.registries.machines.sifter.ISieveRecipe; +import it.unimi.dsi.fastutil.floats.FloatArrayList; +import net.minecraft.item.ItemStack; +import org.jetbrains.annotations.Nullable; + +import java.util.Collection; + +@RegistryDescription +public class Sieve extends StandardListRegistry { + + @RecipeBuilderDescription(example = { + @Example(".input(item('minecraft:clay')).output(item('minecraft:diamond'), 0.5).duration(50)"), + @Example(".input(item('minecraft:gold_ingot')).output(item('minecraft:diamond'), 0.05).output(item('minecraft:clay')).duration(50)"), + @Example(".input(item('minecraft:diamond')).output(item('minecraft:clay'), 0.5).output(item('minecraft:clay'), 0.5).output(item('minecraft:clay'), 0.5).duration(1)") + }) + public RecipeBuilder recipeBuilder() { + return new RecipeBuilder(); + } + + @Override + public Collection getRecipes() { + return MagneticraftApi.getSieveRecipeManager().getRecipes(); + } + + @MethodDescription(example = @Example("item('minecraft:sand')")) + public boolean removeByInput(IIngredient input) { + return getRecipes().removeIf(r -> input.test(r.getInput()) && addBackup(r)); + } + + @MethodDescription(example = @Example("item('minecraft:quartz')")) + public boolean removeByOutput(IIngredient output) { + return getRecipes().removeIf(r -> (output.test(r.getPrimary()) || output.test(r.getSecondary()) || output.test(r.getTertiary())) && addBackup(r)); + } + + @Property(property = "input", comp = @Comp(eq = 1)) + @Property(property = "output", comp = @Comp(gte = 1, lte = 3)) + public static class RecipeBuilder extends AbstractRecipeBuilder { + + @Property(comp = @Comp(gt = 0, lte = 100, unique = "groovyscript.wiki.magneticraft.sieve.chances.required")) + private final FloatArrayList chances = new FloatArrayList(); + @Property(comp = @Comp(gt = 0)) + private float duration; + + @RecipeBuilderMethodDescription + public RecipeBuilder duration(float duration) { + this.duration = duration; + return this; + } + + @RecipeBuilderMethodDescription(field = {"output", "chances"}) + public RecipeBuilder output(ItemStack item, float chance) { + this.output.add(item); + this.chances.add(chance); + return this; + } + + @Override + @RecipeBuilderMethodDescription(field = {"output", "chances"}) + public RecipeBuilder output(ItemStack item) { + return output(item, 1.0f); + } + + @Override + public String getErrorMsg() { + return "Error adding Magneticraft Sieve recipe"; + } + + @Override + public void validate(GroovyLog.Msg msg) { + validateItems(msg, 1, 1, 1, 3); + validateFluids(msg); + chances.trim(); + msg.add(output.size() != chances.size(), "output and chances must be the same length, yet output was {} and chances was {}", output.size(), chances.size()); + for (float chance : chances.elements()) { + msg.add(chance <= 0 || chance > 1, "each chance value must be a float greater than 0 and less than or equal to 1, yet a chance value was {}", chance); + } + msg.add(duration <= 0, "duration must be a float greater than 0, yet it was {}", duration); + } + + @Override + @RecipeBuilderRegistrationMethod + public @Nullable ISieveRecipe register() { + if (!validate()) return null; + ISieveRecipe recipe = null; + float primaryChance = chances.size() >= 1 ? chances.getFloat(0) : 0; + float secondaryChance = chances.size() >= 2 ? chances.getFloat(1) : 0; + float tertiaryChance = chances.size() >= 3 ? chances.getFloat(2) : 0; + if (input.get(0) instanceof OreDictIngredient ore) { + recipe = MagneticraftApi.getSieveRecipeManager().createRecipe(ore.getMatchingStacks()[0], output.get(0), primaryChance, output.getOrEmpty(1), secondaryChance, output.getOrEmpty(2), tertiaryChance, duration, true); + ModSupport.MAGNETICRAFT.get().sieve.add(recipe); + } else { + for (var stack : input.get(0).getMatchingStacks()) { + recipe = MagneticraftApi.getSieveRecipeManager().createRecipe(stack, output.get(0), primaryChance, output.getOrEmpty(1), secondaryChance, output.getOrEmpty(2), tertiaryChance, duration, false); + ModSupport.MAGNETICRAFT.get().sieve.add(recipe); + } + } + return recipe; + } + + } + +} diff --git a/src/main/java/com/cleanroommc/groovyscript/compat/mods/magneticraft/SluiceBox.java b/src/main/java/com/cleanroommc/groovyscript/compat/mods/magneticraft/SluiceBox.java new file mode 100644 index 000000000..324d6cb15 --- /dev/null +++ b/src/main/java/com/cleanroommc/groovyscript/compat/mods/magneticraft/SluiceBox.java @@ -0,0 +1,101 @@ +package com.cleanroommc.groovyscript.compat.mods.magneticraft; + +import com.cleanroommc.groovyscript.api.GroovyLog; +import com.cleanroommc.groovyscript.api.IIngredient; +import com.cleanroommc.groovyscript.api.documentation.annotations.*; +import com.cleanroommc.groovyscript.compat.mods.ModSupport; +import com.cleanroommc.groovyscript.helper.ingredient.OreDictIngredient; +import com.cleanroommc.groovyscript.helper.recipe.AbstractRecipeBuilder; +import com.cleanroommc.groovyscript.registry.StandardListRegistry; +import com.cout970.magneticraft.api.MagneticraftApi; +import com.cout970.magneticraft.api.registries.machines.sluicebox.ISluiceBoxRecipe; +import it.unimi.dsi.fastutil.floats.FloatArrayList; +import kotlin.Pair; +import net.minecraft.item.ItemStack; +import org.jetbrains.annotations.Nullable; + +import java.util.Collection; + +@RegistryDescription +public class SluiceBox extends StandardListRegistry { + + @RecipeBuilderDescription(example = { + @Example(".input(item('minecraft:gold_ingot')).output(item('minecraft:clay'))"), + @Example(".input(item('minecraft:clay')).output(item('minecraft:diamond'), 0.5)"), + @Example(".input(item('minecraft:diamond')).output(item('minecraft:clay'), 0.5).output(item('minecraft:clay'), 0.3).output(item('minecraft:clay'), 0.2).output(item('minecraft:clay'), 0.1)") + }) + public RecipeBuilder recipeBuilder() { + return new RecipeBuilder(); + } + + @Override + public Collection getRecipes() { + return MagneticraftApi.getSluiceBoxRecipeManager().getRecipes(); + } + + @MethodDescription(example = @Example("item('minecraft:sand')")) + public boolean removeByInput(IIngredient input) { + return getRecipes().removeIf(r -> input.test(r.getInput()) && addBackup(r)); + } + + @MethodDescription(example = @Example("item('minecraft:cobblestone')")) + public boolean removeByOutput(IIngredient output) { + return getRecipes().removeIf(r -> r.getOutputs().stream().map(Pair::getFirst).anyMatch(output) && addBackup(r)); + } + + @Property(property = "input", comp = @Comp(eq = 1)) + @Property(property = "output", comp = @Comp(gte = 1)) + public static class RecipeBuilder extends AbstractRecipeBuilder { + + @Property(comp = @Comp(gt = 0, lte = 100, unique = "groovyscript.wiki.magneticraft.sluice_box.chances.required")) + private final FloatArrayList chances = new FloatArrayList(); + + @RecipeBuilderMethodDescription(field = {"output", "chances"}) + public RecipeBuilder output(ItemStack item, float chance) { + this.output.add(item); + this.chances.add(chance); + return this; + } + + @Override + @RecipeBuilderMethodDescription(field = {"output", "chances"}) + public RecipeBuilder output(ItemStack item) { + return output(item, 1.0f); + } + + @Override + public String getErrorMsg() { + return "Error adding Magneticraft Sluice Box recipe"; + } + + @Override + public void validate(GroovyLog.Msg msg) { + validateItems(msg, 1, 1, 1, Integer.MAX_VALUE); + validateFluids(msg); + chances.trim(); + msg.add(output.size() != chances.size(), "output and chances must be the same length, yet output was {} and chances was {}", output.size(), chances.size()); + for (float chance : chances.elements()) { + msg.add(chance <= 0 || chance > 1, "each chance value must be a float greater than 0 and less than or equal to 1, yet a chance value was {}", chance); + } + } + + @Override + @RecipeBuilderRegistrationMethod + public @Nullable ISluiceBoxRecipe register() { + if (!validate()) return null; + ISluiceBoxRecipe recipe = null; + if (input.get(0) instanceof OreDictIngredient ore) { + recipe = MagneticraftApi.getSluiceBoxRecipeManager().createRecipe(ore.getMatchingStacks()[0], output, chances, true); + ModSupport.MAGNETICRAFT.get().sluiceBox.add(recipe); + } else { + for (var stack : input.get(0).getMatchingStacks()) { + recipe = MagneticraftApi.getSluiceBoxRecipeManager().createRecipe(stack, output, chances, false); + ModSupport.MAGNETICRAFT.get().sluiceBox.add(recipe); + } + } + return recipe; + } + + } + +} diff --git a/src/main/java/com/cleanroommc/groovyscript/compat/mods/magneticraft/Thermopile.java b/src/main/java/com/cleanroommc/groovyscript/compat/mods/magneticraft/Thermopile.java new file mode 100644 index 000000000..63a5663b7 --- /dev/null +++ b/src/main/java/com/cleanroommc/groovyscript/compat/mods/magneticraft/Thermopile.java @@ -0,0 +1,93 @@ +package com.cleanroommc.groovyscript.compat.mods.magneticraft; + +import com.cleanroommc.groovyscript.api.GroovyLog; +import com.cleanroommc.groovyscript.api.documentation.annotations.*; +import com.cleanroommc.groovyscript.compat.mods.ModSupport; +import com.cleanroommc.groovyscript.core.mixin.magneticraft.ThermopileRecipeManagerAccessor; +import com.cleanroommc.groovyscript.helper.recipe.AbstractRecipeBuilder; +import com.cleanroommc.groovyscript.registry.StandardListRegistry; +import com.cout970.magneticraft.api.MagneticraftApi; +import com.cout970.magneticraft.api.registries.generators.thermopile.IThermopileRecipe; +import net.minecraft.block.state.IBlockState; +import org.jetbrains.annotations.Nullable; + +import java.util.Collection; + +@RegistryDescription +public class Thermopile extends StandardListRegistry { + + @RecipeBuilderDescription(example = { + @Example(".state(blockstate('minecraft:clay')).conductivity(10).temperature(500)"), + @Example(".state(blockstate('minecraft:diamond_block')).conductivity(70).temperature(700)") + }) + public RecipeBuilder recipeBuilder() { + return new RecipeBuilder(); + } + + /** + * Internally, the API method uses {@link kotlin.collections.CollectionsKt#toMutableList}, + * so a mixin is required to access the actual list. + * + * @see com.cout970.magneticraft.api.internal.registries.generators.thermopile.ThermopileRecipeManager#getRecipes() MagneticraftApi.getThermopileRecipeManager().getRecipes() + */ + @Override + public Collection getRecipes() { + return ThermopileRecipeManagerAccessor.getRecipeList(); + } + + @MethodDescription(example = @Example("blockstate('minecraft:ice')")) + public boolean removeByInput(IBlockState input) { + return getRecipes().removeIf(r -> input == r.getBlockState() && addBackup(r)); + } + + public static class RecipeBuilder extends AbstractRecipeBuilder { + + @Property(comp = @Comp(not = "null")) + private IBlockState state; + @Property + private float conductivity; + @Property + private float temperature; + + @RecipeBuilderMethodDescription + public RecipeBuilder state(IBlockState state) { + this.state = state; + return this; + } + + @RecipeBuilderMethodDescription + public RecipeBuilder conductivity(float conductivity) { + this.conductivity = conductivity; + return this; + } + + @RecipeBuilderMethodDescription + public RecipeBuilder temperature(float temperature) { + this.temperature = temperature; + return this; + } + + @Override + public String getErrorMsg() { + return "Error adding Magneticraft Thermopile recipe"; + } + + @Override + public void validate(GroovyLog.Msg msg) { + validateItems(msg); + validateFluids(msg); + msg.add(state == null, "state must be defined"); + } + + @Override + @RecipeBuilderRegistrationMethod + public @Nullable IThermopileRecipe register() { + if (!validate()) return null; + IThermopileRecipe recipe = MagneticraftApi.getThermopileRecipeManager().createRecipe(state, temperature, conductivity); + ModSupport.MAGNETICRAFT.get().thermopile.add(recipe); + return recipe; + } + + } + +} diff --git a/src/main/java/com/cleanroommc/groovyscript/core/LateMixin.java b/src/main/java/com/cleanroommc/groovyscript/core/LateMixin.java index 1bd8de6dd..865ac9426 100644 --- a/src/main/java/com/cleanroommc/groovyscript/core/LateMixin.java +++ b/src/main/java/com/cleanroommc/groovyscript/core/LateMixin.java @@ -29,7 +29,7 @@ public class LateMixin implements ILateMixinLoader { "industrialforegoing", "inspirations", "jei", - "techreborn", + "magneticraft", "mekanism", "pneumaticcraft", "primal_tech", @@ -38,6 +38,7 @@ public class LateMixin implements ILateMixinLoader { "roots", "tcomplement", "tconstruct", + "techreborn", "thermalexpansion", "woot" ); diff --git a/src/main/java/com/cleanroommc/groovyscript/core/mixin/magneticraft/CrushingTableRecipeManagerAccessor.java b/src/main/java/com/cleanroommc/groovyscript/core/mixin/magneticraft/CrushingTableRecipeManagerAccessor.java new file mode 100644 index 000000000..b7de82979 --- /dev/null +++ b/src/main/java/com/cleanroommc/groovyscript/core/mixin/magneticraft/CrushingTableRecipeManagerAccessor.java @@ -0,0 +1,18 @@ +package com.cleanroommc.groovyscript.core.mixin.magneticraft; + +import com.cout970.magneticraft.api.internal.registries.machines.crushingtable.CrushingTableRecipeManager; +import com.cout970.magneticraft.api.registries.machines.crushingtable.ICrushingTableRecipe; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Accessor; + +import java.util.List; + +@Mixin(value = CrushingTableRecipeManager.class, remap = false) +public interface CrushingTableRecipeManagerAccessor { + + @Accessor("recipes") + static List getRecipes() { + throw new UnsupportedOperationException(); + } + +} diff --git a/src/main/java/com/cleanroommc/groovyscript/core/mixin/magneticraft/GasificationUnitRecipeManagerAccessor.java b/src/main/java/com/cleanroommc/groovyscript/core/mixin/magneticraft/GasificationUnitRecipeManagerAccessor.java new file mode 100644 index 000000000..719a890ff --- /dev/null +++ b/src/main/java/com/cleanroommc/groovyscript/core/mixin/magneticraft/GasificationUnitRecipeManagerAccessor.java @@ -0,0 +1,18 @@ +package com.cleanroommc.groovyscript.core.mixin.magneticraft; + +import com.cout970.magneticraft.api.internal.registries.machines.gasificationunit.GasificationUnitRecipeManager; +import com.cout970.magneticraft.api.registries.machines.gasificationunit.IGasificationUnitRecipe; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Accessor; + +import java.util.List; + +@Mixin(value = GasificationUnitRecipeManager.class, remap = false) +public interface GasificationUnitRecipeManagerAccessor { + + @Accessor("recipes") + static List getRecipes() { + throw new UnsupportedOperationException(); + } + +} diff --git a/src/main/java/com/cleanroommc/groovyscript/core/mixin/magneticraft/HydraulicPressRecipeManagerAccessor.java b/src/main/java/com/cleanroommc/groovyscript/core/mixin/magneticraft/HydraulicPressRecipeManagerAccessor.java new file mode 100644 index 000000000..d73479b51 --- /dev/null +++ b/src/main/java/com/cleanroommc/groovyscript/core/mixin/magneticraft/HydraulicPressRecipeManagerAccessor.java @@ -0,0 +1,18 @@ +package com.cleanroommc.groovyscript.core.mixin.magneticraft; + +import com.cout970.magneticraft.api.internal.registries.machines.hydraulicpress.HydraulicPressRecipeManager; +import com.cout970.magneticraft.api.registries.machines.hydraulicpress.IHydraulicPressRecipe; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Accessor; + +import java.util.List; + +@Mixin(value = HydraulicPressRecipeManager.class, remap = false) +public interface HydraulicPressRecipeManagerAccessor { + + @Accessor("recipes") + static List getRecipes() { + throw new UnsupportedOperationException(); + } + +} diff --git a/src/main/java/com/cleanroommc/groovyscript/core/mixin/magneticraft/ThermopileRecipeManagerAccessor.java b/src/main/java/com/cleanroommc/groovyscript/core/mixin/magneticraft/ThermopileRecipeManagerAccessor.java new file mode 100644 index 000000000..eedbc2253 --- /dev/null +++ b/src/main/java/com/cleanroommc/groovyscript/core/mixin/magneticraft/ThermopileRecipeManagerAccessor.java @@ -0,0 +1,18 @@ +package com.cleanroommc.groovyscript.core.mixin.magneticraft; + +import com.cout970.magneticraft.api.internal.registries.generators.thermopile.ThermopileRecipeManager; +import com.cout970.magneticraft.api.registries.generators.thermopile.IThermopileRecipe; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Accessor; + +import java.util.List; + +@Mixin(value = ThermopileRecipeManager.class, remap = false) +public interface ThermopileRecipeManagerAccessor { + + @Accessor("recipeList") + static List getRecipeList() { + throw new UnsupportedOperationException(); + } + +} diff --git a/src/main/resources/assets/groovyscript/lang/en_us.lang b/src/main/resources/assets/groovyscript/lang/en_us.lang index 9ee5aac25..a4ade8967 100644 --- a/src/main/resources/assets/groovyscript/lang/en_us.lang +++ b/src/main/resources/assets/groovyscript/lang/en_us.lang @@ -1434,6 +1434,54 @@ groovyscript.wiki.threng.etcher.top.value=Sets the top slot of the recipe groovyscript.wiki.threng.etcher.bottom.value=Sets the bottom slot of the recipe +# Magneticraft +groovyscript.wiki.magneticraft.crushing_table.title=Crushing Table +groovyscript.wiki.magneticraft.crushing_table.description=Converts an input itemstack into an output itemstack when placed on top of the Crushing Table and interacted with by a Hammer which has + +groovyscript.wiki.magneticraft.gasification_unit.title=Gasification Unit +groovyscript.wiki.magneticraft.gasification_unit.description=Converts an input itemstack into either an output itemstack, an output fluidstack, or both in a Gasification Unit block. +groovyscript.wiki.magneticraft.gasification_unit.duration.value=Sets the time in ticks the recipe takes to process +groovyscript.wiki.magneticraft.gasification_unit.minTemperature.value=Sets the minimum temperature required to process the recipe + +groovyscript.wiki.magneticraft.grinder.title=Grinder +groovyscript.wiki.magneticraft.grinder.description=Converts an input itemstack into an output itemstack with a chance at a second itemstack in a Grinder Multiblock. +groovyscript.wiki.magneticraft.grinder.ticks.value=Sets the time in ticks the recipe takes to process +groovyscript.wiki.magneticraft.grinder.chance.value=Sets the chance the output itemstack will be created + +groovyscript.wiki.magneticraft.hydraulic_press.title=Hydraulic Press +groovyscript.wiki.magneticraft.hydraulic_press.description=Converts an input itemstack into an output itemstack when set to a given mode in a Hydraulic Press Multiblock. +groovyscript.wiki.magneticraft.hydraulic_press.mode.value=Sets the mode the Hydraulic Press need to be set on +groovyscript.wiki.magneticraft.hydraulic_press.ticks.value=Sets the time in ticks the recipe takes to process +groovyscript.wiki.magneticraft.hydraulic_press.removeByMode=Removes all entries with the given mode + +groovyscript.wiki.magneticraft.oil_heater.title=Oil Heater +groovyscript.wiki.magneticraft.oil_heater.description=Converts an input fluidstack into an output fluidstack in a Oil Heater Multiblock. +groovyscript.wiki.magneticraft.oil_heater.duration.value=Sets the time in ticks the recipe takes to process +groovyscript.wiki.magneticraft.oil_heater.minTemperature.value=Sets the minimum temperature required to process the recipe + +groovyscript.wiki.magneticraft.refinery.title=Refinery +groovyscript.wiki.magneticraft.refinery.description=Converts an input fluidstack into up to three output fluidstacks in a Refinery Multiblock. +groovyscript.wiki.magneticraft.refinery.duration.value=Sets the time in ticks the recipe takes to process + +groovyscript.wiki.magneticraft.sieve.title=Sieve +groovyscript.wiki.magneticraft.sieve.description=Converts an input itemstack into up to three output itemstacks, each with a separate chance in a Sieve Multiblock. +groovyscript.wiki.magneticraft.sieve.duration.value=Sets the time in ticks the recipe takes to process +groovyscript.wiki.magneticraft.sieve.chances.value=Sets the chance of the corresponding output itemstack to be created +groovyscript.wiki.magneticraft.sieve.chances.required=must have the same number of elements as there are outputs + +groovyscript.wiki.magneticraft.sluice_box.title=Sluice Box +groovyscript.wiki.magneticraft.sluice_box.description=Converts an input itemstack into any number of output itemstacks each with a given chance. Consumes a bucket of water per batch, and can be crafted 10 at a time in a Sluice Box. +groovyscript.wiki.magneticraft.sluice_box.chances.value=Sets the chance of the corresponding output itemstack to be created +groovyscript.wiki.magneticraft.sluice_box.chances.required=must have the same number of elements as there are outputs + +groovyscript.wiki.magneticraft.thermopile.title=Thermopile +groovyscript.wiki.magneticraft.thermopile.description=The Thermopile generates energy from temperature differences modified by the thermal resistances of the block. This lets you generate energy when placed on either side of a Thermopile. +groovyscript.wiki.magneticraft.thermopile.state.value=Sets the IBlockState being used +groovyscript.wiki.magneticraft.thermopile.temperature.value=Sets the temperature of the block +groovyscript.wiki.magneticraft.thermopile.conductivity.value=Sets the thermal resistance of the block + + + # Mekanism groovyscript.wiki.mekanism.gasInput.value=Sets the gas inputs of the recipe groovyscript.wiki.mekanism.gasOutput.value=Sets the gas outputs of the recipe diff --git a/src/main/resources/mixin.groovyscript.magneticraft.json b/src/main/resources/mixin.groovyscript.magneticraft.json new file mode 100644 index 000000000..17e5198a1 --- /dev/null +++ b/src/main/resources/mixin.groovyscript.magneticraft.json @@ -0,0 +1,13 @@ +{ + "package": "com.cleanroommc.groovyscript.core.mixin.magneticraft", + "refmap": "mixins.groovyscript.refmap.json", + "target": "@env(DEFAULT)", + "minVersion": "0.8", + "compatibilityLevel": "JAVA_8", + "mixins": [ + "CrushingTableRecipeManagerAccessor", + "GasificationUnitRecipeManagerAccessor", + "HydraulicPressRecipeManagerAccessor", + "ThermopileRecipeManagerAccessor" + ] +} \ No newline at end of file