2014-01-08 02:55:50 +01:00
|
|
|
package mekanism.common.tile;
|
2012-10-02 20:39:40 +02:00
|
|
|
|
2015-03-05 14:24:00 +01:00
|
|
|
import io.netty.buffer.ByteBuf;
|
|
|
|
|
2013-04-13 16:33:37 +02:00
|
|
|
import java.util.ArrayList;
|
|
|
|
|
2015-03-05 14:24:00 +01:00
|
|
|
import mekanism.api.Coord4D;
|
2013-12-01 06:03:40 +01:00
|
|
|
import mekanism.api.EnumColor;
|
2015-03-05 14:24:00 +01:00
|
|
|
import mekanism.api.Range4D;
|
2014-01-17 02:35:05 +01:00
|
|
|
import mekanism.api.gas.Gas;
|
2014-01-17 01:00:53 +01:00
|
|
|
import mekanism.api.gas.GasStack;
|
|
|
|
import mekanism.api.gas.GasTank;
|
2014-01-17 02:35:05 +01:00
|
|
|
import mekanism.api.gas.IGasHandler;
|
|
|
|
import mekanism.api.gas.ITubeConnection;
|
2015-03-08 01:09:23 +01:00
|
|
|
import mekanism.api.transmitters.TransmissionType;
|
2013-08-27 00:49:32 +02:00
|
|
|
import mekanism.common.Mekanism;
|
2015-03-05 14:24:00 +01:00
|
|
|
import mekanism.common.MekanismBlocks;
|
2014-08-01 01:58:12 +02:00
|
|
|
import mekanism.common.MekanismItems;
|
2013-11-30 06:28:02 +01:00
|
|
|
import mekanism.common.SideData;
|
2014-09-06 22:14:49 +02:00
|
|
|
import mekanism.common.Upgrade;
|
2015-03-05 14:24:00 +01:00
|
|
|
import mekanism.common.base.IFactory.RecipeType;
|
|
|
|
import mekanism.common.network.PacketTileEntity.TileEntityMessage;
|
2014-01-08 02:55:50 +01:00
|
|
|
import mekanism.common.recipe.RecipeHandler;
|
2014-09-05 19:32:54 +02:00
|
|
|
import mekanism.common.recipe.inputs.AdvancedMachineInput;
|
2014-09-05 05:20:12 +02:00
|
|
|
import mekanism.common.recipe.machines.AdvancedMachineRecipe;
|
|
|
|
import mekanism.common.recipe.outputs.ItemStackOutput;
|
2015-03-21 19:16:42 +01:00
|
|
|
import mekanism.common.tile.component.TileComponentAdvancedUpgrade;
|
2015-03-08 01:09:23 +01:00
|
|
|
import mekanism.common.tile.component.TileComponentConfig;
|
2014-01-08 02:55:50 +01:00
|
|
|
import mekanism.common.tile.component.TileComponentEjector;
|
|
|
|
import mekanism.common.tile.component.TileComponentUpgrade;
|
2013-08-27 00:57:08 +02:00
|
|
|
import mekanism.common.util.ChargeUtils;
|
2013-12-16 05:01:36 +01:00
|
|
|
import mekanism.common.util.InventoryUtils;
|
2013-08-27 00:57:08 +02:00
|
|
|
import mekanism.common.util.MekanismUtils;
|
2014-04-18 03:34:19 +02:00
|
|
|
import mekanism.common.util.MekanismUtils.ResourceType;
|
2014-12-14 20:04:03 +01:00
|
|
|
import mekanism.common.util.StatUtils;
|
2012-12-20 22:53:39 +01:00
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
2014-04-20 04:44:06 +02:00
|
|
|
import net.minecraftforge.common.util.ForgeDirection;
|
2014-06-26 22:07:46 +02:00
|
|
|
import cpw.mods.fml.common.Optional.Method;
|
2014-04-12 19:49:25 +02:00
|
|
|
import dan200.computercraft.api.lua.ILuaContext;
|
2014-11-10 22:51:37 +01:00
|
|
|
import dan200.computercraft.api.lua.LuaException;
|
2014-06-02 16:52:13 +02:00
|
|
|
import dan200.computercraft.api.peripheral.IComputerAccess;
|
2012-10-09 22:27:10 +02:00
|
|
|
|
2014-09-05 05:20:12 +02:00
|
|
|
public abstract class TileEntityAdvancedElectricMachine<RECIPE extends AdvancedMachineRecipe<RECIPE>> extends TileEntityBasicMachine<AdvancedMachineInput, ItemStackOutput, RECIPE> implements IGasHandler, ITubeConnection
|
2012-10-02 20:39:40 +02:00
|
|
|
{
|
2014-09-06 22:14:49 +02:00
|
|
|
/** How much secondary energy (fuel) this machine uses per tick, not including upgrades. */
|
|
|
|
public int BASE_SECONDARY_ENERGY_PER_TICK;
|
|
|
|
|
|
|
|
/** How much secondary energy this machine uses per tick, including upgrades. */
|
2014-12-14 20:04:03 +01:00
|
|
|
public double secondaryEnergyPerTick;
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2015-03-21 18:21:02 +01:00
|
|
|
public int secondaryEnergyThisTick;
|
|
|
|
|
|
|
|
public static int MAX_GAS = 210;
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-01-17 01:00:53 +01:00
|
|
|
public GasTank gasTank;
|
2015-03-21 18:21:02 +01:00
|
|
|
public Gas prevGas;
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2012-10-02 20:39:40 +02:00
|
|
|
/**
|
2014-03-08 02:00:25 +01:00
|
|
|
* Advanced Electric Machine -- a machine like this has a total of 4 slots. Input slot (0), fuel slot (1), output slot (2),
|
2012-10-22 03:29:26 +02:00
|
|
|
* energy slot (3), and the upgrade slot (4). The machine will not run if it does not have enough electricity, or if it doesn't have enough
|
2012-10-02 20:39:40 +02:00
|
|
|
* fuel ticks.
|
2014-03-08 02:00:25 +01:00
|
|
|
*
|
2012-10-22 03:29:26 +02:00
|
|
|
* @param soundPath - location of the sound effect
|
2012-10-17 20:46:27 +02:00
|
|
|
* @param name - full name of this machine
|
2012-10-02 20:39:40 +02:00
|
|
|
* @param perTick - how much energy this machine uses per tick.
|
|
|
|
* @param secondaryPerTick - how much secondary energy (fuel) this machine uses per tick.
|
|
|
|
* @param ticksRequired - how many ticks it takes to smelt an item.
|
|
|
|
* @param maxEnergy - maximum amount of energy this machine can hold.
|
|
|
|
*/
|
2014-04-18 03:34:19 +02:00
|
|
|
public TileEntityAdvancedElectricMachine(String soundPath, String name, double perTick, int secondaryPerTick, int ticksRequired, double maxEnergy)
|
2012-10-02 20:39:40 +02:00
|
|
|
{
|
2014-04-18 03:34:19 +02:00
|
|
|
super(soundPath, name, MekanismUtils.getResource(ResourceType.GUI, "GuiAdvancedMachine.png"), perTick, ticksRequired, maxEnergy);
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2015-03-08 06:55:22 +01:00
|
|
|
configComponent = new TileComponentConfig(this, TransmissionType.ITEM, TransmissionType.ENERGY);
|
2015-03-08 01:09:23 +01:00
|
|
|
|
2015-03-08 19:27:34 +01:00
|
|
|
configComponent.addOutput(TransmissionType.ITEM, new SideData("None", EnumColor.GREY, InventoryUtils.EMPTY));
|
|
|
|
configComponent.addOutput(TransmissionType.ITEM, new SideData("Input", EnumColor.DARK_RED, new int[] {0}));
|
|
|
|
configComponent.addOutput(TransmissionType.ITEM, new SideData("Extra", EnumColor.PURPLE, new int[] {1}));
|
|
|
|
configComponent.addOutput(TransmissionType.ITEM, new SideData("Output", EnumColor.DARK_BLUE, new int[] {2}));
|
|
|
|
configComponent.addOutput(TransmissionType.ITEM, new SideData("Energy", EnumColor.DARK_GREEN, new int[] {3}));
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2015-03-08 19:27:34 +01:00
|
|
|
configComponent.setConfig(TransmissionType.ITEM, new byte[] {2, 1, 0, 4, 0, 3});
|
2015-03-08 06:55:22 +01:00
|
|
|
configComponent.setInputEnergyConfig();
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-01-17 02:50:59 +01:00
|
|
|
gasTank = new GasTank(MAX_GAS);
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2012-10-24 22:13:24 +02:00
|
|
|
inventory = new ItemStack[5];
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-09-06 22:14:49 +02:00
|
|
|
BASE_SECONDARY_ENERGY_PER_TICK = secondaryPerTick;
|
|
|
|
secondaryEnergyPerTick = secondaryPerTick;
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2015-03-21 19:16:42 +01:00
|
|
|
upgradeComponent = upgradeableSecondaryEfficiency() ? new TileComponentAdvancedUpgrade(this, 4) : new TileComponentUpgrade(this, 4);
|
2015-03-30 14:39:37 +02:00
|
|
|
ejectorComponent = new TileComponentEjector(this);
|
|
|
|
ejectorComponent.setOutputData(TransmissionType.ITEM, configComponent.getOutputs(TransmissionType.ITEM).get(3));
|
2012-10-02 20:39:40 +02:00
|
|
|
}
|
2015-03-05 14:24:00 +01:00
|
|
|
|
|
|
|
public void upgrade(RecipeType type)
|
|
|
|
{
|
|
|
|
worldObj.setBlockToAir(xCoord, yCoord, zCoord);
|
|
|
|
worldObj.setBlock(xCoord, yCoord, zCoord, MekanismBlocks.MachineBlock, 5, 3);
|
|
|
|
|
|
|
|
TileEntityFactory factory = (TileEntityFactory)worldObj.getTileEntity(xCoord, yCoord, zCoord);
|
|
|
|
|
|
|
|
//Basic
|
|
|
|
factory.facing = facing;
|
|
|
|
factory.clientFacing = clientFacing;
|
|
|
|
factory.ticker = ticker;
|
|
|
|
factory.redstone = redstone;
|
|
|
|
factory.redstoneLastTick = redstoneLastTick;
|
|
|
|
factory.doAutoSync = doAutoSync;
|
|
|
|
|
|
|
|
//Electric
|
|
|
|
factory.electricityStored = electricityStored;
|
|
|
|
factory.ic2Registered = ic2Registered;
|
2015-03-19 01:36:29 +01:00
|
|
|
|
2015-03-05 14:24:00 +01:00
|
|
|
//Noisy
|
|
|
|
factory.soundURL = soundURL;
|
|
|
|
|
|
|
|
//Machine
|
|
|
|
factory.progress[0] = operatingTicks;
|
|
|
|
factory.updateDelay = updateDelay;
|
|
|
|
factory.isActive = isActive;
|
|
|
|
factory.clientActive = clientActive;
|
|
|
|
factory.controlType = controlType;
|
|
|
|
factory.prevEnergy = prevEnergy;
|
2015-03-26 04:51:46 +01:00
|
|
|
factory.upgradeComponent.readFrom(upgradeComponent);
|
2015-03-05 14:24:00 +01:00
|
|
|
factory.upgradeComponent.setUpgradeSlot(0);
|
2015-03-26 04:51:46 +01:00
|
|
|
factory.ejectorComponent.readFrom(ejectorComponent);
|
2015-03-30 14:39:37 +02:00
|
|
|
factory.ejectorComponent.setOutputData(TransmissionType.ITEM, factory.configComponent.getOutputs(TransmissionType.ITEM).get(4));
|
2015-03-05 14:24:00 +01:00
|
|
|
factory.recipeType = type;
|
2015-03-21 20:07:24 +01:00
|
|
|
factory.upgradeComponent.setSupported(Upgrade.GAS, type.fuelEnergyUpgrades());
|
2015-03-05 14:24:00 +01:00
|
|
|
|
|
|
|
//Advanced Machine
|
|
|
|
factory.gasTank.setGas(gasTank.getGas());
|
|
|
|
|
|
|
|
factory.inventory[5] = inventory[0];
|
|
|
|
factory.inventory[4] = inventory[1];
|
|
|
|
factory.inventory[5+3] = inventory[2];
|
|
|
|
factory.inventory[1] = inventory[3];
|
|
|
|
factory.inventory[0] = inventory[4];
|
|
|
|
|
2015-03-26 04:51:46 +01:00
|
|
|
for(Upgrade upgrade : factory.upgradeComponent.getSupportedTypes())
|
2015-03-05 14:24:00 +01:00
|
|
|
{
|
|
|
|
factory.recalculateUpgradables(upgrade);
|
|
|
|
}
|
|
|
|
|
|
|
|
factory.upgraded = true;
|
|
|
|
|
|
|
|
factory.markDirty();
|
|
|
|
Mekanism.packetHandler.sendToReceivers(new TileEntityMessage(Coord4D.get(factory), factory.getNetworkedData(new ArrayList())), new Range4D(Coord4D.get(factory)));
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the amount of ticks the declared itemstack can fuel this machine.
|
|
|
|
* @param itemstack - itemstack to check with
|
|
|
|
* @return fuel ticks
|
|
|
|
*/
|
|
|
|
public abstract GasStack getItemGas(ItemStack itemstack);
|
|
|
|
|
|
|
|
public abstract boolean isValidGas(Gas gas);
|
|
|
|
|
|
|
|
@Override
|
2012-10-02 20:39:40 +02:00
|
|
|
public void onUpdate()
|
|
|
|
{
|
2012-10-30 05:14:25 +01:00
|
|
|
super.onUpdate();
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-04-22 05:43:04 +02:00
|
|
|
if(!worldObj.isRemote)
|
2012-10-02 20:39:40 +02:00
|
|
|
{
|
2013-04-23 21:36:43 +02:00
|
|
|
ChargeUtils.discharge(3, this);
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-04-22 05:43:04 +02:00
|
|
|
handleSecondaryFuel();
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2015-03-21 18:21:02 +01:00
|
|
|
boolean inactive = false;
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-09-06 22:14:49 +02:00
|
|
|
RECIPE recipe = getRecipe();
|
2014-09-05 05:20:12 +02:00
|
|
|
|
2015-03-21 18:21:02 +01:00
|
|
|
secondaryEnergyThisTick = useStatisticalMechanics() ? StatUtils.inversePoisson(secondaryEnergyPerTick) : (int)Math.ceil(secondaryEnergyPerTick);
|
|
|
|
|
|
|
|
if(canOperate(recipe) && MekanismUtils.canFunction(this) && getEnergy() >= energyPerTick && gasTank.getStored() >= secondaryEnergyThisTick)
|
2013-01-23 21:42:45 +01:00
|
|
|
{
|
2014-03-08 02:00:25 +01:00
|
|
|
setActive(true);
|
|
|
|
|
2013-07-24 22:03:35 +02:00
|
|
|
operatingTicks++;
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-09-06 22:14:49 +02:00
|
|
|
if(operatingTicks >= ticksRequired)
|
2013-01-23 21:42:45 +01:00
|
|
|
{
|
2014-09-05 05:20:12 +02:00
|
|
|
operate(recipe);
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-04-22 05:43:04 +02:00
|
|
|
operatingTicks = 0;
|
2013-01-23 21:42:45 +01:00
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2015-03-21 18:21:02 +01:00
|
|
|
gasTank.draw(secondaryEnergyThisTick, true);
|
2014-09-06 22:14:49 +02:00
|
|
|
electricityStored -= energyPerTick;
|
2013-04-22 05:43:04 +02:00
|
|
|
}
|
2013-07-24 22:03:35 +02:00
|
|
|
else {
|
2015-03-21 18:21:02 +01:00
|
|
|
inactive = true;
|
|
|
|
setActive(false);
|
2013-07-24 22:03:35 +02:00
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2015-03-21 18:21:02 +01:00
|
|
|
if(inactive && getRecipe() == null)
|
2013-04-22 05:43:04 +02:00
|
|
|
{
|
2013-01-23 21:42:45 +01:00
|
|
|
operatingTicks = 0;
|
2012-10-02 20:39:40 +02:00
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-11-03 00:06:56 +01:00
|
|
|
prevEnergy = getEnergy();
|
2015-04-10 14:34:02 +02:00
|
|
|
|
2015-03-21 18:21:02 +01:00
|
|
|
if(!(gasTank.getGasType() == null || gasTank.getStored() == 0))
|
|
|
|
{
|
|
|
|
prevGas = gasTank.getGasType();
|
|
|
|
}
|
2012-10-02 20:39:40 +02:00
|
|
|
}
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
|
|
|
public void handleSecondaryFuel()
|
|
|
|
{
|
2014-09-06 22:14:49 +02:00
|
|
|
if(inventory[1] != null && gasTank.getNeeded() > 0)
|
2013-01-30 13:53:36 +01:00
|
|
|
{
|
2014-01-17 02:35:05 +01:00
|
|
|
GasStack stack = getItemGas(inventory[1]);
|
|
|
|
int gasNeeded = gasTank.getNeeded();
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-09-07 01:15:00 +02:00
|
|
|
if(stack != null && gasTank.canReceive(stack.getGas()) && gasNeeded >= stack.amount)
|
2013-01-30 13:53:36 +01:00
|
|
|
{
|
2014-01-17 02:35:05 +01:00
|
|
|
gasTank.receive(stack, true);
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-04-02 03:06:57 +02:00
|
|
|
inventory[1].stackSize--;
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-01-30 13:53:36 +01:00
|
|
|
if(inventory[1].stackSize == 0)
|
|
|
|
{
|
|
|
|
inventory[1] = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
}
|
2015-02-19 22:12:28 +01:00
|
|
|
|
2015-02-19 17:36:16 +01:00
|
|
|
public boolean upgradeableSecondaryEfficiency()
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean useStatisticalMechanics()
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-04-02 03:06:57 +02:00
|
|
|
@Override
|
2013-07-20 18:10:14 +02:00
|
|
|
public boolean isItemValidForSlot(int slotID, ItemStack itemstack)
|
2013-04-02 03:06:57 +02:00
|
|
|
{
|
2014-03-08 18:01:45 +01:00
|
|
|
if(slotID == 2)
|
2013-04-02 03:06:57 +02:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
else if(slotID == 4)
|
|
|
|
{
|
2014-08-01 01:58:12 +02:00
|
|
|
return itemstack.getItem() == MekanismItems.SpeedUpgrade || itemstack.getItem() == MekanismItems.EnergyUpgrade;
|
2013-04-02 03:06:57 +02:00
|
|
|
}
|
|
|
|
else if(slotID == 0)
|
|
|
|
{
|
2014-09-05 05:20:12 +02:00
|
|
|
return RecipeHandler.getRecipe(new AdvancedMachineInput(itemstack, gasTank.getGasType()), getRecipes()) != null;
|
2013-04-02 03:06:57 +02:00
|
|
|
}
|
|
|
|
else if(slotID == 3)
|
|
|
|
{
|
2013-08-01 03:20:12 +02:00
|
|
|
return ChargeUtils.canBeDischarged(itemstack);
|
2013-04-02 03:06:57 +02:00
|
|
|
}
|
|
|
|
else if(slotID == 1)
|
|
|
|
{
|
2014-01-17 02:35:05 +01:00
|
|
|
return getItemGas(itemstack) != null;
|
2013-04-02 03:06:57 +02:00
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-12-12 01:53:12 +01:00
|
|
|
return false;
|
2013-04-02 03:06:57 +02:00
|
|
|
}
|
2012-10-02 20:39:40 +02:00
|
|
|
|
2014-03-08 02:00:25 +01:00
|
|
|
@Override
|
2014-09-05 05:20:12 +02:00
|
|
|
public AdvancedMachineInput getInput()
|
2014-03-08 02:00:25 +01:00
|
|
|
{
|
2015-03-21 18:21:02 +01:00
|
|
|
return new AdvancedMachineInput(inventory[0], prevGas);
|
2014-09-05 05:20:12 +02:00
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-09-05 05:20:12 +02:00
|
|
|
@Override
|
|
|
|
public RECIPE getRecipe()
|
|
|
|
{
|
2014-09-06 22:14:49 +02:00
|
|
|
AdvancedMachineInput input = getInput();
|
2015-03-21 18:21:02 +01:00
|
|
|
|
2014-09-06 22:14:49 +02:00
|
|
|
if(cachedRecipe == null || !input.testEquality(cachedRecipe.getInput()))
|
|
|
|
{
|
|
|
|
cachedRecipe = RecipeHandler.getRecipe(input, getRecipes());
|
|
|
|
}
|
2015-03-21 18:21:02 +01:00
|
|
|
|
2014-09-06 22:14:49 +02:00
|
|
|
return cachedRecipe;
|
2014-09-05 05:20:12 +02:00
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-09-05 05:20:12 +02:00
|
|
|
@Override
|
|
|
|
public void operate(RECIPE recipe)
|
|
|
|
{
|
2015-03-21 18:21:02 +01:00
|
|
|
recipe.operate(inventory, 0, 2, gasTank, secondaryEnergyThisTick);
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-04-20 22:15:44 +02:00
|
|
|
markDirty();
|
2015-03-31 01:27:54 +02:00
|
|
|
ejectorComponent.outputItems();
|
2014-03-08 02:00:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-09-05 05:20:12 +02:00
|
|
|
public boolean canOperate(RECIPE recipe)
|
2014-03-08 02:00:25 +01:00
|
|
|
{
|
2015-03-21 18:21:02 +01:00
|
|
|
return recipe != null && recipe.canOperate(inventory, 0, 2, gasTank, secondaryEnergyThisTick);
|
2014-03-08 02:00:25 +01:00
|
|
|
}
|
|
|
|
|
2012-11-15 21:04:12 +01:00
|
|
|
@Override
|
2014-06-02 16:52:13 +02:00
|
|
|
public void handlePacketData(ByteBuf dataStream)
|
2012-10-02 20:39:40 +02:00
|
|
|
{
|
2013-02-27 02:21:30 +01:00
|
|
|
super.handlePacketData(dataStream);
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-01-17 01:00:53 +01:00
|
|
|
if(dataStream.readBoolean())
|
|
|
|
{
|
|
|
|
gasTank.setGas(new GasStack(dataStream.readInt(), dataStream.readInt()));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
gasTank.setGas(null);
|
|
|
|
}
|
2013-02-27 02:21:30 +01:00
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-02-27 02:21:30 +01:00
|
|
|
@Override
|
|
|
|
public ArrayList getNetworkedData(ArrayList data)
|
|
|
|
{
|
|
|
|
super.getNetworkedData(data);
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-01-17 01:00:53 +01:00
|
|
|
if(gasTank.getGas() != null)
|
|
|
|
{
|
|
|
|
data.add(true);
|
|
|
|
data.add(gasTank.getGas().getGas().getID());
|
|
|
|
data.add(gasTank.getStored());
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
data.add(false);
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-02-27 02:21:30 +01:00
|
|
|
return data;
|
2012-10-02 20:39:40 +02:00
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void readFromNBT(NBTTagCompound nbtTags)
|
|
|
|
{
|
|
|
|
super.readFromNBT(nbtTags);
|
|
|
|
|
|
|
|
gasTank.read(nbtTags.getCompoundTag("gasTank"));
|
2015-03-21 18:21:02 +01:00
|
|
|
gasTank.setMaxGas(MAX_GAS);
|
2014-03-08 02:00:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void writeToNBT(NBTTagCompound nbtTags)
|
|
|
|
{
|
|
|
|
super.writeToNBT(nbtTags);
|
|
|
|
|
2014-04-20 05:34:19 +02:00
|
|
|
nbtTags.setTag("gasTank", gasTank.write(new NBTTagCompound()));
|
2014-03-08 02:00:25 +01:00
|
|
|
}
|
|
|
|
|
2012-10-28 23:18:23 +01:00
|
|
|
/**
|
|
|
|
* Gets the scaled secondary energy level for the GUI.
|
|
|
|
* @param i - multiplier
|
|
|
|
* @return scaled secondary energy
|
|
|
|
*/
|
2014-01-17 02:35:05 +01:00
|
|
|
public int getScaledGasLevel(int i)
|
2012-10-02 20:39:40 +02:00
|
|
|
{
|
2014-01-17 02:35:05 +01:00
|
|
|
return gasTank.getStored()*i / gasTank.getMaxGas();
|
2012-10-02 20:39:40 +02:00
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-04-03 21:37:26 +02:00
|
|
|
@Override
|
2013-05-07 21:57:55 +02:00
|
|
|
public boolean canExtractItem(int slotID, ItemStack itemstack, int side)
|
2013-04-03 21:37:26 +02:00
|
|
|
{
|
|
|
|
if(slotID == 3)
|
|
|
|
{
|
2013-08-01 03:20:12 +02:00
|
|
|
return ChargeUtils.canBeOutputted(itemstack, false);
|
2013-04-03 21:37:26 +02:00
|
|
|
}
|
|
|
|
else if(slotID == 2)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2013-04-03 21:37:26 +02:00
|
|
|
return false;
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-01-17 02:35:05 +01:00
|
|
|
@Override
|
|
|
|
public boolean canTubeConnect(ForgeDirection side)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-08-10 04:33:25 +02:00
|
|
|
public int receiveGas(ForgeDirection side, GasStack stack, boolean doTransfer)
|
2014-01-17 02:35:05 +01:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-03-22 15:36:21 +01:00
|
|
|
@Override
|
|
|
|
public int receiveGas(ForgeDirection side, GasStack stack)
|
|
|
|
{
|
|
|
|
return receiveGas(side, stack, true);
|
|
|
|
}
|
|
|
|
|
2014-01-17 02:35:05 +01:00
|
|
|
@Override
|
2014-08-10 04:33:25 +02:00
|
|
|
public GasStack drawGas(ForgeDirection side, int amount, boolean doTransfer)
|
2014-01-17 02:35:05 +01:00
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2015-03-22 15:36:21 +01:00
|
|
|
@Override
|
|
|
|
public GasStack drawGas(ForgeDirection side, int amount)
|
|
|
|
{
|
|
|
|
return drawGas(side, amount, true);
|
|
|
|
}
|
|
|
|
|
2014-01-17 02:35:05 +01:00
|
|
|
@Override
|
|
|
|
public boolean canReceiveGas(ForgeDirection side, Gas type)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean canDrawGas(ForgeDirection side, Gas type)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2012-10-09 22:27:10 +02:00
|
|
|
|
2014-09-06 22:14:49 +02:00
|
|
|
@Override
|
|
|
|
public void recalculateUpgradables(Upgrade upgrade)
|
|
|
|
{
|
|
|
|
super.recalculateUpgradables(upgrade);
|
|
|
|
|
2015-03-21 20:44:17 +01:00
|
|
|
if(upgrade == Upgrade.SPEED || (upgradeableSecondaryEfficiency() && upgrade == Upgrade.GAS))
|
2014-09-06 22:14:49 +02:00
|
|
|
{
|
2015-03-21 19:16:42 +01:00
|
|
|
secondaryEnergyPerTick = MekanismUtils.getSecondaryEnergyPerTickMean(this, BASE_SECONDARY_ENERGY_PER_TICK);
|
2014-09-06 22:14:49 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-06 16:44:14 +01:00
|
|
|
@Override
|
2014-06-26 22:07:46 +02:00
|
|
|
@Method(modid = "ComputerCraft")
|
2014-03-08 02:00:25 +01:00
|
|
|
public String[] getMethodNames()
|
2012-10-09 22:27:10 +02:00
|
|
|
{
|
2012-10-25 23:55:32 +02:00
|
|
|
return new String[] {"getStored", "getSecondaryStored", "getProgress", "isActive", "facing", "canOperate", "getMaxEnergy", "getEnergyNeeded"};
|
2012-10-09 22:27:10 +02:00
|
|
|
}
|
|
|
|
|
2012-11-06 16:44:14 +01:00
|
|
|
@Override
|
2014-06-26 22:07:46 +02:00
|
|
|
@Method(modid = "ComputerCraft")
|
2014-11-10 22:51:37 +01:00
|
|
|
public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] arguments) throws LuaException, InterruptedException
|
2012-10-09 22:27:10 +02:00
|
|
|
{
|
|
|
|
switch(method)
|
|
|
|
{
|
|
|
|
case 0:
|
2013-08-25 03:22:45 +02:00
|
|
|
return new Object[] {getEnergy()};
|
2012-10-09 22:27:10 +02:00
|
|
|
case 1:
|
2014-01-17 02:35:05 +01:00
|
|
|
return new Object[] {gasTank.getStored()};
|
2012-10-09 22:27:10 +02:00
|
|
|
case 2:
|
|
|
|
return new Object[] {operatingTicks};
|
|
|
|
case 3:
|
|
|
|
return new Object[] {isActive};
|
|
|
|
case 4:
|
|
|
|
return new Object[] {facing};
|
|
|
|
case 5:
|
2014-09-05 05:20:12 +02:00
|
|
|
return new Object[] {canOperate(RecipeHandler.getRecipe(getInput(), getRecipes()))};
|
2012-10-25 23:55:32 +02:00
|
|
|
case 6:
|
2014-09-06 22:14:49 +02:00
|
|
|
return new Object[] {maxEnergy};
|
2012-10-25 23:55:32 +02:00
|
|
|
case 7:
|
2014-09-06 22:14:49 +02:00
|
|
|
return new Object[] {maxEnergy-getEnergy()};
|
2012-10-09 22:27:10 +02:00
|
|
|
default:
|
2014-06-03 08:46:03 +02:00
|
|
|
Mekanism.logger.error("Attempted to call unknown method with computer ID " + computer.getID());
|
2012-10-25 23:55:32 +02:00
|
|
|
return new Object[] {"Unknown command."};
|
2012-10-09 22:27:10 +02:00
|
|
|
}
|
|
|
|
}
|
2012-10-02 20:39:40 +02:00
|
|
|
}
|