Skip to content

Commit 4bb599d

Browse files
enhance Pyrotech compat (#366)
* Check if module exists before applying Pyrotech recipe registry. - Fixes #318 * Fix Pyrotech examples. Some machines can't have inputs with stack sizes larger than one. * Update examples, add inheritance and add support for missing machines. - Update examples to show inheritance. - Add inheritance. Inherited recipe will be added to the machines more advanced than the machine. - Add support for missing machines: sawmills, crucibles and Mechanical Compacting Bin. * Check modules before adding inherited recipes. * Check for 0 in Pyrotech recipe builder properties. * Remove unnecessary input amount sets. * Change ForgeRegistryWrapper for checking disabled modules. * Add missing wiki pages and translations. Add notes for inheritance. * Add support for Bloomery, Wither Forge, Worktable and Pit Burning. * Inline and sort. * Add missing annotations and change other forgotten stuff. * Change Wither Forge and Bloomery support * address reviews, intellij warnings, and logged issues --------- Co-authored-by: CaliforniaDemise <vwwwwv@proton.me>
1 parent fa07826 commit 4bb599d

32 files changed

Lines changed: 3588 additions & 228 deletions

examples/postInit/generated/pyrotech_generated.groovy

Lines changed: 520 additions & 40 deletions
Large diffs are not rendered by default.

src/main/java/com/cleanroommc/groovyscript/compat/mods/pyrotech/Anvil.java

Lines changed: 74 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,22 @@
33
import com.cleanroommc.groovyscript.api.GroovyLog;
44
import com.cleanroommc.groovyscript.api.IIngredient;
55
import com.cleanroommc.groovyscript.api.documentation.annotations.*;
6+
import com.cleanroommc.groovyscript.compat.mods.ModSupport;
67
import com.cleanroommc.groovyscript.helper.EnumHelper;
78
import com.cleanroommc.groovyscript.helper.ingredient.IngredientHelper;
89
import com.cleanroommc.groovyscript.helper.recipe.AbstractRecipeBuilder;
910
import com.cleanroommc.groovyscript.registry.ForgeRegistryWrapper;
11+
import com.codetaylor.mc.pyrotech.ModPyrotech;
1012
import com.codetaylor.mc.pyrotech.modules.tech.basic.ModuleTechBasic;
13+
import com.codetaylor.mc.pyrotech.modules.tech.basic.init.recipe.AnvilIroncladRecipesAdd;
14+
import com.codetaylor.mc.pyrotech.modules.tech.basic.init.recipe.AnvilObsidianRecipesAdd;
1115
import com.codetaylor.mc.pyrotech.modules.tech.basic.recipe.AnvilRecipe;
1216
import net.minecraft.item.ItemStack;
17+
import net.minecraft.util.ResourceLocation;
1318
import org.jetbrains.annotations.Nullable;
1419

1520
import java.util.Arrays;
21+
import java.util.Locale;
1622

1723
@RegistryDescription
1824
public class Anvil extends ForgeRegistryWrapper<AnvilRecipe> {
@@ -21,17 +27,27 @@ public Anvil() {
2127
super(ModuleTechBasic.Registries.ANVIL_RECIPE);
2228
}
2329

30+
@Override
31+
public boolean isEnabled() {
32+
return ModPyrotech.INSTANCE.isModuleEnabled(ModuleTechBasic.class);
33+
}
34+
2435
@RecipeBuilderDescription(example = {
25-
@Example(".input(item('minecraft:diamond') * 4).output(item('minecraft:emerald') * 2).hits(5).typeHammer().tierGranite().name('diamond_to_emerald_granite_anvil')"),
26-
@Example(".input(item('minecraft:diamond') * 8).output(item('minecraft:nether_star') * 1).hits(10).typePickaxe().tierIronclad().name('diamond_to_nether_star_ironclad_anvil')"),
27-
@Example(".input(item('minecraft:diamond') * 4).output(item('minecraft:gold_ingot') * 16).hits(5).typePickaxe().tierObsidian().name('diamond_to_gold_obsidian_anvil')")
36+
@Example(".input(item('minecraft:diamond')).output(item('minecraft:emerald') * 2).hits(8).typeHammer().tierGranite().name('diamond_to_emerald_granite_anvil')"),
37+
@Example(".input(item('minecraft:bedrock')).output(item('minecraft:nether_star') * 1).hits(10).typePickaxe().tierIronclad().inherit(true).name('bedrock_to_nether_star')"),
38+
@Example(".input(item('minecraft:gold_block')).output(item('minecraft:gold_ingot') * 16).hits(5).typePickaxe().tierObsidian().name('gold_block_to_gold_obsidian_anvil')")
2839
})
2940
public RecipeBuilder recipeBuilder() {
3041
return new RecipeBuilder();
3142
}
3243

33-
@MethodDescription(type = MethodDescription.Type.ADDITION, example = @Example("'iron_to_clay', ore('ingotIron'), item('minecraft:clay_ball'), 9, 'granite', 'hammer'"))
44+
@MethodDescription(type = MethodDescription.Type.ADDITION)
3445
public AnvilRecipe add(String name, IIngredient input, ItemStack output, int hits, String tier, String type) {
46+
return add(name, input, output, hits, tier, type, false);
47+
}
48+
49+
@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"))
50+
public AnvilRecipe add(String name, IIngredient input, ItemStack output, int hits, String tier, String type, boolean inherit) {
3551
AnvilRecipe.EnumTier enumTier = EnumHelper.valueOfNullable(AnvilRecipe.EnumTier.class, tier, false);
3652
AnvilRecipe.EnumType enumType = EnumHelper.valueOfNullable(AnvilRecipe.EnumType.class, type, false);
3753
if (enumTier == null || enumType == null) {
@@ -46,22 +62,38 @@ public AnvilRecipe add(String name, IIngredient input, ItemStack output, int hit
4662
.hits(hits)
4763
.tier(enumTier)
4864
.type(enumType)
65+
.inherit(inherit)
4966
.name(name)
5067
.input(input)
5168
.output(output)
5269
.register();
5370
}
5471

55-
@MethodDescription(example = @Example("item('minecraft:stone_slab', 3)"))
56-
public void removeByOutput(ItemStack output) {
72+
@MethodDescription(type = MethodDescription.Type.REMOVAL, example = @Example("item('pyrotech:material:37')"))
73+
public void removeByInput(ItemStack input) {
74+
if (GroovyLog.msg("Error removing pyrotech anvil recipe")
75+
.add(IngredientHelper.isEmpty(input), () -> "Input 1 must not be empty")
76+
.error()
77+
.postIfNotEmpty()) {
78+
return;
79+
}
80+
for (AnvilRecipe recipe : getRegistry()) {
81+
if (recipe.getInput().test(input)) {
82+
remove(recipe);
83+
}
84+
}
85+
}
86+
87+
@MethodDescription(type = MethodDescription.Type.REMOVAL, example = @Example("item('minecraft:stone_slab:3') * 2"))
88+
public void removeByOutput(IIngredient output) {
5789
if (GroovyLog.msg("Error removing pyrotech anvil recipe")
5890
.add(IngredientHelper.isEmpty(output), () -> "Output 1 must not be empty")
5991
.error()
6092
.postIfNotEmpty()) {
6193
return;
6294
}
6395
for (AnvilRecipe recipe : getRegistry()) {
64-
if (recipe.getOutput().isItemEqual(output)) {
96+
if (output.test(recipe.getOutput())) {
6597
remove(recipe);
6698
}
6799
}
@@ -74,13 +106,12 @@ public static class RecipeBuilder extends AbstractRecipeBuilder<AnvilRecipe> {
74106

75107
@Property(comp = @Comp(gt = 0))
76108
private int hits;
77-
78-
@Property
109+
@Property(comp = @Comp(not = "null"))
79110
private AnvilRecipe.EnumType type;
80-
81-
@Property
111+
@Property(comp = @Comp(not = "null"))
82112
private AnvilRecipe.EnumTier tier;
83-
113+
@Property
114+
private boolean inherit;
84115

85116
@RecipeBuilderMethodDescription
86117
public RecipeBuilder hits(int hits) {
@@ -104,7 +135,6 @@ public RecipeBuilder typePickaxe() {
104135
return type(AnvilRecipe.EnumType.PICKAXE);
105136
}
106137

107-
@RecipeBuilderMethodDescription
108138
public RecipeBuilder tier(AnvilRecipe.EnumTier tier) {
109139
this.tier = tier;
110140
return this;
@@ -125,6 +155,17 @@ public RecipeBuilder tierObsidian() {
125155
return tier(AnvilRecipe.EnumTier.OBSIDIAN);
126156
}
127157

158+
@RecipeBuilderMethodDescription
159+
public RecipeBuilder inherit(boolean inherit) {
160+
this.inherit = inherit;
161+
return this;
162+
}
163+
164+
@Override
165+
public String getRecipeNamePrefix() {
166+
return "groovyscript_anvil_";
167+
}
168+
128169
@Override
129170
public String getErrorMsg() {
130171
return "Error adding Pyrotech Anvil Recipe";
@@ -138,21 +179,35 @@ protected int getMaxItemInput() {
138179

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

149-
@Override
150191
@RecipeBuilderRegistrationMethod
192+
@Override
151193
public @Nullable AnvilRecipe register() {
152194
if (!validate()) return null;
153-
154195
AnvilRecipe recipe = new AnvilRecipe(output.get(0), input.get(0).toMcIngredient(), hits, type, tier).setRegistryName(super.name);
155-
PyroTech.anvil.add(recipe);
196+
ModSupport.PYROTECH.get().anvil.add(recipe);
197+
if (inherit) {
198+
String name = null;
199+
if (tier.ordinal() < 2) {
200+
name = tier.name().toLowerCase(Locale.ENGLISH) + "_anvil";
201+
AnvilRecipe obsidianRecipe = AnvilObsidianRecipesAdd.INHERIT_TRANSFORMER.apply(recipe);
202+
obsidianRecipe.setRegistryName(new ResourceLocation(super.name.getNamespace(), name + "/" + super.name.getPath()));
203+
ModSupport.PYROTECH.get().anvil.add(obsidianRecipe);
204+
}
205+
if (tier.ordinal() < 1) {
206+
AnvilRecipe ironcladRecipe = AnvilIroncladRecipesAdd.INHERIT_TRANSFORMER.apply(recipe);
207+
ironcladRecipe.setRegistryName(new ResourceLocation(super.name.getNamespace(), name + "/" + super.name.getPath()));
208+
ModSupport.PYROTECH.get().anvil.add(ironcladRecipe);
209+
}
210+
}
156211
return recipe;
157212
}
158213
}

src/main/java/com/cleanroommc/groovyscript/compat/mods/pyrotech/Barrel.java

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
import com.cleanroommc.groovyscript.api.GroovyLog;
44
import com.cleanroommc.groovyscript.api.IIngredient;
55
import com.cleanroommc.groovyscript.api.documentation.annotations.*;
6+
import com.cleanroommc.groovyscript.compat.mods.ModSupport;
67
import com.cleanroommc.groovyscript.helper.ingredient.IngredientHelper;
78
import com.cleanroommc.groovyscript.helper.recipe.AbstractRecipeBuilder;
89
import com.cleanroommc.groovyscript.registry.ForgeRegistryWrapper;
10+
import com.codetaylor.mc.pyrotech.ModPyrotech;
911
import com.codetaylor.mc.pyrotech.modules.tech.basic.ModuleTechBasic;
1012
import com.codetaylor.mc.pyrotech.modules.tech.basic.recipe.BarrelRecipe;
1113
import net.minecraft.item.crafting.Ingredient;
@@ -19,6 +21,11 @@ public Barrel() {
1921
super(ModuleTechBasic.Registries.BARREL_RECIPE);
2022
}
2123

24+
@Override
25+
public boolean isEnabled() {
26+
return ModPyrotech.INSTANCE.isModuleEnabled(ModuleTechBasic.class);
27+
}
28+
2229
@RecipeBuilderDescription(
2330
example = @Example(
2431
".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')")
@@ -38,7 +45,7 @@ public BarrelRecipe add(String name, IIngredient input1, IIngredient input2, IIn
3845
.register();
3946
}
4047

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

62-
@Property(comp = @Comp(gte = 1))
69+
@Property(comp = @Comp(gt = 0))
6370
private int duration;
6471

6572
@RecipeBuilderMethodDescription
@@ -79,26 +86,28 @@ protected int getMaxItemInput() {
7986
return 1;
8087
}
8188

89+
@Override
90+
public String getRecipeNamePrefix() {
91+
return "groovyscript_barrel_";
92+
}
93+
8294
@Override
8395
public void validate(GroovyLog.Msg msg) {
96+
validateName();
8497
validateItems(msg, 4, 4, 0, 0);
8598
validateFluids(msg, 1, 1, 1, 1);
86-
msg.add(duration < 0, "duration must be a non negative integer, yet it was {}", duration);
87-
msg.add(super.name == null, "name cannot be null.");
99+
msg.add(duration <= 0, "duration must be a non negative integer that is larger than 0, yet it was {}", duration);
88100
msg.add(ModuleTechBasic.Registries.BARREL_RECIPE.getValue(super.name) != null, "tried to register {}, but it already exists.", super.name);
89101
}
90102

91103
@RecipeBuilderRegistrationMethod
92104
@Override
93105
public @Nullable BarrelRecipe register() {
94106
if (!validate()) return null;
95-
96107
// Because you need Ingredient[] to register a recipe
97108
Ingredient[] inputIngredient = input.stream().map(IIngredient::toMcIngredient).toArray(Ingredient[]::new);
98-
99109
BarrelRecipe recipe = new BarrelRecipe(fluidOutput.get(0), inputIngredient, fluidInput.get(0), duration).setRegistryName(super.name);
100-
PyroTech.barrel.add(recipe);
101-
110+
ModSupport.PYROTECH.get().barrel.add(recipe);
102111
return recipe;
103112
}
104113
}

0 commit comments

Comments
 (0)