Merge GasUtils into GasTransmission

This commit is contained in:
Aidan Brady 2013-11-30 12:37:47 -05:00
parent 0715a890bd
commit 2c754cd506
8 changed files with 42 additions and 50 deletions

View file

@ -6,6 +6,7 @@ import java.util.Set;
import mekanism.api.transmitters.ITransmitter;
import mekanism.api.transmitters.TransmissionType;
import mekanism.common.Object3D;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.ForgeDirection;
@ -101,4 +102,31 @@ public final class GasTransmission
return 0;
}
public static GasStack removeGas(ItemStack itemStack, Gas type, int amount)
{
if(itemStack != null && itemStack.getItem() instanceof IGasItem)
{
IGasItem item = (IGasItem)itemStack.getItem();
if(type != null && item.getGas(itemStack) != null && item.getGas(itemStack).getGas() != type || !item.canProvideGas(itemStack, type))
{
return null;
}
return item.removeGas(itemStack, amount);
}
return null;
}
public static int addGas(ItemStack itemStack, GasStack stack)
{
if(itemStack != null && itemStack.getItem() instanceof IGasItem && ((IGasItem)itemStack.getItem()).canReceiveGas(itemStack, stack.getGas()))
{
return ((IGasItem)itemStack.getItem()).addGas(itemStack, stack.copy());
}
return 0;
}
}

View file

@ -1,33 +0,0 @@
package mekanism.api.gas;
import net.minecraft.item.ItemStack;
public final class GasUtils
{
public static int addGas(ItemStack itemStack, GasStack stack)
{
if(itemStack != null && itemStack.getItem() instanceof IGasItem && ((IGasItem)itemStack.getItem()).canReceiveGas(itemStack, stack.getGas()))
{
return ((IGasItem)itemStack.getItem()).addGas(itemStack, stack.copy());
}
return 0;
}
public static GasStack removeGas(ItemStack itemStack, Gas type, int amount)
{
if(itemStack != null && itemStack.getItem() instanceof IGasItem)
{
IGasItem item = (IGasItem)itemStack.getItem();
if(type != null && item.getGas(itemStack) != null && item.getGas(itemStack).getGas() != type || !item.canProvideGas(itemStack, type))
{
return null;
}
return item.removeGas(itemStack, amount);
}
return null;
}
}

View file

@ -5,7 +5,7 @@ import java.util.ArrayList;
import mekanism.api.gas.Gas;
import mekanism.api.gas.GasRegistry;
import mekanism.api.gas.GasStack;
import mekanism.api.gas.GasUtils;
import mekanism.api.gas.GasTransmission;
import mekanism.api.gas.IGasAcceptor;
import mekanism.api.gas.IGasItem;
import mekanism.api.gas.IGasStorage;
@ -260,7 +260,7 @@ public class TileEntityFactory extends TileEntityElectricBlock implements IPerip
{
if(inventory[4].getItem() instanceof IGasItem)
{
GasStack removed = GasUtils.removeGas(inventory[4], GasRegistry.getGas("oxygen"), getMaxSecondaryEnergy()-secondaryEnergyStored);
GasStack removed = GasTransmission.removeGas(inventory[4], GasRegistry.getGas("oxygen"), getMaxSecondaryEnergy()-secondaryEnergyStored);
setSecondaryEnergy(secondaryEnergyStored + (removed != null ? removed.amount : 0));
return;

View file

@ -6,7 +6,6 @@ import mekanism.api.gas.Gas;
import mekanism.api.gas.GasRegistry;
import mekanism.api.gas.GasStack;
import mekanism.api.gas.GasTransmission;
import mekanism.api.gas.GasUtils;
import mekanism.api.gas.IGasAcceptor;
import mekanism.api.gas.IGasItem;
import mekanism.api.gas.IGasStorage;
@ -46,17 +45,17 @@ public class TileEntityGasTank extends TileEntityContainerBlock implements IGasS
{
if(inventory[0] != null && getGas() != null)
{
setGas(new GasStack(getGas().getGas(), getGas().amount - GasUtils.addGas(inventory[0], getGas())));
setGas(new GasStack(getGas().getGas(), getGas().amount - GasTransmission.addGas(inventory[0], getGas())));
}
if(inventory[1] != null && (getGas() == null || getGas().amount < getMaxGas()))
{
if(getGas() == null)
{
setGas(GasUtils.removeGas(inventory[1], null, getMaxGas()));
setGas(GasTransmission.removeGas(inventory[1], null, getMaxGas()));
}
else {
GasStack removed = GasUtils.removeGas(inventory[1], getGas().getGas(), getMaxGas()-getGas().amount);
GasStack removed = GasTransmission.removeGas(inventory[1], getGas().getGas(), getMaxGas()-getGas().amount);
setGas(new GasStack(getGas().getGas(), getGas().amount + (removed != null ? removed.amount : 0)));
}
}

View file

@ -5,7 +5,7 @@ import java.util.Map;
import mekanism.api.gas.Gas;
import mekanism.api.gas.GasRegistry;
import mekanism.api.gas.GasStack;
import mekanism.api.gas.GasUtils;
import mekanism.api.gas.GasTransmission;
import mekanism.api.gas.IGasAcceptor;
import mekanism.api.gas.IGasItem;
import mekanism.api.gas.IGasStorage;
@ -101,7 +101,7 @@ public class TileEntityPurificationChamber extends TileEntityAdvancedElectricMac
{
if(inventory[1] != null && secondaryEnergyStored < MAX_SECONDARY_ENERGY)
{
GasStack removed = GasUtils.removeGas(inventory[1], GasRegistry.getGas("oxygen"), MAX_SECONDARY_ENERGY-secondaryEnergyStored);
GasStack removed = GasTransmission.removeGas(inventory[1], GasRegistry.getGas("oxygen"), MAX_SECONDARY_ENERGY-secondaryEnergyStored);
setSecondaryEnergy(secondaryEnergyStored + (removed != null ? removed.amount : 0));
}

View file

@ -6,7 +6,6 @@ import mekanism.api.gas.Gas;
import mekanism.api.gas.GasRegistry;
import mekanism.api.gas.GasStack;
import mekanism.api.gas.GasTransmission;
import mekanism.api.gas.GasUtils;
import mekanism.api.gas.IGasAcceptor;
import mekanism.api.gas.IGasStorage;
import mekanism.api.gas.ITubeConnection;
@ -105,10 +104,10 @@ public class TileEntityRotaryCondensentrator extends TileEntityElectricBlock imp
{
if(getGas() == null)
{
setGas(GasUtils.removeGas(inventory[1], null, getMaxGas()));
setGas(GasTransmission.removeGas(inventory[1], null, getMaxGas()));
}
else {
GasStack removed = GasUtils.removeGas(inventory[1], getGas().getGas(), getMaxGas()-getGas().amount);
GasStack removed = GasTransmission.removeGas(inventory[1], getGas().getGas(), getMaxGas()-getGas().amount);
setGas(new GasStack(getGas().getGas(), getGas().amount + (removed != null ? removed.amount : 0)));
}
}
@ -167,7 +166,7 @@ public class TileEntityRotaryCondensentrator extends TileEntityElectricBlock imp
{
if(inventory[0] != null)
{
setGas(new GasStack(getGas().getGas(), getGas().amount - GasUtils.addGas(inventory[0], getGas())));
setGas(new GasStack(getGas().getGas(), getGas().amount - GasTransmission.addGas(inventory[0], getGas())));
}
}

View file

@ -7,7 +7,6 @@ import mekanism.api.gas.Gas;
import mekanism.api.gas.GasRegistry;
import mekanism.api.gas.GasStack;
import mekanism.api.gas.GasTransmission;
import mekanism.api.gas.GasUtils;
import mekanism.api.gas.IGasAcceptor;
import mekanism.api.gas.IGasItem;
import mekanism.api.gas.ITubeConnection;
@ -111,13 +110,13 @@ public class TileEntityElectrolyticSeparator extends TileEntityElectricBlock imp
{
if(inventory[1] != null && hydrogenStored > 0)
{
hydrogenStored -= GasUtils.addGas(inventory[1], new GasStack(GasRegistry.getGas("hydrogen"), hydrogenStored));
hydrogenStored -= GasTransmission.addGas(inventory[1], new GasStack(GasRegistry.getGas("hydrogen"), hydrogenStored));
MekanismUtils.saveChunk(this);
}
if(inventory[2] != null && oxygenStored > 0)
{
hydrogenStored -= GasUtils.addGas(inventory[2], new GasStack(GasRegistry.getGas("oxygen"), oxygenStored));
hydrogenStored -= GasTransmission.addGas(inventory[2], new GasStack(GasRegistry.getGas("oxygen"), oxygenStored));
MekanismUtils.saveChunk(this);
}
}

View file

@ -5,7 +5,7 @@ import java.util.ArrayList;
import mekanism.api.gas.Gas;
import mekanism.api.gas.GasRegistry;
import mekanism.api.gas.GasStack;
import mekanism.api.gas.GasUtils;
import mekanism.api.gas.GasTransmission;
import mekanism.api.gas.IGasAcceptor;
import mekanism.api.gas.IGasItem;
import mekanism.api.gas.IGasStorage;
@ -47,7 +47,7 @@ public class TileEntityHydrogenGenerator extends TileEntityGenerator implements
if(inventory[0] != null && hydrogenStored < MAX_HYDROGEN)
{
GasStack removed = GasUtils.removeGas(inventory[0], GasRegistry.getGas("hydrogen"), getMaxGas()-hydrogenStored);
GasStack removed = GasTransmission.removeGas(inventory[0], GasRegistry.getGas("hydrogen"), getMaxGas()-hydrogenStored);
setGas(new GasStack(GasRegistry.getGas("hydrogen"), hydrogenStored + (removed != null ? removed.amount : 0)));
}