TechReborn/src/main/java/techreborn/tiles/TileQuantumTank.java

141 lines
4.1 KiB
Java
Raw Normal View History

2015-04-11 11:37:47 +02:00
package techreborn.tiles;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.NetworkManager;
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;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.fluids.capability.CapabilityFluidHandler;
2015-11-08 13:15:45 +01:00
import reborncore.api.IListInfoProvider;
import reborncore.api.tile.IInventoryProvider;
2016-10-08 21:46:16 +02:00
import reborncore.common.IWrenchable;
2016-11-04 21:03:05 +01:00
import reborncore.common.tile.TileLegacyMachineBase;
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;
import java.util.List;
2015-04-11 11:37:47 +02:00
2016-11-04 21:03:05 +01:00
public class TileQuantumTank extends TileLegacyMachineBase
implements 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
2016-10-08 21:46:16 +02:00
public void readFromNBT(NBTTagCompound tagCompound) {
2016-03-25 10:47:34 +01:00
super.readFromNBT(tagCompound);
readFromNBTWithoutCoords(tagCompound);
}
2016-10-08 21:46:16 +02:00
public void readFromNBTWithoutCoords(NBTTagCompound tagCompound) {
2016-03-25 10:47:34 +01:00
tank.readFromNBT(tagCompound);
}
@Override
2016-10-08 21:46:16 +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-10-08 21:46:16 +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
2016-10-08 21:46:16 +02:00
public void onDataPacket(NetworkManager net, SPacketUpdateTileEntity packet) {
2016-11-19 13:50:08 +01:00
world.markBlockRangeForRenderUpdate(getPos().getX(), getPos().getY(), getPos().getZ(), getPos().getX(),
2016-10-08 21:46:16 +02:00
getPos().getY(), getPos().getZ());
2016-03-25 10:47:34 +01:00
readFromNBT(packet.getNbtCompound());
}
@Override
2016-10-08 21:46:16 +02:00
public void updateEntity() {
super.updateEntity();
2016-11-19 13:50:08 +01:00
if (!world.isRemote) {
FluidUtils.drainContainers(tank, inventory, 0, 1);
FluidUtils.fillContainers(tank, inventory, 0, 1, tank.getFluidType());
if (tank.getFluidType() != null && getStackInSlot(2) == ItemStack.EMPTY) {
2016-10-08 21:46:16 +02:00
// inventory.setInventorySlotContents(2, new ItemStack(tank.getFluidType().getBlock()));
} else if (tank.getFluidType() == null && getStackInSlot(2) != ItemStack.EMPTY) {
setInventorySlotContents(2, ItemStack.EMPTY);
2016-03-25 10:47:34 +01:00
}
tank.compareAndUpdate();
}
}
@Override
public boolean hasCapability(Capability<?> capability, EnumFacing facing) {
if(capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY){
return true;
}
return super.hasCapability(capability, facing);
2016-03-25 10:47:34 +01:00
}
@Override
public <T> T getCapability(Capability<T> capability, EnumFacing facing) {
if(capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY){
return (T) tank;
}
return super.getCapability(capability, facing);
2016-03-25 10:47:34 +01:00
}
@Override
2016-10-08 21:46:16 +02:00
public boolean wrenchCanSetFacing(EntityPlayer entityPlayer, EnumFacing side) {
2016-03-25 10:47:34 +01:00
return false;
}
@Override
2016-10-08 21:46:16 +02:00
public EnumFacing getFacing() {
2016-03-25 10:47:34 +01:00
return getFacingEnum();
}
@Override
2016-10-08 21:46:16 +02:00
public boolean wrenchCanRemove(EntityPlayer entityPlayer) {
return entityPlayer.isSneaking();
2016-03-25 10:47:34 +01:00
}
@Override
2016-10-08 21:46:16 +02:00
public float getWrenchDropRate() {
2016-03-25 10:47:34 +01:00
return 1F;
}
@Override
2016-10-08 21:46:16 +02:00
public ItemStack getWrenchDrop(EntityPlayer entityPlayer) {
2016-03-25 10:47:34 +01:00
return getDropWithNBT();
}
2016-10-08 21:46:16 +02:00
public ItemStack getDropWithNBT() {
2016-03-25 10:47:34 +01:00
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
2016-10-08 21:46:16 +02:00
public void addInfo(List<String> info, boolean isRealTile) {
if (isRealTile) {
if (tank.getFluid() != null) {
2016-03-25 10:47:34 +01:00
info.add(tank.getFluidAmount() + " of " + tank.getFluidType().getName());
2016-10-08 21:46:16 +02:00
} else {
2016-03-25 10:47:34 +01:00
info.add("Empty");
}
}
info.add("Capacity " + tank.getCapacity() + " mb");
}
@Override
public Inventory getInventory() {
return inventory;
}
2015-04-11 11:37:47 +02:00
}