Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix erroring material handlers when liquids don't exist #2343

Merged
merged 6 commits into from
Jan 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

import gregtech.api.fluids.store.FluidStorage;
import gregtech.api.fluids.store.FluidStorageKey;
import gregtech.api.fluids.store.FluidStorageKeys;

import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidStack;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand All @@ -10,6 +14,7 @@ public class FluidProperty implements IMaterialProperty {

private final FluidStorage storage = new FluidStorage();
private @Nullable FluidStorageKey primaryKey = null;
private @Nullable Fluid solidifyingFluid = null;

public FluidProperty() {}

Expand All @@ -33,4 +38,33 @@ public void setPrimaryKey(@Nullable FluidStorageKey primaryKey) {

@Override
public void verifyProperty(MaterialProperties properties) {}

/**
* @return the Fluid which solidifies into the material.
*/

public Fluid solidifiesFrom() {
if (this.solidifyingFluid == null) {
return getStorage().get(FluidStorageKeys.LIQUID);
}
return solidifyingFluid;
}

/**
* @param amount the size of the returned FluidStack.
* @return a FluidStack of the Fluid which solidifies into the material.
*/
public FluidStack solidifiesFrom(int amount) {
return new FluidStack(solidifiesFrom(), amount);
}

/**
* Sets the fluid that solidifies into the material.
*
* @param solidifyingFluid The Fluid which solidifies into the material. If left null, it will be left as the
* default value: the material's liquid.
*/
public void setSolidifyingFluid(@Nullable Fluid solidifyingFluid) {
TechLord22 marked this conversation as resolved.
Show resolved Hide resolved
this.solidifyingFluid = solidifyingFluid;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -286,10 +286,10 @@ public static void processIngot(OrePrefix ingotPrefix, Material material, IngotP
}
}

if (material.hasFluid()) {
if (material.hasFluid() && material.getProperty(PropertyKey.FLUID).solidifiesFrom() != null) {
RecipeMaps.FLUID_SOLIDFICATION_RECIPES.recipeBuilder()
.notConsumable(MetaItems.SHAPE_MOLD_INGOT)
.fluidInputs(material.getFluid(L))
.fluidInputs(material.getProperty(PropertyKey.FLUID).solidifiesFrom(L))
.outputs(OreDictUnifier.get(ingotPrefix, material))
.duration(20).EUt(VA[ULV])
.buildAndRegister();
Expand Down Expand Up @@ -424,10 +424,10 @@ public static void processNugget(OrePrefix orePrefix, Material material, DustPro
.output(ingot, material)
.buildAndRegister();

if (material.hasFluid()) {
if (material.hasFluid() && material.getProperty(PropertyKey.FLUID).solidifiesFrom() != null) {
RecipeMaps.FLUID_SOLIDFICATION_RECIPES.recipeBuilder()
.notConsumable(MetaItems.SHAPE_MOLD_NUGGET)
.fluidInputs(material.getFluid(L))
.fluidInputs(material.getProperty(PropertyKey.FLUID).solidifiesFrom(L))
.outputs(OreDictUnifier.get(orePrefix, material, 9))
.duration((int) material.getMass())
.EUt(VA[ULV])
Expand Down Expand Up @@ -465,10 +465,11 @@ public static void processFrame(OrePrefix framePrefix, Material material, DustPr
public static void processBlock(OrePrefix blockPrefix, Material material, DustProperty property) {
ItemStack blockStack = OreDictUnifier.get(blockPrefix, material);
long materialAmount = blockPrefix.getMaterialAmount(material);
if (material.hasFluid()) {
if (material.hasFluid() && material.getProperty(PropertyKey.FLUID).solidifiesFrom() != null) {
RecipeMaps.FLUID_SOLIDFICATION_RECIPES.recipeBuilder()
.notConsumable(MetaItems.SHAPE_MOLD_BLOCK)
.fluidInputs(material.getFluid((int) (materialAmount * L / M)))
.fluidInputs(material.getProperty(PropertyKey.FLUID).solidifiesFrom(
((int) (materialAmount * L / M))))
.outputs(blockStack)
.duration((int) material.getMass()).EUt(VA[ULV])
.buildAndRegister();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,11 +200,12 @@ public static void processGear(OrePrefix gearPrefix, Material material, DustProp
}
}

if (material.hasFluid()) {
if (material.hasFluid() && material.getProperty(PropertyKey.FLUID).solidifiesFrom() != null) {
boolean isSmall = gearPrefix == OrePrefix.gearSmall;
RecipeMaps.FLUID_SOLIDFICATION_RECIPES.recipeBuilder()
.notConsumable(isSmall ? MetaItems.SHAPE_MOLD_GEAR_SMALL : MetaItems.SHAPE_MOLD_GEAR)
.fluidInputs(material.getFluid(L * (isSmall ? 1 : 4)))
.fluidInputs(
material.getProperty(PropertyKey.FLUID).solidifiesFrom(L * (isSmall ? 1 : 4)))
.outputs(stack)
.duration(isSmall ? 20 : 100)
.EUt(VA[ULV])
Expand Down Expand Up @@ -285,10 +286,10 @@ public static void processLens(OrePrefix lensPrefix, Material material, GemPrope
}

public static void processPlate(OrePrefix platePrefix, Material material, DustProperty property) {
if (material.hasFluid()) {
if (material.hasFluid() && material.getProperty(PropertyKey.FLUID).solidifiesFrom() != null) {
RecipeMaps.FLUID_SOLIDFICATION_RECIPES.recipeBuilder()
.notConsumable(MetaItems.SHAPE_MOLD_PLATE)
.fluidInputs(material.getFluid(L))
.fluidInputs(material.getProperty(PropertyKey.FLUID).solidifiesFrom(L))
.outputs(OreDictUnifier.get(platePrefix, material))
.duration(40)
.EUt(VA[ULV])
Expand Down Expand Up @@ -399,10 +400,10 @@ public static void processRotor(OrePrefix rotorPrefix, Material material, IngotP
'S', new UnificationEntry(screw, material),
'R', new UnificationEntry(ring, material));

if (material.hasFluid()) {
if (material.hasFluid() && material.getProperty(PropertyKey.FLUID).solidifiesFrom() != null) {
RecipeMaps.FLUID_SOLIDFICATION_RECIPES.recipeBuilder()
.notConsumable(MetaItems.SHAPE_MOLD_ROTOR)
.fluidInputs(material.getFluid(L * 4))
.fluidInputs(material.getProperty(PropertyKey.FLUID).solidifiesFrom(L * 4))
.outputs(GTUtility.copy(stack))
.duration(120)
.EUt(20)
Expand Down