Search in sources :

Example 1 with PathfinderChecker

use of micdoodle8.mods.galacticraft.api.transmission.grid.PathfinderChecker in project Galacticraft by micdoodle8.

the class FluidNetwork method split.

@Override
public void split(IBufferTransmitter<FluidStack> splitPoint) {
    if (splitPoint instanceof TileEntity) {
        this.pipes.remove(splitPoint);
        /**
         * Loop through the connected blocks and attempt to see if there are
         * connections between the two points elsewhere.
         */
        TileEntity[] connectedBlocks = splitPoint.getAdjacentConnections();
        for (TileEntity connectedBlockA : connectedBlocks) {
            if (connectedBlockA instanceof INetworkConnection) {
                for (final TileEntity connectedBlockB : connectedBlocks) {
                    if (connectedBlockA != connectedBlockB && connectedBlockB instanceof INetworkConnection) {
                        Pathfinder finder = new PathfinderChecker(((TileEntity) splitPoint).getWorld(), (INetworkConnection) connectedBlockB, NetworkType.FLUID, splitPoint);
                        finder.init(new BlockVec3(connectedBlockA));
                        if (finder.results.size() > 0) {
                            for (BlockVec3 node : finder.closedSet) {
                                TileEntity nodeTile = node.getTileEntity(((TileEntity) splitPoint).getWorld());
                                if (nodeTile instanceof INetworkProvider) {
                                    if (nodeTile != splitPoint) {
                                        ((INetworkProvider) nodeTile).setNetwork(this);
                                    }
                                }
                            }
                        } else {
                            /**
                             * The connections A and B are not connected
                             * anymore. Give both of them a new network.
                             */
                            FluidNetwork newNetwork = new FluidNetwork();
                            for (BlockVec3 node : finder.closedSet) {
                                TileEntity nodeTile = node.getTileEntity(((TileEntity) splitPoint).getWorld());
                                if (nodeTile instanceof IBufferTransmitter) {
                                    if (nodeTile != splitPoint) {
                                        newNetwork.pipes.add((IBufferTransmitter<FluidStack>) nodeTile);
                                        newNetwork.pipesAdded.add((IBufferTransmitter<FluidStack>) nodeTile);
                                        newNetwork.onTransmitterAdded((IBufferTransmitter<FluidStack>) nodeTile);
                                        this.pipes.remove(nodeTile);
                                    }
                                }
                            }
                            newNetwork.refresh();
                            newNetwork.register();
                        }
                    }
                }
            }
        }
        if (this.pipes.isEmpty()) {
            this.unregister();
        } else {
            this.updateCapacity();
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) Pathfinder(micdoodle8.mods.galacticraft.api.transmission.grid.Pathfinder) INetworkConnection(micdoodle8.mods.galacticraft.api.transmission.tile.INetworkConnection) FluidStack(net.minecraftforge.fluids.FluidStack) IBufferTransmitter(micdoodle8.mods.galacticraft.api.transmission.tile.IBufferTransmitter) INetworkProvider(micdoodle8.mods.galacticraft.api.transmission.tile.INetworkProvider) PathfinderChecker(micdoodle8.mods.galacticraft.api.transmission.grid.PathfinderChecker) BlockVec3(micdoodle8.mods.galacticraft.api.vector.BlockVec3)

Aggregations

Pathfinder (micdoodle8.mods.galacticraft.api.transmission.grid.Pathfinder)1 PathfinderChecker (micdoodle8.mods.galacticraft.api.transmission.grid.PathfinderChecker)1 IBufferTransmitter (micdoodle8.mods.galacticraft.api.transmission.tile.IBufferTransmitter)1 INetworkConnection (micdoodle8.mods.galacticraft.api.transmission.tile.INetworkConnection)1 INetworkProvider (micdoodle8.mods.galacticraft.api.transmission.tile.INetworkProvider)1 BlockVec3 (micdoodle8.mods.galacticraft.api.vector.BlockVec3)1 TileEntity (net.minecraft.tileentity.TileEntity)1 FluidStack (net.minecraftforge.fluids.FluidStack)1