@Override
	public void onInventoryChanged()
	{
		if (!internalChange)
			onFactoryInventoryChanged();
		super.onInventoryChanged();
	}
	@Override
	public void updateEntity()
	{
		super.updateEntity();
		
		if(!worldObj.isRemote && shouldPumpLiquid())
		{
			for (IFluidTank tank : getTanks())
				MFRLiquidMover.pumpLiquid(tank, this);
		}
		
		if (failedDrops != null)
		{
			if (_failedDropTicks < _failedDropTicksMax)
			{
				_failedDropTicks++;
				return;
			}
			_failedDropTicks = 0;
			if (!doDrop(failedDrops))
			{
				return;
			}
			failedDrops = null;
			onInventoryChanged();
		}
	}
	@Override
	public void writeToNBT(NBTTagCompound tag)
	{
		super.writeToNBT(tag);
		NBTTagList nbttaglist;
		if (_inventory.length > 0)
		{
			nbttaglist = new NBTTagList();
			for(int i = 0; i < _inventory.length; i++)
			{
				if (_inventory[i] != null && _inventory[i].stackSize > 0)
				{
					NBTTagCompound slot = new NBTTagCompound();
					slot.setByte("Slot", (byte)i);
					_inventory[i].writeToNBT(slot);
					nbttaglist.appendTag(slot);
				}
			}
			tag.setTag("Items", nbttaglist);
		}
		
		IFluidTank[] _tanks = getTanks();
		if (_tanks.length > 0)
		{
			NBTTagList tanks = new NBTTagList();
			for(int i = 0, n = _tanks.length; i < n; i++)
			{
				if(_tanks[i].getFluid() != null)
				{
					NBTTagCompound nbttagcompound1 = new NBTTagCompound();
					nbttagcompound1.setByte("Tank", (byte)i);
					
					FluidStack l = _tanks[i].getFluid();
					l.writeToNBT(nbttagcompound1);
					tanks.appendTag(nbttagcompound1);
				}
			}
			tag.setTag("mTanks", tanks);
		}
		
		if (this.isInvNameLocalized())
		{
			NBTTagCompound display = new NBTTagCompound();
			display.setString("Name", getInvName());
			tag.setCompoundTag("display", display);
		}
		
		if (failedDrops != null)
		{
			nbttaglist = new NBTTagList();
			for (ItemStack item : failedDrops)
			{
				NBTTagCompound nbttagcompound1 = new NBTTagCompound();
				item.writeToNBT(nbttagcompound1);
				nbttaglist.appendTag(nbttagcompound1);
			}
			tag.setTag("DropItems", nbttaglist);
		}
	}
	@Override
	public void readFromNBT(NBTTagCompound tag)
	{
		super.readFromNBT(tag);
		_inventory = new ItemStack[getSizeInventory()];
		NBTTagList nbttaglist;
		if (tag.hasKey("Items"))
		{
			nbttaglist = tag.getTagList("Items");
			for (int i = nbttaglist.tagCount(); i --> 0; )
			{
				NBTTagCompound slot = (NBTTagCompound)nbttaglist.tagAt(i);
				int j = slot.getByte("Slot") & 0xff;
				if(j >= 0 && j < _inventory.length)
				{
					_inventory[j] = ItemStack.loadItemStackFromNBT(slot);
					if (_inventory[j].stackSize <= 0)
						_inventory[j] = null;
				}
			}
		}
		onInventoryChanged();

		if (tag.hasKey("mTanks")) {
			IFluidTank[] _tanks = getTanks();
			
			nbttaglist = tag.getTagList("mTanks");
			for(int i = 0; i < nbttaglist.tagCount(); i++)
			{
				NBTTagCompound nbttagcompound1 = (NBTTagCompound)nbttaglist.tagAt(i);
				int j = nbttagcompound1.getByte("Tank") & 0xff;
				if(j >= 0 && j < _tanks.length)
				{
					FluidStack l = FluidStack.loadFluidStackFromNBT(nbttagcompound1);
					if(l != null)
					{
						((FluidTank)_tanks[j]).setFluid(l);
					}
				}
			}
		}
		else if (_tanks != null)
		{ // TODO: remove in 2.8
			IFluidTank tank = _tanks[0];
			if (tank != null && tag.hasKey("tankFluidName"))
			{
				int tankAmount = tag.getInteger("tankAmount");
				FluidStack fluid = FluidRegistry.
						getFluidStack(tag.getString("tankFluidName"), tankAmount);
				if (fluid != null)
				{
					if(fluid.amount > tank.getCapacity())
					{
						fluid.amount = tank.getCapacity();
					}

					((FluidTank)tank).setFluid(fluid);
				}
				tag.removeTag("tankFluidName");
				tag.removeTag("tankAmount");
			}
		}
		
		if (tag.hasKey("display"))
		{
			NBTTagCompound display = tag.getCompoundTag("display");
			if (display.hasKey("Name"))
			{
				this.setInvName(display.getString("Name"));
			}
		}

		if (tag.hasKey("DropItems"))
		{
			List<ItemStack> drops = new ArrayList<ItemStack>();
			nbttaglist = tag.getTagList("DropItems");
			for (int i = nbttaglist.tagCount(); i --> 0; )
			{
				NBTTagCompound nbttagcompound1 = (NBTTagCompound)nbttaglist.tagAt(i);
				ItemStack item = ItemStack.loadItemStackFromNBT(nbttagcompound1);
				if (item != null && item.stackSize > 0)
				{
					drops.add(item);
				}
			}
			if (drops.size() != 0)
			{
				failedDrops = drops;
			}
		}
	}