Skip to content

Commit

Permalink
Fix erroring material handlers when liquids don't exist (GregTechCEu#…
Browse files Browse the repository at this point in the history
  • Loading branch information
bruberu authored Jan 14, 2024
1 parent 9022c0f commit 3e0835e
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 12 deletions.
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) {
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

0 comments on commit 3e0835e

Please sign in to comment.