Search in sources :

Example 36 with IFluidTank

use of net.minecraftforge.fluids.IFluidTank in project ForestryMC by ForestryMC.

the class GuiForestry method getFluidStackAtPosition.

@Nullable
public FluidStack getFluidStackAtPosition(int mouseX, int mouseY) {
    for (Widget widget : widgetManager.getWidgets()) {
        if (widget instanceof TankWidget && widget.isMouseOver(mouseX - guiLeft, mouseY - guiTop)) {
            TankWidget tankWidget = (TankWidget) widget;
            IFluidTank tank = tankWidget.getTank();
            if (tank != null) {
                return tank.getFluid();
            }
        }
    }
    return null;
}
Also used : TankWidget(forestry.core.gui.widgets.TankWidget) TankWidget(forestry.core.gui.widgets.TankWidget) Widget(forestry.core.gui.widgets.Widget) IFluidTank(net.minecraftforge.fluids.IFluidTank) Nullable(javax.annotation.Nullable)

Example 37 with IFluidTank

use of net.minecraftforge.fluids.IFluidTank in project Metalworks by canitzp.

the class TileBase method readCapabilities.

private void readCapabilities(NBTTagCompound nbt, @Nullable EnumFacing side) {
    if (hasEnergyFluidInv().getRight()) {
        IItemHandler inventory = this.getInventory(side);
        if (inventory instanceof IItemHandlerModifiable && nbt.hasKey("Inventory")) {
            for (int i = 0; i < inventory.getSlots(); i++) {
                // clear the inventory, otherwise empty stacks doesn't get overridden while syncing. Forge Bug?
                ((IItemHandlerModifiable) inventory).setStackInSlot(i, ItemStack.EMPTY);
            }
            CapabilityItemHandler.ITEM_HANDLER_CAPABILITY.readNBT(inventory, side, nbt.getTag("Inventory"));
        }
    }
    if (hasEnergyFluidInv().getMiddle()) {
        IFluidHandler tank = getTank(side);
        if (tank instanceof IFluidTank && nbt.hasKey("FluidTank")) {
            CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY.readNBT(tank, side, nbt.getCompoundTag("FluidTank"));
        }
    }
    if (hasEnergyFluidInv().getLeft()) {
        IEnergyStorage energy = getEnergy(side);
        if (energy instanceof CustomEnergyStorage && nbt.hasKey("Energy", Constants.NBT.TAG_COMPOUND)) {
            NBTTagCompound energyTag = nbt.getCompoundTag("Energy");
            ((CustomEnergyStorage) energy).setValues(energyTag.getInteger("Stored"), energyTag.getInteger("Capacity"), energyTag.getInteger("MaxReceive"), energyTag.getInteger("MaxExtract"));
        }
    }
}
Also used : IItemHandlerModifiable(net.minecraftforge.items.IItemHandlerModifiable) CustomEnergyStorage(de.canitzp.metalworks.CustomEnergyStorage) IItemHandler(net.minecraftforge.items.IItemHandler) IEnergyStorage(net.minecraftforge.energy.IEnergyStorage) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) IFluidHandler(net.minecraftforge.fluids.capability.IFluidHandler) IFluidTank(net.minecraftforge.fluids.IFluidTank)

Example 38 with IFluidTank

use of net.minecraftforge.fluids.IFluidTank in project Binnie by ForestryMC.

the class MachineUtil method spaceInTank.

public boolean spaceInTank(final int id, final int amount) {
    final IFluidTank tank = this.getTank(id);
    final int space = tank.getCapacity() - tank.getFluidAmount();
    return amount <= space;
}
Also used : IFluidTank(net.minecraftforge.fluids.IFluidTank)

Example 39 with IFluidTank

use of net.minecraftforge.fluids.IFluidTank in project Binnie by ForestryMC.

the class MachineUtil method fillTank.

public void fillTank(final int id, final FluidStack liquidStack) {
    final IFluidTank tank = this.getTank(id);
    tank.fill(liquidStack, true);
}
Also used : IFluidTank(net.minecraftforge.fluids.IFluidTank)

Example 40 with IFluidTank

use of net.minecraftforge.fluids.IFluidTank in project GTplusplus by GTNewHorizons.

the class GUI_PestKiller method drawFluidTank.

private void drawFluidTank(IFluidTank tank, int x, int y) {
    Color startGrad = new Color(50, 50, 50);
    Color endGrad = new Color(20, 20, 20);
    Container_PestKiller aCont = (Container_PestKiller) this.inventorySlots;
    double aPercentage = 0;
    double aDivisor = (100 / 16);
    int aFrameHeight = 16;
    boolean didRender = false;
    if (aCont != null) {
        TileEntityPestKiller aTile = mTileKiller;
        if (aTile != null) {
            FluidTank aTank = aTile.getTank();
            int aTier = aTile.getTier();
            drawGradientRect(x, y, x + 16, y + 16, startGrad.getRGB(), endGrad.getRGB());
            if (aTier <= 0 || aTier > 2) {
                if (aTank != null && aTank.getFluidAmount() > 0) {
                    aPercentage = MathUtils.findPercentage(aTank.getFluidAmount(), aTank.getCapacity());
                    // Logger.INFO("Percent = "+aPercentage);
                    aFrameHeight = (int) (aPercentage / aDivisor);
                // Logger.INFO("Frame Height = "+aFrameHeight);
                }
                this.fontRendererObj.drawString("Tier: 0", 4, 18, 4210752);
                this.fontRendererObj.drawString("Range: 1x1", 4, 30, 4210752);
                this.fontRendererObj.drawString("Poison: None", 4, 42, 4210752);
                this.fontRendererObj.drawString("Amount: 0", 4, 64, 4210752);
                didRender = true;
            } else if (aTier == 1) {
                if (aTank != null && aTank.getFluidAmount() > 0) {
                    aPercentage = MathUtils.findPercentage(aTank.getFluidAmount(), aTank.getCapacity());
                    // Logger.INFO("Percent = "+aPercentage);
                    aFrameHeight = (int) (aPercentage / aDivisor);
                // Logger.INFO("Frame Height = "+aFrameHeight);
                }
                startGrad = new Color(240, 50, 240);
                endGrad = new Color(130, 30, 130);
                drawGradientRect(x, y + (16 - aFrameHeight), x + 16, y + 16, startGrad.getRGB(), endGrad.getRGB());
                this.fontRendererObj.drawString("Tier: 1", 4, 18, 4210752);
                this.fontRendererObj.drawString("Range: 5x5", 4, 30, 4210752);
                this.fontRendererObj.drawString("Poison: ", 4, 42, 4210752);
                this.fontRendererObj.drawString("" + aTile.getTank().getFluid().getLocalizedName(), 4, 54, 4210752);
                this.fontRendererObj.drawString("Amount: " + aTile.getTank().getFluidAmount(), 4, 64, 4210752);
                didRender = true;
            } else if (aTier == 2) {
                if (aTank != null && aTank.getFluidAmount() > 0) {
                    aPercentage = MathUtils.findPercentage(aTank.getFluidAmount(), aTank.getCapacity());
                    // Logger.INFO("Percent = "+aPercentage);
                    aFrameHeight = (int) (aPercentage / aDivisor);
                // Logger.INFO("Frame Height = "+aFrameHeight);
                }
                short[] aRGB = MISC_MATERIALS.HYDROGEN_CYANIDE.getRGB();
                startGrad = new Color(aRGB[0], aRGB[1], aRGB[2]);
                endGrad = new Color(Math.max(aRGB[0], 0), Math.max(aRGB[1], 0), Math.max(aRGB[2], 0));
                drawGradientRect(x, y + (16 - aFrameHeight), x + 16, y + 16, startGrad.getRGB(), endGrad.getRGB());
                this.fontRendererObj.drawString("Tier: 2", 4, 18, 4210752);
                this.fontRendererObj.drawString("Range: 9x9", 4, 30, 4210752);
                this.fontRendererObj.drawString("Poison: ", 4, 42, 4210752);
                this.fontRendererObj.drawString("" + aTile.getTank().getFluid().getLocalizedName(), 4, 54, 4210752);
                this.fontRendererObj.drawString("Amount: " + aTile.getTank().getFluidAmount(), 4, 64, 4210752);
                didRender = true;
            }
        }
    }
    if (!didRender) {
        startGrad = new Color(255, 30, 120);
        endGrad = new Color(255, 0, 50);
        drawGradientRect(x, y, x + 16, y + 16, startGrad.getRGB(), endGrad.getRGB());
        this.fontRendererObj.drawString("Tier: 0", 4, 18, 4210752);
    }
/*
		 * FluidStack fluid = tank.getFluid(); TextureManager manager =
		 * mc.getTextureManager(); if (fluid != null) {
		 * manager.bindTexture(manager.getResourceLocation(0)); float amount =
		 * fluid.amount; float capacity = tank.getCapacity(); float scale = amount /
		 * capacity; int fluidTankHeight = 60; int fluidAmount = (int) (scale *
		 * fluidTankHeight); drawFluid(x, y + fluidTankHeight - fluidAmount,
		 * fluid.getFluid().getIcon(fluid), 16, fluidAmount); }
		 */
}
Also used : FluidTank(net.minecraftforge.fluids.FluidTank) IFluidTank(net.minecraftforge.fluids.IFluidTank) Color(java.awt.Color) Container_PestKiller(gtPlusPlus.core.container.Container_PestKiller) TileEntityPestKiller(gtPlusPlus.core.tileentities.machines.TileEntityPestKiller)

Aggregations

IFluidTank (net.minecraftforge.fluids.IFluidTank)58 FluidStack (net.minecraftforge.fluids.FluidStack)30 IFluidHandler (net.minecraftforge.fluids.capability.IFluidHandler)10 FluidTank (net.minecraftforge.fluids.FluidTank)9 Nullable (javax.annotation.Nullable)6 Block (net.minecraft.block.Block)6 ItemStack (net.minecraft.item.ItemStack)6 TileEntity (net.minecraft.tileentity.TileEntity)5 NBTBase (net.minecraft.nbt.NBTBase)4 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)4 NBTTagList (net.minecraft.nbt.NBTTagList)4 INBTSerializable (net.minecraftforge.common.util.INBTSerializable)4 Recipe (gregtech.api.recipes.Recipe)3 ArrayList (java.util.ArrayList)3 IItemHandlerModifiable (net.minecraftforge.items.IItemHandlerModifiable)3 FluidTankTileEntity (com.simibubi.create.content.contraptions.fluids.tank.FluidTankTileEntity)2 FluidTankGT (gregapi.fluid.FluidTankGT)2 OreDictItemData (gregapi.oredict.OreDictItemData)2 FuelRecipe (gregtech.api.recipes.recipes.FuelRecipe)2 BlockLiquid (net.minecraft.block.BlockLiquid)2