diff --git a/src/main/java/codechicken/lib/datagen/recipe/FurnaceRecipeBuilder.java b/src/main/java/codechicken/lib/datagen/recipe/FurnaceRecipeBuilder.java index b55e9d84..fe46f8a3 100644 --- a/src/main/java/codechicken/lib/datagen/recipe/FurnaceRecipeBuilder.java +++ b/src/main/java/codechicken/lib/datagen/recipe/FurnaceRecipeBuilder.java @@ -12,6 +12,8 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import java.util.function.Supplier; + /** * Created by covers1624 on 28/12/20. */ @@ -40,6 +42,18 @@ public static FurnaceRecipeBuilder smelting(ItemLike result, int count, Resource return smelting(new ItemStack(result, count), id); } + public static FurnaceRecipeBuilder smelting(Supplier result) { + return smelting(result.get(), 1); + } + + public static FurnaceRecipeBuilder smelting(Supplier result, int count) { + return smelting(new ItemStack(result.get(), count)); + } + + public static FurnaceRecipeBuilder smelting(Supplier result, int count, ResourceLocation id) { + return smelting(new ItemStack(result.get(), count), id); + } + public static FurnaceRecipeBuilder smelting(ItemStack result) { return smelting(result, ForgeRegistries.ITEMS.getKey(result.getItem())); } @@ -63,6 +77,18 @@ public static FurnaceRecipeBuilder blasting(ItemLike result, int count, Resource return blasting(new ItemStack(result, count), id); } + public static FurnaceRecipeBuilder blasting(Supplier result) { + return blasting(result.get(), 1); + } + + public static FurnaceRecipeBuilder blasting(Supplier result, int count) { + return blasting(new ItemStack(result.get(), count)); + } + + public static FurnaceRecipeBuilder blasting(Supplier result, int count, ResourceLocation id) { + return blasting(new ItemStack(result.get(), count), id); + } + public static FurnaceRecipeBuilder blasting(ItemStack result) { return blasting(result, ForgeRegistries.ITEMS.getKey(result.getItem())); } @@ -86,6 +112,18 @@ public static FurnaceRecipeBuilder smoking(ItemLike result, int count, ResourceL return smoking(new ItemStack(result, count), id); } + public static FurnaceRecipeBuilder smoking(Supplier result) { + return smoking(result.get(), 1); + } + + public static FurnaceRecipeBuilder smoking(Supplier result, int count) { + return smoking(new ItemStack(result.get(), count)); + } + + public static FurnaceRecipeBuilder smoking(Supplier result, int count, ResourceLocation id) { + return smoking(new ItemStack(result.get(), count), id); + } + public static FurnaceRecipeBuilder smoking(ItemStack result) { return smoking(result, ForgeRegistries.ITEMS.getKey(result.getItem())); } @@ -109,6 +147,18 @@ public static FurnaceRecipeBuilder campfire(ItemLike result, int count, Resource return campfire(new ItemStack(result, count), id); } + public static FurnaceRecipeBuilder campfire(Supplier result) { + return campfire(result.get(), 1); + } + + public static FurnaceRecipeBuilder campfire(Supplier result, int count) { + return campfire(new ItemStack(result.get(), count)); + } + + public static FurnaceRecipeBuilder campfire(Supplier result, int count, ResourceLocation id) { + return campfire(new ItemStack(result.get(), count), id); + } + public static FurnaceRecipeBuilder campfire(ItemStack result) { return campfire(result, ForgeRegistries.ITEMS.getKey(result.getItem())); } @@ -132,6 +182,18 @@ public static FurnaceRecipeBuilder custom(RecipeSerializer serializer, ItemLi return custom(serializer, new ItemStack(result, count), id); } + public static FurnaceRecipeBuilder custom(RecipeSerializer serializer, Supplier result) { + return custom(serializer, result.get(), 1); + } + + public static FurnaceRecipeBuilder custom(RecipeSerializer serializer, Supplier result, int count) { + return custom(serializer, new ItemStack(result.get(), count)); + } + + public static FurnaceRecipeBuilder custom(RecipeSerializer serializer, Supplier result, int count, ResourceLocation id) { + return custom(serializer, new ItemStack(result.get(), count), id); + } + public static FurnaceRecipeBuilder custom(RecipeSerializer serializer, ItemStack result) { return custom(serializer, result, ForgeRegistries.ITEMS.getKey(result.getItem())); } @@ -153,6 +215,12 @@ public FurnaceRecipeBuilder ingredient(ItemLike item) { return this; } + public FurnaceRecipeBuilder ingredient(Supplier item) { + addAutoCriteria(item.get()); + this.ingredient = Ingredient.of(item.get()); + return this; + } + public FurnaceRecipeBuilder ingredient(Ingredient ingredient) { if (generateCriteria) { logger.warn("Criteria not automatically generated for raw ingredient.", new Throwable("Here, have a stack trace")); diff --git a/src/main/java/codechicken/lib/datagen/recipe/RecipeProvider.java b/src/main/java/codechicken/lib/datagen/recipe/RecipeProvider.java index cd97519b..cb38c5ed 100644 --- a/src/main/java/codechicken/lib/datagen/recipe/RecipeProvider.java +++ b/src/main/java/codechicken/lib/datagen/recipe/RecipeProvider.java @@ -1,7 +1,5 @@ package codechicken.lib.datagen.recipe; -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; import com.google.gson.JsonObject; import net.minecraft.advancements.critereon.*; import net.minecraft.data.CachedOutput; @@ -17,8 +15,6 @@ import net.minecraft.world.level.ItemLike; import net.minecraft.world.level.block.Block; import net.minecraftforge.registries.ForgeRegistries; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; import java.nio.file.Path; import java.util.HashMap; @@ -26,6 +22,7 @@ import java.util.List; import java.util.Map; import java.util.concurrent.CompletableFuture; +import java.util.function.Supplier; /** * Created by covers1624 on 27/12/20. @@ -71,48 +68,84 @@ protected T builder(T builder) { protected ShapedRecipeBuilder shapedRecipe(ItemLike result) { return builder(ShapedRecipeBuilder.builder(result, 1)); } protected ShapedRecipeBuilder shapedRecipe(ItemLike result, int count) { return builder(ShapedRecipeBuilder.builder(new ItemStack(result, count))); } protected ShapedRecipeBuilder shapedRecipe(ItemLike result, int count, ResourceLocation id) { return builder(ShapedRecipeBuilder.builder(new ItemStack(result, count), id)); } + protected ShapedRecipeBuilder shapedRecipe(Supplier result) { return builder(ShapedRecipeBuilder.builder(result.get(), 1)); } + protected ShapedRecipeBuilder shapedRecipe(Supplier result, int count) { return builder(ShapedRecipeBuilder.builder(new ItemStack(result.get(), count))); } + protected ShapedRecipeBuilder shapedRecipe(Supplier result, int count, ResourceLocation id) { return builder(ShapedRecipeBuilder.builder(new ItemStack(result.get(), count), id)); } protected ShapedRecipeBuilder shapedRecipe(ItemStack result) { return builder(ShapedRecipeBuilder.builder(result, ForgeRegistries.ITEMS.getKey(result.getItem()))); } protected ShapedRecipeBuilder shapedRecipe(ItemStack result, ResourceLocation id) { return builder(ShapedRecipeBuilder.builder(result, id)); } + protected ShapelessRecipeBuilder shapelessRecipe(ItemLike result) { return builder(ShapelessRecipeBuilder.builder(result, 1)); } protected ShapelessRecipeBuilder shapelessRecipe(ItemLike result, int count) { return builder(ShapelessRecipeBuilder.builder(new ItemStack(result, count))); } protected ShapelessRecipeBuilder shapelessRecipe(ItemLike result, int count, ResourceLocation id) { return builder(ShapelessRecipeBuilder.builder(new ItemStack(result, count), id)); } + protected ShapelessRecipeBuilder shapelessRecipe(Supplier result) { return builder(ShapelessRecipeBuilder.builder(result.get(), 1)); } + protected ShapelessRecipeBuilder shapelessRecipe(Supplier result, int count) { return builder(ShapelessRecipeBuilder.builder(new ItemStack(result.get(), count))); } + protected ShapelessRecipeBuilder shapelessRecipe(Supplier result, int count, ResourceLocation id) { return builder(ShapelessRecipeBuilder.builder(new ItemStack(result.get(), count), id)); } protected ShapelessRecipeBuilder shapelessRecipe(ItemStack result) { return builder(ShapelessRecipeBuilder.builder(result, ForgeRegistries.ITEMS.getKey(result.getItem()))); } protected ShapelessRecipeBuilder shapelessRecipe(ItemStack result, ResourceLocation id) { return builder(ShapelessRecipeBuilder.builder(result, id)); } + protected FurnaceRecipeBuilder smelting(ItemLike result) { return builder(FurnaceRecipeBuilder.smelting(result, 1)); } protected FurnaceRecipeBuilder smelting(ItemLike result, int count) { return builder(FurnaceRecipeBuilder.smelting(new ItemStack(result, count))); } protected FurnaceRecipeBuilder smelting(ItemLike result, int count, ResourceLocation id) { return builder(FurnaceRecipeBuilder.smelting(new ItemStack(result, count), id)); } + protected FurnaceRecipeBuilder smelting(Supplier result) { return builder(FurnaceRecipeBuilder.smelting(result.get(), 1)); } + protected FurnaceRecipeBuilder smelting(Supplier result, int count) { return builder(FurnaceRecipeBuilder.smelting(new ItemStack(result.get(), count))); } + protected FurnaceRecipeBuilder smelting(Supplier result, int count, ResourceLocation id) { return builder(FurnaceRecipeBuilder.smelting(new ItemStack(result.get(), count), id)); } protected FurnaceRecipeBuilder smelting(ItemStack result) { return builder(FurnaceRecipeBuilder.smelting(result, ForgeRegistries.ITEMS.getKey(result.getItem()))); } protected FurnaceRecipeBuilder smelting(ItemStack result, ResourceLocation id) { return builder(FurnaceRecipeBuilder.smelting(result, id)); } + protected FurnaceRecipeBuilder blasting(ItemLike result) { return builder(FurnaceRecipeBuilder.blasting(result, 1)); } protected FurnaceRecipeBuilder blasting(ItemLike result, int count) { return builder(FurnaceRecipeBuilder.blasting(new ItemStack(result, count))); } protected FurnaceRecipeBuilder blasting(ItemLike result, int count, ResourceLocation id) { return builder(FurnaceRecipeBuilder.blasting(new ItemStack(result, count), id)); } + protected FurnaceRecipeBuilder blasting(Supplier result) { return builder(FurnaceRecipeBuilder.blasting(result.get(), 1)); } + protected FurnaceRecipeBuilder blasting(Supplier result, int count) { return builder(FurnaceRecipeBuilder.blasting(new ItemStack(result.get(), count))); } + protected FurnaceRecipeBuilder blasting(Supplier result, int count, ResourceLocation id) { return builder(FurnaceRecipeBuilder.blasting(new ItemStack(result.get(), count), id)); } protected FurnaceRecipeBuilder blasting(ItemStack result) { return builder(FurnaceRecipeBuilder.blasting(result, ForgeRegistries.ITEMS.getKey(result.getItem()))); } protected FurnaceRecipeBuilder blasting(ItemStack result, ResourceLocation id) { return builder(FurnaceRecipeBuilder.blasting(result, id)); } + protected FurnaceRecipeBuilder smoking(ItemLike result) { return builder(FurnaceRecipeBuilder.smoking(result, 1)); } protected FurnaceRecipeBuilder smoking(ItemLike result, int count) { return builder(FurnaceRecipeBuilder.smoking(new ItemStack(result, count))); } protected FurnaceRecipeBuilder smoking(ItemLike result, int count, ResourceLocation id) { return builder(FurnaceRecipeBuilder.smoking(new ItemStack(result, count), id)); } + protected FurnaceRecipeBuilder smoking(Supplier result) { return builder(FurnaceRecipeBuilder.smoking(result.get(), 1)); } + protected FurnaceRecipeBuilder smoking(Supplier result, int count) { return builder(FurnaceRecipeBuilder.smoking(new ItemStack(result.get(), count))); } + protected FurnaceRecipeBuilder smoking(Supplier result, int count, ResourceLocation id) { return builder(FurnaceRecipeBuilder.smoking(new ItemStack(result.get(), count), id)); } protected FurnaceRecipeBuilder smoking(ItemStack result) { return builder(FurnaceRecipeBuilder.smoking(result, ForgeRegistries.ITEMS.getKey(result.getItem()))); } protected FurnaceRecipeBuilder smoking(ItemStack result, ResourceLocation id) { return builder(FurnaceRecipeBuilder.smoking(result, id)); } + protected FurnaceRecipeBuilder campfire(ItemLike result) { return builder(FurnaceRecipeBuilder.campfire(result, 1)); } protected FurnaceRecipeBuilder campfire(ItemLike result, int count) { return builder(FurnaceRecipeBuilder.campfire(new ItemStack(result, count))); } protected FurnaceRecipeBuilder campfire(ItemLike result, int count, ResourceLocation id) { return builder(FurnaceRecipeBuilder.campfire(new ItemStack(result, count), id)); } + protected FurnaceRecipeBuilder campfire(Supplier result) { return builder(FurnaceRecipeBuilder.campfire(result.get(), 1)); } + protected FurnaceRecipeBuilder campfire(Supplier result, int count) { return builder(FurnaceRecipeBuilder.campfire(new ItemStack(result.get(), count))); } + protected FurnaceRecipeBuilder campfire(Supplier result, int count, ResourceLocation id) { return builder(FurnaceRecipeBuilder.campfire(new ItemStack(result.get(), count), id)); } protected FurnaceRecipeBuilder campfire(ItemStack result) { return builder(FurnaceRecipeBuilder.campfire(result, ForgeRegistries.ITEMS.getKey(result.getItem()))); } protected FurnaceRecipeBuilder campfire(ItemStack result, ResourceLocation id) { return builder(FurnaceRecipeBuilder.campfire(result, id)); } + protected ShapedRecipeBuilder customShaped(RecipeSerializer serializer, ItemLike result) { return builder(ShapedRecipeBuilder.custom(serializer, result, 1)); } protected ShapedRecipeBuilder customShaped(RecipeSerializer serializer, ItemLike result, int count) { return builder(ShapedRecipeBuilder.custom(serializer, new ItemStack(result, count))); } protected ShapedRecipeBuilder customShaped(RecipeSerializer serializer, ItemLike result, int count, ResourceLocation id) { return builder(ShapedRecipeBuilder.custom(serializer, new ItemStack(result, count), id)); } + protected ShapedRecipeBuilder customShaped(RecipeSerializer serializer, Supplier result) { return builder(ShapedRecipeBuilder.custom(serializer, result.get(), 1)); } + protected ShapedRecipeBuilder customShaped(RecipeSerializer serializer, Supplier result, int count) { return builder(ShapedRecipeBuilder.custom(serializer, new ItemStack(result.get(), count))); } + protected ShapedRecipeBuilder customShaped(RecipeSerializer serializer, Supplier result, int count, ResourceLocation id) { return builder(ShapedRecipeBuilder.custom(serializer, new ItemStack(result.get(), count), id)); } protected ShapedRecipeBuilder customShaped(RecipeSerializer serializer, ItemStack result) { return builder(ShapedRecipeBuilder.custom(serializer, result, ForgeRegistries.ITEMS.getKey(result.getItem()))); } protected ShapedRecipeBuilder customShaped(RecipeSerializer serializer, ItemStack result, ResourceLocation id) { return builder(ShapedRecipeBuilder.custom(serializer, result, id)); } + protected ShapelessRecipeBuilder customShapeless(RecipeSerializer serializer, ItemLike result) { return builder(ShapelessRecipeBuilder.custom(serializer, result, 1)); } protected ShapelessRecipeBuilder customShapeless(RecipeSerializer serializer, ItemLike result, int count) { return builder(ShapelessRecipeBuilder.custom(serializer, new ItemStack(result, count))); } protected ShapelessRecipeBuilder customShapeless(RecipeSerializer serializer, ItemLike result, int count, ResourceLocation id) { return builder(ShapelessRecipeBuilder.custom(serializer, new ItemStack(result, count), id)); } + protected ShapelessRecipeBuilder customShapeless(RecipeSerializer serializer, Supplier result) { return builder(ShapelessRecipeBuilder.custom(serializer, result.get(), 1)); } + protected ShapelessRecipeBuilder customShapeless(RecipeSerializer serializer, Supplier result, int count) { return builder(ShapelessRecipeBuilder.custom(serializer, new ItemStack(result.get(), count))); } + protected ShapelessRecipeBuilder customShapeless(RecipeSerializer serializer, Supplier result, int count, ResourceLocation id) { return builder(ShapelessRecipeBuilder.custom(serializer, new ItemStack(result.get(), count), id)); } protected ShapelessRecipeBuilder customShapeless(RecipeSerializer serializer, ItemStack result) { return builder(ShapelessRecipeBuilder.custom(serializer, result, ForgeRegistries.ITEMS.getKey(result.getItem()))); } protected ShapelessRecipeBuilder customShapeless(RecipeSerializer serializer, ItemStack result, ResourceLocation id) { return builder(ShapelessRecipeBuilder.custom(serializer, result, id)); } + protected FurnaceRecipeBuilder customFurnace(RecipeSerializer serializer, ItemLike result) { return builder(FurnaceRecipeBuilder.custom(serializer, result, 1)); } protected FurnaceRecipeBuilder customFurnace(RecipeSerializer serializer, ItemLike result, int count) { return builder(FurnaceRecipeBuilder.custom(serializer, new ItemStack(result, count))); } protected FurnaceRecipeBuilder customFurnace(RecipeSerializer serializer, ItemLike result, int count, ResourceLocation id) { return builder(FurnaceRecipeBuilder.custom(serializer, new ItemStack(result, count), id)); } + protected FurnaceRecipeBuilder customFurnace(RecipeSerializer serializer, Supplier result) { return builder(FurnaceRecipeBuilder.custom(serializer, result.get(), 1)); } + protected FurnaceRecipeBuilder customFurnace(RecipeSerializer serializer, Supplier result, int count) { return builder(FurnaceRecipeBuilder.custom(serializer, new ItemStack(result.get(), count))); } + protected FurnaceRecipeBuilder customFurnace(RecipeSerializer serializer, Supplier result, int count, ResourceLocation id) { return builder(FurnaceRecipeBuilder.custom(serializer, new ItemStack(result.get(), count), id)); } protected FurnaceRecipeBuilder customFurnace(RecipeSerializer serializer, ItemStack result) { return builder(FurnaceRecipeBuilder.custom(serializer, result, ForgeRegistries.ITEMS.getKey(result.getItem()))); } protected FurnaceRecipeBuilder customFurnace(RecipeSerializer serializer, ItemStack result, ResourceLocation id) { return builder(FurnaceRecipeBuilder.custom(serializer, result, id)); } + protected SpecialCraftingRecipeBuilder special(SimpleCraftingRecipeSerializer serializer, String id) { return builder(SpecialCraftingRecipeBuilder.builder(serializer, id)); } protected SpecialCraftingRecipeBuilder special(SimpleCraftingRecipeSerializer serializer, ResourceLocation id) { return builder(SpecialCraftingRecipeBuilder.builder(serializer, id)); } //@formatter:on @@ -125,6 +158,10 @@ protected InventoryChangeTrigger.TriggerInstance hasItem(ItemLike itemIn) { return hasItem(ItemPredicate.Builder.item().of(itemIn).build()); } + protected InventoryChangeTrigger.TriggerInstance hasItem(Supplier itemIn) { + return hasItem(ItemPredicate.Builder.item().of(itemIn.get()).build()); + } + protected InventoryChangeTrigger.TriggerInstance hasItem(TagKey tagIn) { return hasItem(ItemPredicate.Builder.item().of(tagIn).build()); } diff --git a/src/main/java/codechicken/lib/datagen/recipe/ShapedRecipeBuilder.java b/src/main/java/codechicken/lib/datagen/recipe/ShapedRecipeBuilder.java index fcdbede1..6b9ae66e 100644 --- a/src/main/java/codechicken/lib/datagen/recipe/ShapedRecipeBuilder.java +++ b/src/main/java/codechicken/lib/datagen/recipe/ShapedRecipeBuilder.java @@ -19,6 +19,7 @@ import java.util.ArrayList; import java.util.List; +import java.util.function.Supplier; /** * Created by covers1624 on 28/12/20. @@ -46,6 +47,18 @@ public static ShapedRecipeBuilder builder(ItemLike result, int count, ResourceLo return builder(new ItemStack(result, count), id); } + public static ShapedRecipeBuilder builder(Supplier result) { + return builder(result.get(), 1); + } + + public static ShapedRecipeBuilder builder(Supplier result, int count) { + return builder(new ItemStack(result.get(), count)); + } + + public static ShapedRecipeBuilder builder(Supplier result, int count, ResourceLocation id) { + return builder(new ItemStack(result.get(), count), id); + } + public static ShapedRecipeBuilder builder(ItemStack result) { return builder(result, ForgeRegistries.ITEMS.getKey(result.getItem())); } @@ -86,6 +99,11 @@ public ShapedRecipeBuilder key(char key, ItemLike item) { return keyInternal(key, Ingredient.of(item)); } + public ShapedRecipeBuilder key(char key, Supplier item) { + addAutoCriteria(item.get()); + return keyInternal(key, Ingredient.of(item.get())); + } + public ShapedRecipeBuilder key(char key, Ingredient ingredient) { if (generateCriteria) { logger.warn("Criteria not automatically generated for raw ingredient.", new Throwable("Here, have a stack trace")); diff --git a/src/main/java/codechicken/lib/datagen/recipe/ShapelessRecipeBuilder.java b/src/main/java/codechicken/lib/datagen/recipe/ShapelessRecipeBuilder.java index 4694124c..9569e51f 100644 --- a/src/main/java/codechicken/lib/datagen/recipe/ShapelessRecipeBuilder.java +++ b/src/main/java/codechicken/lib/datagen/recipe/ShapelessRecipeBuilder.java @@ -15,6 +15,7 @@ import java.util.ArrayList; import java.util.List; +import java.util.function.Supplier; /** * Created by covers1624 on 28/12/20. @@ -41,6 +42,18 @@ public static ShapelessRecipeBuilder builder(ItemLike result, int count, Resourc return builder(new ItemStack(result, count), id); } + public static ShapelessRecipeBuilder builder(Supplier result) { + return builder(result.get(), 1); + } + + public static ShapelessRecipeBuilder builder(Supplier result, int count) { + return builder(new ItemStack(result.get(), count)); + } + + public static ShapelessRecipeBuilder builder(Supplier result, int count, ResourceLocation id) { + return builder(new ItemStack(result.get(), count), id); + } + public static ShapelessRecipeBuilder builder(ItemStack result) { return builder(result, ForgeRegistries.ITEMS.getKey(result.getItem())); } @@ -84,6 +97,19 @@ public ShapelessRecipeBuilder addIngredient(TagKey tag, int quantity) { return this; } + public ShapelessRecipeBuilder addIngredient(Supplier item) { + return addIngredient(item.get(), 1); + } + + public ShapelessRecipeBuilder addIngredient(Supplier item, int quantity) { + addAutoCriteria(item.get()); + Ingredient ingredient = Ingredient.of(item.get()); + for (int i = 0; i < quantity; ++i) { + ingredients.add(ingredient); + } + return this; + } + public ShapelessRecipeBuilder addIngredient(ItemLike item) { return addIngredient(item, 1); }