2015-04-11 11:37:47 +02:00
|
|
|
package techreborn.tiles;
|
|
|
|
|
2016-05-12 20:16:40 +02:00
|
|
|
import reborncore.common.IWrenchable;
|
2015-04-11 11:37:47 +02:00
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
|
|
|
import net.minecraft.network.NetworkManager;
|
|
|
|
import net.minecraft.network.Packet;
|
2016-03-13 17:08:30 +01:00
|
|
|
import net.minecraft.network.play.server.SPacketUpdateTileEntity;
|
2015-11-23 15:45:16 +01:00
|
|
|
import net.minecraft.util.EnumFacing;
|
2015-04-11 12:30:16 +02:00
|
|
|
import net.minecraftforge.fluids.Fluid;
|
|
|
|
import net.minecraftforge.fluids.FluidStack;
|
|
|
|
import net.minecraftforge.fluids.FluidTankInfo;
|
|
|
|
import net.minecraftforge.fluids.IFluidHandler;
|
2015-11-08 13:15:45 +01:00
|
|
|
import reborncore.api.IListInfoProvider;
|
2016-04-11 18:43:54 +02:00
|
|
|
import reborncore.api.tile.IInventoryProvider;
|
2016-02-20 17:59:31 +01:00
|
|
|
import reborncore.common.tile.TileMachineBase;
|
2015-11-08 13:15:45 +01:00
|
|
|
import reborncore.common.util.FluidUtils;
|
|
|
|
import reborncore.common.util.Inventory;
|
|
|
|
import reborncore.common.util.Tank;
|
2015-04-11 19:14:57 +02:00
|
|
|
import techreborn.init.ModBlocks;
|
2016-04-11 18:50:00 +02:00
|
|
|
|
|
|
|
import java.util.List;
|
2015-04-11 11:37:47 +02:00
|
|
|
|
2016-03-25 10:47:34 +01:00
|
|
|
public class TileQuantumTank extends TileMachineBase
|
2016-04-11 18:43:54 +02:00
|
|
|
implements IFluidHandler,IInventoryProvider, IWrenchable, IListInfoProvider
|
2016-03-25 10:47:34 +01:00
|
|
|
{
|
|
|
|
|
|
|
|
public Tank tank = new Tank("TileQuantumTank", Integer.MAX_VALUE, this);
|
|
|
|
public Inventory inventory = new Inventory(3, "TileQuantumTank", 64, this);
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void readFromNBT(NBTTagCompound tagCompound)
|
|
|
|
{
|
|
|
|
super.readFromNBT(tagCompound);
|
|
|
|
readFromNBTWithoutCoords(tagCompound);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void readFromNBTWithoutCoords(NBTTagCompound tagCompound)
|
|
|
|
{
|
|
|
|
tank.readFromNBT(tagCompound);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-05-18 17:53:54 +02:00
|
|
|
public NBTTagCompound writeToNBT(NBTTagCompound tagCompound)
|
2016-03-25 10:47:34 +01:00
|
|
|
{
|
|
|
|
super.writeToNBT(tagCompound);
|
|
|
|
writeToNBTWithoutCoords(tagCompound);
|
2016-05-18 17:53:54 +02:00
|
|
|
return tagCompound;
|
2016-03-25 10:47:34 +01:00
|
|
|
}
|
|
|
|
|
2016-05-18 17:53:54 +02:00
|
|
|
public NBTTagCompound writeToNBTWithoutCoords(NBTTagCompound tagCompound)
|
2016-03-25 10:47:34 +01:00
|
|
|
{
|
|
|
|
tank.writeToNBT(tagCompound);
|
2016-05-18 17:53:54 +02:00
|
|
|
return tagCompound;
|
2016-03-25 10:47:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onDataPacket(NetworkManager net, SPacketUpdateTileEntity packet)
|
|
|
|
{
|
|
|
|
worldObj.markBlockRangeForRenderUpdate(getPos().getX(), getPos().getY(), getPos().getZ(), getPos().getX(),
|
|
|
|
getPos().getY(), getPos().getZ());
|
|
|
|
readFromNBT(packet.getNbtCompound());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void updateEntity()
|
|
|
|
{
|
|
|
|
super.updateEntity();
|
|
|
|
if (!worldObj.isRemote)
|
|
|
|
{
|
|
|
|
FluidUtils.drainContainers(this, inventory, 0, 1);
|
|
|
|
FluidUtils.fillContainers(this, inventory, 0, 1, tank.getFluidType());
|
|
|
|
if (tank.getFluidType() != null && getStackInSlot(2) == null)
|
|
|
|
{
|
2016-03-27 20:05:05 +02:00
|
|
|
// inventory.setInventorySlotContents(2, new ItemStack(tank.getFluidType().getBlock()));
|
2016-03-25 10:47:34 +01:00
|
|
|
} else if (tank.getFluidType() == null && getStackInSlot(2) != null)
|
|
|
|
{
|
|
|
|
setInventorySlotContents(2, null);
|
|
|
|
}
|
|
|
|
tank.compareAndUpdate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// IFluidHandler
|
|
|
|
@Override
|
|
|
|
public int fill(EnumFacing from, FluidStack resource, boolean doFill)
|
|
|
|
{
|
|
|
|
int fill = tank.fill(resource, doFill);
|
|
|
|
tank.compareAndUpdate();
|
|
|
|
return fill;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public FluidStack drain(EnumFacing from, FluidStack resource, boolean doDrain)
|
|
|
|
{
|
|
|
|
FluidStack drain = tank.drain(resource.amount, doDrain);
|
|
|
|
tank.compareAndUpdate();
|
|
|
|
return drain;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public FluidStack drain(EnumFacing from, int maxDrain, boolean doDrain)
|
|
|
|
{
|
|
|
|
FluidStack drain = tank.drain(maxDrain, doDrain);
|
|
|
|
tank.compareAndUpdate();
|
|
|
|
return drain;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean canFill(EnumFacing from, Fluid fluid)
|
|
|
|
{
|
|
|
|
return tank.getFluid() == null || tank.getFluid().getFluid() == fluid;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean canDrain(EnumFacing from, Fluid fluid)
|
|
|
|
{
|
|
|
|
return tank.getFluid() == null || tank.getFluid().getFluid() == fluid;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public FluidTankInfo[] getTankInfo(EnumFacing from)
|
|
|
|
{
|
|
|
|
return new FluidTankInfo[] { tank.getInfo() };
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean wrenchCanSetFacing(EntityPlayer entityPlayer, EnumFacing side)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public EnumFacing getFacing()
|
|
|
|
{
|
|
|
|
return getFacingEnum();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean wrenchCanRemove(EntityPlayer entityPlayer)
|
|
|
|
{
|
2016-04-03 15:34:39 +02:00
|
|
|
return entityPlayer.isSneaking();
|
2016-03-25 10:47:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public float getWrenchDropRate()
|
|
|
|
{
|
|
|
|
return 1F;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ItemStack getWrenchDrop(EntityPlayer entityPlayer)
|
|
|
|
{
|
|
|
|
return getDropWithNBT();
|
|
|
|
}
|
|
|
|
|
|
|
|
public ItemStack getDropWithNBT()
|
|
|
|
{
|
|
|
|
NBTTagCompound tileEntity = new NBTTagCompound();
|
|
|
|
ItemStack dropStack = new ItemStack(ModBlocks.quantumTank, 1);
|
|
|
|
writeToNBTWithoutCoords(tileEntity);
|
|
|
|
dropStack.setTagCompound(new NBTTagCompound());
|
|
|
|
dropStack.getTagCompound().setTag("tileEntity", tileEntity);
|
|
|
|
return dropStack;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void addInfo(List<String> info, boolean isRealTile)
|
|
|
|
{
|
|
|
|
if (isRealTile)
|
|
|
|
{
|
|
|
|
if (tank.getFluid() != null)
|
|
|
|
{
|
|
|
|
info.add(tank.getFluidAmount() + " of " + tank.getFluidType().getName());
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
info.add("Empty");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
info.add("Capacity " + tank.getCapacity() + " mb");
|
|
|
|
|
|
|
|
}
|
2016-04-11 18:43:54 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public Inventory getInventory() {
|
|
|
|
return inventory;
|
|
|
|
}
|
2015-04-11 11:37:47 +02:00
|
|
|
}
|