From 109b425880ea64a20b0ef7c0481c171d008994c0 Mon Sep 17 00:00:00 2001 From: Waiting Idly <25394029+WaitingIdly@users.noreply.github.com> Date: Tue, 23 Jul 2024 05:21:43 -0700 Subject: [PATCH] add Cyclic compat (#194) --- dependencies.gradle | 1 + examples/postInit/cyclicmagic.groovy | 102 ++++++++++++++ gradle.properties | 1 + .../groovyscript/compat/mods/ModSupport.java | 2 + .../compat/mods/cyclic/Cyclic.java | 13 ++ .../compat/mods/cyclic/Dehydrator.java | 126 ++++++++++++++++++ .../compat/mods/cyclic/Hydrator.java | 123 +++++++++++++++++ .../compat/mods/cyclic/Melter.java | 113 ++++++++++++++++ .../compat/mods/cyclic/Packager.java | 113 ++++++++++++++++ .../compat/mods/cyclic/Solidifier.java | 114 ++++++++++++++++ .../assets/groovyscript/lang/en_us.lang | 21 +++ 11 files changed, 729 insertions(+) create mode 100644 examples/postInit/cyclicmagic.groovy create mode 100644 src/main/java/com/cleanroommc/groovyscript/compat/mods/cyclic/Cyclic.java create mode 100644 src/main/java/com/cleanroommc/groovyscript/compat/mods/cyclic/Dehydrator.java create mode 100644 src/main/java/com/cleanroommc/groovyscript/compat/mods/cyclic/Hydrator.java create mode 100644 src/main/java/com/cleanroommc/groovyscript/compat/mods/cyclic/Melter.java create mode 100644 src/main/java/com/cleanroommc/groovyscript/compat/mods/cyclic/Packager.java create mode 100644 src/main/java/com/cleanroommc/groovyscript/compat/mods/cyclic/Solidifier.java diff --git a/dependencies.gradle b/dependencies.gradle index ae8927f40..f11b783a5 100644 --- a/dependencies.gradle +++ b/dependencies.gradle @@ -52,6 +52,7 @@ final def mod_dependencies = [ 'chisel-235279:2915375' : [project.debug_chisel], 'ctm-267602:2915363' : [project.debug_chisel], 'compact-machines-224218:2707509' : [project.debug_compact_machines], + 'cyclic-239286:4075832' : [project.debug_cyclic], 'brandons_core-231382:3408276' : [project.debug_draconic_evolution], 'draconic_evolution-223565:3431261' : [project.debug_draconic_evolution], 'redstone_flux-270789:2920436' : [project.debug_draconic_evolution, project.debug_thermal], diff --git a/examples/postInit/cyclicmagic.groovy b/examples/postInit/cyclicmagic.groovy new file mode 100644 index 000000000..ea614b72d --- /dev/null +++ b/examples/postInit/cyclicmagic.groovy @@ -0,0 +1,102 @@ + +// Auto generated groovyscript example file +// MODS_LOADED: cyclicmagic + +println 'mod \'cyclicmagic\' detected, running script' + +// DeHydrator: +// Converts an input itemstack into an output itemstack. + +mods.cyclicmagic.dehydrator.removeByInput(item('minecraft:clay')) +mods.cyclicmagic.dehydrator.removeByOutput(item('minecraft:deadbush')) +// mods.cyclicmagic.dehydrator.removeAll() + +mods.cyclicmagic.dehydrator.recipeBuilder() + .input(item('minecraft:gold_ingot')) + .output(item('minecraft:clay')) + .register() + +mods.cyclicmagic.dehydrator.recipeBuilder() + .input(ore('logWood')) + .output(item('minecraft:clay') * 8) + .time(100) + .water(30) + .register() + + +// Hydrator: +// Converts up to 4 input itemstacks and some amount of water into an output itemstack. + +mods.cyclicmagic.hydrator.removeByInput(item('minecraft:dirt')) +mods.cyclicmagic.hydrator.removeByOutput(item('minecraft:clay_ball')) +// mods.cyclicmagic.hydrator.removeAll() + +mods.cyclicmagic.hydrator.recipeBuilder() + .input(item('minecraft:gold_ingot')) + .output(item('minecraft:clay')) + .register() + +mods.cyclicmagic.hydrator.recipeBuilder() + .input(ore('logWood'), ore('sand'), ore('gravel'), item('minecraft:diamond')) + .output(item('minecraft:clay') * 8) + .water(100) + .register() + + +// Melter: +// Converts up to 4 input itemstacks into an output itemstack, while being placed above lava. + +mods.cyclicmagic.melter.removeByInput(item('minecraft:snow')) +mods.cyclicmagic.melter.removeByOutput(fluid('amber')) +// mods.cyclicmagic.melter.removeAll() + +mods.cyclicmagic.melter.recipeBuilder() + .input(item('minecraft:gold_ingot')) + .fluidOutput(fluid('water') * 175) + .register() + +mods.cyclicmagic.melter.recipeBuilder() + .input(ore('logWood'), ore('sand'), ore('gravel'), item('minecraft:diamond')) + .fluidOutput(fluid('lava') * 500) + .register() + + +// Packager: +// Converts up to 6 input itemstacks into an output itemstack. + +mods.cyclicmagic.packager.removeByInput(item('minecraft:grass')) +mods.cyclicmagic.packager.removeByOutput(item('minecraft:melon_block')) +// mods.cyclicmagic.packager.removeAll() + +mods.cyclicmagic.packager.recipeBuilder() + .input(item('minecraft:gold_ingot')) + .output(item('minecraft:clay')) + .register() + +mods.cyclicmagic.packager.recipeBuilder() + .input(ore('logWood'), ore('sand'), ore('gravel'), item('minecraft:diamond'), item('minecraft:diamond_block'), item('minecraft:gold_block')) + .output(item('minecraft:clay') * 4) + .register() + + +// Solidifier: +// Converts up to 4 input itemstacks and an input fluidstack into an output itemstack. + +mods.cyclicmagic.solidifier.removeByInput(fluid('water')) +mods.cyclicmagic.solidifier.removeByInput(item('minecraft:bucket')) +mods.cyclicmagic.solidifier.removeByOutput(item('cyclicmagic:crystallized_obsidian')) +// mods.cyclicmagic.solidifier.removeAll() + +mods.cyclicmagic.solidifier.recipeBuilder() + .input(item('minecraft:clay')) + .fluidInput(fluid('water') * 175) + .output(item('minecraft:gold_ingot') * 3) + .register() + +mods.cyclicmagic.solidifier.recipeBuilder() + .input(ore('logWood'), ore('sand'), ore('gravel'), item('minecraft:diamond')) + .fluidInput(fluid('lava') * 500) + .output(item('minecraft:clay') * 2) + .register() + + diff --git a/gradle.properties b/gradle.properties index 00c17accd..8b490926d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -28,6 +28,7 @@ debug_botania = false debug_calculator = false debug_chisel = false debug_compact_machines = false +debug_cyclic = false debug_draconic_evolution = false debug_enderio = false debug_essentialcraft_4 = 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 c73bc0458..f65df8603 100644 --- a/src/main/java/com/cleanroommc/groovyscript/compat/mods/ModSupport.java +++ b/src/main/java/com/cleanroommc/groovyscript/compat/mods/ModSupport.java @@ -18,6 +18,7 @@ import com.cleanroommc.groovyscript.compat.mods.botania.Botania; import com.cleanroommc.groovyscript.compat.mods.calculator.Calculator; import com.cleanroommc.groovyscript.compat.mods.chisel.Chisel; +import com.cleanroommc.groovyscript.compat.mods.cyclic.Cyclic; import com.cleanroommc.groovyscript.compat.mods.compactmachines.CompactMachines; import com.cleanroommc.groovyscript.compat.mods.draconicevolution.DraconicEvolution; import com.cleanroommc.groovyscript.compat.mods.enderio.EnderIO; @@ -85,6 +86,7 @@ public class ModSupport { public static final GroovyContainer CALCULATOR = new InternalModContainer<>("calculator", "Calculator", Calculator::new); public static final GroovyContainer CHISEL = new InternalModContainer<>("chisel", "Chisel", Chisel::new); public static final GroovyContainer COMPACT_MACHINES = new InternalModContainer<>("compactmachines3", "Compact Machines 3", CompactMachines::new, "compactmachines"); + public static final GroovyContainer CYCLIC = new InternalModContainer<>("cyclicmagic", "Cyclic", Cyclic::new, "cyclic"); public static final GroovyContainer DRACONIC_EVOLUTION = new InternalModContainer<>("draconicevolution", "Draconic Evolution", DraconicEvolution::new, "de"); public static final GroovyContainer ENDER_IO = new InternalModContainer<>("enderio", "Ender IO", EnderIO::new, "eio"); public static final GroovyContainer ESSENTIALCRAFT = new InternalModContainer<>("essentialcraft", "EssentialCraft 4", EssentialCraft::new, "ec4"); diff --git a/src/main/java/com/cleanroommc/groovyscript/compat/mods/cyclic/Cyclic.java b/src/main/java/com/cleanroommc/groovyscript/compat/mods/cyclic/Cyclic.java new file mode 100644 index 000000000..7f7a7e21e --- /dev/null +++ b/src/main/java/com/cleanroommc/groovyscript/compat/mods/cyclic/Cyclic.java @@ -0,0 +1,13 @@ +package com.cleanroommc.groovyscript.compat.mods.cyclic; + +import com.cleanroommc.groovyscript.compat.mods.GroovyPropertyContainer; + +public class Cyclic extends GroovyPropertyContainer { + + public final Dehydrator dehydrator = new Dehydrator(); + public final Hydrator hydrator = new Hydrator(); + public final Melter melter = new Melter(); + public final Packager packager = new Packager(); + public final Solidifier solidifier = new Solidifier(); + +} diff --git a/src/main/java/com/cleanroommc/groovyscript/compat/mods/cyclic/Dehydrator.java b/src/main/java/com/cleanroommc/groovyscript/compat/mods/cyclic/Dehydrator.java new file mode 100644 index 000000000..fde189f64 --- /dev/null +++ b/src/main/java/com/cleanroommc/groovyscript/compat/mods/cyclic/Dehydrator.java @@ -0,0 +1,126 @@ +package com.cleanroommc.groovyscript.compat.mods.cyclic; + +import com.cleanroommc.groovyscript.api.GroovyBlacklist; +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.SimpleObjectStream; +import com.cleanroommc.groovyscript.helper.recipe.AbstractRecipeBuilder; +import com.cleanroommc.groovyscript.registry.VirtualizedRegistry; +import com.lothrazar.cyclicmagic.block.dehydrator.RecipeDeHydrate; +import net.minecraft.item.ItemStack; +import org.jetbrains.annotations.Nullable; + +@RegistryDescription +public class Dehydrator extends VirtualizedRegistry { + + @RecipeBuilderDescription(example = { + @Example(".input(item('minecraft:gold_ingot')).output(item('minecraft:clay'))"), + @Example(".input(ore('logWood')).output(item('minecraft:clay') * 8).time(100).water(30)") + }) + public RecipeBuilder recipeBuilder() { + return new RecipeBuilder(); + } + + @Override + @GroovyBlacklist + public void onReload() { + RecipeDeHydrate.recipes.removeAll(removeScripted()); + RecipeDeHydrate.recipes.addAll(restoreFromBackup()); + } + + public void add(RecipeDeHydrate recipe) { + if (recipe == null) return; + addScripted(recipe); + RecipeDeHydrate.recipes.add(recipe); + } + + public boolean remove(RecipeDeHydrate recipe) { + if (recipe == null) return false; + addBackup(recipe); + RecipeDeHydrate.recipes.remove(recipe); + return true; + } + + @MethodDescription(example = @Example("item('minecraft:clay')")) + public boolean removeByInput(IIngredient input) { + return RecipeDeHydrate.recipes.removeIf(recipe -> { + if (input.test(recipe.getRecipeInput())) { + addBackup(recipe); + return true; + } + return false; + }); + } + + @MethodDescription(example = @Example("item('minecraft:deadbush')")) + public boolean removeByOutput(IIngredient output) { + return RecipeDeHydrate.recipes.removeIf(recipe -> { + if (output.test(recipe.getRecipeOutput())) { + addBackup(recipe); + return true; + } + return false; + }); + } + + @MethodDescription(priority = 2000, example = @Example(commented = true)) + public void removeAll() { + RecipeDeHydrate.recipes.forEach(this::addBackup); + RecipeDeHydrate.recipes.clear(); + } + + @MethodDescription(type = MethodDescription.Type.QUERY) + public SimpleObjectStream streamRecipes() { + return new SimpleObjectStream<>(RecipeDeHydrate.recipes) + .setRemover(this::remove); + } + + @Property(property = "input", valid = @Comp("1")) + @Property(property = "output", valid = @Comp("1")) + public static class RecipeBuilder extends AbstractRecipeBuilder { + + @Property(defaultValue = "100", valid = @Comp(value = "0", type = Comp.Type.GTE)) + private int water = 100; + @Property(defaultValue = "10", valid = @Comp(value = "0", type = Comp.Type.GTE)) + private int time = 10; + + @RecipeBuilderMethodDescription + public RecipeBuilder water(int water) { + this.water = water; + return this; + } + + @RecipeBuilderMethodDescription + public RecipeBuilder time(int time) { + this.time = time; + return this; + } + + @Override + public String getErrorMsg() { + return "Error adding Cyclic Dehydrator recipe"; + } + + @Override + public void validate(GroovyLog.Msg msg) { + validateItems(msg, 1, 1, 1, 1); + validateFluids(msg); + msg.add(water < 0, "water must be a non-negative integer, yet it was {}", water); + msg.add(time < 0, "time must be a non-negative integer, yet it was {}", time); + } + + @Override + @RecipeBuilderRegistrationMethod + public @Nullable RecipeDeHydrate register() { + if (!validate()) return null; + RecipeDeHydrate recipe = null; + for (ItemStack matchingStack : input.get(0).toMcIngredient().getMatchingStacks()) { + recipe = new RecipeDeHydrate(matchingStack, output.get(0), time, water); + ModSupport.CYCLIC.get().dehydrator.add(recipe); + } + return recipe; + } + } +} diff --git a/src/main/java/com/cleanroommc/groovyscript/compat/mods/cyclic/Hydrator.java b/src/main/java/com/cleanroommc/groovyscript/compat/mods/cyclic/Hydrator.java new file mode 100644 index 000000000..8677fe393 --- /dev/null +++ b/src/main/java/com/cleanroommc/groovyscript/compat/mods/cyclic/Hydrator.java @@ -0,0 +1,123 @@ +package com.cleanroommc.groovyscript.compat.mods.cyclic; + +import com.cleanroommc.groovyscript.api.GroovyBlacklist; +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.SimpleObjectStream; +import com.cleanroommc.groovyscript.helper.recipe.AbstractRecipeBuilder; +import com.cleanroommc.groovyscript.registry.VirtualizedRegistry; +import com.google.common.collect.Lists; +import com.lothrazar.cyclicmagic.block.hydrator.RecipeHydrate; +import net.minecraft.item.ItemStack; +import org.jetbrains.annotations.Nullable; + +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +@RegistryDescription +public class Hydrator extends VirtualizedRegistry { + + @RecipeBuilderDescription(example = { + @Example(".input(item('minecraft:gold_ingot')).output(item('minecraft:clay'))"), + @Example(".input(ore('logWood'), ore('sand'), ore('gravel'), item('minecraft:diamond')).output(item('minecraft:clay') * 8).water(100)") + }) + public RecipeBuilder recipeBuilder() { + return new RecipeBuilder(); + } + + @Override + @GroovyBlacklist + public void onReload() { + RecipeHydrate.recipes.removeAll(removeScripted()); + RecipeHydrate.recipes.addAll(restoreFromBackup()); + } + + public void add(RecipeHydrate recipe) { + if (recipe == null) return; + addScripted(recipe); + RecipeHydrate.recipes.add(recipe); + } + + public boolean remove(RecipeHydrate recipe) { + if (recipe == null) return false; + addBackup(recipe); + RecipeHydrate.recipes.remove(recipe); + return true; + } + + @MethodDescription(example = @Example("item('minecraft:dirt')")) + public boolean removeByInput(IIngredient input) { + return RecipeHydrate.recipes.removeIf(recipe -> { + if (recipe.getRecipeInput().stream().anyMatch(input)) { + addBackup(recipe); + return true; + } + return false; + }); + } + + @MethodDescription(example = @Example("item('minecraft:clay_ball')")) + public boolean removeByOutput(IIngredient output) { + return RecipeHydrate.recipes.removeIf(recipe -> { + if (output.test(recipe.getRecipeOutput())) { + addBackup(recipe); + return true; + } + return false; + }); + } + + @MethodDescription(priority = 2000, example = @Example(commented = true)) + public void removeAll() { + RecipeHydrate.recipes.forEach(this::addBackup); + RecipeHydrate.recipes.clear(); + } + + @MethodDescription(type = MethodDescription.Type.QUERY) + public SimpleObjectStream streamRecipes() { + return new SimpleObjectStream<>(RecipeHydrate.recipes) + .setRemover(this::remove); + } + + @Property(property = "input", valid = {@Comp(type = Comp.Type.GTE, value = "1"), @Comp(type = Comp.Type.LTE, value = "6")}) + @Property(property = "output", valid = @Comp("1")) + public static class RecipeBuilder extends AbstractRecipeBuilder { + + @Property(defaultValue = "25", valid = @Comp(value = "0", type = Comp.Type.GTE)) + private int water = 25; + + @RecipeBuilderMethodDescription + public RecipeBuilder water(int water) { + this.water = water; + return this; + } + + @Override + public String getErrorMsg() { + return "Error adding Cyclic Hydrator recipe"; + } + + @Override + public void validate(GroovyLog.Msg msg) { + validateItems(msg, 1, 6, 1, 1); + validateFluids(msg); + msg.add(water < 0, "water must be a non-negative integer, yet it was {}", water); + } + + @Override + @RecipeBuilderRegistrationMethod + public @Nullable RecipeHydrate register() { + if (!validate()) return null; + RecipeHydrate recipe = null; + List> cartesian = Lists.cartesianProduct(input.stream().map(x -> Arrays.asList(x.toMcIngredient().getMatchingStacks())).collect(Collectors.toList())); + for (List stacks : cartesian) { + recipe = new RecipeHydrate(stacks.toArray(new ItemStack[0]), output.get(0), water); + ModSupport.CYCLIC.get().hydrator.add(recipe); + } + return recipe; + } + } +} diff --git a/src/main/java/com/cleanroommc/groovyscript/compat/mods/cyclic/Melter.java b/src/main/java/com/cleanroommc/groovyscript/compat/mods/cyclic/Melter.java new file mode 100644 index 000000000..db65ac0c4 --- /dev/null +++ b/src/main/java/com/cleanroommc/groovyscript/compat/mods/cyclic/Melter.java @@ -0,0 +1,113 @@ +package com.cleanroommc.groovyscript.compat.mods.cyclic; + +import com.cleanroommc.groovyscript.api.GroovyBlacklist; +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.SimpleObjectStream; +import com.cleanroommc.groovyscript.helper.recipe.AbstractRecipeBuilder; +import com.cleanroommc.groovyscript.registry.VirtualizedRegistry; +import com.google.common.collect.Lists; +import com.lothrazar.cyclicmagic.block.melter.RecipeMelter; +import net.minecraft.item.ItemStack; +import org.jetbrains.annotations.Nullable; + +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +@RegistryDescription +public class Melter extends VirtualizedRegistry { + + @RecipeBuilderDescription(example = { + @Example(".input(item('minecraft:gold_ingot')).fluidOutput(fluid('water') * 175)"), + @Example(".input(ore('logWood'), ore('sand'), ore('gravel'), item('minecraft:diamond')).fluidOutput(fluid('lava') * 500)") + }) + public RecipeBuilder recipeBuilder() { + return new RecipeBuilder(); + } + + @Override + @GroovyBlacklist + public void onReload() { + RecipeMelter.recipes.removeAll(removeScripted()); + RecipeMelter.recipes.addAll(restoreFromBackup()); + } + + public void add(RecipeMelter recipe) { + if (recipe == null) return; + addScripted(recipe); + RecipeMelter.recipes.add(recipe); + } + + public boolean remove(RecipeMelter recipe) { + if (recipe == null) return false; + addBackup(recipe); + RecipeMelter.recipes.remove(recipe); + return true; + } + + @MethodDescription(example = @Example("item('minecraft:snow')")) + public boolean removeByInput(IIngredient input) { + return RecipeMelter.recipes.removeIf(recipe -> { + if (recipe.getRecipeInput().stream().anyMatch(input)) { + addBackup(recipe); + return true; + } + return false; + }); + } + + @MethodDescription(example = @Example("fluid('amber')")) + public boolean removeByOutput(IIngredient output) { + return RecipeMelter.recipes.removeIf(recipe -> { + if (output.test(recipe.getOutputFluid())) { + addBackup(recipe); + return true; + } + return false; + }); + } + + @MethodDescription(priority = 2000, example = @Example(commented = true)) + public void removeAll() { + RecipeMelter.recipes.forEach(this::addBackup); + RecipeMelter.recipes.clear(); + } + + @MethodDescription(type = MethodDescription.Type.QUERY) + public SimpleObjectStream streamRecipes() { + return new SimpleObjectStream<>(RecipeMelter.recipes) + .setRemover(this::remove); + } + + @Property(property = "input", valid = {@Comp(type = Comp.Type.GTE, value = "1"), @Comp(type = Comp.Type.LTE, value = "4")}) + @Property(property = "fluidOutput", valid = @Comp("1")) + public static class RecipeBuilder extends AbstractRecipeBuilder { + + @Override + public String getErrorMsg() { + return "Error adding Cyclic Melter recipe"; + } + + @Override + public void validate(GroovyLog.Msg msg) { + validateItems(msg, 1, 4, 0, 0); + validateFluids(msg, 0, 0, 1, 1); + } + + @Override + @RecipeBuilderRegistrationMethod + public @Nullable RecipeMelter register() { + if (!validate()) return null; + RecipeMelter recipe = null; + List> cartesian = Lists.cartesianProduct(input.stream().map(x -> Arrays.asList(x.toMcIngredient().getMatchingStacks())).collect(Collectors.toList())); + for (List stacks : cartesian) { + recipe = new RecipeMelter(stacks.toArray(new ItemStack[0]), fluidOutput.get(0).getFluid().getName(), fluidOutput.get(0).amount); + ModSupport.CYCLIC.get().melter.add(recipe); + } + return recipe; + } + } +} diff --git a/src/main/java/com/cleanroommc/groovyscript/compat/mods/cyclic/Packager.java b/src/main/java/com/cleanroommc/groovyscript/compat/mods/cyclic/Packager.java new file mode 100644 index 000000000..6e64d9735 --- /dev/null +++ b/src/main/java/com/cleanroommc/groovyscript/compat/mods/cyclic/Packager.java @@ -0,0 +1,113 @@ +package com.cleanroommc.groovyscript.compat.mods.cyclic; + +import com.cleanroommc.groovyscript.api.GroovyBlacklist; +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.SimpleObjectStream; +import com.cleanroommc.groovyscript.helper.recipe.AbstractRecipeBuilder; +import com.cleanroommc.groovyscript.registry.VirtualizedRegistry; +import com.google.common.collect.Lists; +import com.lothrazar.cyclicmagic.block.packager.RecipePackager; +import net.minecraft.item.ItemStack; +import org.jetbrains.annotations.Nullable; + +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +@RegistryDescription +public class Packager extends VirtualizedRegistry { + + @RecipeBuilderDescription(example = { + @Example(".input(item('minecraft:gold_ingot')).output(item('minecraft:clay'))"), + @Example(".input(ore('logWood'), ore('sand'), ore('gravel'), item('minecraft:diamond'), item('minecraft:diamond_block'), item('minecraft:gold_block')).output(item('minecraft:clay') * 4)") + }) + public RecipeBuilder recipeBuilder() { + return new RecipeBuilder(); + } + + @Override + @GroovyBlacklist + public void onReload() { + RecipePackager.recipes.removeAll(removeScripted()); + RecipePackager.recipes.addAll(restoreFromBackup()); + } + + public void add(RecipePackager recipe) { + if (recipe == null) return; + addScripted(recipe); + RecipePackager.recipes.add(recipe); + } + + public boolean remove(RecipePackager recipe) { + if (recipe == null) return false; + addBackup(recipe); + RecipePackager.recipes.remove(recipe); + return true; + } + + @MethodDescription(example = @Example("item('minecraft:grass')")) + public boolean removeByInput(IIngredient input) { + return RecipePackager.recipes.removeIf(recipe -> { + if (recipe.getInput().stream().anyMatch(input)) { + addBackup(recipe); + return true; + } + return false; + }); + } + + @MethodDescription(example = @Example("item('minecraft:melon_block')")) + public boolean removeByOutput(IIngredient output) { + return RecipePackager.recipes.removeIf(recipe -> { + if (output.test(recipe.getRecipeOutput())) { + addBackup(recipe); + return true; + } + return false; + }); + } + + @MethodDescription(priority = 2000, example = @Example(commented = true)) + public void removeAll() { + RecipePackager.recipes.forEach(this::addBackup); + RecipePackager.recipes.clear(); + } + + @MethodDescription(type = MethodDescription.Type.QUERY) + public SimpleObjectStream streamRecipes() { + return new SimpleObjectStream<>(RecipePackager.recipes) + .setRemover(this::remove); + } + + @Property(property = "input", valid = {@Comp(type = Comp.Type.GTE, value = "1"), @Comp(type = Comp.Type.LTE, value = "6")}) + @Property(property = "output", valid = @Comp("1")) + public static class RecipeBuilder extends AbstractRecipeBuilder { + + @Override + public String getErrorMsg() { + return "Error adding Cyclic Packager recipe"; + } + + @Override + public void validate(GroovyLog.Msg msg) { + validateItems(msg, 1, 6, 1, 1); + validateFluids(msg); + } + + @Override + @RecipeBuilderRegistrationMethod + public @Nullable RecipePackager register() { + if (!validate()) return null; + RecipePackager recipe = null; + List> cartesian = Lists.cartesianProduct(input.stream().map(x -> Arrays.asList(x.toMcIngredient().getMatchingStacks())).collect(Collectors.toList())); + for (List stacks : cartesian) { + recipe = new RecipePackager(output.get(0), stacks.toArray(new ItemStack[0])); + ModSupport.CYCLIC.get().packager.add(recipe); + } + return recipe; + } + } +} diff --git a/src/main/java/com/cleanroommc/groovyscript/compat/mods/cyclic/Solidifier.java b/src/main/java/com/cleanroommc/groovyscript/compat/mods/cyclic/Solidifier.java new file mode 100644 index 000000000..4cba6412c --- /dev/null +++ b/src/main/java/com/cleanroommc/groovyscript/compat/mods/cyclic/Solidifier.java @@ -0,0 +1,114 @@ +package com.cleanroommc.groovyscript.compat.mods.cyclic; + +import com.cleanroommc.groovyscript.api.GroovyBlacklist; +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.SimpleObjectStream; +import com.cleanroommc.groovyscript.helper.recipe.AbstractRecipeBuilder; +import com.cleanroommc.groovyscript.registry.VirtualizedRegistry; +import com.google.common.collect.Lists; +import com.lothrazar.cyclicmagic.block.solidifier.RecipeSolidifier; +import net.minecraft.item.ItemStack; +import org.jetbrains.annotations.Nullable; + +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +@RegistryDescription +public class Solidifier extends VirtualizedRegistry { + + @RecipeBuilderDescription(example = { + @Example(".input(item('minecraft:clay')).fluidInput(fluid('water') * 175).output(item('minecraft:gold_ingot') * 3)"), + @Example(".input(ore('logWood'), ore('sand'), ore('gravel'), item('minecraft:diamond')).fluidInput(fluid('lava') * 500).output(item('minecraft:clay') * 2)") + }) + public RecipeBuilder recipeBuilder() { + return new RecipeBuilder(); + } + + @Override + @GroovyBlacklist + public void onReload() { + RecipeSolidifier.recipes.removeAll(removeScripted()); + RecipeSolidifier.recipes.addAll(restoreFromBackup()); + } + + public void add(RecipeSolidifier recipe) { + if (recipe == null) return; + addScripted(recipe); + RecipeSolidifier.recipes.add(recipe); + } + + public boolean remove(RecipeSolidifier recipe) { + if (recipe == null) return false; + addBackup(recipe); + RecipeSolidifier.recipes.remove(recipe); + return true; + } + + @MethodDescription(example = {@Example("item('minecraft:bucket')"), @Example("fluid('water')"),}) + public boolean removeByInput(IIngredient input) { + return RecipeSolidifier.recipes.removeIf(recipe -> { + if (input.test(recipe.getFluidIngredient()) || recipe.getRecipeInput().stream().anyMatch(input)) { + addBackup(recipe); + return true; + } + return false; + }); + } + + @MethodDescription(example = @Example("item('cyclicmagic:crystallized_obsidian')")) + public boolean removeByOutput(IIngredient output) { + return RecipeSolidifier.recipes.removeIf(recipe -> { + if (output.test(recipe.getRecipeOutput())) { + addBackup(recipe); + return true; + } + return false; + }); + } + + @MethodDescription(priority = 2000, example = @Example(commented = true)) + public void removeAll() { + RecipeSolidifier.recipes.forEach(this::addBackup); + RecipeSolidifier.recipes.clear(); + } + + @MethodDescription(type = MethodDescription.Type.QUERY) + public SimpleObjectStream streamRecipes() { + return new SimpleObjectStream<>(RecipeSolidifier.recipes) + .setRemover(this::remove); + } + + @Property(property = "input", valid = {@Comp(type = Comp.Type.GTE, value = "1"), @Comp(type = Comp.Type.LTE, value = "4")}) + @Property(property = "fluidInput", valid = @Comp("1")) + @Property(property = "output", valid = @Comp("1")) + public static class RecipeBuilder extends AbstractRecipeBuilder { + + @Override + public String getErrorMsg() { + return "Error adding Cyclic Solidifier recipe"; + } + + @Override + public void validate(GroovyLog.Msg msg) { + validateItems(msg, 1, 4, 1, 1); + validateFluids(msg, 1, 1, 0, 0); + } + + @Override + @RecipeBuilderRegistrationMethod + public @Nullable RecipeSolidifier register() { + if (!validate()) return null; + RecipeSolidifier recipe = null; + List> cartesian = Lists.cartesianProduct(input.stream().map(x -> Arrays.asList(x.toMcIngredient().getMatchingStacks())).collect(Collectors.toList())); + for (List stacks : cartesian) { + recipe = new RecipeSolidifier(stacks.toArray(new ItemStack[0]), output.get(0), fluidInput.get(0).getFluid().getName(), fluidInput.get(0).amount); + ModSupport.CYCLIC.get().solidifier.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 039c0e88e..3efe71ede 100644 --- a/src/main/resources/assets/groovyscript/lang/en_us.lang +++ b/src/main/resources/assets/groovyscript/lang/en_us.lang @@ -722,6 +722,27 @@ groovyscript.wiki.compactmachines3.miniaturization.ticks.value=Sets the time in groovyscript.wiki.compactmachines3.miniaturization.keyMap.value=Sets the IBlockState, specific NBT, if the metadata is checked, and a representative itemstack for each `char` key groovyscript.wiki.compactmachines3.miniaturization.symmetrical.value=Sets if the recipe does not have to test all 4 rotations to determine if the multiblock is valid + +# Cyclic +groovyscript.wiki.cyclicmagic.dehydrator.title=DeHydrator +groovyscript.wiki.cyclicmagic.dehydrator.description=Converts an input itemstack into an output itemstack. +groovyscript.wiki.cyclicmagic.dehydrator.time.value=Sets the amount of time in ticks the recipe takes to process +groovyscript.wiki.cyclicmagic.dehydrator.water.value=Sets the amount of water produced by the DeHydrator on completing a recipe + +groovyscript.wiki.cyclicmagic.hydrator.title=Hydrator +groovyscript.wiki.cyclicmagic.hydrator.description=Converts up to 4 input itemstacks and some amount of water into an output itemstack. +groovyscript.wiki.cyclicmagic.hydrator.water.value=Sets the amount of water consumed by the Hydrator to complete a recipe + +groovyscript.wiki.cyclicmagic.melter.title=Melter +groovyscript.wiki.cyclicmagic.melter.description=Converts up to 4 input itemstacks into an output itemstack, while being placed above lava. + +groovyscript.wiki.cyclicmagic.packager.title=Packager +groovyscript.wiki.cyclicmagic.packager.description=Converts up to 6 input itemstacks into an output itemstack. + +groovyscript.wiki.cyclicmagic.solidifier.title=Solidifier +groovyscript.wiki.cyclicmagic.solidifier.description=Converts up to 4 input itemstacks and an input fluidstack into an output itemstack. + + # Draconic Evolution groovyscript.wiki.draconicevolution.energy_core.title=Energy Core groovyscript.wiki.draconicevolution.energy_core.description=A multiblock with 8 tiers for storing large amounts of energy.