2014-01-26 23:12:03 +01:00
|
|
|
package mekanism.common.tile;
|
|
|
|
|
2015-02-18 03:27:35 +01:00
|
|
|
import io.netty.buffer.ByteBuf;
|
|
|
|
|
2014-01-28 22:19:07 +01:00
|
|
|
import java.util.ArrayList;
|
|
|
|
|
|
|
|
import mekanism.api.Coord4D;
|
2014-08-01 01:58:12 +02:00
|
|
|
import mekanism.api.MekanismConfig.usage;
|
2014-09-03 20:00:03 +02:00
|
|
|
import mekanism.api.Range4D;
|
2014-01-28 22:19:07 +01:00
|
|
|
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.IGasHandler;
|
|
|
|
import mekanism.api.gas.IGasItem;
|
|
|
|
import mekanism.api.gas.ITubeConnection;
|
|
|
|
import mekanism.common.Mekanism;
|
2015-02-18 03:27:35 +01:00
|
|
|
import mekanism.common.Upgrade;
|
2014-08-10 04:20:49 +02:00
|
|
|
import mekanism.common.base.IRedstoneControl;
|
|
|
|
import mekanism.common.base.ISustainedData;
|
2015-02-18 03:27:35 +01:00
|
|
|
import mekanism.common.base.IUpgradeTile;
|
2014-01-26 23:12:03 +01:00
|
|
|
import mekanism.common.block.BlockMachine.MachineType;
|
2014-06-11 11:57:49 +02:00
|
|
|
import mekanism.common.network.PacketTileEntity.TileEntityMessage;
|
2014-01-28 22:19:07 +01:00
|
|
|
import mekanism.common.recipe.RecipeHandler;
|
2014-09-05 05:20:12 +02:00
|
|
|
import mekanism.common.recipe.inputs.GasInput;
|
|
|
|
import mekanism.common.recipe.machines.WasherRecipe;
|
2015-02-18 03:27:35 +01:00
|
|
|
import mekanism.common.tile.component.TileComponentUpgrade;
|
2014-01-28 22:19:07 +01:00
|
|
|
import mekanism.common.util.ChargeUtils;
|
2014-07-10 22:24:55 +02:00
|
|
|
import mekanism.common.util.FluidContainerUtils;
|
2014-01-28 22:19:07 +01:00
|
|
|
import mekanism.common.util.InventoryUtils;
|
|
|
|
import mekanism.common.util.MekanismUtils;
|
2014-01-28 22:49:49 +01:00
|
|
|
import mekanism.common.util.PipeUtils;
|
2014-01-28 22:19:07 +01:00
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
2014-06-02 16:01:21 +02:00
|
|
|
import net.minecraft.entity.player.EntityPlayerMP;
|
2014-01-26 23:12:03 +01:00
|
|
|
import net.minecraft.item.ItemStack;
|
2014-01-28 22:19:07 +01:00
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
|
|
|
import net.minecraft.tileentity.TileEntity;
|
2014-04-20 04:44:06 +02:00
|
|
|
import net.minecraftforge.common.util.ForgeDirection;
|
2014-01-28 22:19:07 +01:00
|
|
|
import net.minecraftforge.fluids.Fluid;
|
|
|
|
import net.minecraftforge.fluids.FluidContainerRegistry;
|
|
|
|
import net.minecraftforge.fluids.FluidRegistry;
|
|
|
|
import net.minecraftforge.fluids.FluidStack;
|
|
|
|
import net.minecraftforge.fluids.FluidTank;
|
|
|
|
import net.minecraftforge.fluids.FluidTankInfo;
|
2014-07-10 22:24:55 +02:00
|
|
|
import net.minecraftforge.fluids.IFluidContainerItem;
|
2014-01-28 22:19:07 +01:00
|
|
|
import net.minecraftforge.fluids.IFluidHandler;
|
|
|
|
|
2015-02-18 03:27:35 +01:00
|
|
|
public class TileEntityChemicalWasher extends TileEntityNoisyElectricBlock implements IGasHandler, ITubeConnection, IRedstoneControl, IFluidHandler, IUpgradeTile, ISustainedData
|
2014-01-26 23:12:03 +01:00
|
|
|
{
|
2014-01-28 22:19:07 +01:00
|
|
|
public FluidTank fluidTank = new FluidTank(MAX_FLUID);
|
|
|
|
public GasTank inputTank = new GasTank(MAX_GAS);
|
|
|
|
public GasTank outputTank = new GasTank(MAX_GAS);
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-01-28 22:19:07 +01:00
|
|
|
public static final int MAX_GAS = 10000;
|
|
|
|
public static final int MAX_FLUID = 10000;
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-01-28 22:19:07 +01:00
|
|
|
public static int WATER_USAGE = 5;
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-01-28 22:19:07 +01:00
|
|
|
public int updateDelay;
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-01-28 22:19:07 +01:00
|
|
|
public int gasOutput = 16;
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-01-28 22:19:07 +01:00
|
|
|
public boolean isActive;
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-01-28 22:19:07 +01:00
|
|
|
public boolean clientActive;
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-01-28 22:19:07 +01:00
|
|
|
public double prevEnergy;
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2015-02-18 03:27:35 +01:00
|
|
|
public final double BASE_ENERGY_USAGE = usage.chemicalWasherUsage;
|
|
|
|
|
|
|
|
public double energyUsage = usage.chemicalWasherUsage;
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-09-06 22:14:49 +02:00
|
|
|
public WasherRecipe cachedRecipe;
|
2015-02-18 03:27:35 +01:00
|
|
|
|
|
|
|
public TileComponentUpgrade upgradeComponent = new TileComponentUpgrade(this, 4);
|
2014-09-06 22:14:49 +02:00
|
|
|
|
2014-01-28 22:19:07 +01:00
|
|
|
/** This machine's current RedstoneControl type. */
|
|
|
|
public RedstoneControl controlType = RedstoneControl.DISABLED;
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-01-26 23:12:03 +01:00
|
|
|
public TileEntityChemicalWasher()
|
|
|
|
{
|
2014-08-28 00:16:59 +02:00
|
|
|
super("washer", "ChemicalWasher", MachineType.CHEMICAL_WASHER.baseEnergy);
|
2015-02-18 03:27:35 +01:00
|
|
|
inventory = new ItemStack[5];
|
2014-01-26 23:12:03 +01:00
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-01-28 22:19:07 +01:00
|
|
|
@Override
|
|
|
|
public void onUpdate()
|
|
|
|
{
|
2014-08-28 00:55:35 +02:00
|
|
|
if(worldObj.isRemote && updateDelay > 0)
|
2014-01-28 22:19:07 +01:00
|
|
|
{
|
2014-08-28 00:55:35 +02:00
|
|
|
updateDelay--;
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-08-28 00:55:35 +02:00
|
|
|
if(updateDelay == 0 && clientActive != isActive)
|
2014-01-28 22:19:07 +01:00
|
|
|
{
|
2014-08-28 00:55:35 +02:00
|
|
|
isActive = clientActive;
|
|
|
|
MekanismUtils.updateBlock(worldObj, xCoord, yCoord, zCoord);
|
2014-01-28 22:19:07 +01:00
|
|
|
}
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-01-28 22:19:07 +01:00
|
|
|
if(!worldObj.isRemote)
|
|
|
|
{
|
2014-09-05 05:20:12 +02:00
|
|
|
WasherRecipe recipe = getRecipe();
|
|
|
|
|
2014-01-28 22:19:07 +01:00
|
|
|
if(updateDelay > 0)
|
|
|
|
{
|
|
|
|
updateDelay--;
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-01-28 22:19:07 +01:00
|
|
|
if(updateDelay == 0 && clientActive != isActive)
|
|
|
|
{
|
2014-08-08 04:48:35 +02:00
|
|
|
Mekanism.packetHandler.sendToReceivers(new TileEntityMessage(Coord4D.get(this), getNetworkedData(new ArrayList())), new Range4D(Coord4D.get(this)));
|
2014-01-28 22:19:07 +01:00
|
|
|
}
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-02-01 18:58:22 +01:00
|
|
|
ChargeUtils.discharge(3, this);
|
|
|
|
manageBuckets();
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-02-01 18:58:22 +01:00
|
|
|
if(inventory[2] != null && outputTank.getGas() != null)
|
2014-01-28 22:19:07 +01:00
|
|
|
{
|
2014-02-01 18:58:22 +01:00
|
|
|
outputTank.draw(GasTransmission.addGas(inventory[2], outputTank.getGas()), true);
|
2014-01-28 22:19:07 +01:00
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2015-02-18 03:27:35 +01:00
|
|
|
if(canOperate(recipe) && getEnergy() >= energyUsage && MekanismUtils.canFunction(this))
|
2014-01-28 22:19:07 +01:00
|
|
|
{
|
|
|
|
setActive(true);
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-09-05 05:20:12 +02:00
|
|
|
operate(recipe);
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2015-02-18 03:27:35 +01:00
|
|
|
setEnergy(getEnergy() - energyUsage);
|
2014-01-28 22:19:07 +01:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
if(prevEnergy >= getEnergy())
|
|
|
|
{
|
|
|
|
setActive(false);
|
|
|
|
}
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-01-28 22:19:07 +01:00
|
|
|
if(outputTank.getGas() != null)
|
|
|
|
{
|
|
|
|
GasStack toSend = new GasStack(outputTank.getGas().getGas(), Math.min(outputTank.getStored(), gasOutput));
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-01-28 22:19:07 +01:00
|
|
|
TileEntity tileEntity = Coord4D.get(this).getFromSide(MekanismUtils.getRight(facing)).getTileEntity(worldObj);
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-01-28 22:19:07 +01:00
|
|
|
if(tileEntity instanceof IGasHandler)
|
|
|
|
{
|
|
|
|
if(((IGasHandler)tileEntity).canReceiveGas(MekanismUtils.getRight(facing).getOpposite(), outputTank.getGas().getGas()))
|
|
|
|
{
|
2014-08-10 04:33:25 +02:00
|
|
|
outputTank.draw(((IGasHandler)tileEntity).receiveGas(MekanismUtils.getRight(facing).getOpposite(), toSend, true), true);
|
2014-01-28 22:19:07 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-01-28 22:19:07 +01:00
|
|
|
prevEnergy = getEnergy();
|
|
|
|
}
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-09-05 05:20:12 +02:00
|
|
|
public WasherRecipe getRecipe()
|
2014-01-28 22:19:07 +01:00
|
|
|
{
|
2014-09-06 22:14:49 +02:00
|
|
|
GasInput input = getInput();
|
2015-02-18 03:27:35 +01:00
|
|
|
|
2014-09-06 22:14:49 +02:00
|
|
|
if(cachedRecipe == null || !input.testEquality(cachedRecipe.getInput()))
|
|
|
|
{
|
|
|
|
cachedRecipe = RecipeHandler.getChemicalWasherRecipe(getInput());
|
|
|
|
}
|
2015-02-18 03:27:35 +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
|
|
|
public GasInput getInput()
|
|
|
|
{
|
|
|
|
return new GasInput(inputTank.getGas());
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-09-05 05:20:12 +02:00
|
|
|
public boolean canOperate(WasherRecipe recipe)
|
|
|
|
{
|
|
|
|
return recipe != null && recipe.canOperate(inputTank, fluidTank, outputTank);
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-09-05 05:20:12 +02:00
|
|
|
public void operate(WasherRecipe recipe)
|
|
|
|
{
|
2015-02-18 03:27:35 +01:00
|
|
|
recipe.operate(inputTank, fluidTank, outputTank, getUpgradedUsage());
|
2014-01-28 22:19:07 +01:00
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-01-28 22:19:07 +01:00
|
|
|
private void manageBuckets()
|
|
|
|
{
|
2014-07-10 22:24:55 +02:00
|
|
|
if(inventory[0] != null)
|
2014-01-28 22:19:07 +01:00
|
|
|
{
|
2014-07-10 22:24:55 +02:00
|
|
|
if(inventory[0].getItem() instanceof IFluidContainerItem)
|
2014-01-28 22:19:07 +01:00
|
|
|
{
|
2014-07-10 22:24:55 +02:00
|
|
|
fluidTank.fill(FluidContainerUtils.extractFluid(fluidTank, inventory[0], FluidRegistry.WATER), true);
|
|
|
|
|
|
|
|
if(((IFluidContainerItem)inventory[0].getItem()).getFluid(inventory[0]) == null || fluidTank.getFluidAmount() == fluidTank.getCapacity())
|
2014-01-28 22:19:07 +01:00
|
|
|
{
|
2014-07-10 22:24:55 +02:00
|
|
|
if(inventory[1] == null)
|
|
|
|
{
|
|
|
|
inventory[1] = inventory[0].copy();
|
|
|
|
inventory[0] = null;
|
|
|
|
|
|
|
|
markDirty();
|
|
|
|
}
|
2014-01-28 22:19:07 +01:00
|
|
|
}
|
2014-07-10 22:24:55 +02:00
|
|
|
}
|
|
|
|
else if(FluidContainerRegistry.isFilledContainer(inventory[0]))
|
|
|
|
{
|
|
|
|
FluidStack itemFluid = FluidContainerRegistry.getFluidForFilledItem(inventory[0]);
|
|
|
|
|
|
|
|
if((fluidTank.getFluid() == null && itemFluid.amount <= MAX_FLUID) || fluidTank.getFluid().amount+itemFluid.amount <= MAX_FLUID)
|
2014-01-28 22:19:07 +01:00
|
|
|
{
|
2014-07-10 22:24:55 +02:00
|
|
|
if(itemFluid.getFluid() != FluidRegistry.WATER || (fluidTank.getFluid() != null && !fluidTank.getFluid().isFluidEqual(itemFluid)))
|
2014-01-28 22:19:07 +01:00
|
|
|
{
|
2014-07-10 22:24:55 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ItemStack containerItem = inventory[0].getItem().getContainerItem(inventory[0]);
|
|
|
|
|
|
|
|
boolean filled = false;
|
|
|
|
|
|
|
|
if(containerItem != null)
|
|
|
|
{
|
|
|
|
if(inventory[1] == null || (inventory[1].isItemEqual(containerItem) && inventory[1].stackSize+1 <= containerItem.getMaxStackSize()))
|
2014-01-28 22:19:07 +01:00
|
|
|
{
|
2014-07-10 22:24:55 +02:00
|
|
|
inventory[0] = null;
|
|
|
|
|
|
|
|
if(inventory[1] == null)
|
|
|
|
{
|
|
|
|
inventory[1] = containerItem;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
inventory[1].stackSize++;
|
|
|
|
}
|
|
|
|
|
|
|
|
filled = true;
|
2014-01-28 22:19:07 +01:00
|
|
|
}
|
2014-07-10 22:24:55 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
inventory[0].stackSize--;
|
|
|
|
|
|
|
|
if(inventory[0].stackSize == 0)
|
|
|
|
{
|
|
|
|
inventory[0] = null;
|
2014-01-28 22:19:07 +01:00
|
|
|
}
|
2014-07-10 22:24:55 +02:00
|
|
|
|
2014-01-28 22:19:07 +01:00
|
|
|
filled = true;
|
|
|
|
}
|
2014-07-10 22:24:55 +02:00
|
|
|
|
|
|
|
if(filled)
|
2014-01-28 22:19:07 +01:00
|
|
|
{
|
2014-07-10 22:24:55 +02:00
|
|
|
fluidTank.fill(itemFluid, true);
|
|
|
|
markDirty();
|
2014-01-28 22:19:07 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-02-18 03:27:35 +01:00
|
|
|
|
|
|
|
public int getUpgradedUsage()
|
|
|
|
{
|
|
|
|
int possibleProcess = Math.min(inputTank.getStored(), outputTank.getNeeded());
|
|
|
|
possibleProcess = Math.min((int)Math.pow(2, upgradeComponent.getUpgrades(Upgrade.SPEED)), possibleProcess);
|
|
|
|
|
|
|
|
return Math.min(fluidTank.getFluidAmount()/WATER_USAGE, possibleProcess);
|
|
|
|
}
|
|
|
|
|
2014-01-28 22:19:07 +01:00
|
|
|
@Override
|
2014-06-02 16:52:13 +02:00
|
|
|
public void handlePacketData(ByteBuf dataStream)
|
2014-01-28 22:19:07 +01:00
|
|
|
{
|
2014-02-01 04:28:58 +01:00
|
|
|
if(!worldObj.isRemote)
|
|
|
|
{
|
|
|
|
int type = dataStream.readInt();
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-02-01 04:28:58 +01:00
|
|
|
if(type == 0)
|
|
|
|
{
|
|
|
|
inputTank.setGas(null);
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-02-01 04:28:58 +01:00
|
|
|
for(EntityPlayer player : playersUsing)
|
|
|
|
{
|
2014-06-11 11:57:49 +02:00
|
|
|
Mekanism.packetHandler.sendTo(new TileEntityMessage(Coord4D.get(this), getNetworkedData(new ArrayList())), (EntityPlayerMP)player);
|
2014-02-01 04:28:58 +01:00
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-02-01 04:28:58 +01:00
|
|
|
return;
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-01-28 22:19:07 +01:00
|
|
|
super.handlePacketData(dataStream);
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-01-28 22:19:07 +01:00
|
|
|
isActive = dataStream.readBoolean();
|
|
|
|
controlType = RedstoneControl.values()[dataStream.readInt()];
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-01-28 22:19:07 +01:00
|
|
|
if(dataStream.readBoolean())
|
|
|
|
{
|
|
|
|
fluidTank.setFluid(new FluidStack(FluidRegistry.getFluid(dataStream.readInt()), dataStream.readInt()));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
fluidTank.setFluid(null);
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-01-28 22:19:07 +01:00
|
|
|
if(dataStream.readBoolean())
|
|
|
|
{
|
|
|
|
inputTank.setGas(new GasStack(GasRegistry.getGas(dataStream.readInt()), dataStream.readInt()));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
inputTank.setGas(null);
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-01-28 22:19:07 +01:00
|
|
|
if(dataStream.readBoolean())
|
|
|
|
{
|
|
|
|
outputTank.setGas(new GasStack(GasRegistry.getGas(dataStream.readInt()), dataStream.readInt()));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
outputTank.setGas(null);
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
|
|
|
|
2014-01-28 22:19:07 +01:00
|
|
|
MekanismUtils.updateBlock(worldObj, xCoord, yCoord, zCoord);
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-01-28 22:19:07 +01:00
|
|
|
@Override
|
|
|
|
public ArrayList getNetworkedData(ArrayList data)
|
|
|
|
{
|
|
|
|
super.getNetworkedData(data);
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-01-28 22:19:07 +01:00
|
|
|
data.add(isActive);
|
|
|
|
data.add(controlType.ordinal());
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-01-28 22:19:07 +01:00
|
|
|
if(fluidTank.getFluid() != null)
|
|
|
|
{
|
|
|
|
data.add(true);
|
|
|
|
data.add(fluidTank.getFluid().getFluid().getID());
|
|
|
|
data.add(fluidTank.getFluidAmount());
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
data.add(false);
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-01-28 22:19:07 +01:00
|
|
|
if(inputTank.getGas() != null)
|
|
|
|
{
|
|
|
|
data.add(true);
|
|
|
|
data.add(inputTank.getGas().getGas().getID());
|
|
|
|
data.add(inputTank.getStored());
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
data.add(false);
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-01-28 22:19:07 +01:00
|
|
|
if(outputTank.getGas() != null)
|
|
|
|
{
|
|
|
|
data.add(true);
|
|
|
|
data.add(outputTank.getGas().getGas().getID());
|
|
|
|
data.add(outputTank.getStored());
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
data.add(false);
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-01-28 22:19:07 +01:00
|
|
|
return data;
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-01-28 22:19:07 +01:00
|
|
|
@Override
|
2014-03-08 02:00:25 +01:00
|
|
|
public void readFromNBT(NBTTagCompound nbtTags)
|
|
|
|
{
|
|
|
|
super.readFromNBT(nbtTags);
|
|
|
|
|
|
|
|
isActive = nbtTags.getBoolean("isActive");
|
|
|
|
controlType = RedstoneControl.values()[nbtTags.getInteger("controlType")];
|
|
|
|
|
|
|
|
fluidTank.readFromNBT(nbtTags.getCompoundTag("leftTank"));
|
|
|
|
inputTank.read(nbtTags.getCompoundTag("rightTank"));
|
|
|
|
outputTank.read(nbtTags.getCompoundTag("centerTank"));
|
|
|
|
}
|
2014-01-28 22:19:07 +01:00
|
|
|
|
|
|
|
@Override
|
2014-03-08 02:00:25 +01:00
|
|
|
public void writeToNBT(NBTTagCompound nbtTags)
|
|
|
|
{
|
|
|
|
super.writeToNBT(nbtTags);
|
|
|
|
|
|
|
|
nbtTags.setBoolean("isActive", isActive);
|
|
|
|
nbtTags.setInteger("controlType", controlType.ordinal());
|
|
|
|
|
2014-04-20 05:34:19 +02:00
|
|
|
nbtTags.setTag("leftTank", fluidTank.writeToNBT(new NBTTagCompound()));
|
|
|
|
nbtTags.setTag("rightTank", inputTank.write(new NBTTagCompound()));
|
|
|
|
nbtTags.setTag("centerTank", outputTank.write(new NBTTagCompound()));
|
2014-03-08 02:00:25 +01:00
|
|
|
}
|
|
|
|
|
2014-01-28 22:19:07 +01:00
|
|
|
@Override
|
|
|
|
public boolean canSetFacing(int i)
|
|
|
|
{
|
|
|
|
return i != 0 && i != 1;
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-01-28 22:19:07 +01:00
|
|
|
public GasTank getTank(ForgeDirection side)
|
|
|
|
{
|
|
|
|
if(side == MekanismUtils.getLeft(facing))
|
|
|
|
{
|
|
|
|
return inputTank;
|
|
|
|
}
|
|
|
|
else if(side == MekanismUtils.getRight(facing))
|
|
|
|
{
|
|
|
|
return outputTank;
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-01-28 22:19:07 +01:00
|
|
|
return null;
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-01-28 22:19:07 +01:00
|
|
|
public int getScaledFluidLevel(int i)
|
|
|
|
{
|
|
|
|
return fluidTank != null ? fluidTank.getFluidAmount()*i / MAX_FLUID : 0;
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-01-28 22:19:07 +01:00
|
|
|
public int getScaledInputGasLevel(int i)
|
|
|
|
{
|
|
|
|
return inputTank != null ? inputTank.getStored()*i / MAX_GAS : 0;
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-01-28 22:19:07 +01:00
|
|
|
public int getScaledOutputGasLevel(int i)
|
|
|
|
{
|
|
|
|
return outputTank != null ? outputTank.getStored()*i / MAX_GAS : 0;
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-01-28 22:19:07 +01:00
|
|
|
@Override
|
2014-03-08 02:00:25 +01:00
|
|
|
public void setActive(boolean active)
|
|
|
|
{
|
|
|
|
isActive = active;
|
|
|
|
|
|
|
|
if(clientActive != active && updateDelay == 0)
|
|
|
|
{
|
2014-08-08 04:48:35 +02:00
|
|
|
Mekanism.packetHandler.sendToReceivers(new TileEntityMessage(Coord4D.get(this), getNetworkedData(new ArrayList())), new Range4D(Coord4D.get(this)));
|
2014-03-08 02:00:25 +01:00
|
|
|
|
|
|
|
updateDelay = 10;
|
|
|
|
clientActive = active;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean getActive()
|
|
|
|
{
|
|
|
|
return isActive;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean renderUpdate()
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean lightUpdate()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2014-01-28 22:19:07 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean canTubeConnect(ForgeDirection side)
|
|
|
|
{
|
2014-01-29 01:29:29 +01:00
|
|
|
return side == MekanismUtils.getLeft(facing) || side == MekanismUtils.getRight(facing);
|
2014-01-28 22:19:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean canReceiveGas(ForgeDirection side, Gas type)
|
|
|
|
{
|
|
|
|
return getTank(side) != null && getTank(side) != outputTank ? getTank(side).canReceive(type) : false;
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-01-28 22:19:07 +01:00
|
|
|
@Override
|
2014-03-08 02:00:25 +01:00
|
|
|
public RedstoneControl getControlType()
|
2014-01-28 22:19:07 +01:00
|
|
|
{
|
|
|
|
return controlType;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-03-08 02:00:25 +01:00
|
|
|
public void setControlType(RedstoneControl type)
|
2014-01-28 22:19:07 +01:00
|
|
|
{
|
|
|
|
controlType = type;
|
|
|
|
MekanismUtils.saveChunk(this);
|
|
|
|
}
|
|
|
|
|
2014-09-16 03:26:29 +02:00
|
|
|
@Override
|
|
|
|
public boolean canPulse()
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-01-28 22:19:07 +01:00
|
|
|
@Override
|
2014-08-10 04:33:25 +02:00
|
|
|
public int receiveGas(ForgeDirection side, GasStack stack, boolean doTransfer)
|
2014-01-28 22:19:07 +01:00
|
|
|
{
|
|
|
|
if(canReceiveGas(side, stack != null ? stack.getGas() : null))
|
|
|
|
{
|
2014-08-10 04:33:25 +02:00
|
|
|
return getTank(side).receive(stack, doTransfer);
|
2014-01-28 22:19:07 +01:00
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-01-28 22:19:07 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-08-10 04:33:25 +02:00
|
|
|
public GasStack drawGas(ForgeDirection side, int amount, boolean doTransfer)
|
2014-01-28 22:19:07 +01:00
|
|
|
{
|
|
|
|
if(canDrawGas(side, null))
|
|
|
|
{
|
2014-08-10 04:33:25 +02:00
|
|
|
return getTank(side).draw(amount, doTransfer);
|
2014-01-28 22:19:07 +01:00
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-01-28 22:19:07 +01:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean canDrawGas(ForgeDirection side, Gas type)
|
|
|
|
{
|
|
|
|
return getTank(side) == outputTank ? getTank(side).canDraw(type) : false;
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-01-28 22:19:07 +01:00
|
|
|
@Override
|
|
|
|
public boolean isItemValidForSlot(int slotID, ItemStack itemstack)
|
|
|
|
{
|
|
|
|
if(slotID == 0)
|
|
|
|
{
|
|
|
|
return FluidContainerRegistry.getFluidForFilledItem(itemstack) != null && FluidContainerRegistry.getFluidForFilledItem(itemstack).getFluid() == FluidRegistry.WATER;
|
|
|
|
}
|
|
|
|
else if(slotID == 2)
|
|
|
|
{
|
|
|
|
return ChargeUtils.canBeDischarged(itemstack);
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-01-28 22:19:07 +01:00
|
|
|
return false;
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-01-28 22:19:07 +01:00
|
|
|
@Override
|
|
|
|
public boolean canExtractItem(int slotID, ItemStack itemstack, int side)
|
|
|
|
{
|
|
|
|
if(slotID == 1)
|
|
|
|
{
|
|
|
|
return itemstack != null && itemstack.getItem() instanceof IGasItem && ((IGasItem)itemstack.getItem()).canProvideGas(itemstack, null);
|
|
|
|
}
|
2014-01-29 01:29:29 +01:00
|
|
|
else if(slotID == 2)
|
|
|
|
{
|
|
|
|
return ChargeUtils.canBeOutputted(itemstack, false);
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-01-28 22:19:07 +01:00
|
|
|
return false;
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-01-28 22:19:07 +01:00
|
|
|
@Override
|
|
|
|
public int[] getAccessibleSlotsFromSide(int side)
|
|
|
|
{
|
|
|
|
if(side == MekanismUtils.getLeft(facing).ordinal())
|
|
|
|
{
|
|
|
|
return new int[] {0};
|
|
|
|
}
|
|
|
|
else if(side == MekanismUtils.getRight(facing).ordinal())
|
|
|
|
{
|
|
|
|
return new int[] {1};
|
|
|
|
}
|
|
|
|
else if(side == 0 || side == 1)
|
|
|
|
{
|
|
|
|
return new int[2];
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-01-28 22:19:07 +01:00
|
|
|
return InventoryUtils.EMPTY;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int fill(ForgeDirection from, FluidStack resource, boolean doFill)
|
|
|
|
{
|
|
|
|
if(canFill(from, resource.getFluid()))
|
|
|
|
{
|
|
|
|
return fluidTank.fill(resource, doFill);
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-01-28 22:19:07 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain)
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public FluidStack drain(ForgeDirection from, int maxDrain, boolean doDrain)
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean canFill(ForgeDirection from, Fluid fluid)
|
|
|
|
{
|
2014-01-28 22:49:49 +01:00
|
|
|
return from == ForgeDirection.UP && fluid == FluidRegistry.WATER;
|
2014-01-28 22:19:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean canDrain(ForgeDirection from, Fluid fluid)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public FluidTankInfo[] getTankInfo(ForgeDirection from)
|
|
|
|
{
|
2014-01-28 22:49:49 +01:00
|
|
|
if(from == ForgeDirection.UP)
|
|
|
|
{
|
|
|
|
return new FluidTankInfo[] {fluidTank.getInfo()};
|
|
|
|
}
|
2014-03-08 02:00:25 +01:00
|
|
|
|
2014-01-28 22:49:49 +01:00
|
|
|
return PipeUtils.EMPTY;
|
2014-01-28 22:19:07 +01:00
|
|
|
}
|
2014-07-27 00:44:24 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void writeSustainedData(ItemStack itemStack)
|
|
|
|
{
|
|
|
|
if(fluidTank.getFluid() != null)
|
|
|
|
{
|
|
|
|
itemStack.stackTagCompound.setTag("fluidTank", fluidTank.getFluid().writeToNBT(new NBTTagCompound()));
|
|
|
|
}
|
|
|
|
|
|
|
|
if(inputTank.getGas() != null)
|
|
|
|
{
|
|
|
|
itemStack.stackTagCompound.setTag("inputTank", inputTank.getGas().write(new NBTTagCompound()));
|
|
|
|
}
|
|
|
|
|
|
|
|
if(outputTank.getGas() != null)
|
|
|
|
{
|
|
|
|
itemStack.stackTagCompound.setTag("outputTank", outputTank.getGas().write(new NBTTagCompound()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void readSustainedData(ItemStack itemStack)
|
|
|
|
{
|
|
|
|
fluidTank.setFluid(FluidStack.loadFluidStackFromNBT(itemStack.stackTagCompound.getCompoundTag("fluidTank")));
|
|
|
|
inputTank.setGas(GasStack.readFromNBT(itemStack.stackTagCompound.getCompoundTag("inputTank")));
|
|
|
|
outputTank.setGas(GasStack.readFromNBT(itemStack.stackTagCompound.getCompoundTag("outputTank")));
|
|
|
|
}
|
2015-02-18 03:27:35 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public TileComponentUpgrade getComponent()
|
|
|
|
{
|
|
|
|
return upgradeComponent;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void recalculateUpgradables(Upgrade upgrade)
|
|
|
|
{
|
|
|
|
super.recalculateUpgradables(upgrade);
|
|
|
|
|
|
|
|
switch(upgrade)
|
|
|
|
{
|
|
|
|
case ENERGY:
|
|
|
|
energyUsage = MekanismUtils.getEnergyPerTick(this, BASE_ENERGY_USAGE);
|
|
|
|
maxEnergy = MekanismUtils.getMaxEnergy(this, BASE_MAX_ENERGY);
|
|
|
|
}
|
|
|
|
}
|
2014-01-26 23:12:03 +01:00
|
|
|
}
|