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;
|
2016-11-19 15:41:00 +01:00
|
|
|
import net.minecraftforge.common.capabilities.Capability;
|
|
|
|
import net.minecraftforge.fluids.capability.CapabilityFluidHandler;
|
2017-01-08 20:34:46 +01:00
|
|
|
|
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-10-08 21:46:16 +02:00
|
|
|
import reborncore.common.IWrenchable;
|
2016-11-04 21:03:05 +01:00
|
|
|
import reborncore.common.tile.TileLegacyMachineBase;
|
2015-11-08 13:15:45 +01:00
|
|
|
import reborncore.common.util.FluidUtils;
|
|
|
|
import reborncore.common.util.Inventory;
|
|
|
|
import reborncore.common.util.Tank;
|
2017-01-08 20:34:46 +01:00
|
|
|
|
|
|
|
import techreborn.client.container.IContainerProvider;
|
|
|
|
import techreborn.client.container.builder.BuiltContainer;
|
|
|
|
import techreborn.client.container.builder.ContainerBuilder;
|
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-11-04 21:03:05 +01:00
|
|
|
public class TileQuantumTank extends TileLegacyMachineBase
|
2017-01-08 20:34:46 +01:00
|
|
|
implements IInventoryProvider, IWrenchable, IListInfoProvider, IContainerProvider {
|
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
|
2017-01-08 20:34:46 +01:00
|
|
|
public void readFromNBT(final NBTTagCompound tagCompound) {
|
2016-03-25 10:47:34 +01:00
|
|
|
super.readFromNBT(tagCompound);
|
2017-01-08 20:34:46 +01:00
|
|
|
this.readFromNBTWithoutCoords(tagCompound);
|
2016-03-25 10:47:34 +01:00
|
|
|
}
|
|
|
|
|
2017-01-08 20:34:46 +01:00
|
|
|
public void readFromNBTWithoutCoords(final NBTTagCompound tagCompound) {
|
|
|
|
this.tank.readFromNBT(tagCompound);
|
2016-03-25 10:47:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-01-08 20:34:46 +01:00
|
|
|
public NBTTagCompound writeToNBT(final NBTTagCompound tagCompound) {
|
2016-03-25 10:47:34 +01:00
|
|
|
super.writeToNBT(tagCompound);
|
2017-01-08 20:34:46 +01:00
|
|
|
this.writeToNBTWithoutCoords(tagCompound);
|
2016-05-18 17:53:54 +02:00
|
|
|
return tagCompound;
|
2016-03-25 10:47:34 +01:00
|
|
|
}
|
|
|
|
|
2017-01-08 20:34:46 +01:00
|
|
|
public NBTTagCompound writeToNBTWithoutCoords(final NBTTagCompound tagCompound) {
|
|
|
|
this.tank.writeToNBT(tagCompound);
|
2016-05-18 17:53:54 +02:00
|
|
|
return tagCompound;
|
2016-03-25 10:47:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-01-08 20:34:46 +01:00
|
|
|
public void onDataPacket(final NetworkManager net, final SPacketUpdateTileEntity packet) {
|
|
|
|
this.world.markBlockRangeForRenderUpdate(this.getPos().getX(), this.getPos().getY(), this.getPos().getZ(),
|
|
|
|
this.getPos().getX(), this.getPos().getY(), this.getPos().getZ());
|
|
|
|
this.readFromNBT(packet.getNbtCompound());
|
2016-03-25 10:47:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-10-08 21:46:16 +02:00
|
|
|
public void updateEntity() {
|
2016-08-10 01:45:07 +02:00
|
|
|
super.updateEntity();
|
2017-01-08 20:34:46 +01:00
|
|
|
if (!this.world.isRemote) {
|
|
|
|
if (FluidUtils.drainContainers(this.tank, this.inventory, 0, 1)
|
|
|
|
|| FluidUtils.fillContainers(this.tank, this.inventory, 0, 1, this.tank.getFluidType()))
|
2016-12-16 15:11:46 +01:00
|
|
|
this.syncWithAll();
|
|
|
|
|
2017-01-08 20:34:46 +01:00
|
|
|
if (this.tank.getFluidType() != null && this.getStackInSlot(2) == ItemStack.EMPTY) {
|
|
|
|
this.inventory.setInventorySlotContents(2, new ItemStack(this.tank.getFluidType().getBlock()));
|
|
|
|
} else if (this.tank.getFluidType() == null && this.getStackInSlot(2) != ItemStack.EMPTY) {
|
|
|
|
this.setInventorySlotContents(2, ItemStack.EMPTY);
|
2016-03-25 10:47:34 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-01-08 20:34:46 +01:00
|
|
|
public boolean hasCapability(final Capability<?> capability, final EnumFacing facing) {
|
2016-11-25 14:25:51 +01:00
|
|
|
if (capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY) {
|
2016-11-19 15:41:00 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return super.hasCapability(capability, facing);
|
2016-03-25 10:47:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-01-08 20:34:46 +01:00
|
|
|
public <T> T getCapability(final Capability<T> capability, final EnumFacing facing) {
|
2016-11-25 14:25:51 +01:00
|
|
|
if (capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY) {
|
2017-01-08 20:34:46 +01:00
|
|
|
return (T) this.tank;
|
2016-11-19 15:41:00 +01:00
|
|
|
}
|
|
|
|
return super.getCapability(capability, facing);
|
2016-03-25 10:47:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-01-08 20:34:46 +01:00
|
|
|
public boolean wrenchCanSetFacing(final EntityPlayer entityPlayer, final EnumFacing side) {
|
2016-03-25 10:47:34 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-10-08 21:46:16 +02:00
|
|
|
public EnumFacing getFacing() {
|
2017-01-08 20:34:46 +01:00
|
|
|
return this.getFacingEnum();
|
2016-03-25 10:47:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-01-08 20:34:46 +01:00
|
|
|
public boolean wrenchCanRemove(final EntityPlayer entityPlayer) {
|
2016-04-03 15:34:39 +02:00
|
|
|
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
|
2017-01-08 20:34:46 +01:00
|
|
|
public ItemStack getWrenchDrop(final EntityPlayer entityPlayer) {
|
|
|
|
return this.getDropWithNBT();
|
2016-03-25 10:47:34 +01:00
|
|
|
}
|
|
|
|
|
2016-10-08 21:46:16 +02:00
|
|
|
public ItemStack getDropWithNBT() {
|
2017-01-08 20:34:46 +01:00
|
|
|
final NBTTagCompound tileEntity = new NBTTagCompound();
|
|
|
|
final ItemStack dropStack = new ItemStack(ModBlocks.QUANTUM_TANK, 1);
|
|
|
|
this.writeToNBTWithoutCoords(tileEntity);
|
2016-03-25 10:47:34 +01:00
|
|
|
dropStack.setTagCompound(new NBTTagCompound());
|
|
|
|
dropStack.getTagCompound().setTag("tileEntity", tileEntity);
|
|
|
|
return dropStack;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-01-08 20:34:46 +01:00
|
|
|
public void addInfo(final List<String> info, final boolean isRealTile) {
|
2016-10-08 21:46:16 +02:00
|
|
|
if (isRealTile) {
|
2017-01-08 20:34:46 +01:00
|
|
|
if (this.tank.getFluid() != null) {
|
|
|
|
info.add(this.tank.getFluidAmount() + " of " + this.tank.getFluidType().getName());
|
2016-10-08 21:46:16 +02:00
|
|
|
} else {
|
2016-03-25 10:47:34 +01:00
|
|
|
info.add("Empty");
|
|
|
|
}
|
|
|
|
}
|
2017-01-08 20:34:46 +01:00
|
|
|
info.add("Capacity " + this.tank.getCapacity() + " mb");
|
2016-03-25 10:47:34 +01:00
|
|
|
|
|
|
|
}
|
2016-04-11 18:43:54 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public Inventory getInventory() {
|
2017-01-08 20:34:46 +01:00
|
|
|
return this.inventory;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public BuiltContainer createContainer(final EntityPlayer player) {
|
|
|
|
return new ContainerBuilder("quantumtank").player(player.inventory).inventory(8, 84).hotbar(8, 142)
|
|
|
|
.addInventory().tile(this).fluidSlot(0, 80, 17).outputSlot(1, 80, 53).fakeSlot(2, 59, 42).addInventory()
|
|
|
|
.create();
|
2016-04-11 18:43:54 +02:00
|
|
|
}
|
2015-04-11 11:37:47 +02:00
|
|
|
}
|