Search in sources :

Example 1 with LiquidTank

use of net.minecraftforge.liquids.LiquidTank in project MineFactoryReloaded by powercrystals.

the class TileEntityFactoryInventory method readFromNBT.

@Override
public void readFromNBT(NBTTagCompound nbttagcompound) {
    super.readFromNBT(nbttagcompound);
    NBTTagList nbttaglist = nbttagcompound.getTagList("Items");
    _inventory = new ItemStack[getSizeInventory()];
    for (int i = 0; i < nbttaglist.tagCount(); i++) {
        NBTTagCompound nbttagcompound1 = (NBTTagCompound) nbttaglist.tagAt(i);
        int j = nbttagcompound1.getByte("Slot") & 0xff;
        if (j >= 0 && j < _inventory.length) {
            ItemStack s = new ItemStack(0, 0, 0);
            s.readFromNBT(nbttagcompound1);
            _inventory[j] = s;
        }
    }
    onFactoryInventoryChanged();
    boolean foundLiquid = false;
    ILiquidTank tank = getTank();
    int tankAmount = nbttagcompound.getInteger("tankAmount");
    if (tank != null && nbttagcompound.hasKey("tankFluidName")) {
        LiquidStack fluid = LiquidDictionary.getLiquid(nbttagcompound.getString("tankFluidName"), tankAmount);
        if (fluid != null) {
            if (fluid.amount > tank.getCapacity()) {
                fluid.amount = tank.getCapacity();
            }
            ((LiquidTank) tank).setLiquid(fluid);
            foundLiquid = true;
        }
    }
    if (!foundLiquid) {
        int tankItemId = nbttagcompound.getInteger("tankItemId");
        int tankItemMeta = nbttagcompound.getInteger("tankItemMeta");
        if (tank != null && Item.itemsList[tankItemId] != null && LiquidContainerRegistry.isLiquid(new ItemStack(tankItemId, 1, tankItemMeta))) {
            ((LiquidTank) tank).setLiquid(new LiquidStack(tankItemId, tankAmount, tankItemMeta));
            if (tank.getLiquid() != null && tank.getLiquid().amount > tank.getCapacity()) {
                tank.getLiquid().amount = tank.getCapacity();
            }
        }
    }
    for (int i = 0; i < getSizeInventory(); i++) {
        if (_inventory[i] != null && _inventory[i].getItem() == null) {
            _inventory[i] = null;
        }
    }
    if (nbttagcompound.hasKey("display")) {
        NBTTagCompound display = nbttagcompound.getCompoundTag("display");
        if (display.hasKey("Name")) {
            this.setInvName(display.getString("Name"));
        }
    }
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) LiquidStack(net.minecraftforge.liquids.LiquidStack) LiquidTank(net.minecraftforge.liquids.LiquidTank) ILiquidTank(net.minecraftforge.liquids.ILiquidTank) ILiquidTank(net.minecraftforge.liquids.ILiquidTank) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ItemStack(net.minecraft.item.ItemStack)

Aggregations

ItemStack (net.minecraft.item.ItemStack)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1 NBTTagList (net.minecraft.nbt.NBTTagList)1 ILiquidTank (net.minecraftforge.liquids.ILiquidTank)1 LiquidStack (net.minecraftforge.liquids.LiquidStack)1 LiquidTank (net.minecraftforge.liquids.LiquidTank)1