Skip to content

Commit

Permalink
Fluid Storage Properties Improvements (#932)
Browse files Browse the repository at this point in the history
* glass tubes for mv acid storage

* drum fluid type handling

* fluid temperatures

* change tube to vial

* make item pipe require wrench

Co-authored-by: brachy84 <[email protected]>
  • Loading branch information
TechLord22 and brachy84 authored May 8, 2022
1 parent 149bad0 commit 1359f4b
Show file tree
Hide file tree
Showing 17 changed files with 289 additions and 58 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package gregtech.api.capability;

import gregtech.api.fluids.MaterialFluid;
import gregtech.api.fluids.fluidType.FluidType;
import gregtech.api.fluids.fluidType.FluidTypes;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidStack;

/**
* Interface for FluidHandlerItemStacks which handle GT's unique fluid mechanics
* @see FluidType
* @see FluidTypes
* @see MaterialFluid
*/
public interface IThermalFluidHandlerItemStack {

/**
*
* @param stack the {@link FluidStack} to check
* @return whether the FluidStack can be used to fill this fluid container
*/
default boolean canFillFluidType(FluidStack stack) {
if (stack == null || stack.getFluid() == null) return false;

Fluid fluid = stack.getFluid();
if (fluid.getTemperature() > getMaxFluidTemperature()) return false;
// fluids less than 120K are cryogenic
if (fluid.getTemperature() < 120 && !isCryoProof()) return false;
if (fluid.isGaseous() && !isGasProof()) return false;

if (fluid instanceof MaterialFluid) {
FluidType fluidType = ((MaterialFluid) fluid).getFluidType();
if (fluidType == FluidTypes.ACID && !isAcidProof()) return false;
if (fluidType == FluidTypes.PLASMA && !isPlasmaProof()) return false;
}
return true;
}

/**
* This is always checked, regardless of the contained fluid being a {@link MaterialFluid} or not
*
* @return the maximum allowed temperature for a fluid to be stored in this container
*/
int getMaxFluidTemperature();

/**
* This is always checked, regardless of the contained fluid being a {@link MaterialFluid} or not
*
* @return true if this fluid container allows gases, otherwise false
*/
boolean isGasProof();

/**
* @see FluidTypes
*
* @return true if this fluid container allows acids, otherwise false
*/
boolean isAcidProof();

/**
* @see FluidTypes
*
* @return true if this fluid container allows cryogenics, otherwise false
*/
boolean isCryoProof();

/**
* @see FluidTypes
*
* @return true if this fluid container allows plasmas, otherwise false
*/
boolean isPlasmaProof();
}
Original file line number Diff line number Diff line change
@@ -1,32 +1,57 @@
package gregtech.api.capability.impl;

import gregtech.api.capability.IThermalFluidHandlerItemStack;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.capability.templates.FluidHandlerItemStackSimple;

import javax.annotation.Nonnull;

public class SimpleThermalFluidHandlerItemStack extends FluidHandlerItemStackSimple {
public class SimpleThermalFluidHandlerItemStack extends FluidHandlerItemStackSimple implements IThermalFluidHandlerItemStack {

public final int minFluidTemperature;
public final int maxFluidTemperature;
private final boolean gasProof;
private final boolean acidProof;
private final boolean cryoProof;
private final boolean plasmaProof;

/**
* @param container The container itemStack, data is stored on it directly as NBT.
* @param capacity The maximum capacity of this fluid tank.
*/
public SimpleThermalFluidHandlerItemStack(@Nonnull ItemStack container, int capacity, int minFluidTemperature, int maxFluidTemperature) {
public SimpleThermalFluidHandlerItemStack(@Nonnull ItemStack container, int capacity, int maxFluidTemperature, boolean gasProof, boolean acidProof, boolean cryoProof, boolean plasmaProof) {
super(container, capacity);
this.minFluidTemperature = minFluidTemperature;
this.maxFluidTemperature = maxFluidTemperature;
this.gasProof = gasProof;
this.acidProof = acidProof;
this.cryoProof = cryoProof;
this.plasmaProof = plasmaProof;
}

@Override
public boolean canFillFluidType(FluidStack fluid) {
int liquidTemperature = fluid.getFluid().getTemperature();
return liquidTemperature >= minFluidTemperature && liquidTemperature <= maxFluidTemperature;
public int getMaxFluidTemperature() {
return maxFluidTemperature;
}

@Override
public boolean isGasProof() {
return gasProof;
}

@Override
public boolean isAcidProof() {
return acidProof;
}

@Override
public boolean isCryoProof() {
return cryoProof;
}

@Override
public boolean isPlasmaProof() {
return plasmaProof;
}

@Override
public FluidStack drain(FluidStack resource, boolean doDrain) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,31 @@
package gregtech.api.capability.impl;

import gregtech.api.capability.IThermalFluidHandlerItemStack;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.capability.templates.FluidHandlerItemStack;

import javax.annotation.Nonnull;

public class ThermalFluidHandlerItemStack extends FluidHandlerItemStack {
public class ThermalFluidHandlerItemStack extends FluidHandlerItemStack implements IThermalFluidHandlerItemStack {

public final int minFluidTemperature;
public final int maxFluidTemperature;
private final int maxFluidTemperature;
private final boolean gasProof;
private final boolean acidProof;
private final boolean cryoProof;
private final boolean plasmaProof;

/**
* @param container The container itemStack, data is stored on it directly as NBT.
* @param capacity The maximum capacity of this fluid tank.
*/
public ThermalFluidHandlerItemStack(@Nonnull ItemStack container, int capacity, int minFluidTemperature, int maxFluidTemperature) {
public ThermalFluidHandlerItemStack(@Nonnull ItemStack container, int capacity, int maxFluidTemperature, boolean gasProof, boolean acidProof, boolean cryoProof, boolean plasmaProof) {
super(container, capacity);
this.minFluidTemperature = minFluidTemperature;
this.maxFluidTemperature = maxFluidTemperature;
}

@Override
public boolean canFillFluidType(FluidStack fluid) {
int liquidTemperature = fluid.getFluid().getTemperature();
return liquidTemperature >= minFluidTemperature && liquidTemperature <= maxFluidTemperature;
this.gasProof = gasProof;
this.acidProof = acidProof;
this.cryoProof = cryoProof;
this.plasmaProof = plasmaProof;
}

@Override
Expand All @@ -46,4 +47,29 @@ private void removeTagWhenEmpty(Boolean doDrain) {
this.container.setTagCompound(null);
}
}

@Override
public int getMaxFluidTemperature() {
return maxFluidTemperature;
}

@Override
public boolean isGasProof() {
return gasProof;
}

@Override
public boolean isAcidProof() {
return acidProof;
}

@Override
public boolean isCryoProof() {
return cryoProof;
}

@Override
public boolean isPlasmaProof() {
return plasmaProof;
}
}
20 changes: 8 additions & 12 deletions src/main/java/gregtech/api/items/metaitem/FilteredFluidStats.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,27 @@

public class FilteredFluidStats implements IItemComponent, IItemCapabilityProvider {

public final int maxCapacity;
public final int minFluidTemperature;
public final int maxFluidTemperature;
public final boolean allowPartlyFill;
public final int capacity;
public final boolean allowPartialFill;
private final Function<FluidStack, Boolean> fillPredicate;

public FilteredFluidStats(int maxCapacity, int minFluidTemperature, int maxFluidTemperature, boolean allowPartlyFill, Function<FluidStack, Boolean> fillPredicate) {
this.maxCapacity = maxCapacity;
this.minFluidTemperature = minFluidTemperature;
this.maxFluidTemperature = maxFluidTemperature;
this.allowPartlyFill = allowPartlyFill;
public FilteredFluidStats(int capacity, boolean allowPartialFill, Function<FluidStack, Boolean> fillPredicate) {
this.capacity = capacity;
this.allowPartialFill = allowPartialFill;
this.fillPredicate = fillPredicate;
}

@Override
public ICapabilityProvider createProvider(ItemStack itemStack) {
if (allowPartlyFill) {
return new ThermalFluidHandlerItemStack(itemStack, maxCapacity, minFluidTemperature, maxFluidTemperature) {
if (allowPartialFill) {
return new ThermalFluidHandlerItemStack(itemStack, capacity, Integer.MAX_VALUE, true, true, true, true) {
@Override
public boolean canFillFluidType(FluidStack fluid) {
return super.canFillFluidType(fluid) && fillPredicate.apply(fluid);
}
};
}
return new SimpleThermalFluidHandlerItemStack(itemStack, maxCapacity, minFluidTemperature, maxFluidTemperature) {
return new SimpleThermalFluidHandlerItemStack(itemStack, capacity, Integer.MAX_VALUE, true, true, true, true) {
@Override
public boolean canFillFluidType(FluidStack fluid) {
return super.canFillFluidType(fluid) && fillPredicate.apply(fluid);
Expand Down
26 changes: 16 additions & 10 deletions src/main/java/gregtech/api/items/metaitem/FluidStats.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,29 @@

public class FluidStats implements IItemComponent, IItemCapabilityProvider {

public final int maxCapacity;
public final int minFluidTemperature;
public final int capacity;
public final int maxFluidTemperature;
public final boolean allowPartlyFill;
private final boolean gasProof;
private final boolean acidProof;
private final boolean cryoProof;
private final boolean plasmaProof;
public final boolean allowPartialFill;

public FluidStats(int maxCapacity, int minFluidTemperature, int maxFluidTemperature, boolean allowPartlyFill) {
this.maxCapacity = maxCapacity;
this.minFluidTemperature = minFluidTemperature;
public FluidStats(int capacity, int maxFluidTemperature, boolean gasProof, boolean acidProof, boolean cryoProof, boolean plasmaProof, boolean allowPartialFill) {
this.capacity = capacity;
this.maxFluidTemperature = maxFluidTemperature;
this.allowPartlyFill = allowPartlyFill;
this.gasProof = gasProof;
this.acidProof = acidProof;
this.cryoProof = cryoProof;
this.plasmaProof = plasmaProof;
this.allowPartialFill = allowPartialFill;
}

@Override
public ICapabilityProvider createProvider(ItemStack itemStack) {
if (allowPartlyFill) {
return new ThermalFluidHandlerItemStack(itemStack, maxCapacity, minFluidTemperature, maxFluidTemperature);
if (allowPartialFill) {
return new ThermalFluidHandlerItemStack(itemStack, capacity, maxFluidTemperature, gasProof, acidProof, cryoProof, plasmaProof);
}
return new SimpleThermalFluidHandlerItemStack(itemStack, maxCapacity, minFluidTemperature, maxFluidTemperature);
return new SimpleThermalFluidHandlerItemStack(itemStack, capacity, maxFluidTemperature, gasProof, acidProof, cryoProof, plasmaProof);
}
}
15 changes: 15 additions & 0 deletions src/main/java/gregtech/api/items/metaitem/MetaItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import gregtech.api.GregTechAPI;
import gregtech.api.capability.GregtechCapabilities;
import gregtech.api.capability.IElectricItem;
import gregtech.api.capability.IThermalFluidHandlerItemStack;
import gregtech.api.capability.impl.CombinedCapabilityProvider;
import gregtech.api.capability.impl.ElectricItem;
import gregtech.api.gui.ModularUI;
Expand Down Expand Up @@ -57,6 +58,7 @@
import net.minecraftforge.oredict.OreDictionary;
import org.apache.commons.lang3.Validate;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.lwjgl.input.Keyboard;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
Expand Down Expand Up @@ -562,6 +564,19 @@ public void addInformation(@Nonnull ItemStack itemStack, @Nullable World worldIn
fluid == null ? 0 : fluid.amount,
fluidTankProperties.getCapacity(),
fluid == null ? "" : fluid.getLocalizedName()));

if (fluidHandler instanceof IThermalFluidHandlerItemStack) {
IThermalFluidHandlerItemStack thermalFluidHandler = (IThermalFluidHandlerItemStack) fluidHandler;
if (Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_RSHIFT)) {
lines.add(I18n.format("gregtech.fluid_pipe.max_temperature", thermalFluidHandler.getMaxFluidTemperature()));
if (thermalFluidHandler.isGasProof()) lines.add(I18n.format("gregtech.fluid_pipe.gas_proof"));
if (thermalFluidHandler.isAcidProof()) lines.add(I18n.format("gregtech.fluid_pipe.acid_proof"));
if (thermalFluidHandler.isCryoProof()) lines.add(I18n.format("gregtech.fluid_pipe.cryo_proof"));
if (thermalFluidHandler.isPlasmaProof()) lines.add(I18n.format("gregtech.fluid_pipe.plasma_proof"));
} else if (thermalFluidHandler.isGasProof() || thermalFluidHandler.isAcidProof() || thermalFluidHandler.isCryoProof() || thermalFluidHandler.isPlasmaProof()) {
lines.add(I18n.format("gregtech.tooltip.fluid_pipe_hold_shift"));
}
}
}

for (IItemBehaviour behaviour : getBehaviours(itemStack)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static void register() {
.color(0xFAFAFA).iconSet(GLASS)
.flags(GENERATE_LENS, NO_SMASHING, EXCLUDE_BLOCK_CRAFTING_RECIPES, DECOMPOSITION_BY_CENTRIFUGING)
.components(SiliconDioxide, 1)
.fluidTemp(1400)
.fluidTemp(1200)
.build();

Perlite = new Material.Builder(2001, "perlite")
Expand Down
Loading

0 comments on commit 1359f4b

Please sign in to comment.