Search in sources :

Example 1 with FluidTankInfo

use of net.minecraftforge.fluids.FluidTankInfo in project LogisticsPipes by RS485.

the class BuildCraftTankHandler method getAvailableLiquid.

@Override
public Map<FluidIdentifier, Long> getAvailableLiquid(TileEntity tile) {
    Map<FluidIdentifier, Long> map = new HashMap<>();
    FluidTankInfo[] tanks = ((IFluidHandler) tile).getTankInfo(ForgeDirection.UNKNOWN);
    for (FluidTankInfo tank : tanks) {
        if (tank == null) {
            continue;
        }
        FluidStack liquid;
        if ((liquid = tank.fluid) != null && liquid.getFluidID() != 0) {
            FluidIdentifier ident = FluidIdentifier.get(liquid);
            if (((IFluidHandler) tile).drain(ForgeDirection.UNKNOWN, 1, false) != null) {
                if (map.containsKey(ident)) {
                    long addition = map.get(ident) + tank.fluid.amount;
                    map.put(ident, addition);
                } else {
                    map.put(ident, (long) tank.fluid.amount);
                }
            }
        }
    }
    return map;
}
Also used : FluidTankInfo(net.minecraftforge.fluids.FluidTankInfo) HashMap(java.util.HashMap) FluidStack(net.minecraftforge.fluids.FluidStack) FluidIdentifier(logisticspipes.utils.FluidIdentifier) IFluidHandler(net.minecraftforge.fluids.IFluidHandler)

Example 2 with FluidTankInfo

use of net.minecraftforge.fluids.FluidTankInfo in project LogisticsPipes by RS485.

the class FluidIdentifier method getFreeSpaceInsideTank.

public int getFreeSpaceInsideTank(IFluidHandler container, ForgeDirection dir) {
    int free = 0;
    FluidTankInfo[] tanks = container.getTankInfo(dir);
    if (tanks != null && tanks.length > 0) {
        for (FluidTankInfo tank : tanks) {
            free += getFreeSpaceInsideTank(tank);
        }
    }
    return free;
}
Also used : FluidTankInfo(net.minecraftforge.fluids.FluidTankInfo)

Example 3 with FluidTankInfo

use of net.minecraftforge.fluids.FluidTankInfo in project Galacticraft by micdoodle8.

the class GCNEIHighlightHandler method handleTextData.

@Override
public List<String> handleTextData(ItemStack stack, World world, EntityPlayer player, MovingObjectPosition mop, List<String> currenttip, ItemInfo.Layout layout) {
    if (stack != null) {
        if (stack.getItem() == Item.getItemFromBlock(GCBlocks.fluidTank)) {
            if (layout == ItemInfo.Layout.BODY) {
                TileEntity tile = world.getTileEntity(mop.getBlockPos());
                if (tile instanceof TileEntityFluidTank) {
                    TileEntityFluidTank tank = (TileEntityFluidTank) tile;
                    FluidTankInfo[] infos = tank.getTankInfo(EnumFacing.DOWN);
                    if (infos.length == 1) {
                        FluidTankInfo info = infos[0];
                        currenttip.add(info.fluid != null ? info.fluid.getLocalizedName() : "Empty");
                        currenttip.add((info.fluid != null ? info.fluid.amount : 0) + " / " + info.capacity);
                    }
                }
            }
        } else if (stack.getItem() == Item.getItemFromBlock(GCBlocks.oxygenPipe) || stack.getItem() == Item.getItemFromBlock(GCBlocks.oxygenPipePull)) {
            if (layout == ItemInfo.Layout.BODY) {
                TileEntity tile = world.getTileEntity(mop.getBlockPos());
                if (tile instanceof TileEntityFluidPipe) {
                    TileEntityFluidPipe pipe = (TileEntityFluidPipe) tile;
                    currenttip.add(((BlockFluidPipe) pipe.getBlockType()).getMode().toString());
                    if (pipe.hasNetwork()) {
                        FluidNetwork network = ((FluidNetwork) pipe.getNetwork());
                        currenttip.add("Network: " + (network.buffer != null ? network.buffer.amount : 0) + " / " + network.getCapacity());
                    } else {
                        currenttip.add("Pipe: " + (pipe.getBuffer() != null ? pipe.getBuffer().amount + " / " + pipe.buffer.getCapacity() : "None"));
                    }
                }
            }
        }
    }
    return currenttip;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) FluidTankInfo(net.minecraftforge.fluids.FluidTankInfo) FluidNetwork(micdoodle8.mods.galacticraft.core.fluid.FluidNetwork) TileEntityFluidTank(micdoodle8.mods.galacticraft.core.tile.TileEntityFluidTank) TileEntityFluidPipe(micdoodle8.mods.galacticraft.core.tile.TileEntityFluidPipe)

Example 4 with FluidTankInfo

use of net.minecraftforge.fluids.FluidTankInfo in project BuildCraft by BuildCraft.

the class TileTank method getTankInfo.

@Override
public FluidTankInfo[] getTankInfo(EnumFacing direction) {
    if (isNotReady())
        return new FluidTankInfo[0];
    FluidTank compositeTank = new FluidTank(tank.getCapacity());
    TileTank tile = getBottomTank();
    if (tile != null && tile.tank.getFluid() != null) {
        compositeTank.setFluid(tile.tank.getFluid().copy());
    } else {
        return new FluidTankInfo[] { compositeTank.getInfo() };
    }
    int capacity = tile.tank.getCapacity();
    tile = getTankAbove(tile);
    while (tile != null) {
        FluidStack liquid = tile.tank.getFluid();
        if (liquid == null || liquid.amount == 0) {
        // NOOP
        } else if (!compositeTank.getFluid().isFluidEqual(liquid)) {
            break;
        } else {
            compositeTank.getFluid().amount += liquid.amount;
        }
        capacity += tile.tank.getCapacity();
        tile = getTankAbove(tile);
    }
    compositeTank.setCapacity(capacity);
    return new FluidTankInfo[] { compositeTank.getInfo() };
}
Also used : FluidTank(net.minecraftforge.fluids.FluidTank) FluidTankInfo(net.minecraftforge.fluids.FluidTankInfo) FluidStack(net.minecraftforge.fluids.FluidStack)

Example 5 with FluidTankInfo

use of net.minecraftforge.fluids.FluidTankInfo in project PneumaticCraft by MineMaarten.

the class SemiBlockRequester method amountRequested.

@Override
public int amountRequested(FluidStack stack) {
    int totalRequestingAmount = getTotalRequestedAmount(stack);
    if (totalRequestingAmount > 0) {
        TileEntity te = getTileEntity();
        if (te instanceof IFluidHandler) {
            int count = 0;
            for (ForgeDirection d : ForgeDirection.VALID_DIRECTIONS) {
                FluidTankInfo[] infos = ((IFluidHandler) te).getTankInfo(d);
                if (infos != null) {
                    for (FluidTankInfo info : infos) {
                        if (info.fluid != null && info.fluid.getFluid() == stack.getFluid()) {
                            count += info.fluid.amount;
                        }
                    }
                    if (count > 0)
                        break;
                }
            }
            count += getIncomingFluid(stack.getFluid());
            int requested = Math.max(0, Math.min(stack.amount, totalRequestingAmount - count));
            return requested;
        }
    }
    return 0;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) FluidTankInfo(net.minecraftforge.fluids.FluidTankInfo) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) IFluidHandler(net.minecraftforge.fluids.IFluidHandler)

Aggregations

FluidTankInfo (net.minecraftforge.fluids.FluidTankInfo)21 FluidStack (net.minecraftforge.fluids.FluidStack)9 IFluidHandler (net.minecraftforge.fluids.IFluidHandler)6 RenderInfo (pneumaticCraft.client.util.RenderUtils.RenderInfo)6 TileEntity (net.minecraft.tileentity.TileEntity)5 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)4 FluidIdentifier (logisticspipes.utils.FluidIdentifier)2 TileEntityFluidTank (micdoodle8.mods.galacticraft.core.tile.TileEntityFluidTank)2 TileEntityLiquidHopper (pneumaticCraft.common.tileentity.TileEntityLiquidHopper)2 TargetPoint (cpw.mods.fml.common.network.NetworkRegistry.TargetPoint)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 TreeSet (java.util.TreeSet)1 ISpecialTankAccessHandler (logisticspipes.interfaces.ISpecialTankAccessHandler)1 ISpecialTankHandler (logisticspipes.interfaces.ISpecialTankHandler)1 ChestContent (logisticspipes.network.packets.hud.ChestContent)1 ItemIdentifier (logisticspipes.utils.item.ItemIdentifier)1 FluidNetwork (micdoodle8.mods.galacticraft.core.fluid.FluidNetwork)1 TileEntityFluidPipe (micdoodle8.mods.galacticraft.core.tile.TileEntityFluidPipe)1 Tessellator (net.minecraft.client.renderer.Tessellator)1