mirror of
https://github.com/Creators-of-Create/Create.git
synced 2025-01-30 06:45:03 +01:00
feat: fluids in datagen without compile-time existence
This commit is contained in:
parent
0b182439e1
commit
e002d68dc2
4 changed files with 97 additions and 4 deletions
|
@ -7,6 +7,7 @@ import java.util.function.Consumer;
|
|||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.simibubi.create.foundation.data.SimpleDatagenIngredient;
|
||||
import com.simibubi.create.foundation.data.recipe.DatagenFluidStack;
|
||||
import com.simibubi.create.foundation.data.recipe.Mods;
|
||||
import com.simibubi.create.foundation.fluid.FluidHelper;
|
||||
import com.simibubi.create.foundation.fluid.FluidIngredient;
|
||||
|
@ -129,6 +130,10 @@ public class ProcessingRecipeBuilder<T extends ProcessingRecipe<?>> {
|
|||
return this;
|
||||
}
|
||||
|
||||
public ProcessingRecipeBuilder<T> require(Mods mod, String fluid, int amount) {
|
||||
return require(new FluidIngredient.DatagenFluidIngredient(mod.asResource(fluid), amount));
|
||||
}
|
||||
|
||||
public ProcessingRecipeBuilder<T> require(Fluid fluid, int amount) {
|
||||
return require(FluidIngredient.fromFluid(fluid, amount));
|
||||
}
|
||||
|
@ -183,6 +188,10 @@ public class ProcessingRecipeBuilder<T extends ProcessingRecipe<?>> {
|
|||
return this;
|
||||
}
|
||||
|
||||
public ProcessingRecipeBuilder<T> output(Mods mod, String fluid, int amount) {
|
||||
return output(new DatagenFluidStack(mod.asResource(fluid), amount));
|
||||
}
|
||||
|
||||
public ProcessingRecipeBuilder<T> output(Fluid fluid, int amount) {
|
||||
fluid = FluidHelper.convertToStill(fluid);
|
||||
return output(new FluidStack(fluid, amount));
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
package com.simibubi.create.foundation.data.recipe;
|
||||
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.level.material.Fluids;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
|
||||
/**
|
||||
* Used to represent fluid outputs in recipe datagen without needing the fluid to exist at runtime.
|
||||
*/
|
||||
@ApiStatus.Internal
|
||||
public final class DatagenFluidStack extends FluidStack {
|
||||
private final ResourceLocation actualFluid;
|
||||
|
||||
public DatagenFluidStack(ResourceLocation fluid, int amount) {
|
||||
// This fluid is a farce
|
||||
super(Fluids.WATER, amount);
|
||||
actualFluid = fluid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Supersedes the result of getFluid() for the purpose of obtaining a string representation of the fluid
|
||||
* @return String value of the actual fluid's ResourceLocation
|
||||
*/
|
||||
public String getActualFluid(){
|
||||
return actualFluid.toString();
|
||||
}
|
||||
}
|
|
@ -11,6 +11,7 @@ import com.simibubi.create.content.fluids.tank.CreativeFluidTankBlockEntity;
|
|||
import com.simibubi.create.content.fluids.transfer.GenericItemEmptying;
|
||||
import com.simibubi.create.content.fluids.transfer.GenericItemFilling;
|
||||
import com.simibubi.create.foundation.blockEntity.SmartBlockEntity;
|
||||
import com.simibubi.create.foundation.data.recipe.DatagenFluidStack;
|
||||
import com.simibubi.create.foundation.utility.Pair;
|
||||
import com.simibubi.create.foundation.utility.RegisteredObjects;
|
||||
|
||||
|
@ -53,11 +54,11 @@ public class FluidHelper {
|
|||
public static boolean isLava(Fluid fluid) {
|
||||
return convertToStill(fluid) == Fluids.LAVA;
|
||||
}
|
||||
|
||||
|
||||
public static boolean isSame(FluidStack fluidStack, FluidStack fluidStack2) {
|
||||
return fluidStack.getFluid() == fluidStack2.getFluid();
|
||||
}
|
||||
|
||||
|
||||
public static boolean isSame(FluidStack fluidStack, Fluid fluid) {
|
||||
return fluidStack.getFluid() == fluid;
|
||||
}
|
||||
|
@ -133,8 +134,9 @@ public class FluidHelper {
|
|||
|
||||
public static JsonElement serializeFluidStack(FluidStack stack) {
|
||||
JsonObject json = new JsonObject();
|
||||
json.addProperty("fluid", RegisteredObjects.getKeyOrThrow(stack.getFluid())
|
||||
.toString());
|
||||
json.addProperty("fluid", stack instanceof DatagenFluidStack datagenFluidStack ?
|
||||
datagenFluidStack.getActualFluid() :
|
||||
RegisteredObjects.getKeyOrThrow(stack.getFluid()).toString());
|
||||
json.addProperty("amount", stack.getAmount());
|
||||
if (stack.hasTag())
|
||||
json.addProperty("nbt", stack.getTag()
|
||||
|
|
|
@ -26,6 +26,8 @@ import net.minecraft.world.level.material.Fluid;
|
|||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.registries.ForgeRegistries;
|
||||
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
|
||||
public abstract class FluidIngredient implements Predicate<FluidStack> {
|
||||
|
||||
public static final FluidIngredient EMPTY = new FluidStackIngredient();
|
||||
|
@ -256,4 +258,55 @@ public abstract class FluidIngredient implements Predicate<FluidStack> {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to represent fluid inputs in recipe datagen without needing the fluid to exist at runtime.
|
||||
*/
|
||||
@ApiStatus.Internal
|
||||
public static final class DatagenFluidIngredient extends FluidIngredient{
|
||||
|
||||
private final ResourceLocation fluid;
|
||||
|
||||
public DatagenFluidIngredient(ResourceLocation fluid, int amountRequired) {
|
||||
this.fluid = fluid;
|
||||
this.amountRequired = amountRequired;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean testInternal(FluidStack t) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void readInternal(FriendlyByteBuf buffer) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void writeInternal(FriendlyByteBuf buffer) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void readInternal(JsonObject json) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void writeInternal(JsonObject json) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<FluidStack> determineMatchingFluidStacks() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonObject serialize() {
|
||||
JsonObject json = super.serialize();
|
||||
json.addProperty("fluid", fluid.toString());
|
||||
return json;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue