Skip to content

Commit

Permalink
Add Supplier methods to RecipeProvider to better support RegistryObjects
Browse files Browse the repository at this point in the history
  • Loading branch information
brandon3055 committed Jan 27, 2024
1 parent 9fbd40b commit 7d8da85
Show file tree
Hide file tree
Showing 4 changed files with 153 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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<? extends ItemLike> result) {
return smelting(result.get(), 1);
}

public static FurnaceRecipeBuilder smelting(Supplier<? extends ItemLike> result, int count) {
return smelting(new ItemStack(result.get(), count));
}

public static FurnaceRecipeBuilder smelting(Supplier<? extends ItemLike> 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()));
}
Expand All @@ -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<? extends ItemLike> result) {
return blasting(result.get(), 1);
}

public static FurnaceRecipeBuilder blasting(Supplier<? extends ItemLike> result, int count) {
return blasting(new ItemStack(result.get(), count));
}

public static FurnaceRecipeBuilder blasting(Supplier<? extends ItemLike> 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()));
}
Expand All @@ -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<? extends ItemLike> result) {
return smoking(result.get(), 1);
}

public static FurnaceRecipeBuilder smoking(Supplier<? extends ItemLike> result, int count) {
return smoking(new ItemStack(result.get(), count));
}

public static FurnaceRecipeBuilder smoking(Supplier<? extends ItemLike> 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()));
}
Expand All @@ -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<? extends ItemLike> result) {
return campfire(result.get(), 1);
}

public static FurnaceRecipeBuilder campfire(Supplier<? extends ItemLike> result, int count) {
return campfire(new ItemStack(result.get(), count));
}

public static FurnaceRecipeBuilder campfire(Supplier<? extends ItemLike> 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()));
}
Expand All @@ -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<? extends ItemLike> result) {
return custom(serializer, result.get(), 1);
}

public static FurnaceRecipeBuilder custom(RecipeSerializer<?> serializer, Supplier<? extends ItemLike> result, int count) {
return custom(serializer, new ItemStack(result.get(), count));
}

public static FurnaceRecipeBuilder custom(RecipeSerializer<?> serializer, Supplier<? extends ItemLike> 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()));
}
Expand All @@ -153,6 +215,12 @@ public FurnaceRecipeBuilder ingredient(ItemLike item) {
return this;
}

public FurnaceRecipeBuilder ingredient(Supplier<? extends ItemLike> 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"));
Expand Down
45 changes: 41 additions & 4 deletions src/main/java/codechicken/lib/datagen/recipe/RecipeProvider.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -17,15 +15,14 @@
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;
import java.util.LinkedList;
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.
Expand Down Expand Up @@ -71,48 +68,84 @@ protected <T extends RecipeBuilder> 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<? extends ItemLike> result) { return builder(ShapedRecipeBuilder.builder(result.get(), 1)); }
protected ShapedRecipeBuilder shapedRecipe(Supplier<? extends ItemLike> result, int count) { return builder(ShapedRecipeBuilder.builder(new ItemStack(result.get(), count))); }
protected ShapedRecipeBuilder shapedRecipe(Supplier<? extends ItemLike> 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<? extends ItemLike> result) { return builder(ShapelessRecipeBuilder.builder(result.get(), 1)); }
protected ShapelessRecipeBuilder shapelessRecipe(Supplier<? extends ItemLike> result, int count) { return builder(ShapelessRecipeBuilder.builder(new ItemStack(result.get(), count))); }
protected ShapelessRecipeBuilder shapelessRecipe(Supplier<? extends ItemLike> 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<? extends ItemLike> result) { return builder(FurnaceRecipeBuilder.smelting(result.get(), 1)); }
protected FurnaceRecipeBuilder smelting(Supplier<? extends ItemLike> result, int count) { return builder(FurnaceRecipeBuilder.smelting(new ItemStack(result.get(), count))); }
protected FurnaceRecipeBuilder smelting(Supplier<? extends ItemLike> 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<? extends ItemLike> result) { return builder(FurnaceRecipeBuilder.blasting(result.get(), 1)); }
protected FurnaceRecipeBuilder blasting(Supplier<? extends ItemLike> result, int count) { return builder(FurnaceRecipeBuilder.blasting(new ItemStack(result.get(), count))); }
protected FurnaceRecipeBuilder blasting(Supplier<? extends ItemLike> 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<? extends ItemLike> result) { return builder(FurnaceRecipeBuilder.smoking(result.get(), 1)); }
protected FurnaceRecipeBuilder smoking(Supplier<? extends ItemLike> result, int count) { return builder(FurnaceRecipeBuilder.smoking(new ItemStack(result.get(), count))); }
protected FurnaceRecipeBuilder smoking(Supplier<? extends ItemLike> 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<? extends ItemLike> result) { return builder(FurnaceRecipeBuilder.campfire(result.get(), 1)); }
protected FurnaceRecipeBuilder campfire(Supplier<? extends ItemLike> result, int count) { return builder(FurnaceRecipeBuilder.campfire(new ItemStack(result.get(), count))); }
protected FurnaceRecipeBuilder campfire(Supplier<? extends ItemLike> 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<? extends ItemLike> result) { return builder(ShapedRecipeBuilder.custom(serializer, result.get(), 1)); }
protected ShapedRecipeBuilder customShaped(RecipeSerializer<?> serializer, Supplier<? extends ItemLike> result, int count) { return builder(ShapedRecipeBuilder.custom(serializer, new ItemStack(result.get(), count))); }
protected ShapedRecipeBuilder customShaped(RecipeSerializer<?> serializer, Supplier<? extends ItemLike> 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<? extends ItemLike> result) { return builder(ShapelessRecipeBuilder.custom(serializer, result.get(), 1)); }
protected ShapelessRecipeBuilder customShapeless(RecipeSerializer<?> serializer, Supplier<? extends ItemLike> result, int count) { return builder(ShapelessRecipeBuilder.custom(serializer, new ItemStack(result.get(), count))); }
protected ShapelessRecipeBuilder customShapeless(RecipeSerializer<?> serializer, Supplier<? extends ItemLike> 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<? extends ItemLike> result) { return builder(FurnaceRecipeBuilder.custom(serializer, result.get(), 1)); }
protected FurnaceRecipeBuilder customFurnace(RecipeSerializer<?> serializer, Supplier<? extends ItemLike> result, int count) { return builder(FurnaceRecipeBuilder.custom(serializer, new ItemStack(result.get(), count))); }
protected FurnaceRecipeBuilder customFurnace(RecipeSerializer<?> serializer, Supplier<? extends ItemLike> 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
Expand All @@ -125,6 +158,10 @@ protected InventoryChangeTrigger.TriggerInstance hasItem(ItemLike itemIn) {
return hasItem(ItemPredicate.Builder.item().of(itemIn).build());
}

protected InventoryChangeTrigger.TriggerInstance hasItem(Supplier<? extends ItemLike> itemIn) {
return hasItem(ItemPredicate.Builder.item().of(itemIn.get()).build());
}

protected InventoryChangeTrigger.TriggerInstance hasItem(TagKey<Item> tagIn) {
return hasItem(ItemPredicate.Builder.item().of(tagIn).build());
}
Expand Down
Loading

0 comments on commit 7d8da85

Please sign in to comment.