2015-04-11 11:37:47 +02:00
|
|
|
package techreborn.tiles;
|
|
|
|
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
import net.minecraft.inventory.IInventory;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
|
|
|
import net.minecraft.network.NetworkManager;
|
|
|
|
import net.minecraft.network.Packet;
|
|
|
|
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
|
|
|
|
import net.minecraft.tileentity.TileEntity;
|
|
|
|
import net.minecraftforge.common.util.ForgeDirection;
|
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-04-11 11:37:47 +02:00
|
|
|
import techreborn.util.FluidUtils;
|
|
|
|
import techreborn.util.Inventory;
|
|
|
|
import techreborn.util.Tank;
|
|
|
|
|
|
|
|
public class TileQuantumTank extends TileEntity implements IFluidHandler, IInventory {
|
|
|
|
|
2015-04-11 12:53:27 +02:00
|
|
|
public Tank tank = new Tank("TileQuantumTank", Integer.MAX_VALUE, this);
|
2015-04-11 11:37:47 +02:00
|
|
|
public Inventory inventory = new Inventory(3, "TileQuantumTank", 64);
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void readFromNBT(NBTTagCompound tagCompound) {
|
|
|
|
super.readFromNBT(tagCompound);
|
|
|
|
tank.readFromNBT(tagCompound);
|
|
|
|
inventory.readFromNBT(tagCompound);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void writeToNBT(NBTTagCompound tagCompound) {
|
|
|
|
super.writeToNBT(tagCompound);
|
|
|
|
tank.writeToNBT(tagCompound);
|
|
|
|
inventory.writeToNBT(tagCompound);
|
|
|
|
}
|
|
|
|
|
|
|
|
public Packet getDescriptionPacket() {
|
|
|
|
NBTTagCompound nbtTag = new NBTTagCompound();
|
|
|
|
writeToNBT(nbtTag);
|
|
|
|
return new S35PacketUpdateTileEntity(this.xCoord, this.yCoord, this.zCoord, 1, nbtTag);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity packet) {
|
|
|
|
worldObj.markBlockRangeForRenderUpdate(xCoord, yCoord, zCoord, xCoord, yCoord, zCoord);
|
|
|
|
readFromNBT(packet.func_148857_g());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void updateEntity() {
|
|
|
|
super.updateEntity();
|
|
|
|
FluidUtils.drainContainers(this, inventory, 0, 1);
|
|
|
|
FluidUtils.fillContainers(this, inventory, 0, 1, tank.getFluidType());
|
|
|
|
if(tank.getFluidType() != null && getStackInSlot(2) == null){
|
|
|
|
inventory.setInventorySlotContents(2, new ItemStack(tank.getFluidType().getBlock()));
|
|
|
|
} else if(tank.getFluidType() == null && getStackInSlot(2) != null){
|
|
|
|
setInventorySlotContents(2, null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//IFluidHandler
|
|
|
|
@Override
|
|
|
|
public int fill(ForgeDirection from, FluidStack resource, boolean doFill) {
|
|
|
|
return tank.fill(resource, doFill);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain) {
|
|
|
|
return tank.drain(resource.amount, doDrain);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public FluidStack drain(ForgeDirection from, int maxDrain, boolean doDrain) {
|
|
|
|
return tank.drain(maxDrain, doDrain);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean canFill(ForgeDirection from, Fluid fluid) {
|
|
|
|
return tank.getFluid() == null || tank.getFluid().getFluid() == fluid;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean canDrain(ForgeDirection from, Fluid fluid) {
|
|
|
|
return tank.getFluid() == null || tank.getFluid().getFluid() == fluid;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public FluidTankInfo[] getTankInfo(ForgeDirection from) {
|
|
|
|
return getTankInfo(from);
|
|
|
|
}
|
|
|
|
|
|
|
|
//IInventory
|
|
|
|
@Override
|
|
|
|
public int getSizeInventory() {
|
|
|
|
return inventory.getSizeInventory();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ItemStack getStackInSlot(int slot) {
|
|
|
|
return inventory.getStackInSlot(slot);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ItemStack decrStackSize(int slotId, int count) {
|
|
|
|
return inventory.decrStackSize(slotId, count);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ItemStack getStackInSlotOnClosing(int slot) {
|
|
|
|
return inventory.getStackInSlotOnClosing(slot);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setInventorySlotContents(int slot, ItemStack stack) {
|
|
|
|
inventory.setInventorySlotContents(slot, stack);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getInventoryName() {
|
|
|
|
return inventory.getInventoryName();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean hasCustomInventoryName() {
|
|
|
|
return inventory.hasCustomInventoryName();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getInventoryStackLimit() {
|
|
|
|
return inventory.getInventoryStackLimit();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isUseableByPlayer(EntityPlayer player) {
|
|
|
|
return inventory.isUseableByPlayer(player);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void openInventory() {
|
|
|
|
inventory.openInventory();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void closeInventory() {
|
|
|
|
inventory.closeInventory();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isItemValidForSlot(int slot, ItemStack stack) {
|
|
|
|
return inventory.isItemValidForSlot(slot, stack);
|
|
|
|
}
|
|
|
|
}
|