Search in sources :

Example 1 with TileEntityCache

use of pneumaticCraft.common.util.TileEntityCache in project PneumaticCraft by MineMaarten.

the class ModuleNetworkManager method getConnectedModules.

public Set<TubeModule> getConnectedModules(TubeModule module) {
    Set<TubeModule> modules = new HashSet<TubeModule>();
    Set<TileEntityPressureTube> traversedTubes = new HashSet<TileEntityPressureTube>();
    Stack<TileEntityPressureTube> pendingTubes = new Stack<TileEntityPressureTube>();
    pendingTubes.push((TileEntityPressureTube) module.getTube());
    while (!pendingTubes.isEmpty()) {
        TileEntityPressureTube tube = pendingTubes.pop();
        for (TubeModule m : tube.modules) {
            if (m != null)
                modules.add(m);
        }
        TileEntityCache[] cache = ((TileEntityPneumaticBase) ((IPneumaticMachine) tube).getAirHandler()).getTileCache();
        for (ForgeDirection d : ForgeDirection.VALID_DIRECTIONS) {
            if (tube.sidesConnected[d.ordinal()]) {
                TileEntityPressureTube newTube = ModInteractionUtils.getInstance().getTube(cache[d.ordinal()].getTileEntity());
                if (newTube != null && !traversedTubes.contains(newTube)) {
                    pendingTubes.add(newTube);
                    traversedTubes.add(newTube);
                }
            }
        }
    }
    return modules;
}
Also used : ForgeDirection(net.minecraftforge.common.util.ForgeDirection) TileEntityPressureTube(pneumaticCraft.common.tileentity.TileEntityPressureTube) TileEntityCache(pneumaticCraft.common.util.TileEntityCache) HashSet(java.util.HashSet) Stack(java.util.Stack) TileEntityPneumaticBase(pneumaticCraft.common.tileentity.TileEntityPneumaticBase)

Aggregations

HashSet (java.util.HashSet)1 Stack (java.util.Stack)1 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)1 TileEntityPneumaticBase (pneumaticCraft.common.tileentity.TileEntityPneumaticBase)1 TileEntityPressureTube (pneumaticCraft.common.tileentity.TileEntityPressureTube)1 TileEntityCache (pneumaticCraft.common.util.TileEntityCache)1