package powercrystals.minefactoryreloaded.tile.machine;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.liquids.ILiquidTank;
import net.minecraftforge.liquids.ITankContainer;
import net.minecraftforge.liquids.LiquidContainerRegistry;
import net.minecraftforge.liquids.LiquidDictionary;
import net.minecraftforge.liquids.LiquidStack;
import net.minecraftforge.liquids.LiquidTank;
import powercrystals.minefactoryreloaded.MineFactoryReloadedCore;
import powercrystals.minefactoryreloaded.gui.client.GuiFactoryInventory;
import powercrystals.minefactoryreloaded.gui.client.GuiFactoryPowered;
import powercrystals.minefactoryreloaded.gui.container.ContainerFactoryPowered;
import powercrystals.minefactoryreloaded.setup.Machine;
import powercrystals.minefactoryreloaded.tile.base.TileEntityFactoryPowered;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public class TileEntityMeatPacker extends TileEntityFactoryPowered implements ITankContainer
{
private LiquidTank _tank;
public TileEntityMeatPacker()
{
super(Machine.MeatPacker);
_tank = new LiquidTank(4 * LiquidContainerRegistry.BUCKET_VOLUME);
}
@Override
public int getSizeInventory()
{
return 0;
}
@Override
public String getGuiBackground()
{
return "meatpacker.png";
}
@Override
@SideOnly(Side.CLIENT)
public GuiFactoryInventory getGui(InventoryPlayer inventoryPlayer)
{
return new GuiFactoryPowered(getContainer(inventoryPlayer), this);
}
@Override
public ContainerFactoryPowered getContainer(InventoryPlayer inventoryPlayer)
{
return new ContainerFactoryPowered(this, inventoryPlayer);
}
@Override
protected boolean activateMachine()
{
if(_tank.getLiquid() != null && _tank.getLiquid().amount >= 2)
{
setWorkDone(getWorkDone() + 1);
if(getWorkDone() >= getWorkMax())
{
ItemStack item;
if(_tank.getLiquid().itemID == LiquidDictionary.getCanonicalLiquid("meat").itemID)
{
item = new ItemStack(MineFactoryReloadedCore.meatIngotRawItem);
}
else
{
item = new ItemStack(MineFactoryReloadedCore.meatNuggetRawItem);
}
doDrop(item);
setWorkDone(0);
}
_tank.drain(2, true);
return true;
}
return false;
}
@Override
public int getEnergyStoredMax()
{
return 16000;
}
@Override
public int getWorkMax()
{
return 50;
}
@Override
public int getIdleTicksMax()
{
return 0;
}
@Override
public boolean allowBucketFill()
{
return true;
}
@Override
public int fill(ForgeDirection from, LiquidStack resource, boolean doFill)
{
if(resource == null || (resource.itemID != LiquidDictionary.getCanonicalLiquid("meat").itemID && resource.itemID != LiquidDictionary.getCanonicalLiquid("pinkslime").itemID))
{
return 0;
}
else
{
if(_tank.getLiquid() != null && _tank.getLiquid().amount == 1)
{
_tank.drain(1, true);
}
return _tank.fill(resource, doFill);
}
}
@Override
public ILiquidTank getTank()
{
return _tank;
}
@Override
public int fill(int tankIndex, LiquidStack resource, boolean doFill)
{
return fill(ForgeDirection.UNKNOWN, resource, doFill);
}
@Override
public LiquidStack drain(ForgeDirection from, int maxDrain, boolean doDrain)
{
return null;
}
@Override
public LiquidStack drain(int tankIndex, int maxDrain, boolean doDrain)
{
return null;
}
@Override
public ILiquidTank[] getTanks(ForgeDirection direction)
{
return new ILiquidTank[] { _tank };
}
@Override
public ILiquidTank getTank(ForgeDirection direction, LiquidStack type)
{
if(type != null && type.itemID == LiquidDictionary.getCanonicalLiquid("sewage").itemID)
{
return _tank;
}
return null;
}
@Override
public boolean manageSolids()
{
return true;
}
}