From 7711c80664fdfa703b5e60e62af437655da783ae Mon Sep 17 00:00:00 2001 From: Draknyte1 Date: Sat, 27 Feb 2016 21:24:45 +1000 Subject: Added Custom GT Cables/Wire & also added a copy of EnderIO's Gas Conduit classes. Time to combine the two, yeah? Also stripped out a heap of constants and refactored them together. --- .../enderio/conduit/gas/ConduitGasTank.java | 164 +++++++++++++++++++++ 1 file changed, 164 insertions(+) create mode 100644 src/Java/miscutil/enderio/conduit/gas/ConduitGasTank.java (limited to 'src/Java/miscutil/enderio/conduit/gas/ConduitGasTank.java') diff --git a/src/Java/miscutil/enderio/conduit/gas/ConduitGasTank.java b/src/Java/miscutil/enderio/conduit/gas/ConduitGasTank.java new file mode 100644 index 0000000000..08aef66656 --- /dev/null +++ b/src/Java/miscutil/enderio/conduit/gas/ConduitGasTank.java @@ -0,0 +1,164 @@ +package crazypants.enderio.conduit.gas; + +import cpw.mods.fml.common.Optional.Method; +import mekanism.api.gas.Gas; +import mekanism.api.gas.GasStack; +import mekanism.api.gas.GasTank; +import net.minecraft.nbt.NBTTagCompound; + +public class ConduitGasTank + extends GasTank +{ + private int capacity; + + ConduitGasTank(int capacity) + { + super(capacity); + this.capacity = capacity; + } + + public float getFilledRatio() + { + if (getStored() <= 0) { + return 0.0F; + } + if (getMaxGas() <= 0) { + return -1.0F; + } + float res = getStored() / getMaxGas(); + return res; + } + + public boolean isFull() + { + return getStored() >= getMaxGas(); + } + + public void setAmount(int amount) + { + if (this.stored != null) { + this.stored.amount = amount; + } + } + + public int getAvailableSpace() + { + return getMaxGas() - getStored(); + } + + public void addAmount(int amount) + { + setAmount(getStored() + amount); + } + + public int getMaxGas() + { + return this.capacity; + } + + public void setCapacity(int capacity) + { + this.capacity = capacity; + if (getStored() > capacity) { + setAmount(capacity); + } + } + + @Optional.Method(modid="MekanismAPI|gas") + public int receive(GasStack resource, boolean doReceive) + { + if ((resource == null) || (resource.getGas().getID() < 0)) { + return 0; + } + if ((this.stored == null) || (this.stored.getGas().getID() < 0)) + { + if (resource.amount <= this.capacity) + { + if (doReceive) { + setGas(resource.copy()); + } + return resource.amount; + } + if (doReceive) + { + this.stored = resource.copy(); + this.stored.amount = this.capacity; + } + return this.capacity; + } + if (!this.stored.isGasEqual(resource)) { + return 0; + } + int space = this.capacity - this.stored.amount; + if (resource.amount <= space) + { + if (doReceive) { + addAmount(resource.amount); + } + return resource.amount; + } + if (doReceive) { + this.stored.amount = this.capacity; + } + return space; + } + + @Optional.Method(modid="MekanismAPI|gas") + public GasStack draw(int maxDrain, boolean doDraw) + { + if ((this.stored == null) || (this.stored.getGas().getID() < 0)) { + return null; + } + if (this.stored.amount <= 0) { + return null; + } + int used = maxDrain; + if (this.stored.amount < used) { + used = this.stored.amount; + } + if (doDraw) { + addAmount(-used); + } + GasStack drained = new GasStack(this.stored.getGas().getID(), used); + if (this.stored.amount < 0) { + this.stored.amount = 0; + } + return drained; + } + + public String getGasName() + { + return this.stored != null ? this.stored.getGas().getLocalizedName() : null; + } + + public boolean containsValidGas() + { + return GasUtil.isGasValid(this.stored); + } + + public NBTTagCompound write(NBTTagCompound nbt) + { + if (containsValidGas()) { + this.stored.write(nbt); + } else { + nbt.setBoolean("emptyGasTank", true); + } + return nbt; + } + + public void read(NBTTagCompound nbt) + { + if (!nbt.hasKey("emptyGasTank")) + { + GasStack gas = GasStack.readFromNBT(nbt); + if (gas != null) { + setGas(gas); + } + } + } + + public boolean isEmpty() + { + return (this.stored == null) || (this.stored.amount == 0); + } +} -- cgit