Work on a more intuitive form of accepting gas in items and blocks

This commit is contained in:
Aidan C. Brady 2013-12-12 16:54:55 -05:00
parent 85a2c981df
commit 338da4d92c
27 changed files with 536 additions and 756 deletions

View file

@ -17,7 +17,7 @@ import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.Event;
import cpw.mods.fml.common.FMLCommonHandler;
public class GasNetwork extends DynamicNetwork<IGasAcceptor, GasNetwork>
public class GasNetwork extends DynamicNetwork<IGasHandler, GasNetwork>
{
public int transferDelay = 0;
@ -82,9 +82,9 @@ public class GasNetwork extends DynamicNetwork<IGasAcceptor, GasNetwork>
for(Object obj : availableAcceptors)
{
if(obj instanceof IGasAcceptor && obj != emitter)
if(obj instanceof IGasHandler && obj != emitter)
{
IGasAcceptor acceptor = (IGasAcceptor)obj;
IGasHandler acceptor = (IGasHandler)obj;
int currentSending = sending;
@ -94,7 +94,7 @@ public class GasNetwork extends DynamicNetwork<IGasAcceptor, GasNetwork>
remaining--;
}
toSend -= acceptor.receiveGas(new GasStack(stack.getGas(), currentSending));
toSend -= acceptor.receiveGas(acceptorDirections.get(acceptor).getOpposite(), new GasStack(stack.getGas(), currentSending));
}
}
}
@ -157,21 +157,21 @@ public class GasNetwork extends DynamicNetwork<IGasAcceptor, GasNetwork>
}
@Override
public synchronized Set<IGasAcceptor> getAcceptors(Object... data)
public synchronized Set<IGasHandler> getAcceptors(Object... data)
{
Gas type = (Gas)data[0];
Set<IGasAcceptor> toReturn = new HashSet<IGasAcceptor>();
Set<IGasHandler> toReturn = new HashSet<IGasHandler>();
for(IGasAcceptor acceptor : possibleAcceptors)
for(IGasHandler acceptor : possibleAcceptors)
{
if(acceptorDirections.get(acceptor) == null)
{
continue;
}
if(acceptor.canReceiveGas(acceptorDirections.get(acceptor).getOpposite(), type))
{
int stored = ((IGasStorage)acceptor).getGas() != null ? ((IGasStorage)acceptor).getGas().amount : 0;
if(!(acceptor instanceof IGasStorage) || (acceptor instanceof IGasStorage && (((IGasStorage)acceptor).getMaxGas() - stored) > 0))
{
toReturn.add(acceptor);
}
toReturn.add(acceptor);
}
}
@ -203,9 +203,9 @@ public class GasNetwork extends DynamicNetwork<IGasAcceptor, GasNetwork>
for(ITransmitter<GasNetwork> pipe : transmitters)
{
IGasAcceptor[] acceptors = GasTransmission.getConnectedAcceptors((TileEntity)pipe);
IGasHandler[] acceptors = GasTransmission.getConnectedAcceptors((TileEntity)pipe);
for(IGasAcceptor acceptor : acceptors)
for(IGasHandler acceptor : acceptors)
{
if(acceptor != null && !(acceptor instanceof ITransmitter))
{

View file

@ -0,0 +1,149 @@
package mekanism.api.gas;
import net.minecraft.nbt.NBTTagCompound;
public class GasTank
{
public GasStack stored;
public int maxGas;
private GasTank() {}
public GasTank(int max)
{
maxGas = max;
}
public void setGas(GasStack stack)
{
stored = stack;
}
public GasStack draw(int amount, boolean doDrain)
{
if(stored == null || amount <= 0)
{
return null;
}
GasStack ret = new GasStack(getGas().getGas(), Math.min(getStored(), amount));
if(ret.amount > 0)
{
if(doDrain)
{
stored.amount -= ret.amount;
if(stored.amount <= 0)
{
stored = null;
}
}
return ret;
}
return null;
}
public int fill(GasStack amount, boolean doFill)
{
if(amount == null || (stored != null && stored.amount == maxGas))
{
return 0;
}
int toFill = Math.min(maxGas-getStored(), amount.amount);
if(doFill)
{
if(stored == null)
{
stored = amount;
}
else {
stored.amount = Math.min(maxGas, getStored()+amount.amount);
}
}
return toFill;
}
public boolean canReceive(Gas gas)
{
if(getNeeded() == 0 || stored != null && (gas != null && gas != stored.getGas()))
{
return false;
}
return true;
}
public boolean canDraw(Gas gas)
{
if(stored == null || (gas != null && gas != stored.getGas()))
{
return false;
}
return true;
}
public int getNeeded()
{
return getMaxGas()-getStored();
}
public int getMaxGas()
{
return maxGas;
}
public GasStack getGas()
{
return stored;
}
public int getStored()
{
return stored != null ? stored.amount : 0;
}
public NBTTagCompound write(NBTTagCompound nbtTags)
{
if(stored != null)
{
stored.write(nbtTags);
}
nbtTags.setInteger("maxGas", maxGas);
return nbtTags;
}
private void read(NBTTagCompound nbtTags)
{
if(nbtTags.hasKey("stored"))
{
stored = GasStack.readFromNBT(nbtTags);
}
maxGas = nbtTags.getInteger("maxGas");
}
public static GasTank readFromNBT(NBTTagCompound nbtTags)
{
if(nbtTags == null || nbtTags.hasNoTags())
{
return null;
}
GasTank tank = new GasTank();
tank.read(nbtTags);
return tank;
}
}

View file

@ -44,17 +44,17 @@ public final class GasTransmission
* @param tileEntity - center tile entity
* @return array of IGasAcceptors
*/
public static IGasAcceptor[] getConnectedAcceptors(TileEntity tileEntity)
public static IGasHandler[] getConnectedAcceptors(TileEntity tileEntity)
{
IGasAcceptor[] acceptors = new IGasAcceptor[] {null, null, null, null, null, null};
IGasHandler[] acceptors = new IGasHandler[] {null, null, null, null, null, null};
for(ForgeDirection orientation : ForgeDirection.VALID_DIRECTIONS)
{
TileEntity acceptor = Object3D.get(tileEntity).getFromSide(orientation).getTileEntity(tileEntity.worldObj);
if(acceptor instanceof IGasAcceptor)
if(acceptor instanceof IGasHandler)
{
acceptors[orientation.ordinal()] = (IGasAcceptor)acceptor;
acceptors[orientation.ordinal()] = (IGasHandler)acceptor;
}
}

View file

@ -1,25 +0,0 @@
package mekanism.api.gas;
import net.minecraftforge.common.ForgeDirection;
/**
* Implement this if your tile entity accepts gas from a foreign, external source.
* @author AidanBrady
*
*/
public interface IGasAcceptor
{
/**
* Transfer a certain amount of gas to this acceptor.
* @param amount - amount to transfer
* @return rejects
*/
public int receiveGas(GasStack stack);
/**
* Whether or not this tile entity accepts gas from a certain side.
* @param side - side to check
* @return if tile entity accepts gas
*/
public boolean canReceiveGas(ForgeDirection side, Gas type);
}

View file

@ -0,0 +1,41 @@
package mekanism.api.gas;
import net.minecraftforge.common.ForgeDirection;
/**
* Implement this if your tile entity accepts gas from a foreign, external source.
* @author AidanBrady
*
*/
public interface IGasHandler
{
/**
* Transfer a certain amount of gas to this block.
* @param amount - amount to transfer
* @return gas added
*/
public int receiveGas(ForgeDirection side, GasStack stack);
/**
* Draws a certain amount of gas from this block.
* @param amount - amount to draw
* @return gas drawn
*/
public GasStack drawGas(ForgeDirection side, int amount);
/**
* Whether or not this block can accept gas from a certain side.
* @param side - side to check
* @param type - type of gas to check
* @return if block accepts gas
*/
public boolean canReceiveGas(ForgeDirection side, Gas type);
/**
* Whether or not this block can be drawn of gas from a certain side.
* @param side - side to check
* @param type - type of gas to check
* @return if block can be drawn of gas
*/
public boolean canDrawGas(ForgeDirection side, Gas type);
}

View file

@ -7,7 +7,7 @@ import net.minecraft.item.ItemStack;
* @author AidanBrady
*
*/
public interface IGasItem extends IGasStorage
public interface IGasItem
{
/**
* Gets the rate of transfer this item can handle.
@ -48,4 +48,28 @@ public interface IGasItem extends IGasStorage
* @return if the item can provide gas
*/
public boolean canProvideGas(ItemStack itemstack, Gas type);
/**
* Get the gas of a declared type.
* @param type - type of gas
* @param data - ItemStack parameter if necessary
* @return gas stored
*/
public GasStack getGas(ItemStack itemstack);
/**
* Set the gas of a declared type to a new amount;
* @param type - type of gas
* @param data - ItemStack parameter if necessary
* @param amount - amount to store
*/
public void setGas(ItemStack itemstack, GasStack stack);
/**
* Gets the maximum amount of gas this tile entity can store.
* @param type - type of gas
* @param data - ItemStack parameter if necessary
* @return maximum gas
*/
public int getMaxGas(ItemStack itemstack);
}

View file

@ -1,34 +0,0 @@
package mekanism.api.gas;
/**
* Implement this if your tile entity can store some form of gas. If you want your item to store gas, implement IStorageTank
* instead.
* @author AidanBrady
*
*/
public interface IGasStorage
{
/**
* Get the gas of a declared type.
* @param type - type of gas
* @param data - ItemStack parameter if necessary
* @return gas stored
*/
public GasStack getGas(Object... data);
/**
* Set the gas of a declared type to a new amount;
* @param type - type of gas
* @param data - ItemStack parameter if necessary
* @param amount - amount to store
*/
public void setGas(GasStack stack, Object... data);
/**
* Gets the maximum amount of gas this tile entity can store.
* @param type - type of gas
* @param data - ItemStack parameter if necessary
* @return maximum gas
*/
public int getMaxGas(Object... data);
}

View file

@ -43,7 +43,7 @@ public class GuiChemicalFormulator extends GuiMekanism
if(xAxis >= 134 && xAxis <= 150 && yAxis >= 14 && yAxis <= 72)
{
drawCreativeTabHoveringText(tileEntity.gasTank != null ? tileEntity.gasTank.getGas().getLocalizedName() + ": " + tileEntity.gasTank.amount : MekanismUtils.localize("gui.empty"), xAxis, yAxis);
drawCreativeTabHoveringText(tileEntity.gasTank.getGas() != null ? tileEntity.gasTank.getGas().getGas().getLocalizedName() + ": " + tileEntity.gasTank.getStored() : MekanismUtils.localize("gui.empty"), xAxis, yAxis);
}
super.drawGuiContainerForegroundLayer(mouseX, mouseY);
@ -73,7 +73,7 @@ public class GuiChemicalFormulator extends GuiMekanism
if(tileEntity.getScaledGasLevel(58) > 0)
{
displayGauge(134, 14, tileEntity.getScaledGasLevel(58), null, tileEntity.gasTank);
displayGauge(134, 14, tileEntity.getScaledGasLevel(58), null, tileEntity.gasTank.getGas());
}
}

View file

@ -30,11 +30,11 @@ public class GuiGasTank extends GuiMekanism
int xAxis = (mouseX - (width - xSize) / 2);
int yAxis = (mouseY - (height - ySize) / 2);
String capacityInfo = (tileEntity.getGas() != null ? tileEntity.getGas().amount : 0) + "/" + tileEntity.MAX_GAS;
String capacityInfo = tileEntity.gasTank.getStored() + "/" + tileEntity.MAX_GAS;
fontRenderer.drawString(tileEntity.getInvName(), 43, 6, 0x404040);
fontRenderer.drawString(capacityInfo, 45, 40, 0x404040);
fontRenderer.drawString("Gas: " + (tileEntity.getGas() != null ? tileEntity.getGas().getGas().getLocalizedName() : "None"), 45, 49, 0x404040);
fontRenderer.drawString("Gas: " + (tileEntity.gasTank.getGas() != null ? tileEntity.gasTank.getGas().getGas().getLocalizedName() : "None"), 45, 49, 0x404040);
fontRenderer.drawString(MekanismUtils.localize("container.inventory"), 8, ySize - 96 + 2, 0x404040);
super.drawGuiContainerForegroundLayer(mouseX, mouseY);
@ -51,9 +51,9 @@ public class GuiGasTank extends GuiMekanism
int guiHeight = (height - ySize) / 2;
drawTexturedModalRect(guiWidth, guiHeight, 0, 0, xSize, ySize);
if(tileEntity.getGas() != null)
if(tileEntity.gasTank.getGas() != null)
{
int scale = (int)(((double)tileEntity.getGas().amount / tileEntity.MAX_GAS) * 72);
int scale = (int)(((double)tileEntity.gasTank.getStored() / tileEntity.MAX_GAS) * 72);
drawTexturedModalRect(guiWidth + 65, guiHeight + 17, 176, 0, scale, 20);
}
}

View file

@ -45,7 +45,7 @@ public class GuiRotaryCondensentrator extends GuiMekanism
if(xAxis >= 26 && xAxis <= 42 && yAxis >= 14 && yAxis <= 72)
{
drawCreativeTabHoveringText(tileEntity.gasTank != null ? tileEntity.gasTank.getGas().getLocalizedName() + ": " + tileEntity.gasTank.amount : MekanismUtils.localize("gui.empty"), xAxis, yAxis);
drawCreativeTabHoveringText(tileEntity.gasTank.getGas() != null ? tileEntity.gasTank.getGas().getGas().getLocalizedName() + ": " + tileEntity.gasTank.getStored() : MekanismUtils.localize("gui.empty"), xAxis, yAxis);
}
if(xAxis >= 134 && xAxis <= 150 && yAxis >= 14 && yAxis <= 72)
@ -86,7 +86,7 @@ public class GuiRotaryCondensentrator extends GuiMekanism
if(tileEntity.getScaledGasLevel(58) > 0)
{
displayGauge(26, 14, tileEntity.getScaledGasLevel(58), null, tileEntity.gasTank);
displayGauge(26, 14, tileEntity.getScaledGasLevel(58), null, tileEntity.gasTank.getGas());
}
if(tileEntity.getScaledFluidLevel(58) > 0)

View file

@ -189,6 +189,11 @@ public class FluidNetwork extends DynamicNetwork<IFluidHandler, FluidNetwork>
for(IFluidHandler acceptor : possibleAcceptors)
{
if(acceptorDirections.get(acceptor) == null)
{
continue;
}
if(acceptor.canFill(acceptorDirections.get(acceptor).getOpposite(), fluidToSend.getFluid()))
{
toReturn.add(acceptor);

View file

@ -211,7 +211,7 @@ public class BlockGasTank extends BlockContainer
ItemStack itemStack = new ItemStack(Mekanism.GasTank);
IGasItem storageTank = (IGasItem)itemStack.getItem();
storageTank.setGas(tileEntity.gasStored, itemStack);
storageTank.setGas(itemStack, tileEntity.gasTank.getGas());
ISustainedInventory inventory = (ISustainedInventory)itemStack.getItem();
inventory.setInventory(((ISustainedInventory)tileEntity).getInventory(), itemStack);

View file

@ -918,8 +918,12 @@ public class BlockMachine extends BlockContainer implements ISpecialBounds
if(tileEntity instanceof TileEntityRotaryCondensentrator)
{
IGasItem gasItem = (IGasItem)itemStack.getItem();
gasItem.setGas(((TileEntityRotaryCondensentrator)tileEntity).getGas(), itemStack);
TileEntityRotaryCondensentrator condensentrator = (TileEntityRotaryCondensentrator)tileEntity;
if(condensentrator.gasTank.getGas() != null)
{
itemStack.stackTagCompound.setCompoundTag("gasStack", condensentrator.gasTank.getGas().write(new NBTTagCompound()));
}
}
return itemStack;

View file

@ -107,14 +107,14 @@ public class ContainerRotaryCondensentrator extends Container
{
if(slotID != 0 && slotID != 1)
{
if(((IGasItem)slotStack.getItem()).canProvideGas(slotStack, tileEntity.gasTank != null ? tileEntity.gasTank.getGas() : null))
if(((IGasItem)slotStack.getItem()).canProvideGas(slotStack, tileEntity.gasTank.getGas() != null ? tileEntity.gasTank.getGas().getGas() : null))
{
if(!mergeItemStack(slotStack, 0, 1, false))
{
return null;
}
}
else if(((IGasItem)slotStack.getItem()).canReceiveGas(slotStack, tileEntity.gasTank != null ? tileEntity.gasTank.getGas() : null))
else if(((IGasItem)slotStack.getItem()).canReceiveGas(slotStack, tileEntity.gasTank.getGas() != null ? tileEntity.gasTank.getGas().getGas() : null))
{
if(!mergeItemStack(slotStack, 1, 2, false))
{

View file

@ -69,7 +69,7 @@ public class ItemBlockGasTank extends ItemBlock implements IGasItem, ISustainedI
if(place)
{
TileEntityGasTank tileEntity = (TileEntityGasTank)world.getBlockTileEntity(x, y, z);
tileEntity.gasStored = getGas(stack);
tileEntity.gasTank.setGas(getGas(stack));
((ISustainedInventory)tileEntity).setInventory(getInventory(stack));
}
@ -106,64 +106,52 @@ public class ItemBlockGasTank extends ItemBlock implements IGasItem, ISustainedI
}
@Override
public GasStack getGas(Object... data)
public GasStack getGas(ItemStack itemstack)
{
if(data[0] instanceof ItemStack)
if(itemstack.stackTagCompound == null)
{
ItemStack itemstack = (ItemStack)data[0];
if(itemstack.stackTagCompound == null)
{
return null;
}
GasStack stored = GasStack.readFromNBT(itemstack.stackTagCompound.getCompoundTag("stored"));
if(stored == null)
{
itemstack.setItemDamage(100);
}
else {
itemstack.setItemDamage((int)Math.max(1, (Math.abs((((float)stored.amount/getMaxGas(itemstack))*100)-100))));
}
return stored;
return null;
}
return null;
GasStack stored = GasStack.readFromNBT(itemstack.stackTagCompound.getCompoundTag("stored"));
if(stored == null)
{
itemstack.setItemDamage(100);
}
else {
itemstack.setItemDamage((int)Math.max(1, (Math.abs((((float)stored.amount/getMaxGas(itemstack))*100)-100))));
}
return stored;
}
@Override
public void setGas(GasStack stack, Object... data)
public void setGas(ItemStack itemstack, GasStack stack)
{
if(data[0] instanceof ItemStack)
if(itemstack.stackTagCompound == null)
{
ItemStack itemstack = (ItemStack)data[0];
itemstack.setTagCompound(new NBTTagCompound());
}
if(stack == null || stack.amount == 0)
{
itemstack.setItemDamage(100);
itemstack.stackTagCompound.removeTag("stored");
}
else {
int amount = Math.max(0, Math.min(stack.amount, getMaxGas(itemstack)));
GasStack gasStack = new GasStack(stack.getGas(), amount);
if(itemstack.stackTagCompound == null)
{
itemstack.setTagCompound(new NBTTagCompound());
}
if(stack == null || stack.amount == 0)
{
itemstack.setItemDamage(100);
itemstack.stackTagCompound.removeTag("stored");
}
else {
int amount = Math.max(0, Math.min(stack.amount, getMaxGas(itemstack)));
GasStack gasStack = new GasStack(stack.getGas(), amount);
itemstack.setItemDamage((int)Math.max(1, (Math.abs((((float)amount/getMaxGas(itemstack))*100)-100))));
itemstack.stackTagCompound.setCompoundTag("stored", gasStack.write(new NBTTagCompound()));
}
itemstack.setItemDamage((int)Math.max(1, (Math.abs((((float)amount/getMaxGas(itemstack))*100)-100))));
itemstack.stackTagCompound.setCompoundTag("stored", gasStack.write(new NBTTagCompound()));
}
}
public ItemStack getEmptyItem()
{
ItemStack empty = new ItemStack(this);
setGas(null, empty);
setGas(empty, null);
empty.setItemDamage(100);
return empty;
}
@ -172,27 +160,22 @@ public class ItemBlockGasTank extends ItemBlock implements IGasItem, ISustainedI
public void getSubItems(int i, CreativeTabs tabs, List list)
{
ItemStack empty = new ItemStack(this);
setGas(null, empty);
setGas(empty, null);
empty.setItemDamage(100);
list.add(empty);
for(Gas type : GasRegistry.getRegisteredGasses())
{
ItemStack filled = new ItemStack(this);
setGas(new GasStack(type, ((IGasItem)filled.getItem()).getMaxGas(filled)), filled);
setGas(filled, new GasStack(type, ((IGasItem)filled.getItem()).getMaxGas(filled)));
list.add(filled);
}
}
@Override
public int getMaxGas(Object... data)
public int getMaxGas(ItemStack itemstack)
{
if(data[0] instanceof ItemStack)
{
return MAX_GAS;
}
return 0;
return MAX_GAS;
}
@Override
@ -210,7 +193,7 @@ public class ItemBlockGasTank extends ItemBlock implements IGasItem, ISustainedI
}
int toUse = Math.min(getMaxGas(itemstack)-getStored(itemstack), Math.min(getRate(itemstack), stack.amount));
setGas(new GasStack(stack.getGas(), getStored(itemstack)+toUse), itemstack);
setGas(itemstack, new GasStack(stack.getGas(), getStored(itemstack)+toUse));
return toUse;
}
@ -226,7 +209,7 @@ public class ItemBlockGasTank extends ItemBlock implements IGasItem, ISustainedI
Gas type = getGas(itemstack).getGas();
int gasToUse = Math.min(getStored(itemstack), Math.min(getRate(itemstack), amount));
setGas(new GasStack(type, getStored(itemstack)-gasToUse), itemstack);
setGas(itemstack, new GasStack(type, getStored(itemstack)-gasToUse));
return new GasStack(type, gasToUse);
}

View file

@ -10,14 +10,12 @@ import java.util.List;
import mekanism.api.EnumColor;
import mekanism.api.energy.EnergizedItemManager;
import mekanism.api.energy.IEnergizedItem;
import mekanism.api.gas.Gas;
import mekanism.api.gas.GasStack;
import mekanism.api.gas.IGasItem;
import mekanism.common.IElectricChest;
import mekanism.common.IFactory;
import mekanism.common.IInvConfiguration;
import mekanism.common.IRedstoneControl;
import mekanism.common.IRedstoneControl.RedstoneControl;
import mekanism.common.IInvConfiguration;
import mekanism.common.ISustainedInventory;
import mekanism.common.ISustainedTank;
import mekanism.common.IUpgradeManagement;
@ -82,7 +80,7 @@ import cpw.mods.fml.relauncher.SideOnly;
* @author AidanBrady
*
*/
public class ItemBlockMachine extends ItemBlock implements IEnergizedItem, IItemElectric, ISpecialElectricItem, IUpgradeManagement, IFactory, ISustainedInventory, ISustainedTank, IElectricChest, IEnergyContainerItem, IGasItem
public class ItemBlockMachine extends ItemBlock implements IEnergizedItem, IItemElectric, ISpecialElectricItem, IUpgradeManagement, IFactory, ISustainedInventory, ISustainedTank, IElectricChest, IEnergyContainerItem
{
public Block metaBlock;
@ -150,13 +148,6 @@ public class ItemBlockMachine extends ItemBlock implements IEnergizedItem, IItem
}
}
GasStack gasStack = getGas(itemstack);
if(gasStack != null)
{
list.add(EnumColor.YELLOW + "Stored " + gasStack.getGas().getLocalizedName() + ": " + EnumColor.GREY + gasStack.amount);
}
if(supportsUpgrades(itemstack))
{
list.add(EnumColor.PURPLE + "Energy: " + EnumColor.GREY + "x" + (getEnergyMultiplier(itemstack)+1));
@ -315,7 +306,11 @@ public class ItemBlockMachine extends ItemBlock implements IEnergizedItem, IItem
if(tileEntity instanceof TileEntityRotaryCondensentrator)
{
((TileEntityRotaryCondensentrator)tileEntity).setGas(getGas(stack));
if(stack.stackTagCompound != null && stack.stackTagCompound.hasKey("gasStack"))
{
GasStack gasStack = GasStack.readFromNBT(stack.stackTagCompound.getCompoundTag("gasStack"));
((TileEntityRotaryCondensentrator)tileEntity).gasTank.setGas(gasStack);
}
}
((ISustainedInventory)tileEntity).setInventory(getInventory(stack));
@ -945,121 +940,4 @@ public class ItemBlockMachine extends ItemBlock implements IEnergizedItem, IItem
{
return IC2ItemManager.getManager(this);
}
@Override
public int getMaxGas(Object... data)
{
if(data[0] instanceof ItemStack)
{
if(MachineType.get((ItemStack)data[0]) == MachineType.ROTARY_CONDENSENTRATOR)
{
return TileEntityRotaryCondensentrator.MAX_GAS;
}
}
return 0;
}
@Override
public int getRate(ItemStack itemstack)
{
return ItemBlockGasTank.TRANSFER_RATE;
}
@Override
public int addGas(ItemStack itemstack, GasStack stack)
{
if(MachineType.get(itemstack) != MachineType.ROTARY_CONDENSENTRATOR || (getGas(itemstack) != null && getGas(itemstack).getGas() != stack.getGas()))
{
return 0;
}
int toUse = Math.min(getMaxGas(itemstack)-getStored(itemstack), Math.min(getRate(itemstack), stack.amount));
setGas(new GasStack(stack.getGas(), getStored(itemstack)+toUse), itemstack);
return toUse;
}
@Override
public GasStack removeGas(ItemStack itemstack, int amount)
{
if(MachineType.get(itemstack) != MachineType.ROTARY_CONDENSENTRATOR || getGas(itemstack) == null)
{
return null;
}
Gas type = getGas(itemstack).getGas();
int gasToUse = Math.min(getStored(itemstack), Math.min(getRate(itemstack), amount));
setGas(new GasStack(type, getStored(itemstack)-gasToUse), itemstack);
return new GasStack(type, gasToUse);
}
private int getStored(ItemStack itemstack)
{
return getGas(itemstack) != null ? getGas(itemstack).amount : 0;
}
@Override
public boolean canReceiveGas(ItemStack itemstack, Gas type)
{
return MachineType.get(itemstack) == MachineType.ROTARY_CONDENSENTRATOR && (getGas(itemstack) == null || getGas(itemstack).getGas() == type);
}
@Override
public boolean canProvideGas(ItemStack itemstack, Gas type)
{
return false;
}
@Override
public GasStack getGas(Object... data)
{
if(data[0] instanceof ItemStack)
{
ItemStack itemstack = (ItemStack)data[0];
if(MachineType.get(itemstack) != MachineType.ROTARY_CONDENSENTRATOR || itemstack.stackTagCompound == null)
{
return null;
}
GasStack stored = GasStack.readFromNBT(itemstack.stackTagCompound.getCompoundTag("stored"));
return stored;
}
return null;
}
@Override
public void setGas(GasStack stack, Object... data)
{
if(data[0] instanceof ItemStack)
{
ItemStack itemstack = (ItemStack)data[0];
if(MachineType.get(itemstack) != MachineType.ROTARY_CONDENSENTRATOR)
{
return;
}
if(itemstack.stackTagCompound == null)
{
itemstack.setTagCompound(new NBTTagCompound());
}
if(stack == null || stack.amount == 0)
{
itemstack.stackTagCompound.removeTag("stored");
}
else {
int amount = Math.max(0, Math.min(stack.amount, getMaxGas(itemstack)));
GasStack gasStack = new GasStack(stack.getGas(), amount);
itemstack.stackTagCompound.setCompoundTag("stored", gasStack.write(new NBTTagCompound()));
}
}
}
}

View file

@ -80,18 +80,13 @@ public class ItemJetpack extends ItemArmor implements IGasItem
public void useGas(ItemStack stack)
{
setGas(new GasStack(getGas(stack).getGas(), getGas(stack).amount-1), stack);
setGas(stack, new GasStack(getGas(stack).getGas(), getGas(stack).amount-1));
}
@Override
public int getMaxGas(Object... data)
public int getMaxGas(ItemStack itemstack)
{
if(data[0] instanceof ItemStack)
{
return MAX_GAS;
}
return 0;
return MAX_GAS;
}
@Override
@ -114,7 +109,7 @@ public class ItemJetpack extends ItemArmor implements IGasItem
}
int toUse = Math.min(getMaxGas(itemstack)-getStored(itemstack), Math.min(getRate(itemstack), stack.amount));
setGas(new GasStack(stack.getGas(), getStored(itemstack)+toUse), itemstack);
setGas(itemstack, new GasStack(stack.getGas(), getStored(itemstack)+toUse));
return toUse;
}
@ -130,7 +125,7 @@ public class ItemJetpack extends ItemArmor implements IGasItem
Gas type = getGas(itemstack).getGas();
int gasToUse = Math.min(getStored(itemstack), Math.min(getRate(itemstack), amount));
setGas(new GasStack(type, getStored(itemstack)-gasToUse), itemstack);
setGas(itemstack, new GasStack(type, getStored(itemstack)-gasToUse));
return new GasStack(type, gasToUse);
}
@ -153,31 +148,24 @@ public class ItemJetpack extends ItemArmor implements IGasItem
}
@Override
public GasStack getGas(Object... data)
public GasStack getGas(ItemStack itemstack)
{
if(data[0] instanceof ItemStack)
if(itemstack.stackTagCompound == null)
{
ItemStack itemstack = (ItemStack)data[0];
if(itemstack.stackTagCompound == null)
{
return null;
}
GasStack stored = GasStack.readFromNBT(itemstack.stackTagCompound.getCompoundTag("stored"));
if(stored == null)
{
itemstack.setItemDamage(100);
}
else {
itemstack.setItemDamage((int)Math.max(1, (Math.abs((((float)stored.amount/getMaxGas(itemstack))*100)-100))));
}
return stored;
return null;
}
return null;
GasStack stored = GasStack.readFromNBT(itemstack.stackTagCompound.getCompoundTag("stored"));
if(stored == null)
{
itemstack.setItemDamage(100);
}
else {
itemstack.setItemDamage((int)Math.max(1, (Math.abs((((float)stored.amount/getMaxGas(itemstack))*100)-100))));
}
return stored;
}
public JetpackMode getMode(ItemStack stack)
@ -201,36 +189,31 @@ public class ItemJetpack extends ItemArmor implements IGasItem
}
@Override
public void setGas(GasStack stack, Object... data)
public void setGas(ItemStack itemstack, GasStack stack)
{
if(data[0] instanceof ItemStack)
if(itemstack.stackTagCompound == null)
{
ItemStack itemstack = (ItemStack)data[0];
itemstack.setTagCompound(new NBTTagCompound());
}
if(stack == null || stack.amount == 0)
{
itemstack.setItemDamage(100);
itemstack.stackTagCompound.removeTag("stored");
}
else {
int amount = Math.max(0, Math.min(stack.amount, getMaxGas(itemstack)));
GasStack gasStack = new GasStack(stack.getGas(), amount);
if(itemstack.stackTagCompound == null)
{
itemstack.setTagCompound(new NBTTagCompound());
}
if(stack == null || stack.amount == 0)
{
itemstack.setItemDamage(100);
itemstack.stackTagCompound.removeTag("stored");
}
else {
int amount = Math.max(0, Math.min(stack.amount, getMaxGas(itemstack)));
GasStack gasStack = new GasStack(stack.getGas(), amount);
itemstack.setItemDamage((int)Math.max(1, (Math.abs((((float)amount/getMaxGas(itemstack))*100)-100))));
itemstack.stackTagCompound.setCompoundTag("stored", gasStack.write(new NBTTagCompound()));
}
itemstack.setItemDamage((int)Math.max(1, (Math.abs((((float)amount/getMaxGas(itemstack))*100)-100))));
itemstack.stackTagCompound.setCompoundTag("stored", gasStack.write(new NBTTagCompound()));
}
}
public ItemStack getEmptyItem()
{
ItemStack empty = new ItemStack(this);
setGas(null, empty);
setGas(empty, null);
empty.setItemDamage(100);
return empty;
}
@ -239,12 +222,12 @@ public class ItemJetpack extends ItemArmor implements IGasItem
public void getSubItems(int i, CreativeTabs tabs, List list)
{
ItemStack empty = new ItemStack(this);
setGas(null, empty);
setGas(empty, null);
empty.setItemDamage(100);
list.add(empty);
ItemStack filled = new ItemStack(this);
setGas(new GasStack(GasRegistry.getGas("hydrogen"), ((IGasItem)filled.getItem()).getMaxGas(filled)), filled);
setGas(filled, new GasStack(GasRegistry.getGas("hydrogen"), ((IGasItem)filled.getItem()).getMaxGas(filled)));
list.add(filled);
}

View file

@ -10,7 +10,6 @@ import mekanism.api.gas.IGasItem;
import mekanism.client.render.ModelCustomArmor;
import mekanism.client.render.ModelCustomArmor.ArmorModel;
import mekanism.common.Mekanism;
import mekanism.common.item.ItemJetpack.JetpackMode;
import net.minecraft.client.model.ModelBiped;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.Entity;
@ -75,18 +74,13 @@ public class ItemScubaTank extends ItemArmor implements IGasItem
public void useGas(ItemStack stack)
{
setGas(new GasStack(getGas(stack).getGas(), getGas(stack).amount-1), stack);
setGas(stack, new GasStack(getGas(stack).getGas(), getGas(stack).amount-1));
}
@Override
public int getMaxGas(Object... data)
public int getMaxGas(ItemStack itemstack)
{
if(data[0] instanceof ItemStack)
{
return MAX_GAS;
}
return 0;
return MAX_GAS;
}
@Override
@ -109,7 +103,7 @@ public class ItemScubaTank extends ItemArmor implements IGasItem
}
int toUse = Math.min(getMaxGas(itemstack)-getStored(itemstack), Math.min(getRate(itemstack), stack.amount));
setGas(new GasStack(stack.getGas(), getStored(itemstack)+toUse), itemstack);
setGas(itemstack, new GasStack(stack.getGas(), getStored(itemstack)+toUse));
return toUse;
}
@ -125,7 +119,7 @@ public class ItemScubaTank extends ItemArmor implements IGasItem
Gas type = getGas(itemstack).getGas();
int gasToUse = Math.min(getStored(itemstack), Math.min(getRate(itemstack), amount));
setGas(new GasStack(type, getStored(itemstack)-gasToUse), itemstack);
setGas(itemstack, new GasStack(type, getStored(itemstack)-gasToUse));
return new GasStack(type, gasToUse);
}
@ -173,64 +167,52 @@ public class ItemScubaTank extends ItemArmor implements IGasItem
}
@Override
public GasStack getGas(Object... data)
public GasStack getGas(ItemStack itemstack)
{
if(data[0] instanceof ItemStack)
if(itemstack.stackTagCompound == null)
{
ItemStack itemstack = (ItemStack)data[0];
if(itemstack.stackTagCompound == null)
{
return null;
}
GasStack stored = GasStack.readFromNBT(itemstack.stackTagCompound.getCompoundTag("stored"));
if(stored == null)
{
itemstack.setItemDamage(100);
}
else {
itemstack.setItemDamage((int)Math.max(1, (Math.abs((((float)stored.amount/getMaxGas(itemstack))*100)-100))));
}
return stored;
return null;
}
return null;
GasStack stored = GasStack.readFromNBT(itemstack.stackTagCompound.getCompoundTag("stored"));
if(stored == null)
{
itemstack.setItemDamage(100);
}
else {
itemstack.setItemDamage((int)Math.max(1, (Math.abs((((float)stored.amount/getMaxGas(itemstack))*100)-100))));
}
return stored;
}
@Override
public void setGas(GasStack stack, Object... data)
public void setGas(ItemStack itemstack, GasStack stack)
{
if(data[0] instanceof ItemStack)
if(itemstack.stackTagCompound == null)
{
ItemStack itemstack = (ItemStack)data[0];
itemstack.setTagCompound(new NBTTagCompound());
}
if(stack == null || stack.amount == 0)
{
itemstack.setItemDamage(100);
itemstack.stackTagCompound.removeTag("stored");
}
else {
int amount = Math.max(0, Math.min(stack.amount, getMaxGas(itemstack)));
GasStack gasStack = new GasStack(stack.getGas(), amount);
if(itemstack.stackTagCompound == null)
{
itemstack.setTagCompound(new NBTTagCompound());
}
if(stack == null || stack.amount == 0)
{
itemstack.setItemDamage(100);
itemstack.stackTagCompound.removeTag("stored");
}
else {
int amount = Math.max(0, Math.min(stack.amount, getMaxGas(itemstack)));
GasStack gasStack = new GasStack(stack.getGas(), amount);
itemstack.setItemDamage((int)Math.max(1, (Math.abs((((float)amount/getMaxGas(itemstack))*100)-100))));
itemstack.stackTagCompound.setCompoundTag("stored", gasStack.write(new NBTTagCompound()));
}
itemstack.setItemDamage((int)Math.max(1, (Math.abs((((float)amount/getMaxGas(itemstack))*100)-100))));
itemstack.stackTagCompound.setCompoundTag("stored", gasStack.write(new NBTTagCompound()));
}
}
public ItemStack getEmptyItem()
{
ItemStack empty = new ItemStack(this);
setGas(null, empty);
setGas(empty, null);
empty.setItemDamage(100);
return empty;
}
@ -239,12 +221,12 @@ public class ItemScubaTank extends ItemArmor implements IGasItem
public void getSubItems(int i, CreativeTabs tabs, List list)
{
ItemStack empty = new ItemStack(this);
setGas(null, empty);
setGas(empty, null);
empty.setItemDamage(100);
list.add(empty);
ItemStack filled = new ItemStack(this);
setGas(new GasStack(GasRegistry.getGas("oxygen"), ((IGasItem)filled.getItem()).getMaxGas(filled)), filled);
setGas(filled, new GasStack(GasRegistry.getGas("oxygen"), ((IGasItem)filled.getItem()).getMaxGas(filled)));
list.add(filled);
}
}

View file

@ -5,10 +5,10 @@ import java.util.ArrayList;
import mekanism.api.Object3D;
import mekanism.api.gas.GasRegistry;
import mekanism.api.gas.GasStack;
import mekanism.api.gas.GasTank;
import mekanism.api.gas.GasTransmission;
import mekanism.api.gas.IGasAcceptor;
import mekanism.api.gas.IGasHandler;
import mekanism.api.gas.IGasItem;
import mekanism.api.gas.IGasStorage;
import mekanism.api.gas.ITubeConnection;
import mekanism.common.IActiveState;
import mekanism.common.IRedstoneControl;
@ -26,9 +26,9 @@ import net.minecraftforge.common.ForgeDirection;
import com.google.common.io.ByteArrayDataInput;
public class TileEntityChemicalFormulator extends TileEntityElectricBlock implements IActiveState, IGasStorage, ITubeConnection, IRedstoneControl
public class TileEntityChemicalFormulator extends TileEntityElectricBlock implements IActiveState, ITubeConnection, IRedstoneControl
{
public GasStack gasTank;
public GasTank gasTank = new GasTank(MAX_GAS);
public static final int MAX_GAS = 10000;
@ -87,12 +87,9 @@ public class TileEntityChemicalFormulator extends TileEntityElectricBlock implem
ChargeUtils.discharge(1, this);
if(getGas() != null)
if(inventory[2] != null && gasTank.getGas() != null)
{
if(inventory[2] != null)
{
setGas(new GasStack(getGas().getGas(), getGas().amount - GasTransmission.addGas(inventory[2], getGas())));
}
gasTank.draw(GasTransmission.addGas(inventory[2], gasTank.getGas()), true);
}
if(canOperate() && getEnergy() >= ENERGY_USAGE && MekanismUtils.canFunction(this))
@ -107,7 +104,7 @@ public class TileEntityChemicalFormulator extends TileEntityElectricBlock implem
else {
GasStack stack = RecipeHandler.getChemicalFormulatorOutput(inventory[0], true);
setGas(new GasStack(stack.getGas(), getStoredGas()+stack.amount));
gasTank.fill(stack, true);
operatingTicks = 0;
}
}
@ -120,20 +117,18 @@ public class TileEntityChemicalFormulator extends TileEntityElectricBlock implem
prevEnergy = getEnergy();
if(getGas() != null)
if(gasTank.getGas() != null)
{
GasStack toSend = new GasStack(getGas().getGas(), Math.min(getGas().amount, gasOutput));
setGas(new GasStack(getGas().getGas(), getGas().amount - GasTransmission.emitGasToNetwork(toSend, this, MekanismUtils.getLeft(facing))));
GasStack toSend = new GasStack(gasTank.getGas().getGas(), Math.min(gasTank.getStored(), gasOutput));
gasTank.draw(GasTransmission.emitGasToNetwork(toSend, this, MekanismUtils.getLeft(facing)), true);
TileEntity tileEntity = Object3D.get(this).getFromSide(MekanismUtils.getRight(facing)).getTileEntity(worldObj);
if(tileEntity instanceof IGasAcceptor)
if(tileEntity instanceof IGasHandler)
{
if(((IGasAcceptor)tileEntity).canReceiveGas(MekanismUtils.getLeft(facing).getOpposite(), getGas().getGas()))
if(((IGasHandler)tileEntity).canReceiveGas(MekanismUtils.getLeft(facing).getOpposite(), gasTank.getGas().getGas()))
{
int added = ((IGasAcceptor)tileEntity).receiveGas(new GasStack(getGas().getGas(), Math.min(getGas().amount, gasOutput)));
setGas(new GasStack(getGas().getGas(), getGas().amount - added));
gasTank.draw(((IGasHandler)tileEntity).receiveGas(MekanismUtils.getLeft(facing).getOpposite(), toSend), true);
}
}
}
@ -185,11 +180,6 @@ public class TileEntityChemicalFormulator extends TileEntityElectricBlock implem
return new int[0];
}
public int getStoredGas()
{
return gasTank != null ? gasTank.amount : 0;
}
public int getScaledProgress(int i)
{
return operatingTicks*i / TICKS_REQUIRED;
@ -204,7 +194,7 @@ public class TileEntityChemicalFormulator extends TileEntityElectricBlock implem
GasStack stack = RecipeHandler.getChemicalFormulatorOutput(inventory[0], false);
if(stack == null || (getGas() != null && (getGas().getGas() != stack.getGas() || getMaxGas()-getGas().amount < stack.amount)))
if(stack == null || (gasTank.getGas() != null && (gasTank.getGas().getGas() != stack.getGas() || gasTank.getNeeded() < stack.amount)))
{
return false;
}
@ -223,7 +213,7 @@ public class TileEntityChemicalFormulator extends TileEntityElectricBlock implem
if(dataStream.readBoolean())
{
gasTank = new GasStack(GasRegistry.getGas(dataStream.readInt()), dataStream.readInt());
gasTank.setGas(new GasStack(GasRegistry.getGas(dataStream.readInt()), dataStream.readInt()));
}
else {
gasTank = null;
@ -242,11 +232,11 @@ public class TileEntityChemicalFormulator extends TileEntityElectricBlock implem
data.add(controlType.ordinal());
data.add(operatingTicks);
if(gasTank != null)
if(gasTank.getGas() != null)
{
data.add(true);
data.add(gasTank.getGas().getID());
data.add(gasTank.amount);
data.add(gasTank.getGas().getGas().getID());
data.add(gasTank.getStored());
}
else {
data.add(false);
@ -263,8 +253,7 @@ public class TileEntityChemicalFormulator extends TileEntityElectricBlock implem
isActive = nbtTags.getBoolean("isActive");
controlType = RedstoneControl.values()[nbtTags.getInteger("controlType")];
operatingTicks = nbtTags.getInteger("operatingTicks");
gasTank = GasStack.readFromNBT(nbtTags.getCompoundTag("gasTank"));
gasTank = GasTank.readFromNBT(nbtTags.getCompoundTag("gasTank"));
}
@Override
@ -275,11 +264,7 @@ public class TileEntityChemicalFormulator extends TileEntityElectricBlock implem
nbtTags.setBoolean("isActive", isActive);
nbtTags.setInteger("controlType", controlType.ordinal());
nbtTags.setInteger("operatingTicks", operatingTicks);
if(gasTank != null)
{
nbtTags.setCompoundTag("gasTank", gasTank.write(new NBTTagCompound()));
}
nbtTags.setCompoundTag("gasTank", gasTank.write(new NBTTagCompound()));
}
@Override
@ -290,7 +275,7 @@ public class TileEntityChemicalFormulator extends TileEntityElectricBlock implem
public int getScaledGasLevel(int i)
{
return gasTank != null ? gasTank.amount*i / MAX_GAS : 0;
return gasTank.getGas() != null ? gasTank.getStored()*i / MAX_GAS : 0;
}
@Override
@ -330,32 +315,6 @@ public class TileEntityChemicalFormulator extends TileEntityElectricBlock implem
{
return side == MekanismUtils.getRight(facing);
}
@Override
public GasStack getGas(Object... data)
{
return gasTank;
}
@Override
public void setGas(GasStack stack, Object... data)
{
if(stack == null || stack.amount == 0)
{
gasTank = null;
}
else {
gasTank = new GasStack(stack.getGas(), Math.max(Math.min(stack.amount, getMaxGas()), 0));
}
MekanismUtils.saveChunk(this);
}
@Override
public int getMaxGas(Object... data)
{
return MAX_GAS;
}
@Override
public RedstoneControl getControlType()

View file

@ -1,29 +1,9 @@
package mekanism.common.tileentity;
import java.util.ArrayList;
import mekanism.api.Object3D;
import mekanism.api.gas.Gas;
import mekanism.api.gas.GasRegistry;
import mekanism.api.gas.GasStack;
import mekanism.api.gas.GasTransmission;
import mekanism.api.gas.IGasAcceptor;
import mekanism.common.IRedstoneControl.RedstoneControl;
import mekanism.common.Mekanism;
import mekanism.common.PacketHandler;
import mekanism.common.PacketHandler.Transmission;
import mekanism.common.network.PacketTileEntity;
import mekanism.common.util.ChargeUtils;
import mekanism.common.util.MekanismUtils;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.fluids.FluidContainerRegistry;
import net.minecraftforge.fluids.FluidStack;
import com.google.common.io.ByteArrayDataInput;
public class TileEntityChemicalInfuser extends TileEntityElectricBlock //implements IActiveState, IGasStorage, IGasAcceptor, ITubeConnection, IRedstoneControl
{
@ -131,11 +111,11 @@ public class TileEntityChemicalInfuser extends TileEntityElectricBlock //impleme
TileEntity tileEntity = Object3D.get(this).getFromSide(MekanismUtils.getLeft(facing)).getTileEntity(worldObj);
if(tileEntity instanceof IGasAcceptor)
if(tileEntity instanceof IGasHandler)
{
if(((IGasAcceptor)tileEntity).canReceiveGas(MekanismUtils.getLeft(facing).getOpposite(), getGas().getGas()))
if(((IGasHandler)tileEntity).canReceiveGas(MekanismUtils.getLeft(facing).getOpposite(), getGas().getGas()))
{
int added = ((IGasAcceptor)tileEntity).receiveGas(new GasStack(getGas().getGas(), Math.min(getGas().amount, gasOutput)));
int added = ((IGasHandler)tileEntity).receiveGas(new GasStack(getGas().getGas(), Math.min(getGas().amount, gasOutput)));
setGas(new GasStack(getGas().getGas(), getGas().amount - added));
}
@ -196,7 +176,7 @@ public class TileEntityChemicalInfuser extends TileEntityElectricBlock //impleme
{
setActive(true);
setGas(new GasStack(GasRegistry.getGas(fluidTank.getFluid().getFluid()), getGas() != null ? getGas().amount+1 : 1));
fluidTank.drain(1, true);
fluidTank.draw(1, true);
setEnergy(getEnergy() - ENERGY_USAGE);
}
else {

View file

@ -2,8 +2,8 @@ package mekanism.common.tileentity;
import mekanism.api.EnumColor;
import mekanism.common.SideData;
import mekanism.common.TileComponentEjector;
import mekanism.common.Tier.FactoryTier;
import mekanism.common.TileComponentEjector;
import mekanism.common.block.BlockMachine.MachineType;
public class TileEntityEliteFactory extends TileEntityFactory

View file

@ -1,7 +1,6 @@
package mekanism.common.tileentity;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import mekanism.api.EnumColor;
@ -10,9 +9,8 @@ import mekanism.api.gas.Gas;
import mekanism.api.gas.GasRegistry;
import mekanism.api.gas.GasStack;
import mekanism.api.gas.GasTransmission;
import mekanism.api.gas.IGasAcceptor;
import mekanism.api.gas.IGasHandler;
import mekanism.api.gas.IGasItem;
import mekanism.api.gas.IGasStorage;
import mekanism.api.gas.ITubeConnection;
import mekanism.client.sound.IHasSound;
import mekanism.common.IActiveState;
@ -43,7 +41,7 @@ import dan200.computer.api.IComputerAccess;
import dan200.computer.api.ILuaContext;
import dan200.computer.api.IPeripheral;
public class TileEntityFactory extends TileEntityElectricBlock implements IPeripheral, IActiveState, IInvConfiguration, IUpgradeTile, IHasSound, IRedstoneControl, IGasAcceptor, IGasStorage, ITubeConnection
public class TileEntityFactory extends TileEntityElectricBlock implements IPeripheral, IActiveState, IInvConfiguration, IUpgradeTile, IHasSound, IRedstoneControl, IGasHandler, ITubeConnection
{
/** This Factory's tier. */
public FactoryTier tier;
@ -870,49 +868,14 @@ public class TileEntityFactory extends TileEntityElectricBlock implements IPerip
{
return ejectorComponent;
}
@Override
public GasStack getGas(Object... data)
{
if(secondaryEnergyStored == 0)
{
return null;
}
return new GasStack(GasRegistry.getGas("oxygen"), secondaryEnergyStored);
}
@Override
public void setGas(GasStack stack, Object... data)
{
if(stack == null)
{
setSecondaryEnergy(0);
}
else if(stack.getGas() == GasRegistry.getGas("oxygen"))
{
setSecondaryEnergy(stack.amount);
}
MekanismUtils.saveChunk(this);
}
@Override
public int getMaxGas(Object... data)
{
return getMaxSecondaryEnergy();
}
@Override
public int receiveGas(GasStack stack)
public int receiveGas(ForgeDirection side, GasStack stack)
{
if(stack.getGas() == GasRegistry.getGas("oxygen"))
{
int stored = getGas() != null ? getGas().amount : 0;
int toUse = Math.min(getMaxGas()-stored, stack.amount);
setGas(new GasStack(stack.getGas(), stored + toUse));
int toUse = Math.min(getMaxSecondaryEnergy()-secondaryEnergyStored, stack.amount);
secondaryEnergyStored += toUse;
return toUse;
}
@ -930,4 +893,16 @@ public class TileEntityFactory extends TileEntityElectricBlock implements IPerip
{
return recipeType == RecipeType.PURIFYING.ordinal();
}
@Override
public GasStack drawGas(ForgeDirection side, int amount)
{
return null;
}
@Override
public boolean canDrawGas(ForgeDirection side, Gas type)
{
return false;
}
}

View file

@ -6,10 +6,10 @@ import mekanism.api.Object3D;
import mekanism.api.gas.Gas;
import mekanism.api.gas.GasRegistry;
import mekanism.api.gas.GasStack;
import mekanism.api.gas.GasTank;
import mekanism.api.gas.GasTransmission;
import mekanism.api.gas.IGasAcceptor;
import mekanism.api.gas.IGasHandler;
import mekanism.api.gas.IGasItem;
import mekanism.api.gas.IGasStorage;
import mekanism.api.gas.ITubeConnection;
import mekanism.common.IRedstoneControl;
import mekanism.common.util.MekanismUtils;
@ -20,12 +20,12 @@ import net.minecraftforge.common.ForgeDirection;
import com.google.common.io.ByteArrayDataInput;
public class TileEntityGasTank extends TileEntityContainerBlock implements IGasStorage, IGasAcceptor, ITubeConnection, IRedstoneControl
public class TileEntityGasTank extends TileEntityContainerBlock implements IGasHandler, ITubeConnection, IRedstoneControl
{
/** The type of gas stored in this tank. */
public GasStack gasStored;
public GasTank gasTank = new GasTank(MAX_GAS);
public final int MAX_GAS = 96000;
public static final int MAX_GAS = 96000;
/** How fast this tank can output gas. */
public int output = 16;
@ -42,38 +42,29 @@ public class TileEntityGasTank extends TileEntityContainerBlock implements IGasS
@Override
public void onUpdate()
{
if(inventory[0] != null && getGas() != null)
{
if(inventory[0] != null && gasTank.getGas() != null)
{
setGas(new GasStack(getGas().getGas(), getGas().amount - GasTransmission.addGas(inventory[0], getGas())));
gasTank.draw(GasTransmission.addGas(inventory[0], gasTank.getGas()), true);
}
if(inventory[1] != null && (getGas() == null || getGas().amount < getMaxGas()))
if(inventory[1] != null && (gasTank.getGas() == null || gasTank.getGas().amount < gasTank.getMaxGas()))
{
if(getGas() == null)
{
setGas(GasTransmission.removeGas(inventory[1], null, getMaxGas()));
}
else {
GasStack removed = GasTransmission.removeGas(inventory[1], getGas().getGas(), getMaxGas()-getGas().amount);
setGas(new GasStack(getGas().getGas(), getGas().amount + (removed != null ? removed.amount : 0)));
}
gasTank.fill(GasTransmission.removeGas(inventory[1], null, gasTank.getNeeded()), true);
}
if(!worldObj.isRemote && getGas() != null && MekanismUtils.canFunction(this))
if(!worldObj.isRemote && gasTank.getGas() != null && MekanismUtils.canFunction(this))
{
GasStack toSend = new GasStack(getGas().getGas(), Math.min(getGas().amount, output));
setGas(new GasStack(getGas().getGas(), getGas().amount - GasTransmission.emitGasToNetwork(toSend, this, ForgeDirection.getOrientation(facing))));
GasStack toSend = new GasStack(gasTank.getGas().getGas(), Math.min(gasTank.getStored(), output));
gasTank.draw(GasTransmission.emitGasToNetwork(toSend, this, ForgeDirection.getOrientation(facing)), true);
TileEntity tileEntity = Object3D.get(this).getFromSide(ForgeDirection.getOrientation(facing)).getTileEntity(worldObj);
if(tileEntity instanceof IGasAcceptor)
if(tileEntity instanceof IGasHandler)
{
if(((IGasAcceptor)tileEntity).canReceiveGas(ForgeDirection.getOrientation(facing).getOpposite(), getGas().getGas()))
if(((IGasHandler)tileEntity).canReceiveGas(ForgeDirection.getOrientation(facing).getOpposite(), gasTank.getGas().getGas()))
{
int added = ((IGasAcceptor)tileEntity).receiveGas(new GasStack(getGas().getGas(), Math.min(getGas().amount, output)));
setGas(new GasStack(getGas().getGas(), getGas().amount - added));
gasTank.draw(((IGasHandler)tileEntity).receiveGas(ForgeDirection.getOrientation(facing).getOpposite(), toSend), true);
}
}
}
@ -100,11 +91,11 @@ public class TileEntityGasTank extends TileEntityContainerBlock implements IGasS
{
if(slotID == 0)
{
return itemstack.getItem() instanceof IGasItem && (getGas() == null || ((IGasItem)itemstack.getItem()).canReceiveGas(itemstack, getGas().getGas()));
return itemstack.getItem() instanceof IGasItem && (gasTank.getGas() == null || ((IGasItem)itemstack.getItem()).canReceiveGas(itemstack, gasTank.getGas().getGas()));
}
else if(slotID == 1)
{
return itemstack.getItem() instanceof IGasItem && (getGas() == null || ((IGasItem)itemstack.getItem()).canProvideGas(itemstack, getGas().getGas()));
return itemstack.getItem() instanceof IGasItem && (gasTank.getGas() == null || ((IGasItem)itemstack.getItem()).canProvideGas(itemstack, gasTank.getGas().getGas()));
}
return true;
@ -117,51 +108,32 @@ public class TileEntityGasTank extends TileEntityContainerBlock implements IGasS
}
@Override
public GasStack getGas(Object... data)
public int receiveGas(ForgeDirection side, GasStack stack)
{
return gasStored;
return gasTank.fill(stack, true);
}
@Override
public void setGas(GasStack stack, Object... data)
public GasStack drawGas(ForgeDirection side, int amount)
{
if(stack == null || stack.amount == 0)
{
gasStored = null;
}
else {
gasStored = new GasStack(stack.getGas(), Math.max(Math.min(stack.amount, getMaxGas()), 0));
}
MekanismUtils.saveChunk(this);
}
@Override
public int getMaxGas(Object... data)
{
return MAX_GAS;
return null;
}
@Override
public int receiveGas(GasStack stack)
public boolean canDrawGas(ForgeDirection side, Gas type)
{
if(gasStored == null || (gasStored != null && gasStored.getGas() == stack.getGas()))
{
int stored = getGas() != null ? getGas().amount : 0;
int toUse = Math.min(getMaxGas()-stored, stack.amount);
setGas(new GasStack(stack.getGas(), stored + toUse));
return toUse;
}
return 0;
return gasTank.canDraw(type);
}
@Override
public boolean canReceiveGas(ForgeDirection side, Gas type)
{
return (getGas() == null || getGas().getGas() == type) && side != ForgeDirection.getOrientation(facing);
if(side != ForgeDirection.getOrientation(facing))
{
return gasTank.canReceive(type);
}
return false;
}
@Override
@ -171,10 +143,10 @@ public class TileEntityGasTank extends TileEntityContainerBlock implements IGasS
if(dataStream.readBoolean())
{
gasStored = new GasStack(GasRegistry.getGas(dataStream.readInt()), dataStream.readInt());
gasTank.setGas(new GasStack(GasRegistry.getGas(dataStream.readInt()), dataStream.readInt()));
}
else {
gasStored = null;
gasTank.setGas(null);
}
controlType = RedstoneControl.values()[dataStream.readInt()];
@ -187,10 +159,7 @@ public class TileEntityGasTank extends TileEntityContainerBlock implements IGasS
{
super.readFromNBT(nbtTags);
try {
gasStored = GasStack.readFromNBT(nbtTags.getCompoundTag("gasStored"));
} catch(Exception e) {}
gasTank = GasTank.readFromNBT(nbtTags.getCompoundTag("gasTank"));
controlType = RedstoneControl.values()[nbtTags.getInteger("controlType")];
}
@ -199,11 +168,7 @@ public class TileEntityGasTank extends TileEntityContainerBlock implements IGasS
{
super.writeToNBT(nbtTags);
if(gasStored != null)
{
nbtTags.setCompoundTag("gasStored", gasStored.write(new NBTTagCompound()));
}
nbtTags.setCompoundTag("gasTank", gasTank.write(new NBTTagCompound()));
nbtTags.setInteger("controlType", controlType.ordinal());
}
@ -212,11 +177,11 @@ public class TileEntityGasTank extends TileEntityContainerBlock implements IGasS
{
super.getNetworkedData(data);
if(gasStored != null)
if(gasTank.getGas() != null)
{
data.add(true);
data.add(gasStored.getGas().getID());
data.add(gasStored.amount);
data.add(gasTank.getGas().getGas().getID());
data.add(gasTank.getStored());
}
else {
data.add(false);

View file

@ -6,20 +6,18 @@ import mekanism.api.gas.Gas;
import mekanism.api.gas.GasRegistry;
import mekanism.api.gas.GasStack;
import mekanism.api.gas.GasTransmission;
import mekanism.api.gas.IGasAcceptor;
import mekanism.api.gas.IGasHandler;
import mekanism.api.gas.IGasItem;
import mekanism.api.gas.IGasStorage;
import mekanism.api.gas.ITubeConnection;
import mekanism.common.Mekanism;
import mekanism.common.RecipeHandler.Recipe;
import mekanism.common.block.BlockMachine.MachineType;
import mekanism.common.util.MekanismUtils;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.common.ForgeDirection;
public class TileEntityPurificationChamber extends TileEntityAdvancedElectricMachine implements IGasAcceptor, IGasStorage, ITubeConnection
public class TileEntityPurificationChamber extends TileEntityAdvancedElectricMachine implements IGasHandler, ITubeConnection
{
public TileEntityPurificationChamber()
{
@ -43,47 +41,12 @@ public class TileEntityPurificationChamber extends TileEntityAdvancedElectricMac
}
@Override
public GasStack getGas(Object... data)
{
if(secondaryEnergyStored == 0)
{
return null;
}
return new GasStack(GasRegistry.getGas("oxygen"), secondaryEnergyStored);
}
@Override
public void setGas(GasStack stack, Object... data)
{
if(stack == null)
{
setSecondaryEnergy(0);
}
else if(stack.getGas() == GasRegistry.getGas("oxygen"))
{
setSecondaryEnergy(stack.amount);
}
MekanismUtils.saveChunk(this);
}
@Override
public int getMaxGas(Object... data)
{
return MAX_SECONDARY_ENERGY;
}
@Override
public int receiveGas(GasStack stack)
public int receiveGas(ForgeDirection side, GasStack stack)
{
if(stack.getGas() == GasRegistry.getGas("oxygen"))
{
int stored = getGas() != null ? getGas().amount : 0;
int toUse = Math.min(getMaxGas()-stored, stack.amount);
setGas(new GasStack(stack.getGas(), stored + toUse));
int toUse = Math.min(MAX_SECONDARY_ENERGY-secondaryEnergyStored, stack.amount);
secondaryEnergyStored += toUse;
return toUse;
}
@ -113,4 +76,16 @@ public class TileEntityPurificationChamber extends TileEntityAdvancedElectricMac
{
return true;
}
@Override
public GasStack drawGas(ForgeDirection side, int amount)
{
return null;
}
@Override
public boolean canDrawGas(ForgeDirection side, Gas type)
{
return false;
}
}

View file

@ -6,9 +6,9 @@ import mekanism.api.Object3D;
import mekanism.api.gas.Gas;
import mekanism.api.gas.GasRegistry;
import mekanism.api.gas.GasStack;
import mekanism.api.gas.GasTank;
import mekanism.api.gas.GasTransmission;
import mekanism.api.gas.IGasAcceptor;
import mekanism.api.gas.IGasStorage;
import mekanism.api.gas.IGasHandler;
import mekanism.api.gas.ITubeConnection;
import mekanism.common.IActiveState;
import mekanism.common.IRedstoneControl;
@ -34,9 +34,9 @@ import net.minecraftforge.fluids.IFluidHandler;
import com.google.common.io.ByteArrayDataInput;
public class TileEntityRotaryCondensentrator extends TileEntityElectricBlock implements IActiveState, ISustainedTank, IFluidHandler, IGasStorage, IGasAcceptor, ITubeConnection, IRedstoneControl
public class TileEntityRotaryCondensentrator extends TileEntityElectricBlock implements IActiveState, ISustainedTank, IFluidHandler, IGasHandler, ITubeConnection, IRedstoneControl
{
public GasStack gasTank;
public GasTank gasTank = new GasTank(MAX_GAS);
public FluidTank fluidTank;
@ -100,16 +100,9 @@ public class TileEntityRotaryCondensentrator extends TileEntityElectricBlock imp
if(mode == 0)
{
if(inventory[1] != null && (getGas() == null || getGas().amount < getMaxGas()))
if(inventory[1] != null && (gasTank.getGas() == null || gasTank.getStored() < gasTank.getMaxGas()))
{
if(getGas() == null)
{
setGas(GasTransmission.removeGas(inventory[1], null, getMaxGas()));
}
else {
GasStack removed = GasTransmission.removeGas(inventory[1], getGas().getGas(), getMaxGas()-getGas().amount);
setGas(new GasStack(getGas().getGas(), getGas().amount + (removed != null ? removed.amount : 0)));
}
gasTank.fill(GasTransmission.removeGas(inventory[1], null, gasTank.getNeeded()), true);
}
if(inventory[2] != null)
@ -146,11 +139,11 @@ public class TileEntityRotaryCondensentrator extends TileEntityElectricBlock imp
}
}
if(getEnergy() >= ENERGY_USAGE && MekanismUtils.canFunction(this) && isValidGas(gasTank) && (fluidTank.getFluid() == null || (fluidTank.getFluid().amount < 10000 && gasEquals(gasTank, fluidTank.getFluid()))))
if(getEnergy() >= ENERGY_USAGE && MekanismUtils.canFunction(this) && isValidGas(gasTank.getGas()) && (fluidTank.getFluid() == null || (fluidTank.getFluid().amount < 10000 && gasEquals(gasTank.getGas(), fluidTank.getFluid()))))
{
setActive(true);
fluidTank.fill(new FluidStack(getGas().getGas().getFluid(), 1), true);
setGas(new GasStack(getGas().getGas(), getGas().amount-1));
fluidTank.fill(new FluidStack(gasTank.getGas().getGas().getFluid(), 1), true);
gasTank.draw(1, true);
setEnergy(getEnergy() - ENERGY_USAGE);
}
else {
@ -162,28 +155,23 @@ public class TileEntityRotaryCondensentrator extends TileEntityElectricBlock imp
}
else if(mode == 1)
{
if(getGas() != null)
if(inventory[0] != null && gasTank.getGas() != null)
{
if(inventory[0] != null)
{
setGas(new GasStack(getGas().getGas(), getGas().amount - GasTransmission.addGas(inventory[0], getGas())));
}
gasTank.draw(GasTransmission.addGas(inventory[0], gasTank.getGas()), true);
}
if(getGas() != null)
if(gasTank.getGas() != null)
{
GasStack toSend = new GasStack(getGas().getGas(), Math.min(getGas().amount, gasOutput));
setGas(new GasStack(getGas().getGas(), getGas().amount - GasTransmission.emitGasToNetwork(toSend, this, MekanismUtils.getLeft(facing))));
GasStack toSend = new GasStack(gasTank.getGas().getGas(), Math.min(gasTank.getGas().amount, gasOutput));
gasTank.draw(GasTransmission.emitGasToNetwork(toSend, this, MekanismUtils.getLeft(facing)), true);
TileEntity tileEntity = Object3D.get(this).getFromSide(MekanismUtils.getLeft(facing)).getTileEntity(worldObj);
if(tileEntity instanceof IGasAcceptor)
if(tileEntity instanceof IGasHandler)
{
if(((IGasAcceptor)tileEntity).canReceiveGas(MekanismUtils.getLeft(facing).getOpposite(), getGas().getGas()))
if(((IGasHandler)tileEntity).canReceiveGas(MekanismUtils.getLeft(facing).getOpposite(), gasTank.getGas().getGas()))
{
int added = ((IGasAcceptor)tileEntity).receiveGas(new GasStack(getGas().getGas(), Math.min(getGas().amount, gasOutput)));
setGas(new GasStack(getGas().getGas(), getGas().amount - added));
gasTank.draw(((IGasHandler)tileEntity).receiveGas(MekanismUtils.getLeft(facing).getOpposite(), toSend), true);
}
}
}
@ -238,10 +226,10 @@ public class TileEntityRotaryCondensentrator extends TileEntityElectricBlock imp
}
}
if(getEnergy() >= ENERGY_USAGE && MekanismUtils.canFunction(this) && isValidFluid(fluidTank.getFluid()) && (gasTank == null || (gasTank.amount < MAX_GAS && gasEquals(gasTank, fluidTank.getFluid()))))
if(getEnergy() >= ENERGY_USAGE && MekanismUtils.canFunction(this) && isValidFluid(fluidTank.getFluid()) && (gasTank == null || (gasTank.getStored() < MAX_GAS && gasEquals(gasTank.getGas(), fluidTank.getFluid()))))
{
setActive(true);
setGas(new GasStack(GasRegistry.getGas(fluidTank.getFluid().getFluid()), getGas() != null ? getGas().amount+1 : 1));
gasTank.fill(new GasStack(GasRegistry.getGas(fluidTank.getFluid().getFluid()), 1), true);
fluidTank.drain(1, true);
setEnergy(getEnergy() - ENERGY_USAGE);
}
@ -323,10 +311,10 @@ public class TileEntityRotaryCondensentrator extends TileEntityElectricBlock imp
if(dataStream.readBoolean())
{
gasTank = new GasStack(GasRegistry.getGas(dataStream.readInt()), dataStream.readInt());
gasTank.setGas(new GasStack(GasRegistry.getGas(dataStream.readInt()), dataStream.readInt()));
}
else {
gasTank = null;
gasTank.setGas(null);
}
@ -352,11 +340,11 @@ public class TileEntityRotaryCondensentrator extends TileEntityElectricBlock imp
data.add(false);
}
if(gasTank != null)
if(gasTank.getGas() != null)
{
data.add(true);
data.add(gasTank.getGas().getID());
data.add(gasTank.amount);
data.add(gasTank.getGas().getGas().getID());
data.add(gasTank.getStored());
}
else {
data.add(false);
@ -374,7 +362,7 @@ public class TileEntityRotaryCondensentrator extends TileEntityElectricBlock imp
isActive = nbtTags.getBoolean("isActive");
controlType = RedstoneControl.values()[nbtTags.getInteger("controlType")];
gasTank = GasStack.readFromNBT(nbtTags.getCompoundTag("gasTank"));
gasTank = GasTank.readFromNBT(nbtTags.getCompoundTag("gasTank"));
if(nbtTags.hasKey("fluidTank"))
{
@ -390,11 +378,7 @@ public class TileEntityRotaryCondensentrator extends TileEntityElectricBlock imp
nbtTags.setInteger("mode", mode);
nbtTags.setBoolean("isActive", isActive);
nbtTags.setInteger("controlType", controlType.ordinal());
if(gasTank != null)
{
nbtTags.setCompoundTag("gasTank", gasTank.write(new NBTTagCompound()));
}
nbtTags.setCompoundTag("gasTank", gasTank.write(new NBTTagCompound()));
if(fluidTank.getFluid() != null)
{
@ -415,7 +399,7 @@ public class TileEntityRotaryCondensentrator extends TileEntityElectricBlock imp
public int getScaledGasLevel(int i)
{
return gasTank != null ? gasTank.amount*i / MAX_GAS : 0;
return gasTank.getGas() != null ? gasTank.getStored()*i / MAX_GAS : 0;
}
@Override
@ -457,51 +441,27 @@ public class TileEntityRotaryCondensentrator extends TileEntityElectricBlock imp
}
@Override
public int receiveGas(GasStack stack)
public int receiveGas(ForgeDirection side, GasStack stack)
{
if(gasTank == null || (gasTank != null && gasTank.getGas() == stack.getGas()))
{
int stored = getGas() != null ? getGas().amount : 0;
int toUse = Math.min(getMaxGas()-stored, stack.amount);
setGas(new GasStack(stack.getGas(), stored + toUse));
return toUse;
}
return 0;
return gasTank.fill(stack, true);
}
@Override
public GasStack drawGas(ForgeDirection side, int amount)
{
return gasTank.draw(amount, true);
}
@Override
public boolean canDrawGas(ForgeDirection side, Gas type)
{
return mode == 1 && side == MekanismUtils.getLeft(facing) ? gasTank.canDraw(type) : false;
}
@Override
public boolean canReceiveGas(ForgeDirection side, Gas type)
{
return mode == 0 && (getGas() == null || getGas().getGas() == type) && side == MekanismUtils.getLeft(facing);
}
@Override
public GasStack getGas(Object... data)
{
return gasTank;
}
@Override
public void setGas(GasStack stack, Object... data)
{
if(stack == null || stack.amount == 0)
{
gasTank = null;
}
else {
gasTank = new GasStack(stack.getGas(), Math.max(Math.min(stack.amount, getMaxGas()), 0));
}
MekanismUtils.saveChunk(this);
}
@Override
public int getMaxGas(Object... data)
{
return MAX_GAS;
return mode == 0 && side == MekanismUtils.getLeft(facing) ? gasTank.canReceive(type) : false;
}
@Override

View file

@ -8,7 +8,7 @@ import mekanism.api.gas.Gas;
import mekanism.api.gas.GasRegistry;
import mekanism.api.gas.GasStack;
import mekanism.api.gas.GasTransmission;
import mekanism.api.gas.IGasAcceptor;
import mekanism.api.gas.IGasHandler;
import mekanism.api.gas.IGasItem;
import mekanism.api.gas.ITubeConnection;
import mekanism.common.ISustainedTank;
@ -134,11 +134,11 @@ public class TileEntityElectrolyticSeparator extends TileEntityElectricBlock imp
TileEntity tileEntity = Object3D.get(this).getFromSide(ForgeDirection.getOrientation(facing)).getTileEntity(worldObj);
if(tileEntity instanceof IGasAcceptor)
if(tileEntity instanceof IGasHandler)
{
if(((IGasAcceptor)tileEntity).canReceiveGas(ForgeDirection.getOrientation(facing).getOpposite(), outputType))
if(((IGasHandler)tileEntity).canReceiveGas(ForgeDirection.getOrientation(facing).getOpposite(), outputType))
{
int added = ((IGasAcceptor)tileEntity).receiveGas(new GasStack(outputType, Math.min(getStored(outputType), output)));
int added = ((IGasHandler)tileEntity).receiveGas(ForgeDirection.getOrientation(facing).getOpposite(), new GasStack(outputType, Math.min(getStored(outputType), output)));
setStored(outputType, getStored(outputType) - added);
}

View file

@ -6,9 +6,8 @@ import mekanism.api.gas.Gas;
import mekanism.api.gas.GasRegistry;
import mekanism.api.gas.GasStack;
import mekanism.api.gas.GasTransmission;
import mekanism.api.gas.IGasAcceptor;
import mekanism.api.gas.IGasHandler;
import mekanism.api.gas.IGasItem;
import mekanism.api.gas.IGasStorage;
import mekanism.api.gas.ITubeConnection;
import mekanism.common.util.ChargeUtils;
import mekanism.common.util.MekanismUtils;
@ -22,7 +21,7 @@ import com.google.common.io.ByteArrayDataInput;
import dan200.computer.api.IComputerAccess;
import dan200.computer.api.ILuaContext;
public class TileEntityHydrogenGenerator extends TileEntityGenerator implements IGasAcceptor, IGasStorage, ITubeConnection
public class TileEntityHydrogenGenerator extends TileEntityGenerator implements IGasHandler, ITubeConnection
{
/** The maximum amount of hydrogen this block can store. */
public int MAX_HYDROGEN = 18000;
@ -47,8 +46,8 @@ public class TileEntityHydrogenGenerator extends TileEntityGenerator implements
if(inventory[0] != null && hydrogenStored < MAX_HYDROGEN)
{
GasStack removed = GasTransmission.removeGas(inventory[0], GasRegistry.getGas("hydrogen"), getMaxGas()-hydrogenStored);
setGas(new GasStack(GasRegistry.getGas("hydrogen"), hydrogenStored + (removed != null ? removed.amount : 0)));
GasStack removed = GasTransmission.removeGas(inventory[0], GasRegistry.getGas("hydrogen"), MAX_HYDROGEN-hydrogenStored);
hydrogenStored += removed != null ? removed.amount : 0;
}
if(canOperate())
@ -100,32 +99,6 @@ public class TileEntityHydrogenGenerator extends TileEntityGenerator implements
{
return ForgeDirection.getOrientation(side) == MekanismUtils.getRight(facing) ? new int[] {1} : new int[] {0};
}
@Override
public GasStack getGas(Object... data)
{
if(hydrogenStored == 0)
{
return null;
}
return new GasStack(GasRegistry.getGas("hydrogen"), hydrogenStored);
}
@Override
public void setGas(GasStack stack, Object... data)
{
if(stack == null)
{
hydrogenStored = 0;
}
else if(stack.getGas() == GasRegistry.getGas("hydrogen"))
{
hydrogenStored = Math.max(Math.min(stack.amount, getMaxGas()), 0);
}
MekanismUtils.saveChunk(this);
}
@Override
public boolean canOperate()
@ -194,15 +167,12 @@ public class TileEntityHydrogenGenerator extends TileEntityGenerator implements
}
@Override
public int receiveGas(GasStack stack)
public int receiveGas(ForgeDirection side, GasStack stack)
{
if(stack.getGas() == GasRegistry.getGas("hydrogen"))
{
int stored = getGas() != null ? getGas().amount : 0;
int toUse = Math.min(getMaxGas()-stored, stack.amount);
setGas(new GasStack(stack.getGas(), stored + toUse));
int toUse = Math.min(MAX_HYDROGEN-hydrogenStored, stack.amount);
hydrogenStored += toUse;
return toUse;
}
@ -230,16 +200,22 @@ public class TileEntityHydrogenGenerator extends TileEntityGenerator implements
{
return type == GasRegistry.getGas("hydrogen") && side != ForgeDirection.getOrientation(facing);
}
@Override
public GasStack drawGas(ForgeDirection side, int amount)
{
return null;
}
@Override
public boolean canDrawGas(ForgeDirection side, Gas type)
{
return false;
}
@Override
public boolean canTubeConnect(ForgeDirection side)
{
return side != ForgeDirection.getOrientation(facing);
}
@Override
public int getMaxGas(Object... data)
{
return MAX_HYDROGEN;
}
}