Search in sources :

Example 1 with IFluidPipe

use of blusunrize.immersiveengineering.api.fluid.IFluidPipe 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)

Aggregations

IFluidPipe (blusunrize.immersiveengineering.api.fluid.IFluidPipe)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 TileEntity (net.minecraft.tileentity.TileEntity)1 EnumFacing (net.minecraft.util.EnumFacing)1 BlockPos (net.minecraft.util.math.BlockPos)1 IFluidHandler (net.minecraftforge.fluids.capability.IFluidHandler)1 IFluidTankProperties (net.minecraftforge.fluids.capability.IFluidTankProperties)1