Processing recipe generation addon utilities

This commit is contained in:
kotakotik22 2021-07-05 18:30:23 +02:00
parent b0d4376730
commit 159f96ca57
3 changed files with 34 additions and 15 deletions

View file

@ -230,8 +230,8 @@ public class ProcessingRecipeBuilder<T extends ProcessingRecipe<?>> {
if (!(recipeType.serializer instanceof ProcessingRecipeSerializer))
throw new IllegalStateException("Cannot datagen ProcessingRecipe of type: " + typeName);
this.id = Create.asResource(typeName + "/" + recipe.getId()
.getPath());
this.id = new ResourceLocation(recipe.getId().getNamespace(),
typeName + "/" + recipe.getId().getPath());
this.serializer = (ProcessingRecipeSerializer<S>) recipe.getSerializer();
}

View file

@ -33,7 +33,7 @@ public abstract class CreateRecipeProvider extends RecipeProvider {
}
@FunctionalInterface
interface GeneratedRecipe {
public interface GeneratedRecipe {
void register(Consumer<IFinishedRecipe> consumer);
}

View file

@ -17,6 +17,7 @@ import net.minecraft.data.DirectoryCache;
import net.minecraft.data.IDataProvider;
import net.minecraft.item.crafting.Ingredient;
import net.minecraft.util.IItemProvider;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fluids.FluidAttributes;
public abstract class ProcessingRecipeGen extends CreateRecipeProvider {
@ -66,13 +67,13 @@ public abstract class ProcessingRecipeGen extends CreateRecipeProvider {
* Create a processing recipe with a single itemstack ingredient, using its id
* as the name of the recipe
*/
protected <T extends ProcessingRecipe<?>> GeneratedRecipe create(Supplier<IItemProvider> singleIngredient,
protected <T extends ProcessingRecipe<?>> GeneratedRecipe create(String namespace, Supplier<IItemProvider> singleIngredient,
UnaryOperator<ProcessingRecipeBuilder<T>> transform) {
ProcessingRecipeSerializer<T> serializer = getSerializer();
GeneratedRecipe generatedRecipe = c -> {
IItemProvider iItemProvider = singleIngredient.get();
transform
.apply(new ProcessingRecipeBuilder<>(serializer.getFactory(), Create.asResource(iItemProvider.asItem()
.apply(new ProcessingRecipeBuilder<>(serializer.getFactory(), new ResourceLocation(namespace, iItemProvider.asItem()
.getRegistryName()
.getPath())).withItemIngredients(Ingredient.fromItems(iItemProvider)))
.build(c);
@ -81,22 +82,40 @@ public abstract class ProcessingRecipeGen extends CreateRecipeProvider {
return generatedRecipe;
}
/**
* Create a processing recipe with a single itemstack ingredient, using its id
* as the name of the recipe
*/
protected <T extends ProcessingRecipe<?>> GeneratedRecipe create(Supplier<IItemProvider> singleIngredient,
UnaryOperator<ProcessingRecipeBuilder<T>> transform) {
return create(Create.ID, singleIngredient, transform);
}
/**
* Create a new processing recipe, with recipe definitions provided by the
* function
*/
protected <T extends ProcessingRecipe<?>> GeneratedRecipe create(String name,
UnaryOperator<ProcessingRecipeBuilder<T>> transform) {
protected <T extends ProcessingRecipe<?>> GeneratedRecipe create(ResourceLocation name,
UnaryOperator<ProcessingRecipeBuilder<T>> transform) {
ProcessingRecipeSerializer<T> serializer = getSerializer();
GeneratedRecipe generatedRecipe =
c -> transform.apply(new ProcessingRecipeBuilder<>(serializer.getFactory(), Create.asResource(name)))
c -> transform.apply(new ProcessingRecipeBuilder<>(serializer.getFactory(), name))
.build(c);
all.add(generatedRecipe);
return generatedRecipe;
}
/**
* Create a new processing recipe, with recipe definitions provided by the
* function
*/
protected <T extends ProcessingRecipe<?>> GeneratedRecipe create(String name,
UnaryOperator<ProcessingRecipeBuilder<T>> transform) {
return create(Create.asResource(name), transform);
}
@SuppressWarnings("unchecked")
private <T extends ProcessingRecipe<?>> ProcessingRecipeSerializer<T> getSerializer() {
protected <T extends ProcessingRecipe<?>> ProcessingRecipeSerializer<T> getSerializer() {
ProcessingRecipeSerializer<T> serializer = (ProcessingRecipeSerializer<T>) getRecipeType().serializer;
return serializer;
}