Search in sources :

Example 1 with IFluidHandler

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

the class PipeFluidBasic method sinkAmount.

@Override
public int sinkAmount(FluidStack stack) {
    if (!guiOpenedBy.isEmpty()) {
        //Don't sink when the gui is open
        return 0;
    }
    FluidIdentifier ident = FluidIdentifier.get(stack);
    if (filterInv.getStackInSlot(0) == null) {
        return 0;
    }
    if (!ident.equals(FluidIdentifier.get(filterInv.getIDStackInSlot(0).getItem()))) {
        return 0;
    }
    int onTheWay = this.countOnRoute(ident);
    int freeSpace = -onTheWay;
    for (Pair<TileEntity, ForgeDirection> pair : getAdjacentTanks(true)) {
        FluidTank tank = ((PipeFluidTransportLogistics) transport).sideTanks[pair.getValue2().ordinal()];
        freeSpace += ident.getFreeSpaceInsideTank((IFluidHandler) pair.getValue1(), pair.getValue2().getOpposite());
        freeSpace += ident.getFreeSpaceInsideTank(tank);
        if (freeSpace >= stack.amount) {
            return stack.amount;
        }
    }
    return freeSpace;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) FluidTank(net.minecraftforge.fluids.FluidTank) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) FluidIdentifier(logisticspipes.utils.FluidIdentifier) IFluidHandler(net.minecraftforge.fluids.IFluidHandler)

Example 2 with IFluidHandler

use of net.minecraftforge.fluids.IFluidHandler 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 3 with IFluidHandler

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

the class FluidNetwork method refreshAcceptors.

public void refreshAcceptors() {
    if (this.acceptors == null) {
        this.acceptors = Maps.newHashMap();
    } else {
        this.acceptors.clear();
    }
    try {
        Iterator<IBufferTransmitter<FluidStack>> it = this.pipes.iterator();
        while (it.hasNext()) {
            IBufferTransmitter<FluidStack> transmitter = it.next();
            TileEntity tile = (TileEntity) transmitter;
            if (transmitter == null || tile.isInvalid() || tile.getWorld() == null) {
                it.remove();
                continue;
            }
            if (!transmitter.canTransmit()) {
                continue;
            }
            int i = 0;
            for (TileEntity acceptor : transmitter.getAdjacentConnections()) {
                if (!(acceptor instanceof IBufferTransmitter) && acceptor instanceof IFluidHandler) {
                    EnumFacing facing = EnumFacing.getFront(i).getOpposite();
                    BlockPos acceptorPos = tile.getPos().offset(facing.getOpposite());
                    EnumSet<EnumFacing> facingSet = this.acceptorDirections.get(acceptorPos);
                    if (facingSet != null) {
                        facingSet.add(facing);
                    } else {
                        facingSet = EnumSet.of(facing);
                    }
                    this.acceptors.put(acceptorPos, (IFluidHandler) acceptor);
                    this.acceptorDirections.put(acceptorPos, facingSet);
                }
                i++;
            }
        }
    } catch (Exception e) {
        FMLLog.severe("Failed to refresh liquid acceptors");
        e.printStackTrace();
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) FluidStack(net.minecraftforge.fluids.FluidStack) EnumFacing(net.minecraft.util.EnumFacing) IBufferTransmitter(micdoodle8.mods.galacticraft.api.transmission.tile.IBufferTransmitter) BlockPos(net.minecraft.util.BlockPos) IFluidHandler(net.minecraftforge.fluids.IFluidHandler)

Example 4 with IFluidHandler

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

the class FluidNetwork method getAcceptors.

public List<Pair<BlockPos, IFluidHandler>> getAcceptors(FluidStack toSend) {
    List<Pair<BlockPos, IFluidHandler>> toReturn = new LinkedList<>();
    if (GCCoreUtil.getEffectiveSide() == Side.CLIENT) {
        return toReturn;
    }
    if (this.acceptors == null || this.acceptors.isEmpty()) {
        this.refreshAcceptors();
    }
    List<BlockPos> acceptorsCopy = new ArrayList<>();
    acceptorsCopy.addAll(acceptors.keySet());
    for (BlockPos coords : acceptorsCopy) {
        EnumSet<EnumFacing> sides = acceptorDirections.get(coords);
        if (sides == null || sides.isEmpty()) {
            continue;
        }
        TileEntity tile = this.worldObj.getTileEntity(coords);
        if (!(tile instanceof IFluidHandler)) {
            continue;
        }
        IFluidHandler acceptor = (IFluidHandler) tile;
        Fluid fluidToSend = toSend.getFluid();
        for (EnumFacing side : sides) {
            if (acceptor.canFill(side, fluidToSend)) {
                toReturn.add(Pair.of(coords, acceptor));
                break;
            }
        }
    }
    return toReturn;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) EnumFacing(net.minecraft.util.EnumFacing) Fluid(net.minecraftforge.fluids.Fluid) BlockPos(net.minecraft.util.BlockPos) IFluidHandler(net.minecraftforge.fluids.IFluidHandler) Pair(org.apache.commons.lang3.tuple.Pair)

Example 5 with IFluidHandler

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

the class TankUtils method pushFluidToConsumers.

public static void pushFluidToConsumers(IFluidTank tank, int flowCap, BlockTileCache[] tileBuffer) {
    int amountToPush = flowCap;
    for (EnumFacing side : EnumFacing.VALUES) {
        FluidStack fluidStack = tank.drain(amountToPush, false);
        if (fluidStack != null && fluidStack.amount > 0) {
            TileEntity tile = tileBuffer[side.ordinal()].getTile();
            if (tile instanceof IFluidHandler) {
                int used = ((IFluidHandler) tile).fill(side.getOpposite(), fluidStack, true);
                if (used > 0) {
                    amountToPush -= used;
                    tank.drain(used, true);
                    if (amountToPush <= 0) {
                        return;
                    }
                }
            }
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) FluidStack(net.minecraftforge.fluids.FluidStack) EnumFacing(net.minecraft.util.EnumFacing) IFluidHandler(net.minecraftforge.fluids.IFluidHandler)

Aggregations

IFluidHandler (net.minecraftforge.fluids.IFluidHandler)44 TileEntity (net.minecraft.tileentity.TileEntity)34 FluidStack (net.minecraftforge.fluids.FluidStack)32 EnumFacing (net.minecraft.util.EnumFacing)13 ItemStack (net.minecraft.item.ItemStack)12 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)11 IInventory (net.minecraft.inventory.IInventory)9 FluidTankInfo (net.minecraftforge.fluids.FluidTankInfo)6 IPipeTile (buildcraft.api.transport.IPipeTile)5 ArrayList (java.util.ArrayList)5 Fluid (net.minecraftforge.fluids.Fluid)5 FluidIdentifier (logisticspipes.utils.FluidIdentifier)3 Block (net.minecraft.block.Block)3 IBlockState (net.minecraft.block.state.IBlockState)3 ChunkPosition (net.minecraft.world.ChunkPosition)3 IFluidContainerItem (net.minecraftforge.fluids.IFluidContainerItem)3 TargetPoint (cpw.mods.fml.common.network.NetworkRegistry.TargetPoint)2 HashMap (java.util.HashMap)2 IBufferTransmitter (micdoodle8.mods.galacticraft.api.transmission.tile.IBufferTransmitter)2 RadiationFluidTileEntity (minechem.radiation.RadiationFluidTileEntity)2