88import net .fabricmc .fabric .api .datagen .v1 .provider .FabricRecipeProvider ;
99import net .fabricmc .fabric .api .tag .convention .v1 .ConventionalItemTags ;
1010import net .minecraft .advancement .criterion .InventoryChangedCriterion ;
11- import net .minecraft .data .server .recipe .RecipeJsonProvider ;
11+ import net .minecraft .data .server .recipe .RecipeExporter ;
1212import net .minecraft .data .server .recipe .ShapedRecipeJsonBuilder ;
1313import net .minecraft .data .server .recipe .ShapelessRecipeJsonBuilder ;
14+ import net .minecraft .item .Item ;
1415import net .minecraft .item .Items ;
15- import net .minecraft .predicate .NbtPredicate ;
1616import net .minecraft .predicate .NumberRange ;
17- import net .minecraft .predicate .item .EnchantmentPredicate ;
1817import net .minecraft .predicate .item .ItemPredicate ;
1918import net .minecraft .recipe .Ingredient ;
2019import net .minecraft .recipe .book .RecipeCategory ;
2120import net .minecraft .registry .tag .ItemTags ;
21+ import net .minecraft .registry .tag .TagKey ;
2222import net .minecraft .util .Identifier ;
2323
2424import java .util .List ;
25- import java .util .function . Consumer ;
25+ import java .util .Optional ;
2626
2727public class CinderscapesRecipeProvider extends FabricRecipeProvider {
2828 protected CinderscapesRecipeProvider (FabricDataOutput dataOutput ) {
2929 super (dataOutput );
3030 }
3131
3232 @ Override
33- public void generate (Consumer < RecipeJsonProvider > exporter ) {
33+ public void generate (RecipeExporter exporter ) {
3434 // vanilla recipes
3535 ShapedRecipeJsonBuilder .create (RecipeCategory .REDSTONE , Items .COMPARATOR , 1 )
3636 .pattern (" T " )
@@ -39,8 +39,7 @@ public void generate(Consumer<RecipeJsonProvider> exporter) {
3939 .input ('T' , Items .REDSTONE_TORCH )
4040 .input ('Q' , ConventionalItemTags .QUARTZ )
4141 .input ('S' , Items .STONE )
42- .criterion ("has_quartz" , InventoryChangedCriterion .Conditions .items (
43- new ItemPredicate (ConventionalItemTags .QUARTZ , null , NumberRange .IntRange .ANY , NumberRange .IntRange .ANY , EnchantmentPredicate .ARRAY_OF_ANY , EnchantmentPredicate .ARRAY_OF_ANY , null , NbtPredicate .ANY )))
42+ .criterion ("has_quartz" , InventoryChangedCriterion .Conditions .items (getItemTagPredicate (ConventionalItemTags .QUARTZ )))
4443 .offerTo (exporter , new Identifier ("minecraft" , "comparator" ));
4544
4645 ShapedRecipeJsonBuilder .create (RecipeCategory .REDSTONE , Items .DAYLIGHT_DETECTOR , 1 )
@@ -50,8 +49,7 @@ public void generate(Consumer<RecipeJsonProvider> exporter) {
5049 .input ('G' , Items .GLASS )
5150 .input ('Q' , ConventionalItemTags .QUARTZ )
5251 .input ('W' , ItemTags .WOODEN_SLABS )
53- .criterion ("has_quartz" , InventoryChangedCriterion .Conditions .items (
54- new ItemPredicate (ConventionalItemTags .QUARTZ , null , NumberRange .IntRange .ANY , NumberRange .IntRange .ANY , EnchantmentPredicate .ARRAY_OF_ANY , EnchantmentPredicate .ARRAY_OF_ANY , null , NbtPredicate .ANY )))
52+ .criterion ("has_quartz" , InventoryChangedCriterion .Conditions .items (getItemTagPredicate (ConventionalItemTags .QUARTZ )))
5553 .offerTo (exporter , new Identifier ("minecraft" , "daylight_detector" ));
5654
5755 ShapedRecipeJsonBuilder .create (RecipeCategory .REDSTONE , Items .OBSERVER , 1 )
@@ -61,8 +59,7 @@ public void generate(Consumer<RecipeJsonProvider> exporter) {
6159 .input ('C' , Items .COBBLESTONE )
6260 .input ('Q' , ConventionalItemTags .QUARTZ )
6361 .input ('R' , Items .REDSTONE )
64- .criterion ("has_quartz" , InventoryChangedCriterion .Conditions .items (
65- new ItemPredicate (ConventionalItemTags .QUARTZ , null , NumberRange .IntRange .ANY , NumberRange .IntRange .ANY , EnchantmentPredicate .ARRAY_OF_ANY , EnchantmentPredicate .ARRAY_OF_ANY , null , NbtPredicate .ANY )))
62+ .criterion ("has_quartz" , InventoryChangedCriterion .Conditions .items (getItemTagPredicate (ConventionalItemTags .QUARTZ )))
6663 .offerTo (exporter , new Identifier ("minecraft" , "observer" ));
6764
6865
@@ -84,8 +81,7 @@ public void generate(Consumer<RecipeJsonProvider> exporter) {
8481 .input (CinderscapesItemTags .SULFURS )
8582 .input (ItemTags .COALS )
8683 .input (Items .BONE_MEAL )
87- .criterion ("has_sulfurs" , InventoryChangedCriterion .Conditions .items (
88- new ItemPredicate (CinderscapesItemTags .SULFURS , null , NumberRange .IntRange .ANY , NumberRange .IntRange .ANY , EnchantmentPredicate .ARRAY_OF_ANY , EnchantmentPredicate .ARRAY_OF_ANY , null , NbtPredicate .ANY )))
84+ .criterion ("has_sulfurs" , InventoryChangedCriterion .Conditions .items (getItemTagPredicate (CinderscapesItemTags .SULFURS )))
8985 .offerTo (exporter );
9086
9187
@@ -110,13 +106,11 @@ public void generate(Consumer<RecipeJsonProvider> exporter) {
110106 .offerTo (exporter );
111107 offerStonecuttingRecipe (exporter , RecipeCategory .BUILDING_BLOCKS , CinderscapesBlocks .ROSE_QUARTZ_PILLAR , CinderscapesBlocks .ROSE_QUARTZ_BLOCK );
112108 createSlabRecipe (RecipeCategory .BUILDING_BLOCKS , CinderscapesBlocks .ROSE_QUARTZ_SLAB , Ingredient .ofItems (CinderscapesBlocks .CHISELED_ROSE_QUARTZ_BLOCK , CinderscapesBlocks .ROSE_QUARTZ_BLOCK , CinderscapesBlocks .ROSE_QUARTZ_PILLAR ))
113- .criterion ("has_quartz_blocks" , InventoryChangedCriterion .Conditions .items (
114- new ItemPredicate (CinderscapesItemTags .ROSE_QUARTZ_CONVERTIBLES , null , NumberRange .IntRange .ANY , NumberRange .IntRange .ANY , EnchantmentPredicate .ARRAY_OF_ANY , EnchantmentPredicate .ARRAY_OF_ANY , null , NbtPredicate .ANY )))
109+ .criterion ("has_quartz_blocks" , InventoryChangedCriterion .Conditions .items (getItemTagPredicate (CinderscapesItemTags .ROSE_QUARTZ_CONVERTIBLES )))
115110 .offerTo (exporter );
116111 offerStonecuttingRecipe (exporter , RecipeCategory .BUILDING_BLOCKS , CinderscapesBlocks .ROSE_QUARTZ_SLAB , CinderscapesBlocks .ROSE_QUARTZ_BLOCK , 2 );
117112 createStairsRecipe (CinderscapesBlocks .ROSE_QUARTZ_STAIRS , Ingredient .ofItems (CinderscapesBlocks .CHISELED_ROSE_QUARTZ_BLOCK , CinderscapesBlocks .ROSE_QUARTZ_BLOCK , CinderscapesBlocks .ROSE_QUARTZ_PILLAR ))
118- .criterion ("has_quartz_blocks" , InventoryChangedCriterion .Conditions .items (
119- new ItemPredicate (CinderscapesItemTags .ROSE_QUARTZ_CONVERTIBLES , null , NumberRange .IntRange .ANY , NumberRange .IntRange .ANY , EnchantmentPredicate .ARRAY_OF_ANY , EnchantmentPredicate .ARRAY_OF_ANY , null , NbtPredicate .ANY )))
113+ .criterion ("has_quartz_blocks" , InventoryChangedCriterion .Conditions .items (getItemTagPredicate (CinderscapesItemTags .ROSE_QUARTZ_CONVERTIBLES )))
120114 .offerTo (exporter );
121115 offerStonecuttingRecipe (exporter , RecipeCategory .BUILDING_BLOCKS , CinderscapesBlocks .ROSE_QUARTZ_STAIRS , CinderscapesBlocks .ROSE_QUARTZ_BLOCK );
122116 offerSmelting (exporter , List .of (CinderscapesBlocks .ROSE_QUARTZ_BLOCK ), RecipeCategory .BUILDING_BLOCKS , CinderscapesBlocks .SMOOTH_ROSE_QUARTZ , 0.1f , 200 , "building_blocks" );
@@ -147,13 +141,11 @@ public void generate(Consumer<RecipeJsonProvider> exporter) {
147141 .offerTo (exporter );
148142 offerStonecuttingRecipe (exporter , RecipeCategory .BUILDING_BLOCKS , CinderscapesBlocks .SMOKY_QUARTZ_PILLAR , CinderscapesBlocks .SMOKY_QUARTZ_BLOCK );
149143 createSlabRecipe (RecipeCategory .BUILDING_BLOCKS , CinderscapesBlocks .SMOKY_QUARTZ_SLAB , Ingredient .ofItems (CinderscapesBlocks .CHISELED_SMOKY_QUARTZ_BLOCK , CinderscapesBlocks .SMOKY_QUARTZ_BLOCK , CinderscapesBlocks .SMOKY_QUARTZ_PILLAR ))
150- .criterion ("has_quartz_blocks" , InventoryChangedCriterion .Conditions .items (
151- new ItemPredicate (CinderscapesItemTags .SMOKY_QUARTZ_CONVERTIBLES , null , NumberRange .IntRange .ANY , NumberRange .IntRange .ANY , EnchantmentPredicate .ARRAY_OF_ANY , EnchantmentPredicate .ARRAY_OF_ANY , null , NbtPredicate .ANY )))
144+ .criterion ("has_quartz_blocks" , InventoryChangedCriterion .Conditions .items (getItemTagPredicate (CinderscapesItemTags .SMOKY_QUARTZ_CONVERTIBLES )))
152145 .offerTo (exporter );
153146 offerStonecuttingRecipe (exporter , RecipeCategory .BUILDING_BLOCKS , CinderscapesBlocks .SMOKY_QUARTZ_SLAB , CinderscapesBlocks .SMOKY_QUARTZ_BLOCK , 2 );
154147 createStairsRecipe (CinderscapesBlocks .SMOKY_QUARTZ_STAIRS , Ingredient .ofItems (CinderscapesBlocks .CHISELED_SMOKY_QUARTZ_BLOCK , CinderscapesBlocks .SMOKY_QUARTZ_BLOCK , CinderscapesBlocks .SMOKY_QUARTZ_PILLAR ))
155- .criterion ("has_quartz_blocks" , InventoryChangedCriterion .Conditions .items (
156- new ItemPredicate (CinderscapesItemTags .SMOKY_QUARTZ_CONVERTIBLES , null , NumberRange .IntRange .ANY , NumberRange .IntRange .ANY , EnchantmentPredicate .ARRAY_OF_ANY , EnchantmentPredicate .ARRAY_OF_ANY , null , NbtPredicate .ANY )))
148+ .criterion ("has_quartz_blocks" , InventoryChangedCriterion .Conditions .items (getItemTagPredicate (CinderscapesItemTags .SMOKY_QUARTZ_CONVERTIBLES )))
157149 .offerTo (exporter );
158150 offerStonecuttingRecipe (exporter , RecipeCategory .BUILDING_BLOCKS , CinderscapesBlocks .SMOKY_QUARTZ_STAIRS , CinderscapesBlocks .SMOKY_QUARTZ_BLOCK );
159151 offerSmelting (exporter , List .of (CinderscapesBlocks .SMOKY_QUARTZ_BLOCK ), RecipeCategory .BUILDING_BLOCKS , CinderscapesBlocks .SMOOTH_SMOKY_QUARTZ , 0.1f , 200 , "building_blocks" );
@@ -184,13 +176,11 @@ public void generate(Consumer<RecipeJsonProvider> exporter) {
184176 .offerTo (exporter );
185177 offerStonecuttingRecipe (exporter , RecipeCategory .BUILDING_BLOCKS , CinderscapesBlocks .SULFUR_QUARTZ_PILLAR , CinderscapesBlocks .SULFUR_QUARTZ_BLOCK );
186178 createSlabRecipe (RecipeCategory .BUILDING_BLOCKS , CinderscapesBlocks .SULFUR_QUARTZ_SLAB , Ingredient .ofItems (CinderscapesBlocks .CHISELED_SULFUR_QUARTZ_BLOCK , CinderscapesBlocks .SULFUR_QUARTZ_BLOCK , CinderscapesBlocks .SULFUR_QUARTZ_PILLAR ))
187- .criterion ("has_quartz_blocks" , InventoryChangedCriterion .Conditions .items (
188- new ItemPredicate (CinderscapesItemTags .SULFUR_QUARTZ_CONVERTIBLES , null , NumberRange .IntRange .ANY , NumberRange .IntRange .ANY , EnchantmentPredicate .ARRAY_OF_ANY , EnchantmentPredicate .ARRAY_OF_ANY , null , NbtPredicate .ANY )))
179+ .criterion ("has_quartz_blocks" , InventoryChangedCriterion .Conditions .items (getItemTagPredicate (CinderscapesItemTags .SULFUR_QUARTZ_CONVERTIBLES )))
189180 .offerTo (exporter );
190181 offerStonecuttingRecipe (exporter , RecipeCategory .BUILDING_BLOCKS , CinderscapesBlocks .SULFUR_QUARTZ_SLAB , CinderscapesBlocks .SULFUR_QUARTZ_BLOCK , 2 );
191182 createStairsRecipe (CinderscapesBlocks .SULFUR_QUARTZ_STAIRS , Ingredient .ofItems (CinderscapesBlocks .CHISELED_SULFUR_QUARTZ_BLOCK , CinderscapesBlocks .SULFUR_QUARTZ_BLOCK , CinderscapesBlocks .SULFUR_QUARTZ_PILLAR ))
192- .criterion ("has_quartz_blocks" , InventoryChangedCriterion .Conditions .items (
193- new ItemPredicate (CinderscapesItemTags .SULFUR_QUARTZ_CONVERTIBLES , null , NumberRange .IntRange .ANY , NumberRange .IntRange .ANY , EnchantmentPredicate .ARRAY_OF_ANY , EnchantmentPredicate .ARRAY_OF_ANY , null , NbtPredicate .ANY )))
183+ .criterion ("has_quartz_blocks" , InventoryChangedCriterion .Conditions .items (getItemTagPredicate (CinderscapesItemTags .SULFUR_QUARTZ_CONVERTIBLES )))
194184 .offerTo (exporter );
195185 offerStonecuttingRecipe (exporter , RecipeCategory .BUILDING_BLOCKS , CinderscapesBlocks .SULFUR_QUARTZ_STAIRS , CinderscapesBlocks .SULFUR_QUARTZ_BLOCK );
196186 offerSmelting (exporter , List .of (CinderscapesBlocks .SULFUR_QUARTZ_BLOCK ), RecipeCategory .BUILDING_BLOCKS , CinderscapesBlocks .SMOOTH_SULFUR_QUARTZ , 0.1f , 200 , "building_blocks" );
@@ -280,6 +270,20 @@ public void generate(Consumer<RecipeJsonProvider> exporter) {
280270 .offerTo (exporter );
281271 }
282272
273+ // Returns an ItemPredicate matching any item in the provided ItemTag key.
274+ private static ItemPredicate getItemTagPredicate (TagKey <Item > itemTagKey ) {
275+ return new ItemPredicate (
276+ Optional .of (itemTagKey ),
277+ Optional .empty (),
278+ NumberRange .IntRange .ANY ,
279+ NumberRange .IntRange .ANY ,
280+ List .of (),
281+ List .of (),
282+ Optional .empty (),
283+ Optional .empty ()
284+ );
285+ }
286+
283287 @ Override
284288 protected Identifier getRecipeIdentifier (Identifier identifier ) {
285289 return new Identifier (Cinderscapes .NAMESPACE , identifier .getPath ());
0 commit comments