Search in sources :

Example 6 with IFluidTankProperties

use of net.minecraftforge.fluids.capability.IFluidTankProperties in project ImmersiveEngineering by BluSunrize.

the class TileEntityFluidPipe method getConnectedFluidHandlers.

public static Set<DirectionalFluidOutput> getConnectedFluidHandlers(BlockPos node, World world) {
    if (indirectConnections.containsKey(node))
        return indirectConnections.get(node);
    ArrayList<BlockPos> openList = new ArrayList();
    ArrayList<BlockPos> closedList = new ArrayList();
    Set<DirectionalFluidOutput> fluidHandlers = Collections.newSetFromMap(new ConcurrentHashMap<DirectionalFluidOutput, Boolean>());
    openList.add(node);
    while (!openList.isEmpty() && closedList.size() < 1024) {
        BlockPos next = openList.get(0);
        if (world.isBlockLoaded(next)) {
            TileEntity pipeTile = world.getTileEntity(next);
            if (!closedList.contains(next) && (pipeTile instanceof IFluidPipe)) {
                if (pipeTile instanceof TileEntityFluidPipe)
                    closedList.add(next);
                IFluidTankProperties[] tankInfo;
                for (int i = 0; i < 6; i++) {
                    //						boolean b = (te instanceof TileEntityFluidPipe)? (((TileEntityFluidPipe) te).sideConfig[i]==0): (((TileEntityFluidPump) te).sideConfig[i]==1);
                    EnumFacing fd = EnumFacing.getFront(i);
                    if (((IFluidPipe) pipeTile).hasOutputConnection(fd)) {
                        BlockPos nextPos = next.offset(fd);
                        if (world.isBlockLoaded(nextPos)) {
                            TileEntity adjacentTile = world.getTileEntity(nextPos);
                            if (adjacentTile != null)
                                if (adjacentTile instanceof TileEntityFluidPipe)
                                    openList.add(nextPos);
                                else if (adjacentTile.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, fd.getOpposite())) {
                                    IFluidHandler handler = adjacentTile.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, fd.getOpposite());
                                    tankInfo = handler.getTankProperties();
                                    if (tankInfo != null && tankInfo.length > 0)
                                        fluidHandlers.add(new DirectionalFluidOutput(handler, adjacentTile, fd));
                                }
                        }
                    }
                }
            }
        }
        openList.remove(0);
    }
    if (FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER) {
        if (!indirectConnections.containsKey(node)) {
            indirectConnections.put(node, newSetFromMap(new ConcurrentHashMap<DirectionalFluidOutput, Boolean>()));
            indirectConnections.get(node).addAll(fluidHandlers);
        }
    }
    return fluidHandlers;
}
Also used : EnumFacing(net.minecraft.util.EnumFacing) IFluidHandler(net.minecraftforge.fluids.capability.IFluidHandler) TileEntity(net.minecraft.tileentity.TileEntity) IFluidTankProperties(net.minecraftforge.fluids.capability.IFluidTankProperties) BlockPos(net.minecraft.util.math.BlockPos) IFluidPipe(blusunrize.immersiveengineering.api.fluid.IFluidPipe) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap)

Example 7 with IFluidTankProperties

use of net.minecraftforge.fluids.capability.IFluidTankProperties in project Railcraft by Railcraft.

the class AdvancedFluidHandler method getFluidLevel.

public float getFluidLevel(Fluid fluid) {
    int amount = 0;
    int capacity = 0;
    for (IFluidTankProperties tank : getTankProperties()) {
        FluidStack liquid = tank.getContents();
        if (liquid == null || liquid.getFluid() != fluid)
            continue;
        amount += liquid.amount;
        capacity += tank.getCapacity();
    }
    return capacity == 0 ? 0 : amount / (float) capacity;
}
Also used : IFluidTankProperties(net.minecraftforge.fluids.capability.IFluidTankProperties) FluidStack(net.minecraftforge.fluids.FluidStack)

Aggregations

IFluidTankProperties (net.minecraftforge.fluids.capability.IFluidTankProperties)7 FluidStack (net.minecraftforge.fluids.FluidStack)4 TileEntity (net.minecraft.tileentity.TileEntity)3 EnumFacing (net.minecraft.util.EnumFacing)3 IFluidHandler (net.minecraftforge.fluids.capability.IFluidHandler)3 FluidTankProperties (net.minecraftforge.fluids.capability.FluidTankProperties)2 IFluidPipe (blusunrize.immersiveengineering.api.fluid.IFluidPipe)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 IBlockState (net.minecraft.block.state.IBlockState)1 BlockPos (net.minecraft.util.math.BlockPos)1