mirror of
https://github.com/Creators-of-Create/Create.git
synced 2024-12-29 00:16:27 +01:00
Merge pull request #1895 from kotakotik22/mc1.16/dev
changes to make it easier for addons
This commit is contained in:
commit
5becf40b60
4 changed files with 46 additions and 27 deletions
|
@ -240,57 +240,57 @@ public class AllShapes {
|
||||||
return Block.makeCuboidShape(x1, y1, z1, x2, y2, z2);
|
return Block.makeCuboidShape(x1, y1, z1, x2, y2, z2);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class Builder {
|
public static class Builder {
|
||||||
VoxelShape shape;
|
VoxelShape shape;
|
||||||
|
|
||||||
public Builder(VoxelShape shape) {
|
public Builder(VoxelShape shape) {
|
||||||
this.shape = shape;
|
this.shape = shape;
|
||||||
}
|
}
|
||||||
|
|
||||||
Builder add(VoxelShape shape) {
|
public Builder add(VoxelShape shape) {
|
||||||
this.shape = VoxelShapes.or(this.shape, shape);
|
this.shape = VoxelShapes.or(this.shape, shape);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
Builder add(double x1, double y1, double z1, double x2, double y2, double z2) {
|
public Builder add(double x1, double y1, double z1, double x2, double y2, double z2) {
|
||||||
return add(cuboid(x1, y1, z1, x2, y2, z2));
|
return add(cuboid(x1, y1, z1, x2, y2, z2));
|
||||||
}
|
}
|
||||||
|
|
||||||
Builder erase(double x1, double y1, double z1, double x2, double y2, double z2) {
|
public Builder erase(double x1, double y1, double z1, double x2, double y2, double z2) {
|
||||||
this.shape =
|
this.shape =
|
||||||
VoxelShapes.combineAndSimplify(shape, cuboid(x1, y1, z1, x2, y2, z2), IBooleanFunction.ONLY_FIRST);
|
VoxelShapes.combineAndSimplify(shape, cuboid(x1, y1, z1, x2, y2, z2), IBooleanFunction.ONLY_FIRST);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
VoxelShape build() {
|
public VoxelShape build() {
|
||||||
return shape;
|
return shape;
|
||||||
}
|
}
|
||||||
|
|
||||||
VoxelShaper build(BiFunction<VoxelShape, Direction, VoxelShaper> factory, Direction direction) {
|
public VoxelShaper build(BiFunction<VoxelShape, Direction, VoxelShaper> factory, Direction direction) {
|
||||||
return factory.apply(shape, direction);
|
return factory.apply(shape, direction);
|
||||||
}
|
}
|
||||||
|
|
||||||
VoxelShaper build(BiFunction<VoxelShape, Axis, VoxelShaper> factory, Axis axis) {
|
public VoxelShaper build(BiFunction<VoxelShape, Axis, VoxelShaper> factory, Axis axis) {
|
||||||
return factory.apply(shape, axis);
|
return factory.apply(shape, axis);
|
||||||
}
|
}
|
||||||
|
|
||||||
VoxelShaper forDirectional(Direction direction) {
|
public VoxelShaper forDirectional(Direction direction) {
|
||||||
return build(VoxelShaper::forDirectional, direction);
|
return build(VoxelShaper::forDirectional, direction);
|
||||||
}
|
}
|
||||||
|
|
||||||
VoxelShaper forAxis() {
|
public VoxelShaper forAxis() {
|
||||||
return build(VoxelShaper::forAxis, Axis.Y);
|
return build(VoxelShaper::forAxis, Axis.Y);
|
||||||
}
|
}
|
||||||
|
|
||||||
VoxelShaper forHorizontalAxis() {
|
public VoxelShaper forHorizontalAxis() {
|
||||||
return build(VoxelShaper::forHorizontalAxis, Axis.Z);
|
return build(VoxelShaper::forHorizontalAxis, Axis.Z);
|
||||||
}
|
}
|
||||||
|
|
||||||
VoxelShaper forHorizontal(Direction direction) {
|
public VoxelShaper forHorizontal(Direction direction) {
|
||||||
return build(VoxelShaper::forHorizontal, direction);
|
return build(VoxelShaper::forHorizontal, direction);
|
||||||
}
|
}
|
||||||
|
|
||||||
VoxelShaper forDirectional() {
|
public VoxelShaper forDirectional() {
|
||||||
return forDirectional(UP);
|
return forDirectional(UP);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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