From 3de1eb28215baef3e18cce41acfea44de79edf76 Mon Sep 17 00:00:00 2001 From: Turing6 <39919441+Testure@users.noreply.github.com> Date: Thu, 23 May 2024 07:19:25 -0500 Subject: [PATCH] Tinkers' Construct Documentation (#157) * Basic docs * Finish docs * Add example script * Add .register() * Split entity melting * Changes * Update en_us.lang * Gen example script * Fix errors * Split casting into different files * Better descriptions * forgor the script :skull: * Use resource handler * add register description * use clear for entity melting * Improve alloying description * alloying removal examples * Ahhh * Use description defaults * use clear() * ` * the schizophrenia is getting worse * Add missing lang key * add property annotations --- examples/postInit/tconstruct.groovy | 99 ++++++ examples/postInit/tinkersconstruct.groovy | 24 -- .../mods/tinkersconstruct/Alloying.java | 14 +- .../compat/mods/tinkersconstruct/Casting.java | 293 ------------------ .../mods/tinkersconstruct/CastingBasin.java | 164 ++++++++++ .../mods/tinkersconstruct/CastingTable.java | 163 ++++++++++ .../compat/mods/tinkersconstruct/Drying.java | 16 +- .../mods/tinkersconstruct/EntityMelting.java | 160 ++++++++++ .../compat/mods/tinkersconstruct/Melting.java | 167 +--------- .../mods/tinkersconstruct/SmelteryFuel.java | 10 +- .../tinkersconstruct/TinkersConstruct.java | 9 +- .../recipe/MeltingRecipeBuilder.java | 9 + .../assets/groovyscript/lang/en_us.lang | 43 +++ 13 files changed, 694 insertions(+), 477 deletions(-) create mode 100644 examples/postInit/tconstruct.groovy delete mode 100644 examples/postInit/tinkersconstruct.groovy delete mode 100644 src/main/java/com/cleanroommc/groovyscript/compat/mods/tinkersconstruct/Casting.java create mode 100644 src/main/java/com/cleanroommc/groovyscript/compat/mods/tinkersconstruct/CastingBasin.java create mode 100644 src/main/java/com/cleanroommc/groovyscript/compat/mods/tinkersconstruct/CastingTable.java create mode 100644 src/main/java/com/cleanroommc/groovyscript/compat/mods/tinkersconstruct/EntityMelting.java diff --git a/examples/postInit/tconstruct.groovy b/examples/postInit/tconstruct.groovy new file mode 100644 index 000000000..dc7ba6a61 --- /dev/null +++ b/examples/postInit/tconstruct.groovy @@ -0,0 +1,99 @@ + +// Auto generated groovyscript example file +// MODS_LOADED: tconstruct + +println 'mod \'tconstruct\' detected, running script' + +// Alloying: +// Modifies what fluids can be mixed together in the Smeltery. + +mods.tconstruct.alloying.removeByInputs(fluid('cobalt')*2,fluid('ardite')*2) +mods.tconstruct.alloying.removeByInputsAndOutput(fluid('knightslime')*72,fluid('iron')*72,fluid('stone')*144,fluid('purpleslime')*125) +mods.tconstruct.alloying.removeByOutput(fluid('pigiron')) +// mods.tconstruct.alloying.removeAll() + +mods.tconstruct.alloying.recipeBuilder() + .fluidOutput(fluid('iron') * 3) + .fluidInput(fluid('clay') * 1,fluid('lava') * 2) + .register() + + +mods.tconstruct.alloying.add(fluid('lava') * 144, fluid('water') * 500, fluid('iron') * 5, fluid('clay') * 60) + +// Casting Basin: +// Pours out fluid into a basin to solidify it into a solid, optionally with a cast itemstack. + +mods.tconstruct.casting_basin.removeByCast(item('minecraft:planks:0')) +mods.tconstruct.casting_basin.removeByInput(fluid('clay')) +mods.tconstruct.casting_basin.removeByOutput(item('minecraft:iron_block')) +// mods.tconstruct.casting_basin.removeAll() + +mods.tconstruct.casting_basin.recipeBuilder() + .fluidInput(fluid('water')) + .output(item('minecraft:dirt')) + .cast(item('minecraft:cobblestone')) + .coolingTime(40) + .register() + + +// Casting Table: +// Pours out fluid onto a table to solidify it into a solid, optionally with a cast itemstack. + +mods.tconstruct.casting_table.removeByCast(item('minecraft:bucket')) +mods.tconstruct.casting_table.removeByInput(fluid('iron')) +mods.tconstruct.casting_table.removeByOutput(item('minecraft:gold_ingot')) +// mods.tconstruct.casting_table.removeAll() + +mods.tconstruct.casting_table.recipeBuilder() + .fluidInput(fluid('lava') * 50) + .output(item('minecraft:diamond')) + .coolingTime(750) + .consumesCast(true) + .cast(ore('gemEmerald')) + .register() + + +// Drying Rack: +// Convert an item into a different item by hanging it out to dry. + +// mods.tconstruct.drying.removeAll() + +mods.tconstruct.drying.recipeBuilder() + .input(item('minecraft:clay')) + .output(item('minecraft:dirt')) + .time(45) + .register() + + + +// Entity Melting: +// Allows mobs to create a bit of fluid when hurt by the Smeltery. + +// mods.tconstruct.entity_melting.removeAll() + +mods.tconstruct.entity_melting.recipeBuilder() + .fluidOutput(fluid('iron') * 500) + .input(resource('minecraft:pig')) + .register() + + +// Melting: +// Modifies what items can be melted down in the Smeltery. + +// mods.tconstruct.melting.removeAll() + +mods.tconstruct.melting.recipeBuilder() + .input(item('minecraft:gravel')) + .fluidOutput(fluid('lava') * 25) + .time(80) + .register() + + + +// Smeltery Fuel: +// Modifies what fluids are accepted as fuels for the Smeltery and how long each fuels the Smeltery. + +// mods.tconstruct.smeltery_fuel.removeAll() + +mods.tconstruct.smeltery_fuel.addFuel(fluid('water'), 250) + diff --git a/examples/postInit/tinkersconstruct.groovy b/examples/postInit/tinkersconstruct.groovy deleted file mode 100644 index 572595d28..000000000 --- a/examples/postInit/tinkersconstruct.groovy +++ /dev/null @@ -1,24 +0,0 @@ - -// MODS_LOADED: tconstruct -println 'mod \'tinkers construct\' detected, running script' - -// accessing tinker conxtruct -//mods.tconstruct -//mods.ticon -//mods.tinkersconstruct - -// Alloying -// requires at least 2 inputs and exactly 1 output -mods.tconstruct.Alloying.recipeBuilder() - .fluidInput(fluid('manyullyn') * 1) - .fluidInput(fluid('water') * 999) - .fluidOutput(fluid('obsidian') * 1000) - .register() - -mods.tconstruct.Alloying.removeByInputs(fluid('water') * 125, fluid('lava') * 125) -mods.tconstruct.Alloying.removeByOutput(fluid('clay')) -mods.tconstruct.Alloying.removeByInputsAndOutput(fluid('manyullyn'), fluid('cobalt') * 2, fluid('ardite') * 2) // first output then inputs - -// Casting -// There are 2 types: table and basin casting -//mods.tconstruct.casting.Table. diff --git a/src/main/java/com/cleanroommc/groovyscript/compat/mods/tinkersconstruct/Alloying.java b/src/main/java/com/cleanroommc/groovyscript/compat/mods/tinkersconstruct/Alloying.java index 8236d00a2..0caf11fe2 100644 --- a/src/main/java/com/cleanroommc/groovyscript/compat/mods/tinkersconstruct/Alloying.java +++ b/src/main/java/com/cleanroommc/groovyscript/compat/mods/tinkersconstruct/Alloying.java @@ -2,6 +2,7 @@ import com.cleanroommc.groovyscript.api.GroovyBlacklist; import com.cleanroommc.groovyscript.api.GroovyLog; +import com.cleanroommc.groovyscript.api.documentation.annotations.*; import com.cleanroommc.groovyscript.core.mixin.tconstruct.TinkerRegistryAccessor; import com.cleanroommc.groovyscript.helper.SimpleObjectStream; import com.cleanroommc.groovyscript.helper.recipe.AbstractRecipeBuilder; @@ -13,8 +14,10 @@ import java.util.Arrays; import java.util.List; +@RegistryDescription public class Alloying extends VirtualizedRegistry { + @RecipeBuilderDescription(example = @Example(".fluidOutput(fluid('iron') * 3).fluidInput(fluid('clay') * 1,fluid('lava') * 2)")) public RecipeBuilder recipeBuilder() { return new RecipeBuilder(); } @@ -26,6 +29,7 @@ public void onReload() { restoreFromBackup().forEach(TinkerRegistryAccessor.getAlloyRegistry()::add); } + @MethodDescription(type = MethodDescription.Type.ADDITION, example = @Example("fluid('lava') * 144, fluid('water') * 500, fluid('iron') * 5, fluid('clay') * 60")) public AlloyRecipe add(FluidStack output, FluidStack... inputs) { AlloyRecipe recipe = new AlloyRecipe(output, inputs); add(recipe); @@ -45,6 +49,7 @@ public boolean remove(AlloyRecipe recipe) { return true; } + @MethodDescription(example = @Example("fluid('pigiron')")) public boolean removeByOutput(FluidStack output) { if (TinkerRegistryAccessor.getAlloyRegistry().removeIf(recipe -> { boolean found = recipe.getResult().isFluidEqual(output); @@ -59,6 +64,7 @@ public boolean removeByOutput(FluidStack output) { return false; } + @MethodDescription(description = "groovyscript.wiki.tconstruct.alloying.removeByInputs", example = @Example("fluid('cobalt')*2,fluid('ardite')*2")) public boolean removeByInputs(FluidStack... inputs) { List list = Arrays.asList(inputs); if (TinkerRegistryAccessor.getAlloyRegistry().removeIf(recipe -> { @@ -74,6 +80,7 @@ public boolean removeByInputs(FluidStack... inputs) { return false; } + @MethodDescription(example = @Example("fluid('knightslime')*72,fluid('iron')*72,fluid('stone')*144,fluid('purpleslime')*125")) public boolean removeByInputsAndOutput(FluidStack output, FluidStack... inputs) { List list = Arrays.asList(inputs); if (TinkerRegistryAccessor.getAlloyRegistry().removeIf(recipe -> { @@ -89,15 +96,19 @@ public boolean removeByInputsAndOutput(FluidStack output, FluidStack... inputs) return false; } + @MethodDescription(priority = 2000, example = @Example(commented = true)) public void removeAll() { TinkerRegistryAccessor.getAlloyRegistry().forEach(this::addBackup); - TinkerRegistryAccessor.getAlloyRegistry().forEach(TinkerRegistryAccessor.getAlloyRegistry()::remove); + TinkerRegistryAccessor.getAlloyRegistry().clear(); } + @MethodDescription(type = MethodDescription.Type.QUERY) public SimpleObjectStream streamRecipes() { return new SimpleObjectStream<>(TinkerRegistryAccessor.getAlloyRegistry()).setRemover(this::remove); } + @Property(property = "fluidInput", valid = {@Comp(value = "2", type = Comp.Type.GTE), @Comp(value = "Integer.MAX_VALUE", type = Comp.Type.LTE)}) + @Property(property = "fluidOutput", valid = @Comp("1")) public class RecipeBuilder extends AbstractRecipeBuilder { @Override @@ -111,6 +122,7 @@ public void validate(GroovyLog.Msg msg) { } @Override + @RecipeBuilderRegistrationMethod public @Nullable AlloyRecipe register() { if (!validate()) return null; AlloyRecipe recipe = new AlloyRecipe(fluidOutput.get(0), fluidInput.toArray(new FluidStack[0])); diff --git a/src/main/java/com/cleanroommc/groovyscript/compat/mods/tinkersconstruct/Casting.java b/src/main/java/com/cleanroommc/groovyscript/compat/mods/tinkersconstruct/Casting.java deleted file mode 100644 index c019c803b..000000000 --- a/src/main/java/com/cleanroommc/groovyscript/compat/mods/tinkersconstruct/Casting.java +++ /dev/null @@ -1,293 +0,0 @@ -package com.cleanroommc.groovyscript.compat.mods.tinkersconstruct; - -import com.cleanroommc.groovyscript.api.GroovyBlacklist; -import com.cleanroommc.groovyscript.api.GroovyLog; -import com.cleanroommc.groovyscript.api.IDynamicGroovyProperty; -import com.cleanroommc.groovyscript.api.IIngredient; -import com.cleanroommc.groovyscript.compat.mods.tinkersconstruct.recipe.MeltingRecipeBuilder; -import com.cleanroommc.groovyscript.core.mixin.tconstruct.TinkerRegistryAccessor; -import com.cleanroommc.groovyscript.helper.Alias; -import com.cleanroommc.groovyscript.helper.SimpleObjectStream; -import com.cleanroommc.groovyscript.helper.recipe.AbstractRecipeBuilder; -import com.cleanroommc.groovyscript.registry.VirtualizedRegistry; -import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; -import net.minecraft.item.ItemStack; -import net.minecraftforge.fluids.FluidRegistry; -import net.minecraftforge.fluids.FluidStack; -import org.jetbrains.annotations.Nullable; -import slimeknights.tconstruct.library.smeltery.CastingRecipe; -import slimeknights.tconstruct.library.smeltery.ICastingRecipe; - -import java.util.Map; - -public class Casting implements IDynamicGroovyProperty { - - private final Map properties = new Object2ObjectOpenHashMap<>(); - - public final Table table = new Table(); - public final Basin basin = new Basin(); - - public Casting() { - for (String s : Alias.generateOf("Table")) this.properties.put(s, this.table); - for (String s : Alias.generateOf("Basin")) this.properties.put(s, this.basin); - } - - @Override - public @Nullable Object getProperty(String name) { - return properties.get(name); - } - - @Override - public Map getProperties() { - return properties; - } - - public static class Table extends VirtualizedRegistry { - - public RecipeBuilder recipeBuilder() { - return new RecipeBuilder(); - } - - @Override - @GroovyBlacklist - public void onReload() { - removeScripted().forEach(TinkerRegistryAccessor.getTableCastRegistry()::remove); - restoreFromBackup().forEach(TinkerRegistryAccessor.getTableCastRegistry()::add); - } - - public void add(ICastingRecipe recipe) { - if (recipe == null) return; - addScripted(recipe); - TinkerRegistryAccessor.getTableCastRegistry().add(recipe); - } - - public boolean remove(ICastingRecipe recipe) { - if (recipe == null) return false; - addBackup(recipe); - TinkerRegistryAccessor.getTableCastRegistry().remove(recipe); - return true; - } - - public boolean removeByOutput(ItemStack output) { - if (TinkerRegistryAccessor.getTableCastRegistry().removeIf(recipe -> { - boolean found = recipe.getResult(ItemStack.EMPTY, FluidRegistry.WATER).isItemEqual(output); - if (found) addBackup(recipe); - return found; - })) return true; - - GroovyLog.msg("Error removing Tinkers Construct Casting Table recipe") - .add("could not find recipe with output {}", output) - .error() - .post(); - return false; - } - - public boolean removeByInput(FluidStack input) { - if (TinkerRegistryAccessor.getTableCastRegistry().removeIf(recipe -> { - boolean found = recipe.getFluid(ItemStack.EMPTY, input.getFluid()).isFluidEqual(input); - if (found) addBackup(recipe); - return found; - })) return true; - - GroovyLog.msg("Error removing Tinkers Construct Casting Table recipe") - .add("could not find recipe with input {}", input) - .error() - .post(); - return false; - } - - public boolean removeByCast(IIngredient cast) { - if (TinkerRegistryAccessor.getTableCastRegistry().removeIf(recipe -> { - boolean found = recipe.matches(cast.getMatchingStacks()[0], recipe.getFluid(cast.getMatchingStacks()[0], FluidRegistry.WATER).getFluid()); - if (found) addBackup(recipe); - return found; - })) return true; - - GroovyLog.msg("Error removing Tinkers Construct Casting Table recipe") - .add("could not find recipe with cast {}", cast) - .error() - .post(); - return false; - } - - public void removeAll() { - TinkerRegistryAccessor.getTableCastRegistry().forEach(this::addBackup); - TinkerRegistryAccessor.getTableCastRegistry().forEach(TinkerRegistryAccessor.getTableCastRegistry()::remove); - } - - public SimpleObjectStream streamRecipes() { - return new SimpleObjectStream<>(TinkerRegistryAccessor.getTableCastRegistry()).setRemover(this::remove); - } - - public class RecipeBuilder extends AbstractRecipeBuilder { - - private IIngredient cast; - private int time = 200; - private boolean consumesCast = false; - - public RecipeBuilder coolingTime(int time) { - this.time = Math.max(time, 1); - return this; - } - - public RecipeBuilder consumesCast(boolean consumesCast) { - this.consumesCast = consumesCast; - return this; - } - - public RecipeBuilder consumesCast() { - return consumesCast(!consumesCast); - } - - public RecipeBuilder cast(IIngredient ingredient) { - this.cast = ingredient; - return this; - } - - @Override - public String getErrorMsg() { - return "Error adding Tinkers Construct Casting Table recipe"; - } - - @Override - public void validate(GroovyLog.Msg msg) { - validateFluids(msg, 1, 1, 0, 0); - validateItems(msg, 0, 0, 1, 1); - } - - @Override - public @Nullable ICastingRecipe register() { - if (!validate()) return null; - CastingRecipe recipe = new CastingRecipe(output.get(0), cast != null ? MeltingRecipeBuilder.recipeMatchFromIngredient(cast) - : null, fluidInput.get(0), time, consumesCast, false); - add(recipe); - return recipe; - } - } - } - - public static class Basin extends VirtualizedRegistry { - - public RecipeBuilder recipeBuilder() { - return new RecipeBuilder(); - } - - @Override - @GroovyBlacklist - public void onReload() { - removeScripted().forEach(TinkerRegistryAccessor.getBasinCastRegistry()::remove); - restoreFromBackup().forEach(TinkerRegistryAccessor.getBasinCastRegistry()::add); - } - - public void add(ICastingRecipe recipe) { - if (recipe == null) return; - addScripted(recipe); - TinkerRegistryAccessor.getBasinCastRegistry().add(recipe); - } - - public boolean remove(ICastingRecipe recipe) { - if (recipe == null) return false; - addBackup(recipe); - TinkerRegistryAccessor.getBasinCastRegistry().remove(recipe); - return true; - } - - public boolean removeByOutput(ItemStack output) { - if (TinkerRegistryAccessor.getBasinCastRegistry().removeIf(recipe -> { - boolean found = ItemStack.areItemStacksEqual(recipe.getResult(ItemStack.EMPTY, FluidRegistry.WATER), output); - if (found) addBackup(recipe); - return found; - })) return true; - - GroovyLog.msg("Error removing Tinkers Construct Casting Basin recipe") - .add("could not find recipe with output {}", output) - .error() - .post(); - return false; - } - - public boolean removeByInput(FluidStack input) { - if (TinkerRegistryAccessor.getBasinCastRegistry().removeIf(recipe -> { - boolean found = recipe.getFluid(ItemStack.EMPTY, input.getFluid()).isFluidEqual(input); - if (found) addBackup(recipe); - return found; - })) return true; - - GroovyLog.msg("Error removing Tinkers Construct Casting Basin recipe") - .add("could not find recipe with input {}", input) - .error() - .post(); - return false; - } - - public boolean removeByCast(IIngredient cast) { - ItemStack castStack = cast.getMatchingStacks()[0]; - if (TinkerRegistryAccessor.getBasinCastRegistry().removeIf(recipe -> { - boolean found = recipe.matches(castStack, recipe.getFluid(castStack, FluidRegistry.WATER).getFluid()); - if (found) addBackup(recipe); - return found; - })) return true; - - GroovyLog.msg("Error removing Tinkers Construct Casting Basin recipe") - .add("could not find recipe with cast {}", cast) - .error() - .post(); - return false; - } - - public void removeAll() { - TinkerRegistryAccessor.getBasinCastRegistry().forEach(this::addBackup); - TinkerRegistryAccessor.getBasinCastRegistry().forEach(TinkerRegistryAccessor.getBasinCastRegistry()::remove); - } - - public SimpleObjectStream streamRecipes() { - return new SimpleObjectStream<>(TinkerRegistryAccessor.getBasinCastRegistry()).setRemover(this::remove); - } - - public class RecipeBuilder extends AbstractRecipeBuilder { - - private IIngredient cast; - private int time = 200; - private boolean consumesCast = false; - - public RecipeBuilder coolingTime(int time) { - this.time = Math.max(time, 1); - return this; - } - - public RecipeBuilder consumesCast(boolean consumesCast) { - this.consumesCast = consumesCast; - return this; - } - - public RecipeBuilder consumesCast() { - return consumesCast(!consumesCast); - } - - public RecipeBuilder cast(IIngredient ingredient) { - this.cast = ingredient; - return this; - } - - @Override - public String getErrorMsg() { - return "Error adding Tinkers Construct Casting Basin recipe"; - } - - @Override - public void validate(GroovyLog.Msg msg) { - validateFluids(msg, 1, 1, 0, 0); - validateItems(msg, 0, 0, 1, 1); - } - - @Override - public @Nullable ICastingRecipe register() { - if (!validate()) return null; - CastingRecipe recipe = new CastingRecipe(output.get(0), cast != null ? MeltingRecipeBuilder.recipeMatchFromIngredient(cast) - : null, fluidInput.get(0), time, consumesCast, false); - add(recipe); - return recipe; - } - } - } -} diff --git a/src/main/java/com/cleanroommc/groovyscript/compat/mods/tinkersconstruct/CastingBasin.java b/src/main/java/com/cleanroommc/groovyscript/compat/mods/tinkersconstruct/CastingBasin.java new file mode 100644 index 000000000..392e26a5f --- /dev/null +++ b/src/main/java/com/cleanroommc/groovyscript/compat/mods/tinkersconstruct/CastingBasin.java @@ -0,0 +1,164 @@ +package com.cleanroommc.groovyscript.compat.mods.tinkersconstruct; + +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.tinkersconstruct.recipe.MeltingRecipeBuilder; +import com.cleanroommc.groovyscript.core.mixin.tconstruct.TinkerRegistryAccessor; +import com.cleanroommc.groovyscript.helper.Alias; +import com.cleanroommc.groovyscript.helper.SimpleObjectStream; +import com.cleanroommc.groovyscript.helper.recipe.AbstractRecipeBuilder; +import com.cleanroommc.groovyscript.registry.VirtualizedRegistry; +import net.minecraft.item.ItemStack; +import net.minecraftforge.fluids.FluidRegistry; +import net.minecraftforge.fluids.FluidStack; +import org.jetbrains.annotations.Nullable; +import slimeknights.tconstruct.library.smeltery.CastingRecipe; +import slimeknights.tconstruct.library.smeltery.ICastingRecipe; + +@RegistryDescription +public class CastingBasin extends VirtualizedRegistry { + + @RecipeBuilderDescription(example = @Example(".fluidInput(fluid('water')).output(item('minecraft:dirt')).cast(item('minecraft:cobblestone')).coolingTime(40)")) + public RecipeBuilder recipeBuilder() { + return new RecipeBuilder(); + } + + public CastingBasin() { + super(Alias.generateOfClass(CastingBasin.class).andGenerate("Basin")); + } + + @Override + @GroovyBlacklist + public void onReload() { + removeScripted().forEach(TinkerRegistryAccessor.getBasinCastRegistry()::remove); + restoreFromBackup().forEach(TinkerRegistryAccessor.getBasinCastRegistry()::add); + } + + public void add(ICastingRecipe recipe) { + if (recipe == null) return; + addScripted(recipe); + TinkerRegistryAccessor.getBasinCastRegistry().add(recipe); + } + + public boolean remove(ICastingRecipe recipe) { + if (recipe == null) return false; + addBackup(recipe); + TinkerRegistryAccessor.getBasinCastRegistry().remove(recipe); + return true; + } + + @MethodDescription(example = @Example("item('minecraft:iron_block')")) + public boolean removeByOutput(ItemStack output) { + if (TinkerRegistryAccessor.getBasinCastRegistry().removeIf(recipe -> { + boolean found = ItemStack.areItemStacksEqual(recipe.getResult(ItemStack.EMPTY, FluidRegistry.WATER), output); + if (found) addBackup(recipe); + return found; + })) return true; + + GroovyLog.msg("Error removing Tinkers Construct Casting Basin recipe") + .add("could not find recipe with output {}", output) + .error() + .post(); + return false; + } + + @MethodDescription(example = @Example("fluid('clay')")) + public boolean removeByInput(FluidStack input) { + if (TinkerRegistryAccessor.getBasinCastRegistry().removeIf(recipe -> { + boolean found = recipe.getFluid(ItemStack.EMPTY, input.getFluid()).isFluidEqual(input); + if (found) addBackup(recipe); + return found; + })) return true; + + GroovyLog.msg("Error removing Tinkers Construct Casting Basin recipe") + .add("could not find recipe with input {}", input) + .error() + .post(); + return false; + } + + @MethodDescription(example = @Example("item('minecraft:planks:0')")) + public boolean removeByCast(IIngredient cast) { + ItemStack castStack = cast.getMatchingStacks()[0]; + if (TinkerRegistryAccessor.getBasinCastRegistry().removeIf(recipe -> { + boolean found = recipe.matches(castStack, recipe.getFluid(castStack, FluidRegistry.WATER).getFluid()); + if (found) addBackup(recipe); + return found; + })) return true; + + GroovyLog.msg("Error removing Tinkers Construct Casting Basin recipe") + .add("could not find recipe with cast {}", cast) + .error() + .post(); + return false; + } + + @MethodDescription(priority = 2000, example = @Example(commented = true)) + public void removeAll() { + TinkerRegistryAccessor.getBasinCastRegistry().forEach(this::addBackup); + TinkerRegistryAccessor.getBasinCastRegistry().clear(); + } + + @MethodDescription(type = MethodDescription.Type.QUERY) + public SimpleObjectStream streamRecipes() { + return new SimpleObjectStream<>(TinkerRegistryAccessor.getBasinCastRegistry()).setRemover(this::remove); + } + + @Property(property = "fluidInput", valid = @Comp("1")) + @Property(property = "output", valid = @Comp("1")) + public class RecipeBuilder extends AbstractRecipeBuilder { + + @Property + private IIngredient cast; + @Property(defaultValue = "200", valid = @Comp(value = "1", type = Comp.Type.GTE)) + private int time = 200; + @Property + private boolean consumesCast = false; + + @RecipeBuilderMethodDescription(field = "time") + public RecipeBuilder coolingTime(int time) { + this.time = Math.max(time, 1); + return this; + } + + @RecipeBuilderMethodDescription + public RecipeBuilder consumesCast(boolean consumesCast) { + this.consumesCast = consumesCast; + return this; + } + + @RecipeBuilderMethodDescription + public RecipeBuilder consumesCast() { + return consumesCast(!consumesCast); + } + + @RecipeBuilderMethodDescription + public RecipeBuilder cast(IIngredient ingredient) { + this.cast = ingredient; + return this; + } + + @Override + public String getErrorMsg() { + return "Error adding Tinkers Construct Casting Basin recipe"; + } + + @Override + public void validate(GroovyLog.Msg msg) { + validateFluids(msg, 1, 1, 0, 0); + validateItems(msg, 0, 0, 1, 1); + } + + @Override + @RecipeBuilderRegistrationMethod + public @Nullable ICastingRecipe register() { + if (!validate()) return null; + CastingRecipe recipe = new CastingRecipe(output.get(0), cast != null ? MeltingRecipeBuilder.recipeMatchFromIngredient(cast) + : null, fluidInput.get(0), time, consumesCast, false); + add(recipe); + return recipe; + } + } +} diff --git a/src/main/java/com/cleanroommc/groovyscript/compat/mods/tinkersconstruct/CastingTable.java b/src/main/java/com/cleanroommc/groovyscript/compat/mods/tinkersconstruct/CastingTable.java new file mode 100644 index 000000000..b1b3157a1 --- /dev/null +++ b/src/main/java/com/cleanroommc/groovyscript/compat/mods/tinkersconstruct/CastingTable.java @@ -0,0 +1,163 @@ +package com.cleanroommc.groovyscript.compat.mods.tinkersconstruct; + +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.tinkersconstruct.recipe.MeltingRecipeBuilder; +import com.cleanroommc.groovyscript.core.mixin.tconstruct.TinkerRegistryAccessor; +import com.cleanroommc.groovyscript.helper.Alias; +import com.cleanroommc.groovyscript.helper.SimpleObjectStream; +import com.cleanroommc.groovyscript.helper.recipe.AbstractRecipeBuilder; +import com.cleanroommc.groovyscript.registry.VirtualizedRegistry; +import net.minecraft.item.ItemStack; +import net.minecraftforge.fluids.FluidRegistry; +import net.minecraftforge.fluids.FluidStack; +import org.jetbrains.annotations.Nullable; +import slimeknights.tconstruct.library.smeltery.CastingRecipe; +import slimeknights.tconstruct.library.smeltery.ICastingRecipe; + +@RegistryDescription +public class CastingTable extends VirtualizedRegistry { + + @RecipeBuilderDescription(example = @Example(".fluidInput(fluid('lava') * 50).output(item('minecraft:diamond')).coolingTime(750).consumesCast(true).cast(ore('gemEmerald'))")) + public RecipeBuilder recipeBuilder() { + return new RecipeBuilder(); + } + + public CastingTable() { + super(Alias.generateOfClass(CastingTable.class).andGenerate("Table")); + } + + @Override + @GroovyBlacklist + public void onReload() { + removeScripted().forEach(TinkerRegistryAccessor.getTableCastRegistry()::remove); + restoreFromBackup().forEach(TinkerRegistryAccessor.getTableCastRegistry()::add); + } + + public void add(ICastingRecipe recipe) { + if (recipe == null) return; + addScripted(recipe); + TinkerRegistryAccessor.getTableCastRegistry().add(recipe); + } + + public boolean remove(ICastingRecipe recipe) { + if (recipe == null) return false; + addBackup(recipe); + TinkerRegistryAccessor.getTableCastRegistry().remove(recipe); + return true; + } + + @MethodDescription(example = @Example("item('minecraft:gold_ingot')")) + public boolean removeByOutput(ItemStack output) { + if (TinkerRegistryAccessor.getTableCastRegistry().removeIf(recipe -> { + boolean found = recipe.getResult(ItemStack.EMPTY, FluidRegistry.WATER).isItemEqual(output); + if (found) addBackup(recipe); + return found; + })) return true; + + GroovyLog.msg("Error removing Tinkers Construct Casting Table recipe") + .add("could not find recipe with output {}", output) + .error() + .post(); + return false; + } + + @MethodDescription(example = @Example("fluid('iron')")) + public boolean removeByInput(FluidStack input) { + if (TinkerRegistryAccessor.getTableCastRegistry().removeIf(recipe -> { + boolean found = recipe.getFluid(ItemStack.EMPTY, input.getFluid()).isFluidEqual(input); + if (found) addBackup(recipe); + return found; + })) return true; + + GroovyLog.msg("Error removing Tinkers Construct Casting Table recipe") + .add("could not find recipe with input {}", input) + .error() + .post(); + return false; + } + + @MethodDescription(example = @Example("item('minecraft:bucket')")) + public boolean removeByCast(IIngredient cast) { + if (TinkerRegistryAccessor.getTableCastRegistry().removeIf(recipe -> { + boolean found = recipe.matches(cast.getMatchingStacks()[0], recipe.getFluid(cast.getMatchingStacks()[0], FluidRegistry.WATER).getFluid()); + if (found) addBackup(recipe); + return found; + })) return true; + + GroovyLog.msg("Error removing Tinkers Construct Casting Table recipe") + .add("could not find recipe with cast {}", cast) + .error() + .post(); + return false; + } + + @MethodDescription(priority = 2000, example = @Example(commented = true)) + public void removeAll() { + TinkerRegistryAccessor.getTableCastRegistry().forEach(this::addBackup); + TinkerRegistryAccessor.getTableCastRegistry().clear(); + } + + @MethodDescription(type = MethodDescription.Type.QUERY) + public SimpleObjectStream streamRecipes() { + return new SimpleObjectStream<>(TinkerRegistryAccessor.getTableCastRegistry()).setRemover(this::remove); + } + + @Property(property = "fluidInput", valid = @Comp("1")) + @Property(property = "output", valid = @Comp("1")) + public class RecipeBuilder extends AbstractRecipeBuilder { + + @Property + private IIngredient cast; + @Property(defaultValue = "200", valid = @Comp(value = "1", type = Comp.Type.GTE)) + private int time = 200; + @Property + private boolean consumesCast = false; + + @RecipeBuilderMethodDescription(field = "time") + public RecipeBuilder coolingTime(int time) { + this.time = Math.max(time, 1); + return this; + } + + @RecipeBuilderMethodDescription + public RecipeBuilder consumesCast(boolean consumesCast) { + this.consumesCast = consumesCast; + return this; + } + + @RecipeBuilderMethodDescription + public RecipeBuilder consumesCast() { + return consumesCast(!consumesCast); + } + + @RecipeBuilderMethodDescription + public RecipeBuilder cast(IIngredient ingredient) { + this.cast = ingredient; + return this; + } + + @Override + public String getErrorMsg() { + return "Error adding Tinkers Construct Casting Table recipe"; + } + + @Override + public void validate(GroovyLog.Msg msg) { + validateFluids(msg, 1, 1, 0, 0); + validateItems(msg, 0, 0, 1, 1); + } + + @Override + @RecipeBuilderRegistrationMethod + public @Nullable ICastingRecipe register() { + if (!validate()) return null; + CastingRecipe recipe = new CastingRecipe(output.get(0), cast != null ? MeltingRecipeBuilder.recipeMatchFromIngredient(cast) + : null, fluidInput.get(0), time, consumesCast, false); + add(recipe); + return recipe; + } + } +} \ No newline at end of file diff --git a/src/main/java/com/cleanroommc/groovyscript/compat/mods/tinkersconstruct/Drying.java b/src/main/java/com/cleanroommc/groovyscript/compat/mods/tinkersconstruct/Drying.java index 533448e24..017be0918 100644 --- a/src/main/java/com/cleanroommc/groovyscript/compat/mods/tinkersconstruct/Drying.java +++ b/src/main/java/com/cleanroommc/groovyscript/compat/mods/tinkersconstruct/Drying.java @@ -3,6 +3,7 @@ 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.tinkersconstruct.recipe.MeltingRecipeBuilder; import com.cleanroommc.groovyscript.core.mixin.tconstruct.TinkerRegistryAccessor; import com.cleanroommc.groovyscript.helper.SimpleObjectStream; @@ -13,8 +14,10 @@ import org.jetbrains.annotations.Nullable; import slimeknights.tconstruct.library.DryingRecipe; +@RegistryDescription public class Drying extends VirtualizedRegistry { + @RecipeBuilderDescription(example = @Example(".input(item('minecraft:clay')).output(item('minecraft:dirt')).time(45)")) public RecipeBuilder recipeBuilder() { return new RecipeBuilder(); } @@ -26,6 +29,7 @@ public void onReload() { restoreFromBackup().forEach(TinkerRegistryAccessor.getDryingRegistry()::add); } + @MethodDescription(type = MethodDescription.Type.ADDITION) public DryingRecipe add(IIngredient input, ItemStack output, int time) { DryingRecipe recipe = new DryingRecipe(MeltingRecipeBuilder.recipeMatchFromIngredient(input), output, time); add(recipe); @@ -45,6 +49,7 @@ public boolean remove(DryingRecipe recipe) { return true; } + @MethodDescription public boolean removeByInput(IIngredient input) { NonNullList matching = NonNullList.from(ItemStack.EMPTY, input.getMatchingStacks()); if (TinkerRegistryAccessor.getDryingRegistry().removeIf(recipe -> { @@ -60,6 +65,7 @@ public boolean removeByInput(IIngredient input) { return false; } + @MethodDescription public boolean removeByOutput(ItemStack output) { if (TinkerRegistryAccessor.getDryingRegistry().removeIf(recipe -> { boolean found = ItemStack.areItemStacksEqual(recipe.output, output); @@ -74,6 +80,7 @@ public boolean removeByOutput(ItemStack output) { return false; } + @MethodDescription public boolean removeByInputAndOutput(IIngredient input, ItemStack output) { NonNullList matching = NonNullList.from(ItemStack.EMPTY, input.getMatchingStacks()); if (TinkerRegistryAccessor.getDryingRegistry().removeIf(recipe -> { @@ -89,19 +96,25 @@ public boolean removeByInputAndOutput(IIngredient input, ItemStack output) { return false; } + @MethodDescription(priority = 2000, example = @Example(commented = true)) public void removeAll() { TinkerRegistryAccessor.getDryingRegistry().forEach(this::addBackup); - TinkerRegistryAccessor.getDryingRegistry().forEach(TinkerRegistryAccessor.getDryingRegistry()::remove); + TinkerRegistryAccessor.getDryingRegistry().clear(); } + @MethodDescription(type = MethodDescription.Type.QUERY) public SimpleObjectStream streamRecipes() { return new SimpleObjectStream<>(TinkerRegistryAccessor.getDryingRegistry()).setRemover(this::remove); } + @Property(property = "input", valid = @Comp("1")) + @Property(property = "output", valid = @Comp("1")) public class RecipeBuilder extends AbstractRecipeBuilder { + @Property(defaultValue = "20", valid = @Comp(value = "1", type = Comp.Type.GTE)) private int time = 20; + @RecipeBuilderMethodDescription public RecipeBuilder time(int time) { this.time = time; return this; @@ -119,6 +132,7 @@ public void validate(GroovyLog.Msg msg) { } @Override + @RecipeBuilderRegistrationMethod public @Nullable DryingRecipe register() { if (!validate()) return null; DryingRecipe recipe = new DryingRecipe(MeltingRecipeBuilder.recipeMatchFromIngredient(input.get(0)), output.get(0), time); diff --git a/src/main/java/com/cleanroommc/groovyscript/compat/mods/tinkersconstruct/EntityMelting.java b/src/main/java/com/cleanroommc/groovyscript/compat/mods/tinkersconstruct/EntityMelting.java new file mode 100644 index 000000000..bf6473482 --- /dev/null +++ b/src/main/java/com/cleanroommc/groovyscript/compat/mods/tinkersconstruct/EntityMelting.java @@ -0,0 +1,160 @@ +package com.cleanroommc.groovyscript.compat.mods.tinkersconstruct; + +import com.cleanroommc.groovyscript.api.GroovyBlacklist; +import com.cleanroommc.groovyscript.api.GroovyLog; +import com.cleanroommc.groovyscript.api.documentation.annotations.*; +import com.cleanroommc.groovyscript.compat.mods.tinkersconstruct.recipe.EntityMeltingRecipe; +import com.cleanroommc.groovyscript.core.mixin.tconstruct.TinkerRegistryAccessor; +import com.cleanroommc.groovyscript.helper.SimpleObjectStream; +import com.cleanroommc.groovyscript.helper.recipe.IRecipeBuilder; +import com.cleanroommc.groovyscript.registry.VirtualizedRegistry; +import net.minecraft.entity.EntityList; +import net.minecraft.util.ResourceLocation; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fml.common.registry.EntityEntry; +import org.jetbrains.annotations.Nullable; + +import java.util.List; +import java.util.stream.Collectors; + +@RegistryDescription +public class EntityMelting extends VirtualizedRegistry { + + @RecipeBuilderDescription(example = @Example(".fluidOutput(fluid('iron') * 500).input(resource('minecraft:pig'))")) + public RecipeBuilder recipeBuilder() { + return new RecipeBuilder(); + } + + @Override + @GroovyBlacklist + public void onReload() { + removeScripted().forEach(recipe -> TinkerRegistryAccessor.getEntityMeltingRegistry().remove(recipe.name, recipe.result)); + restoreFromBackup().forEach(recipe -> TinkerRegistryAccessor.getEntityMeltingRegistry().put(recipe.name, recipe.result)); + } + + @MethodDescription(type = MethodDescription.Type.QUERY) + protected List getAllRecipes() { + return TinkerRegistryAccessor.getEntityMeltingRegistry().entrySet().stream().map(EntityMeltingRecipe::fromMapEntry).collect(Collectors.toList()); + } + + public EntityMeltingRecipe add(EntityEntry entity, FluidStack output) { + EntityMeltingRecipe recipe = new EntityMeltingRecipe(entity, output); + add(recipe); + return recipe; + } + + public void add(EntityMeltingRecipe recipe) { + if (recipe == null || recipe.name == null) return; + addScripted(recipe); + TinkerRegistryAccessor.getEntityMeltingRegistry().put(recipe.name, recipe.result); + } + + public boolean remove(EntityMeltingRecipe recipe) { + if (recipe == null || recipe.name == null) return false; + addBackup(recipe); + TinkerRegistryAccessor.getEntityMeltingRegistry().remove(recipe.name, recipe.result); + return true; + } + + @MethodDescription + public boolean removeByInput(EntityEntry entity) { + ResourceLocation name = entity.getRegistryName(); + if (TinkerRegistryAccessor.getEntityMeltingRegistry().entrySet().removeIf(entry -> { + boolean found = entry.getKey().equals(name); + if (found) addBackup(new EntityMeltingRecipe(entry.getKey(), entry.getValue())); + return found; + })) return true; + + GroovyLog.msg("Error removing Tinkers Construct Entity Melting recipe") + .add("could not find recipe with input {}", name) + .error() + .post(); + return false; + } + + @MethodDescription + public boolean removeByOutput(FluidStack output) { + if (TinkerRegistryAccessor.getEntityMeltingRegistry().entrySet().removeIf(entry -> { + boolean found = entry.getValue().isFluidEqual(output); + if (found) addBackup(new EntityMeltingRecipe(entry.getKey(), entry.getValue())); + return found; + })) return true; + + GroovyLog.msg("Error removing Tinkers Construct Entity Melting recipe") + .add("could not find recipe with output {}", output) + .error() + .post(); + return false; + } + + @MethodDescription(priority = 2000, example = @Example(commented = true)) + public void removeAll() { + TinkerRegistryAccessor.getEntityMeltingRegistry().forEach((name, result) -> addBackup(new EntityMeltingRecipe(name, result))); + TinkerRegistryAccessor.getEntityMeltingRegistry().clear(); + } + + @MethodDescription(description = "groovyscript.wiki.streamRecipes", type = MethodDescription.Type.QUERY) + public SimpleObjectStream streamRecipes() { + return new SimpleObjectStream<>(getAllRecipes()).setRemover(this::remove); + } + + public class RecipeBuilder implements IRecipeBuilder { + + @Property(valid = @Comp(value = "null", type = Comp.Type.NOT)) + private FluidStack output; + @Property(valid = @Comp(value = "null", type = Comp.Type.NOT)) + private ResourceLocation input; + + @RecipeBuilderMethodDescription(field = "output") + public RecipeBuilder fluidOutput(FluidStack stack) { + this.output = stack; + return this; + } + + @RecipeBuilderMethodDescription + public RecipeBuilder input(ResourceLocation name) { + this.input = name; + return this; + } + + @RecipeBuilderMethodDescription + public RecipeBuilder input(String name) { + return input(new ResourceLocation(name)); + } + + @RecipeBuilderMethodDescription + public RecipeBuilder input(String modid, String name) { + return input(new ResourceLocation(modid, name)); + } + + @RecipeBuilderMethodDescription + public RecipeBuilder input(EntityEntry entity) { + return input(entity.getRegistryName()); + } + + private String getErrorMsg() { + return "Error adding Tinkers Construct Entity Melting recipe"; + } + + private void validate(GroovyLog.Msg msg) { + msg.add(input == null || EntityList.getClass(input) == null, "Expected valid entity name, got " + input); + msg.add(output == null || output.amount < 1, "Expected 1 output fluid but found none!"); + } + + @Override + public boolean validate() { + GroovyLog.Msg msg = GroovyLog.msg(this.getErrorMsg()).error(); + this.validate(msg); + return !msg.postIfNotEmpty(); + } + + @Override + @RecipeBuilderRegistrationMethod + public @Nullable EntityMeltingRecipe register() { + if (!validate()) return null; + EntityMeltingRecipe recipe = new EntityMeltingRecipe(input, output); + add(recipe); + return recipe; + } + } +} diff --git a/src/main/java/com/cleanroommc/groovyscript/compat/mods/tinkersconstruct/Melting.java b/src/main/java/com/cleanroommc/groovyscript/compat/mods/tinkersconstruct/Melting.java index c74dd1d5b..f1d52242a 100644 --- a/src/main/java/com/cleanroommc/groovyscript/compat/mods/tinkersconstruct/Melting.java +++ b/src/main/java/com/cleanroommc/groovyscript/compat/mods/tinkersconstruct/Melting.java @@ -3,30 +3,23 @@ import com.cleanroommc.groovyscript.api.GroovyBlacklist; import com.cleanroommc.groovyscript.api.GroovyLog; import com.cleanroommc.groovyscript.api.IIngredient; -import com.cleanroommc.groovyscript.compat.mods.tinkersconstruct.recipe.EntityMeltingRecipe; +import com.cleanroommc.groovyscript.api.documentation.annotations.Example; +import com.cleanroommc.groovyscript.api.documentation.annotations.MethodDescription; +import com.cleanroommc.groovyscript.api.documentation.annotations.RecipeBuilderDescription; +import com.cleanroommc.groovyscript.api.documentation.annotations.RegistryDescription; import com.cleanroommc.groovyscript.compat.mods.tinkersconstruct.recipe.MeltingRecipeBuilder; import com.cleanroommc.groovyscript.compat.mods.tinkersconstruct.recipe.MeltingRecipeRegistry; import com.cleanroommc.groovyscript.core.mixin.tconstruct.TinkerRegistryAccessor; import com.cleanroommc.groovyscript.helper.SimpleObjectStream; -import com.cleanroommc.groovyscript.helper.recipe.IRecipeBuilder; -import com.cleanroommc.groovyscript.registry.AbstractReloadableStorage; -import com.cleanroommc.groovyscript.registry.VirtualizedRegistry; -import net.minecraft.entity.EntityList; import net.minecraft.item.ItemStack; import net.minecraft.util.NonNullList; -import net.minecraft.util.ResourceLocation; import net.minecraftforge.fluids.FluidStack; -import net.minecraftforge.fml.common.registry.EntityEntry; -import org.jetbrains.annotations.Nullable; import slimeknights.tconstruct.library.smeltery.MeltingRecipe; -import java.util.List; -import java.util.stream.Collectors; - +@RegistryDescription public class Melting extends MeltingRecipeRegistry { - public final EntityMelting entityMelting = new EntityMelting(); - + @RecipeBuilderDescription(example = @Example(".input(item('minecraft:gravel')).fluidOutput(fluid('lava') * 25).time(80)")) public RecipeBuilder recipeBuilder() { return new RecipeBuilder(this); } @@ -36,9 +29,9 @@ public RecipeBuilder recipeBuilder() { public void onReload() { removeScripted().forEach(TinkerRegistryAccessor.getMeltingRegistry()::remove); restoreFromBackup().forEach(TinkerRegistryAccessor.getMeltingRegistry()::add); - entityMelting.onReload(); } + @MethodDescription(type = MethodDescription.Type.ADDITION) public MeltingRecipe add(IIngredient input, FluidStack output, int temp) { MeltingRecipe recipe = new MeltingRecipe(MeltingRecipeBuilder.recipeMatchFromIngredient(input, output.amount), output, temp); add(recipe); @@ -58,6 +51,7 @@ public boolean remove(MeltingRecipe recipe) { return true; } + @MethodDescription public boolean removeByInput(IIngredient input) { NonNullList matching = NonNullList.from(ItemStack.EMPTY, input.getMatchingStacks()); if (TinkerRegistryAccessor.getMeltingRegistry().removeIf(recipe -> { @@ -73,6 +67,7 @@ public boolean removeByInput(IIngredient input) { return false; } + @MethodDescription public boolean removeByOutput(FluidStack output) { if (TinkerRegistryAccessor.getMeltingRegistry().removeIf(recipe -> { boolean found = recipe.getResult().isFluidEqual(output); @@ -87,6 +82,7 @@ public boolean removeByOutput(FluidStack output) { return false; } + @MethodDescription public boolean removeByInputAndOutput(IIngredient input, FluidStack output) { NonNullList matching = NonNullList.from(ItemStack.EMPTY, input.getMatchingStacks()); if (TinkerRegistryAccessor.getMeltingRegistry().removeIf(recipe -> { @@ -102,11 +98,13 @@ public boolean removeByInputAndOutput(IIngredient input, FluidStack output) { return false; } + @MethodDescription(priority = 2000, example = @Example(commented = true)) public void removeAll() { TinkerRegistryAccessor.getMeltingRegistry().forEach(this::addBackup); - TinkerRegistryAccessor.getMeltingRegistry().forEach(TinkerRegistryAccessor.getMeltingRegistry()::remove); + TinkerRegistryAccessor.getMeltingRegistry().clear(); } + @MethodDescription(type = MethodDescription.Type.QUERY) public SimpleObjectStream streamRecipes() { return new SimpleObjectStream<>(TinkerRegistryAccessor.getMeltingRegistry()).setRemover(this::remove); } @@ -117,143 +115,4 @@ public RecipeBuilder(Melting melting) { super(melting, "Tinkers Construct Melting recipe"); } } - - public static class EntityMelting extends VirtualizedRegistry { - - @Override - @GroovyBlacklist - protected AbstractReloadableStorage createRecipeStorage() { - return new AbstractReloadableStorage<>() { - @Override - @GroovyBlacklist - protected boolean compareRecipe(EntityMeltingRecipe recipe, EntityMeltingRecipe recipe2) { - return recipe.equals(recipe2); - } - }; - } - - public RecipeBuilder recipeBuilder() { - return new RecipeBuilder(); - } - - @Override - @GroovyBlacklist - public void onReload() { - removeScripted().forEach(recipe -> TinkerRegistryAccessor.getEntityMeltingRegistry().remove(recipe.name, recipe.result)); - restoreFromBackup().forEach(recipe -> TinkerRegistryAccessor.getEntityMeltingRegistry().put(recipe.name, recipe.result)); - } - - protected List getAllRecipes() { - return TinkerRegistryAccessor.getEntityMeltingRegistry().entrySet().stream().map(EntityMeltingRecipe::fromMapEntry).collect(Collectors.toList()); - } - - public EntityMeltingRecipe add(EntityEntry entity, FluidStack output) { - EntityMeltingRecipe recipe = new EntityMeltingRecipe(entity, output); - add(recipe); - return recipe; - } - - public void add(EntityMeltingRecipe recipe) { - if (recipe == null || recipe.name == null) return; - addScripted(recipe); - TinkerRegistryAccessor.getEntityMeltingRegistry().put(recipe.name, recipe.result); - } - - public boolean remove(EntityMeltingRecipe recipe) { - if (recipe == null || recipe.name == null) return false; - addBackup(recipe); - TinkerRegistryAccessor.getEntityMeltingRegistry().remove(recipe.name, recipe.result); - return true; - } - - public boolean removeByInput(EntityEntry entity) { - ResourceLocation name = entity.getRegistryName(); - if (TinkerRegistryAccessor.getEntityMeltingRegistry().entrySet().removeIf(entry -> { - boolean found = entry.getKey().equals(name); - if (found) addBackup(new EntityMeltingRecipe(entry.getKey(), entry.getValue())); - return found; - })) return true; - - GroovyLog.msg("Error removing Tinkers Construct Entity Melting recipe") - .add("could not find recipe with input {}", name) - .error() - .post(); - return false; - } - - public boolean removeByOutput(FluidStack output) { - if (TinkerRegistryAccessor.getEntityMeltingRegistry().entrySet().removeIf(entry -> { - boolean found = entry.getValue().isFluidEqual(output); - if (found) addBackup(new EntityMeltingRecipe(entry.getKey(), entry.getValue())); - return found; - })) return true; - - GroovyLog.msg("Error removing Tinkers Construct Entity Melting recipe") - .add("could not find recipe with output {}", output) - .error() - .post(); - return false; - } - - public void removeAll() { - TinkerRegistryAccessor.getEntityMeltingRegistry().forEach((name, result) -> addBackup(new EntityMeltingRecipe(name, result))); - TinkerRegistryAccessor.getEntityMeltingRegistry().forEach(TinkerRegistryAccessor.getEntityMeltingRegistry()::remove); - } - - public SimpleObjectStream streamRecipes() { - return new SimpleObjectStream<>(getAllRecipes()).setRemover(this::remove); - } - - public class RecipeBuilder implements IRecipeBuilder { - - private FluidStack output; - private ResourceLocation input; - - public RecipeBuilder fluidOutput(FluidStack stack) { - this.output = stack; - return this; - } - - public RecipeBuilder input(ResourceLocation name) { - this.input = name; - return this; - } - - public RecipeBuilder input(String name) { - return input(new ResourceLocation(name)); - } - - public RecipeBuilder input(String modid, String name) { - return input(new ResourceLocation(modid, name)); - } - - public RecipeBuilder input(EntityEntry entity) { - return input(entity.getRegistryName()); - } - - private String getErrorMsg() { - return "Error adding Tinkers Construct Entity Melting recipe"; - } - - private void validate(GroovyLog.Msg msg) { - msg.add(input == null || EntityList.getClass(input) == null, "Expected valid entity name, got " + input); - msg.add(output == null || output.amount < 1, "Expected 1 output fluid but found none!"); - } - - @Override - public boolean validate() { - GroovyLog.Msg msg = GroovyLog.msg(this.getErrorMsg()).error(); - this.validate(msg); - return !msg.postIfNotEmpty(); - } - - @Override - public @Nullable EntityMeltingRecipe register() { - if (!validate()) return null; - EntityMeltingRecipe recipe = new EntityMeltingRecipe(input, output); - add(recipe); - return recipe; - } - } - } } diff --git a/src/main/java/com/cleanroommc/groovyscript/compat/mods/tinkersconstruct/SmelteryFuel.java b/src/main/java/com/cleanroommc/groovyscript/compat/mods/tinkersconstruct/SmelteryFuel.java index 223aa6f98..8e35dcea0 100644 --- a/src/main/java/com/cleanroommc/groovyscript/compat/mods/tinkersconstruct/SmelteryFuel.java +++ b/src/main/java/com/cleanroommc/groovyscript/compat/mods/tinkersconstruct/SmelteryFuel.java @@ -2,6 +2,9 @@ import com.cleanroommc.groovyscript.api.GroovyBlacklist; import com.cleanroommc.groovyscript.api.GroovyLog; +import com.cleanroommc.groovyscript.api.documentation.annotations.Example; +import com.cleanroommc.groovyscript.api.documentation.annotations.MethodDescription; +import com.cleanroommc.groovyscript.api.documentation.annotations.RegistryDescription; import com.cleanroommc.groovyscript.compat.mods.tinkersconstruct.recipe.SmelteryFuelRecipe; import com.cleanroommc.groovyscript.core.mixin.tconstruct.TinkerRegistryAccessor; import com.cleanroommc.groovyscript.helper.SimpleObjectStream; @@ -12,6 +15,7 @@ import java.util.List; import java.util.stream.Collectors; +@RegistryDescription(category = RegistryDescription.Category.ENTRIES) public class SmelteryFuel extends VirtualizedRegistry { @Override @@ -37,12 +41,14 @@ protected List getAllRecipes() { return TinkerRegistryAccessor.getSmelteryFuels().entrySet().stream().map(SmelteryFuelRecipe::fromMapEntry).collect(Collectors.toList()); } + @MethodDescription(type = MethodDescription.Type.ADDITION, example = @Example("fluid('water'), 250")) public SmelteryFuelRecipe addFuel(FluidStack fluid, int duration) { SmelteryFuelRecipe recipe = new SmelteryFuelRecipe(fluid, duration); add(recipe); return recipe; } + @MethodDescription public boolean removeFuel(FluidStack fluid) { if (TinkerRegistryAccessor.getSmelteryFuels().entrySet().removeIf(entry -> { boolean found = entry.getKey().isFluidEqual(fluid); @@ -70,11 +76,13 @@ public boolean remove(SmelteryFuelRecipe recipe) { return true; } + @MethodDescription(priority = 2000, example = @Example(commented = true)) public void removeAll() { TinkerRegistryAccessor.getSmelteryFuels().forEach((fluid, duration) -> addBackup(new SmelteryFuelRecipe(fluid, duration))); - TinkerRegistryAccessor.getSmelteryFuels().forEach(TinkerRegistryAccessor.getSmelteryFuels()::remove); + TinkerRegistryAccessor.getSmelteryFuels().clear(); } + @MethodDescription(type = MethodDescription.Type.QUERY) public SimpleObjectStream streamRecipes() { return new SimpleObjectStream<>(getAllRecipes()).setRemover(this::remove); } diff --git a/src/main/java/com/cleanroommc/groovyscript/compat/mods/tinkersconstruct/TinkersConstruct.java b/src/main/java/com/cleanroommc/groovyscript/compat/mods/tinkersconstruct/TinkersConstruct.java index 278873038..bc898aad8 100644 --- a/src/main/java/com/cleanroommc/groovyscript/compat/mods/tinkersconstruct/TinkersConstruct.java +++ b/src/main/java/com/cleanroommc/groovyscript/compat/mods/tinkersconstruct/TinkersConstruct.java @@ -16,18 +16,21 @@ public class TinkersConstruct extends ModPropertyContainer { public final Drying drying = new Drying(); public final Melting melting = new Melting(); + public final EntityMelting entityMelting = new EntityMelting(); public final SmelteryFuel smelteryFuel = new SmelteryFuel(); public final Alloying alloying = new Alloying(); - public final Casting casting = new Casting(); + public final CastingTable castingTable = new CastingTable(); + public final CastingBasin castingBasin = new CastingBasin(); public final Materials materials = new Materials(); public TinkersConstruct() { addRegistry(drying); addRegistry(melting); + addRegistry(entityMelting); addRegistry(smelteryFuel); addRegistry(alloying); - addRegistry(casting.table); - addRegistry(casting.basin); + addRegistry(castingTable); + addRegistry(castingBasin); addRegistry(materials); } diff --git a/src/main/java/com/cleanroommc/groovyscript/compat/mods/tinkersconstruct/recipe/MeltingRecipeBuilder.java b/src/main/java/com/cleanroommc/groovyscript/compat/mods/tinkersconstruct/recipe/MeltingRecipeBuilder.java index 1bf42a3d7..5c49a1bad 100644 --- a/src/main/java/com/cleanroommc/groovyscript/compat/mods/tinkersconstruct/recipe/MeltingRecipeBuilder.java +++ b/src/main/java/com/cleanroommc/groovyscript/compat/mods/tinkersconstruct/recipe/MeltingRecipeBuilder.java @@ -2,6 +2,10 @@ import com.cleanroommc.groovyscript.api.GroovyLog; import com.cleanroommc.groovyscript.api.IIngredient; +import com.cleanroommc.groovyscript.api.documentation.annotations.Comp; +import com.cleanroommc.groovyscript.api.documentation.annotations.Property; +import com.cleanroommc.groovyscript.api.documentation.annotations.RecipeBuilderMethodDescription; +import com.cleanroommc.groovyscript.api.documentation.annotations.RecipeBuilderRegistrationMethod; import com.cleanroommc.groovyscript.core.mixin.tconstruct.MeltingRecipeAccessor; import com.cleanroommc.groovyscript.helper.ingredient.OreDictIngredient; import com.cleanroommc.groovyscript.helper.recipe.AbstractRecipeBuilder; @@ -9,8 +13,10 @@ import slimeknights.mantle.util.RecipeMatch; import slimeknights.tconstruct.library.smeltery.MeltingRecipe; +@Property(property = "input", valid = @Comp("1")) public class MeltingRecipeBuilder extends AbstractRecipeBuilder { + @Property(defaultValue = "300", valid = @Comp(value = "1", type = Comp.Type.GTE)) private int temp = 300; private final MeltingRecipeRegistry registry; private final String recipeName; @@ -29,11 +35,13 @@ public MeltingRecipeBuilder(MeltingRecipeRegistry registry, String recipeName) { this.recipeName = recipeName; } + @RecipeBuilderMethodDescription(field = "temp") public MeltingRecipeBuilder temperature(int temp) { this.temp = temp + 300; return this; } + @RecipeBuilderMethodDescription(field = "temp") public MeltingRecipeBuilder time(int time) { int t = fluidOutput.get(0) != null ? fluidOutput.get(0).getFluid().getTemperature() : 300; this.temp = MeltingRecipeAccessor.invokeCalcTemperature(t, time); @@ -53,6 +61,7 @@ public void validate(GroovyLog.Msg msg) { } @Override + @RecipeBuilderRegistrationMethod public @Nullable MeltingRecipe register() { if (!validate()) return null; int amount = fluidOutput.get(0).amount; diff --git a/src/main/resources/assets/groovyscript/lang/en_us.lang b/src/main/resources/assets/groovyscript/lang/en_us.lang index 6dddea30a..c67743bb3 100644 --- a/src/main/resources/assets/groovyscript/lang/en_us.lang +++ b/src/main/resources/assets/groovyscript/lang/en_us.lang @@ -71,6 +71,7 @@ groovyscript.wiki.craftingrecipe.ingredients.value=Sets the items required for t groovyscript.wiki.removeByInput=Removes all recipes that match the given input groovyscript.wiki.removeByOutput=Removes all recipes that match the given output +groovyscript.wiki.removeByInputAndOutput=Removes all recipes that match the given input and the given output groovyscript.wiki.removeByOre=Removes all recipes that match the given ore groovyscript.wiki.removeByCatalyst=Removes all recipes that match the given catalyst groovyscript.wiki.removeByInputAndCatalyst=This removes all recipes that match the given input and Catalyst @@ -1358,6 +1359,48 @@ groovyscript.wiki.rustic.evaporating_basin.description=Converts fluids into item groovyscript.wiki.rustic.evaporating_basin.time.value=Sets the time in ticks the recipe will take +# Tinkers +groovyscript.wiki.tconstruct.smeltery_fuel.title=Smeltery Fuel +groovyscript.wiki.tconstruct.smeltery_fuel.description=Modifies what fluids are accepted as fuels for the Smeltery and how long each fuels the Smeltery. +groovyscript.wiki.tconstruct.smeltery_fuel.addFuel=Adds the given fluid as a smeltery fuel with the given burn time +groovyscript.wiki.tconstruct.smeltery_fuel.removeFuel=Removes the given fluid from being a smeltery fuel + +groovyscript.wiki.tconstruct.drying.title=Drying Rack +groovyscript.wiki.tconstruct.drying.description=Convert an item into a different item by hanging it out to dry. +groovyscript.wiki.tconstruct.drying.add=Adds a new recipe in the format `input`, `output`, `time` +groovyscript.wiki.tconstruct.drying.time.value=The time in ticks it takes for the item to dry + +groovyscript.wiki.tconstruct.casting_table.title=Casting Table +groovyscript.wiki.tconstruct.casting_table.description=Pours out fluid onto a table to solidify it into a solid, optionally with a cast itemstack. +groovyscript.wiki.tconstruct.casting_table.removeByCast=Removes all recipes that use the given item as a cast +groovyscript.wiki.tconstruct.casting_table.cast.value=The item to use as a cast. null for no cast +groovyscript.wiki.tconstruct.casting_table.time.value=The time in ticks it takes for the recipe to complete +groovyscript.wiki.tconstruct.casting_table.consumesCast.value=Whether the cast item is destroyed + +groovyscript.wiki.tconstruct.casting_basin.title=Casting Basin +groovyscript.wiki.tconstruct.casting_basin.description=Pours out fluid into a basin to solidify it into a solid, optionally with a cast itemstack. +groovyscript.wiki.tconstruct.casting_basin.removeByCast=Removes all recipes that use the given item as a cast +groovyscript.wiki.tconstruct.casting_basin.cast.value=The item to use as a cast. null for no cast +groovyscript.wiki.tconstruct.casting_basin.time.value=The time in ticks it takes for the recipe to complete +groovyscript.wiki.tconstruct.casting_basin.consumesCast.value=Whether the cast item is destroyed + +groovyscript.wiki.tconstruct.melting.title=Melting +groovyscript.wiki.tconstruct.melting.description=Modifies what items can be melted down in the Smeltery. +groovyscript.wiki.tconstruct.melting.add=Adds a new recipe in the format `input`, `output`, `time` +groovyscript.wiki.tconstruct.melting.temp.value=Required temperature for melting. Also determines the speed of the melt + +groovyscript.wiki.tconstruct.entity_melting.title=Entity Melting +groovyscript.wiki.tconstruct.entity_melting.description=Allows mobs to create a bit of fluid when hurt by the Smeltery. +groovyscript.wiki.tconstruct.entity_melting.input.value=The entity to melt +groovyscript.wiki.tconstruct.entity_melting.output.value=The fluid created each damage tick + +groovyscript.wiki.tconstruct.alloying.title=Alloying +groovyscript.wiki.tconstruct.alloying.description=Modifies what fluids can be mixed together in the Smeltery. +groovyscript.wiki.tconstruct.alloying.add=Adds a new recipe in the format `output`, `inputs` +groovyscript.wiki.tconstruct.alloying.removeByInputsAndOutput=Removes all recipes that match the given output and the given inputs +groovyscript.wiki.tconstruct.alloying.removeByInputs=Removes all recipes that match the given inputs + + # Thaumcraft groovyscript.wiki.thaumcraft.arcane_workbench.title=Arcane Workbench groovyscript.wiki.thaumcraft.arcane_workbench.description=A special crafting table, allowing additional requirements in the form of Vis Crystals, Vis, and having a specific research.