Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
560 changes: 520 additions & 40 deletions examples/postInit/pyrotech.groovy

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,22 @@
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.EnumHelper;
import com.cleanroommc.groovyscript.helper.ingredient.IngredientHelper;
import com.cleanroommc.groovyscript.helper.recipe.AbstractRecipeBuilder;
import com.cleanroommc.groovyscript.registry.ForgeRegistryWrapper;
import com.codetaylor.mc.pyrotech.ModPyrotech;
import com.codetaylor.mc.pyrotech.modules.tech.basic.ModuleTechBasic;
import com.codetaylor.mc.pyrotech.modules.tech.basic.init.recipe.AnvilIroncladRecipesAdd;
import com.codetaylor.mc.pyrotech.modules.tech.basic.init.recipe.AnvilObsidianRecipesAdd;
import com.codetaylor.mc.pyrotech.modules.tech.basic.recipe.AnvilRecipe;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import org.jetbrains.annotations.Nullable;

import java.util.Arrays;
import java.util.Locale;

@RegistryDescription
public class Anvil extends ForgeRegistryWrapper<AnvilRecipe> {
Expand All @@ -21,17 +27,27 @@ public Anvil() {
super(ModuleTechBasic.Registries.ANVIL_RECIPE);
}

@Override
public boolean isEnabled() {
return ModPyrotech.INSTANCE.isModuleEnabled(ModuleTechBasic.class);
}

@RecipeBuilderDescription(example = {
@Example(".input(item('minecraft:diamond') * 4).output(item('minecraft:emerald') * 2).hits(5).typeHammer().tierGranite().name('diamond_to_emerald_granite_anvil')"),
@Example(".input(item('minecraft:diamond') * 8).output(item('minecraft:nether_star') * 1).hits(10).typePickaxe().tierIronclad().name('diamond_to_nether_star_ironclad_anvil')"),
@Example(".input(item('minecraft:diamond') * 4).output(item('minecraft:gold_ingot') * 16).hits(5).typePickaxe().tierObsidian().name('diamond_to_gold_obsidian_anvil')")
@Example(".input(item('minecraft:diamond')).output(item('minecraft:emerald') * 2).hits(8).typeHammer().tierGranite().name('diamond_to_emerald_granite_anvil')"),
@Example(".input(item('minecraft:bedrock')).output(item('minecraft:nether_star') * 1).hits(10).typePickaxe().tierIronclad().inherit(true).name('bedrock_to_nether_star')"),
@Example(".input(item('minecraft:gold_block')).output(item('minecraft:gold_ingot') * 16).hits(5).typePickaxe().tierObsidian().name('gold_block_to_gold_obsidian_anvil')")
})
public RecipeBuilder recipeBuilder() {
return new RecipeBuilder();
}

@MethodDescription(type = MethodDescription.Type.ADDITION, example = @Example("'iron_to_clay', ore('ingotIron'), item('minecraft:clay_ball'), 9, 'granite', 'hammer'"))
@MethodDescription(type = MethodDescription.Type.ADDITION)
public AnvilRecipe add(String name, IIngredient input, ItemStack output, int hits, String tier, String type) {
return add(name, input, output, hits, tier, type, false);
}

@MethodDescription(type = MethodDescription.Type.ADDITION, description = "groovyscript.wiki.pyrotech.anvil.add.inherit", example = @Example("'flint_from_gravel', ore('gravel'), item('minecraft:flint'), 5, 'granite', 'pickaxe', true"))
public AnvilRecipe add(String name, IIngredient input, ItemStack output, int hits, String tier, String type, boolean inherit) {
AnvilRecipe.EnumTier enumTier = EnumHelper.valueOfNullable(AnvilRecipe.EnumTier.class, tier, false);
AnvilRecipe.EnumType enumType = EnumHelper.valueOfNullable(AnvilRecipe.EnumType.class, type, false);
if (enumTier == null || enumType == null) {
Expand All @@ -46,22 +62,38 @@ public AnvilRecipe add(String name, IIngredient input, ItemStack output, int hit
.hits(hits)
.tier(enumTier)
.type(enumType)
.inherit(inherit)
.name(name)
.input(input)
.output(output)
.register();
}

@MethodDescription(example = @Example("item('minecraft:stone_slab', 3)"))
public void removeByOutput(ItemStack output) {
@MethodDescription(type = MethodDescription.Type.REMOVAL, example = @Example("item('pyrotech:material:37')"))
public void removeByInput(ItemStack input) {
if (GroovyLog.msg("Error removing pyrotech anvil recipe")
.add(IngredientHelper.isEmpty(input), () -> "Input 1 must not be empty")
.error()
.postIfNotEmpty()) {
return;
}
for (AnvilRecipe recipe : getRegistry()) {
if (recipe.getInput().test(input)) {
remove(recipe);
}
}
}

@MethodDescription(type = MethodDescription.Type.REMOVAL, example = @Example("item('minecraft:stone_slab:3') * 2"))
public void removeByOutput(IIngredient output) {
if (GroovyLog.msg("Error removing pyrotech anvil recipe")
.add(IngredientHelper.isEmpty(output), () -> "Output 1 must not be empty")
.error()
.postIfNotEmpty()) {
return;
}
for (AnvilRecipe recipe : getRegistry()) {
if (recipe.getOutput().isItemEqual(output)) {
if (output.test(recipe.getOutput())) {
remove(recipe);
}
}
Expand All @@ -74,13 +106,12 @@ public static class RecipeBuilder extends AbstractRecipeBuilder<AnvilRecipe> {

@Property(comp = @Comp(gt = 0))
private int hits;

@Property
@Property(comp = @Comp(not = "null"))
private AnvilRecipe.EnumType type;

@Property
@Property(comp = @Comp(not = "null"))
private AnvilRecipe.EnumTier tier;

@Property
private boolean inherit;

@RecipeBuilderMethodDescription
public RecipeBuilder hits(int hits) {
Expand All @@ -104,7 +135,6 @@ public RecipeBuilder typePickaxe() {
return type(AnvilRecipe.EnumType.PICKAXE);
}

@RecipeBuilderMethodDescription
public RecipeBuilder tier(AnvilRecipe.EnumTier tier) {
this.tier = tier;
return this;
Expand All @@ -125,6 +155,17 @@ public RecipeBuilder tierObsidian() {
return tier(AnvilRecipe.EnumTier.OBSIDIAN);
}

@RecipeBuilderMethodDescription
public RecipeBuilder inherit(boolean inherit) {
this.inherit = inherit;
return this;
}

@Override
public String getRecipeNamePrefix() {
return "groovyscript_anvil_";
}

@Override
public String getErrorMsg() {
return "Error adding Pyrotech Anvil Recipe";
Expand All @@ -138,21 +179,35 @@ protected int getMaxItemInput() {

@Override
public void validate(GroovyLog.Msg msg) {
validateName();
validateItems(msg, 1, 1, 1, 1);
msg.add(hits < 0, "duration must be a non negative integer, yet it was {}", hits);
msg.add(type == null, "type cannot be null. ");
msg.add(hits <= 0, "duration must be a non negative integer that is larger than 0, yet it was {}", hits);
msg.add(type == null, "type cannot be null.");
msg.add(tier == null, "tier cannot be null.");
msg.add(super.name == null, "name cannot be null.");
msg.add(ModuleTechBasic.Registries.ANVIL_RECIPE.getValue(super.name) != null, "tried to register {}, but it already exists.", super.name);
msg.add(tier == AnvilRecipe.EnumTier.OBSIDIAN && inherit, "nothing can inherit from obsidian anvil.");
}

@Override
@RecipeBuilderRegistrationMethod
@Override
public @Nullable AnvilRecipe register() {
if (!validate()) return null;

AnvilRecipe recipe = new AnvilRecipe(output.get(0), input.get(0).toMcIngredient(), hits, type, tier).setRegistryName(super.name);
PyroTech.anvil.add(recipe);
ModSupport.PYROTECH.get().anvil.add(recipe);
if (inherit) {
String name = null;
if (tier.ordinal() < 2) {
name = tier.name().toLowerCase(Locale.ENGLISH) + "_anvil";
AnvilRecipe obsidianRecipe = AnvilObsidianRecipesAdd.INHERIT_TRANSFORMER.apply(recipe);
obsidianRecipe.setRegistryName(new ResourceLocation(super.name.getNamespace(), name + "/" + super.name.getPath()));
ModSupport.PYROTECH.get().anvil.add(obsidianRecipe);
}
if (tier.ordinal() < 1) {
AnvilRecipe ironcladRecipe = AnvilIroncladRecipesAdd.INHERIT_TRANSFORMER.apply(recipe);
ironcladRecipe.setRegistryName(new ResourceLocation(super.name.getNamespace(), name + "/" + super.name.getPath()));
ModSupport.PYROTECH.get().anvil.add(ironcladRecipe);
}
}
return recipe;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
import com.cleanroommc.groovyscript.api.GroovyLog;
import com.cleanroommc.groovyscript.api.IIngredient;
import com.cleanroommc.groovyscript.api.documentation.annotations.*;
import com.cleanroommc.groovyscript.compat.mods.ModSupport;
import com.cleanroommc.groovyscript.helper.ingredient.IngredientHelper;
import com.cleanroommc.groovyscript.helper.recipe.AbstractRecipeBuilder;
import com.cleanroommc.groovyscript.registry.ForgeRegistryWrapper;
import com.codetaylor.mc.pyrotech.ModPyrotech;
import com.codetaylor.mc.pyrotech.modules.tech.basic.ModuleTechBasic;
import com.codetaylor.mc.pyrotech.modules.tech.basic.recipe.BarrelRecipe;
import net.minecraft.item.crafting.Ingredient;
Expand All @@ -19,6 +21,11 @@ public Barrel() {
super(ModuleTechBasic.Registries.BARREL_RECIPE);
}

@Override
public boolean isEnabled() {
return ModPyrotech.INSTANCE.isModuleEnabled(ModuleTechBasic.class);
}

@RecipeBuilderDescription(
example = @Example(
".input(item('minecraft:diamond'), item('minecraft:diamond'), item('minecraft:diamond'), item('minecraft:emerald')).fluidInput(fluid('water') * 1000).fluidOutput(fluid('amongium') * 1000).duration(1000).name('diamond_emerald_and_water_to_amongium')")
Expand All @@ -38,7 +45,7 @@ public BarrelRecipe add(String name, IIngredient input1, IIngredient input2, IIn
.register();
}

@MethodDescription(example = @Example("fluid('freckleberry_wine') * 1000"))
@MethodDescription(type = MethodDescription.Type.REMOVAL, example = @Example("fluid('freckleberry_wine') * 1000"))
public void removeByOutput(FluidStack output) {
if (GroovyLog.msg("Error removing barrel recipe")
.add(IngredientHelper.isEmpty(output), () -> "Output 1 must not be empty")
Expand All @@ -59,7 +66,7 @@ public void removeByOutput(FluidStack output) {
@Property(property = "name")
public static class RecipeBuilder extends AbstractRecipeBuilder<BarrelRecipe> {

@Property(comp = @Comp(gte = 1))
@Property(comp = @Comp(gt = 0))
private int duration;

@RecipeBuilderMethodDescription
Expand All @@ -79,26 +86,28 @@ protected int getMaxItemInput() {
return 1;
}

@Override
public String getRecipeNamePrefix() {
return "groovyscript_barrel_";
}

@Override
public void validate(GroovyLog.Msg msg) {
validateName();
validateItems(msg, 4, 4, 0, 0);
validateFluids(msg, 1, 1, 1, 1);
msg.add(duration < 0, "duration must be a non negative integer, yet it was {}", duration);
msg.add(super.name == null, "name cannot be null.");
msg.add(duration <= 0, "duration must be a non negative integer that is larger than 0, yet it was {}", duration);
msg.add(ModuleTechBasic.Registries.BARREL_RECIPE.getValue(super.name) != null, "tried to register {}, but it already exists.", super.name);
}

@RecipeBuilderRegistrationMethod
@Override
public @Nullable BarrelRecipe register() {
if (!validate()) return null;

// Because you need Ingredient[] to register a recipe
Ingredient[] inputIngredient = input.stream().map(IIngredient::toMcIngredient).toArray(Ingredient[]::new);

BarrelRecipe recipe = new BarrelRecipe(fluidOutput.get(0), inputIngredient, fluidInput.get(0), duration).setRegistryName(super.name);
PyroTech.barrel.add(recipe);

ModSupport.PYROTECH.get().barrel.add(recipe);
return recipe;
}
}
Expand Down
Loading