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"));
}
}
}
Aggregations