mirror of
https://github.com/Creators-of-Create/Create.git
synced 2024-12-29 00:16:27 +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))
|
if (!(recipeType.serializer instanceof ProcessingRecipeSerializer))
|
||||||
throw new IllegalStateException("Cannot datagen ProcessingRecipe of type: " + typeName);
|
throw new IllegalStateException("Cannot datagen ProcessingRecipe of type: " + typeName);
|
||||||
|
|
||||||
this.id = Create.asResource(typeName + "/" + recipe.getId()
|
this.id = new ResourceLocation(recipe.getId().getNamespace(),
|
||||||
.getPath());
|
typeName + "/" + recipe.getId().getPath());
|
||||||
this.serializer = (ProcessingRecipeSerializer<S>) recipe.getSerializer();
|
this.serializer = (ProcessingRecipeSerializer<S>) recipe.getSerializer();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,7 @@ public abstract class CreateRecipeProvider extends RecipeProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
@FunctionalInterface
|
@FunctionalInterface
|
||||||
interface GeneratedRecipe {
|
public interface GeneratedRecipe {
|
||||||
void register(Consumer<IFinishedRecipe> consumer);
|
void register(Consumer<IFinishedRecipe> consumer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,7 @@ import net.minecraft.data.DirectoryCache;
|
||||||
import net.minecraft.data.IDataProvider;
|
import net.minecraft.data.IDataProvider;
|
||||||
import net.minecraft.item.crafting.Ingredient;
|
import net.minecraft.item.crafting.Ingredient;
|
||||||
import net.minecraft.util.IItemProvider;
|
import net.minecraft.util.IItemProvider;
|
||||||
|
import net.minecraft.util.ResourceLocation;
|
||||||
import net.minecraftforge.fluids.FluidAttributes;
|
import net.minecraftforge.fluids.FluidAttributes;
|
||||||
|
|
||||||
public abstract class ProcessingRecipeGen extends CreateRecipeProvider {
|
public abstract class ProcessingRecipeGen extends CreateRecipeProvider {
|
||||||
|
@ -37,14 +38,14 @@ public abstract class ProcessingRecipeGen extends CreateRecipeProvider {
|
||||||
generators.add(new PressingRecipeGen(gen));
|
generators.add(new PressingRecipeGen(gen));
|
||||||
generators.add(new FillingRecipeGen(gen));
|
generators.add(new FillingRecipeGen(gen));
|
||||||
generators.add(new EmptyingRecipeGen(gen));
|
generators.add(new EmptyingRecipeGen(gen));
|
||||||
|
|
||||||
gen.addProvider(new IDataProvider() {
|
gen.addProvider(new IDataProvider() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return "Create's Processing Recipes";
|
return "Create's Processing Recipes";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void act(DirectoryCache dc) throws IOException {
|
public void act(DirectoryCache dc) throws IOException {
|
||||||
generators.forEach(g -> {
|
generators.forEach(g -> {
|
||||||
|
@ -57,22 +58,22 @@ public abstract class ProcessingRecipeGen extends CreateRecipeProvider {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public ProcessingRecipeGen(DataGenerator p_i48262_1_) {
|
public ProcessingRecipeGen(DataGenerator p_i48262_1_) {
|
||||||
super(p_i48262_1_);
|
super(p_i48262_1_);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a processing recipe with a single itemstack ingredient, using its id
|
* Create a processing recipe with a single itemstack ingredient, using its id
|
||||||
* as the name of the recipe
|
* 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) {
|
UnaryOperator<ProcessingRecipeBuilder<T>> transform) {
|
||||||
ProcessingRecipeSerializer<T> serializer = getSerializer();
|
ProcessingRecipeSerializer<T> serializer = getSerializer();
|
||||||
GeneratedRecipe generatedRecipe = c -> {
|
GeneratedRecipe generatedRecipe = c -> {
|
||||||
IItemProvider iItemProvider = singleIngredient.get();
|
IItemProvider iItemProvider = singleIngredient.get();
|
||||||
transform
|
transform
|
||||||
.apply(new ProcessingRecipeBuilder<>(serializer.getFactory(), Create.asResource(iItemProvider.asItem()
|
.apply(new ProcessingRecipeBuilder<>(serializer.getFactory(), new ResourceLocation(namespace, iItemProvider.asItem()
|
||||||
.getRegistryName()
|
.getRegistryName()
|
||||||
.getPath())).withItemIngredients(Ingredient.fromItems(iItemProvider)))
|
.getPath())).withItemIngredients(Ingredient.fromItems(iItemProvider)))
|
||||||
.build(c);
|
.build(c);
|
||||||
|
@ -81,22 +82,40 @@ public abstract class ProcessingRecipeGen extends CreateRecipeProvider {
|
||||||
return generatedRecipe;
|
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
|
* Create a new processing recipe, with recipe definitions provided by the
|
||||||
* function
|
* function
|
||||||
*/
|
*/
|
||||||
protected <T extends ProcessingRecipe<?>> GeneratedRecipe create(String name,
|
protected <T extends ProcessingRecipe<?>> GeneratedRecipe create(ResourceLocation name,
|
||||||
UnaryOperator<ProcessingRecipeBuilder<T>> transform) {
|
UnaryOperator<ProcessingRecipeBuilder<T>> transform) {
|
||||||
ProcessingRecipeSerializer<T> serializer = getSerializer();
|
ProcessingRecipeSerializer<T> serializer = getSerializer();
|
||||||
GeneratedRecipe generatedRecipe =
|
GeneratedRecipe generatedRecipe =
|
||||||
c -> transform.apply(new ProcessingRecipeBuilder<>(serializer.getFactory(), Create.asResource(name)))
|
c -> transform.apply(new ProcessingRecipeBuilder<>(serializer.getFactory(), name))
|
||||||
.build(c);
|
.build(c);
|
||||||
all.add(generatedRecipe);
|
all.add(generatedRecipe);
|
||||||
return 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")
|
@SuppressWarnings("unchecked")
|
||||||
private <T extends ProcessingRecipe<?>> ProcessingRecipeSerializer<T> getSerializer() {
|
protected <T extends ProcessingRecipe<?>> ProcessingRecipeSerializer<T> getSerializer() {
|
||||||
ProcessingRecipeSerializer<T> serializer = (ProcessingRecipeSerializer<T>) getRecipeType().serializer;
|
ProcessingRecipeSerializer<T> serializer = (ProcessingRecipeSerializer<T>) getRecipeType().serializer;
|
||||||
return serializer;
|
return serializer;
|
||||||
}
|
}
|
||||||
|
@ -105,7 +124,7 @@ public abstract class ProcessingRecipeGen extends CreateRecipeProvider {
|
||||||
public final String getName() {
|
public final String getName() {
|
||||||
return "Create's Processing Recipes: " + getRecipeType();
|
return "Create's Processing Recipes: " + getRecipeType();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract AllRecipeTypes getRecipeType();
|
protected abstract AllRecipeTypes getRecipeType();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue