Search in sources :

Example 11 with LiquidStack

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

the class GuiFactoryInventory method drawTank.

protected void drawTank(int xOffset, int yOffset, int liquidId, int liquidMeta, int level) {
    LiquidStack stack = LiquidDictionary.getCanonicalLiquid(new LiquidStack(liquidId, 1, liquidMeta));
    if (liquidId <= 0 || stack == null) {
        return;
    }
    ItemStack itemStack = stack.asItemStack();
    Icon icon = stack.getRenderingIcon();
    if (icon == null) {
        try {
            icon = itemStack.getIconIndex();
        } catch (Throwable _) {
        }
        if (icon == null)
            icon = Block.lavaMoving.getIcon(0, 0);
    }
    int vertOffset = 0;
    while (level > 0) {
        int texHeight = 0;
        if (level > 16) {
            texHeight = 16;
            level -= 16;
        } else {
            texHeight = level;
            level = 0;
        }
        mc.renderEngine.bindTexture(stack.getTextureSheet());
        drawTexturedModelRectFromIcon(xOffset, yOffset - texHeight - vertOffset, icon, 16, texHeight);
        vertOffset = vertOffset + 16;
    }
    this.mc.renderEngine.bindTexture(MineFactoryReloadedCore.guiFolder + _tileEntity.getGuiBackground());
    this.drawTexturedModalRect(xOffset, yOffset - 60, 176, 0, 16, 60);
}
Also used : LiquidStack(net.minecraftforge.liquids.LiquidStack) Icon(net.minecraft.util.Icon) ItemStack(net.minecraft.item.ItemStack)

Example 12 with LiquidStack

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

the class GuiLiquiCrafter method drawTank.

@Override
protected void drawTank(int xOffset, int yOffset, int liquidId, int liquidMeta, int level) {
    LiquidStack stack = LiquidDictionary.getCanonicalLiquid(new LiquidStack(liquidId, 1, liquidMeta));
    if (liquidId <= 0 || stack == null) {
        return;
    }
    int vertOffset = 0;
    while (level > 0) {
        int texHeight = 0;
        if (level > 16) {
            texHeight = 16;
            level -= 16;
        } else {
            texHeight = level;
            level = 0;
        }
        mc.renderEngine.bindTexture(stack.getTextureSheet());
        drawTexturedModelRectFromIcon(xOffset, yOffset - texHeight - vertOffset, stack.getRenderingIcon(), 16, texHeight);
        vertOffset = vertOffset + 16;
    }
    this.mc.renderEngine.bindTexture(MineFactoryReloadedCore.guiFolder + _tileEntity.getGuiBackground());
    this.drawTexturedModalRect(xOffset, yOffset - 33, 232, 0, 16, 33);
}
Also used : LiquidStack(net.minecraftforge.liquids.LiquidStack)

Example 13 with LiquidStack

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

the class TileEntityUnifier method fill.

@Override
public int fill(ForgeDirection from, LiquidStack resource, boolean doFill) {
    if (resource == null || resource.amount == 0)
        return 0;
    LiquidStack converted = unifierTransformLiquid(resource, doFill);
    if (converted == null || converted.amount == 0)
        return 0;
    int filled = _tank.fill(converted, doFill);
    if (filled == converted.amount) {
        return resource.amount;
    } else {
        return filled * resource.amount / converted.amount + (resource.amount & _roundingCompensation);
    }
}
Also used : LiquidStack(net.minecraftforge.liquids.LiquidStack)

Example 14 with LiquidStack

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

the class TileEntityFactoryInventory method writeToNBT.

@Override
public void writeToNBT(NBTTagCompound nbttagcompound) {
    super.writeToNBT(nbttagcompound);
    NBTTagList nbttaglist = new NBTTagList();
    for (int i = 0; i < _inventory.length; i++) {
        if (_inventory[i] != null) {
            NBTTagCompound nbttagcompound1 = new NBTTagCompound();
            nbttagcompound1.setByte("Slot", (byte) i);
            _inventory[i].writeToNBT(nbttagcompound1);
            nbttaglist.appendTag(nbttagcompound1);
        }
    }
    if (getTank() != null && getTank().getLiquid() != null) {
        LiquidStack fluid = getTank().getLiquid();
        nbttagcompound.setInteger("tankAmount", fluid.amount);
        String name = LiquidDictionary.findLiquidName(fluid);
        if (name != null) {
            nbttagcompound.setString("tankFluidName", name);
        }
        nbttagcompound.setInteger("tankItemId", getTank().getLiquid().itemID);
        nbttagcompound.setInteger("tankMeta", getTank().getLiquid().itemMeta);
    }
    if (this.isInvNameLocalized()) {
        NBTTagCompound display = new NBTTagCompound();
        display.setString("Name", getInvName());
        nbttagcompound.setCompoundTag("display", display);
    }
    nbttagcompound.setTag("Items", nbttaglist);
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) LiquidStack(net.minecraftforge.liquids.LiquidStack) NBTTagCompound(net.minecraft.nbt.NBTTagCompound)

Example 15 with LiquidStack

use of net.minecraftforge.liquids.LiquidStack 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

LiquidStack (net.minecraftforge.liquids.LiquidStack)22 ItemStack (net.minecraft.item.ItemStack)13 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)4 NBTTagList (net.minecraft.nbt.NBTTagList)4 LinkedList (java.util.LinkedList)3 ILiquidTank (net.minecraftforge.liquids.ILiquidTank)3 LiquidContainerData (net.minecraftforge.liquids.LiquidContainerData)3 PostInit (cpw.mods.fml.common.Mod.PostInit)2 TileEntity (net.minecraft.tileentity.TileEntity)2 ITankContainer (net.minecraftforge.liquids.ITankContainer)2 IInventoryManager (powercrystals.core.inventory.IInventoryManager)2 Init (cpw.mods.fml.common.Mod.Init)1 EntityLiving (net.minecraft.entity.EntityLiving)1 ICrafting (net.minecraft.inventory.ICrafting)1 Item (net.minecraft.item.Item)1 Icon (net.minecraft.util.Icon)1 BiomeGenBase (net.minecraft.world.biome.BiomeGenBase)1 LiquidTank (net.minecraftforge.liquids.LiquidTank)1 BlockPosition (powercrystals.core.position.BlockPosition)1 IFactoryRanchable (powercrystals.minefactoryreloaded.api.IFactoryRanchable)1