33import com .cleanroommc .groovyscript .api .GroovyLog ;
44import com .cleanroommc .groovyscript .api .IIngredient ;
55import com .cleanroommc .groovyscript .api .documentation .annotations .*;
6+ import com .cleanroommc .groovyscript .compat .mods .ModSupport ;
67import com .cleanroommc .groovyscript .helper .EnumHelper ;
78import com .cleanroommc .groovyscript .helper .ingredient .IngredientHelper ;
89import com .cleanroommc .groovyscript .helper .recipe .AbstractRecipeBuilder ;
910import com .cleanroommc .groovyscript .registry .ForgeRegistryWrapper ;
11+ import com .codetaylor .mc .pyrotech .ModPyrotech ;
1012import 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 ;
1115import com .codetaylor .mc .pyrotech .modules .tech .basic .recipe .AnvilRecipe ;
1216import net .minecraft .item .ItemStack ;
17+ import net .minecraft .util .ResourceLocation ;
1318import org .jetbrains .annotations .Nullable ;
1419
1520import java .util .Arrays ;
21+ import java .util .Locale ;
1622
1723@ RegistryDescription
1824public 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 }
0 commit comments