mirror of
https://github.com/Creators-of-Create/Create.git
synced 2025-03-03 22:34:42 +01:00
feat: fluids in datagen without compile-time existence
This commit is contained in:
parent
ddae967de6
commit
3cc4a76bc0
4 changed files with 94 additions and 2 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;
|
||||
|
@ -130,6 +131,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));
|
||||
}
|
||||
|
@ -188,6 +193,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,7 +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 net.createmod.catnip.platform.CatnipServices;
|
||||
import net.createmod.catnip.data.Pair;
|
||||
import net.minecraft.nbt.TagParser;
|
||||
|
@ -133,7 +133,8 @@ public class FluidHelper {
|
|||
|
||||
public static JsonElement serializeFluidStack(FluidStack stack) {
|
||||
JsonObject json = new JsonObject();
|
||||
json.addProperty("fluid", CatnipServices.REGISTRIES.getKeyOrThrow(stack.getFluid())
|
||||
json.addProperty("fluid", stack instanceof DatagenFluidStack datagenFluidStack ?
|
||||
datagenFluidStack.getActualFluid() : CatnipServices.REGISTRIES.getKeyOrThrow(stack.getFluid())
|
||||
.toString());
|
||||
json.addProperty("amount", stack.getAmount());
|
||||
if (stack.hasTag())
|
||||
|
|
|
@ -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…
Add table
Reference in a new issue