content: package thebetweenlands.common.tile;
  
  import net.minecraft.block.state.IBlockState;
  import net.minecraft.nbt.NBTTagCompound;
  import net.minecraft.network.NetworkManager;
  import net.minecraft.network.play.server.SPacketUpdateTileEntity;
  import net.minecraft.tileentity.TileEntity;
  import net.minecraft.util.EnumFacing;
  import net.minecraft.util.math.BlockPos;
  import net.minecraft.world.World;
  import net.minecraftforge.common.capabilities.Capability;
  import net.minecraftforge.fluids.Fluid;
  import net.minecraftforge.fluids.capability.CapabilityFluidHandler;
  
  public class TileEntityFilteredSiltGlassJar extends TileEntity {
      public FluidTankTile tank;
  
  	public TileEntityFilteredSiltGlassJar() {
          this.tank = new FluidTankTile(null, Fluid.BUCKET_VOLUME * 4);
          this.tank.setTileEntity(this);
  	}
  
  	@Override
  	public boolean shouldRefresh(World world, BlockPos pos, IBlockState oldState, IBlockState newState) {
  		return oldState.getBlock() != newState.getBlock();
  	}
  
  	public int getTankFluidAmount() {
  		return tank.getFluidAmount();
  	}
  
  	public int getScaledFluid(int scale) {
  		return tank.getFluid() != null ? (int) ((float) tank.getFluidAmount() / (float) tank.getCapacity() * scale) : 0;
  	}
  
      public void markForUpdate() {
          IBlockState state = this.getWorld().getBlockState(this.getPos());
          this.getWorld().notifyBlockUpdate(this.getPos(), state, state, 3);
      }
  
      @Override
      public void onDataPacket(NetworkManager net, SPacketUpdateTileEntity packet) {
          this.readPacketNbt(packet.getNbtCompound());
      }
  
      @Override
      public SPacketUpdateTileEntity getUpdatePacket() {
          NBTTagCompound nbt = new NBTTagCompound();
          this.writePacketNbt(nbt);
          return new SPacketUpdateTileEntity(pos, 0, nbt);
      }
  
  	@Override
      public NBTTagCompound getUpdateTag() {
  		NBTTagCompound tag = super.getUpdateTag();
          this.writePacketNbt(tag);
          return tag;
      }
  
      @Override
      public void handleUpdateTag(NBTTagCompound nbt) {
          super.handleUpdateTag(nbt);
          this.readPacketNbt(nbt);
      }
  
      protected NBTTagCompound writePacketNbt(NBTTagCompound nbt) {
          nbt.setTag("tank", tank.writeToNBT(new NBTTagCompound()));
          return nbt;
      }
  
      protected void readPacketNbt(NBTTagCompound nbt) {
          NBTTagCompound compound = nbt;
          tank.readFromNBT(compound.getCompoundTag("tank"));
      }
  
  	@Override
  	public void readFromNBT(NBTTagCompound tagCompound) {
  		super.readFromNBT(tagCompound);
  		tank.readFromNBT(tagCompound);
  	}
  
  	@Override
  	public NBTTagCompound writeToNBT(NBTTagCompound tagCompound) {
  		super.writeToNBT(tagCompound);
  		tank.writeToNBT(tagCompound);
  		return tagCompound;
  	}
  
  	@Override
  	public boolean hasCapability(Capability<?> capability, EnumFacing facing) {
  		return capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY || super.hasCapability(capability, facing);
  	}
  
  	@SuppressWarnings("unchecked")
  	@Override
  	public <T> T getCapability(Capability<T> capability, EnumFacing facing) {
  		if (capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY)
  			return (T) tank;
  		return super.getCapability(capability, facing);
  	}
  }
  