mirror of
https://github.com/Creators-of-Create/Create.git
synced 2024-11-10 03:53:12 +01:00
Processing recipe generation addon utilities
This commit is contained in:
parent
b0d4376730
commit
159f96ca57
3 changed files with 34 additions and 15 deletions
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ public abstract class CreateRecipeProvider extends RecipeProvider {
|
|||
}
|
||||
|
||||
@FunctionalInterface
|
||||
interface GeneratedRecipe {
|
||||
public interface GeneratedRecipe {
|
||||
void register(Consumer<IFinishedRecipe> consumer);
|
||||
}
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
@ -37,14 +38,14 @@ public abstract class ProcessingRecipeGen extends CreateRecipeProvider {
|
|||
generators.add(new PressingRecipeGen(gen));
|
||||
generators.add(new FillingRecipeGen(gen));
|
||||
generators.add(new EmptyingRecipeGen(gen));
|
||||
|
||||
|
||||
gen.addProvider(new IDataProvider() {
|
||||
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Create's Processing Recipes";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void act(DirectoryCache dc) throws IOException {
|
||||
generators.forEach(g -> {
|
||||
|
@ -57,22 +58,22 @@ public abstract class ProcessingRecipeGen extends CreateRecipeProvider {
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public ProcessingRecipeGen(DataGenerator p_i48262_1_) {
|
||||
super(p_i48262_1_);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
|
@ -105,7 +124,7 @@ public abstract class ProcessingRecipeGen extends CreateRecipeProvider {
|
|||
public final String getName() {
|
||||
return "Create's Processing Recipes: " + getRecipeType();
|
||||
}
|
||||
|
||||
|
||||
protected abstract AllRecipeTypes getRecipeType();
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue