diff options
| author | Draknyte1 <Draknyte1@hotmail.com> | 2016-02-27 21:24:45 +1000 |
|---|---|---|
| committer | Draknyte1 <Draknyte1@hotmail.com> | 2016-02-27 21:24:45 +1000 |
| commit | 7711c80664fdfa703b5e60e62af437655da783ae (patch) | |
| tree | 1a251a5919b7c6d4f32de7efca6a36d97cef0233 /src/Java/miscutil/enderio/conduit/gas/ConduitGasTank.java | |
| parent | 707621bc6afd36856feafb052c2e65c52fe79986 (diff) | |
| download | GT5-Unofficial-7711c80664fdfa703b5e60e62af437655da783ae.tar.gz GT5-Unofficial-7711c80664fdfa703b5e60e62af437655da783ae.tar.bz2 GT5-Unofficial-7711c80664fdfa703b5e60e62af437655da783ae.zip | |
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.
Diffstat (limited to 'src/Java/miscutil/enderio/conduit/gas/ConduitGasTank.java')
| -rw-r--r-- | src/Java/miscutil/enderio/conduit/gas/ConduitGasTank.java | 164 |
1 files changed, 164 insertions, 0 deletions
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); + } +} |
