Search in sources :

Example 1 with INetworkConnection

use of micdoodle8.mods.galacticraft.api.transmission.tile.INetworkConnection in project Galacticraft by micdoodle8.

the class ChunkPowerHandler method onChunkLoad.

@SubscribeEvent
public void onChunkLoad(ChunkEvent.Load event) {
    if (!event.world.isRemote && event.getChunk() != null) {
        try {
            ArrayList<Object> tileList = Lists.newArrayList();
            tileList.addAll(event.getChunk().getTileEntityMap().values());
            for (Object o : tileList) {
                if (o instanceof TileEntity) {
                    TileEntity tile = (TileEntity) o;
                    if (tile instanceof INetworkConnection) {
                        ((INetworkConnection) tile).refresh();
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        if (ConfigManagerCore.retrogenOil && GCCoreUtil.getDimensionID(event.world) == 0) {
            EventHandlerGC.retrogenOil(event.world, event.getChunk());
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) INetworkConnection(micdoodle8.mods.galacticraft.api.transmission.tile.INetworkConnection) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 2 with INetworkConnection

use of micdoodle8.mods.galacticraft.api.transmission.tile.INetworkConnection in project Galacticraft by micdoodle8.

the class BlockEnclosed method onNeighborBlockChange.

@Override
public void onNeighborBlockChange(World world, BlockPos pos, IBlockState state, Block block) {
    int metadata = state.getBlock().getMetaFromState(state);
    final TileEntity tileEntity = world.getTileEntity(pos);
    if (metadata == EnumEnclosedBlockType.TE_CONDUIT.getMeta()) {
        super.onNeighborBlockChange(world, pos, state, block);
    } else if (metadata == EnumEnclosedBlockType.OXYGEN_PIPE.getMeta()) {
        super.onNeighborBlockChange(world, pos, state, block);
        if (tileEntity instanceof INetworkConnection) {
            ((INetworkConnection) tileEntity).refresh();
        }
    } else if (metadata <= 6) {
        super.onNeighborBlockChange(world, pos, state, block);
        if (CompatibilityManager.isIc2Loaded() && tileEntity != null) {
            try {
                if (onBlockNeighbourChangeIC2a != null) {
                    onBlockNeighbourChangeIC2a.invoke(tileEntity, block);
                } else if (onBlockNeighbourChangeIC2b != null) {
                    onBlockNeighbourChangeIC2b.invoke(tileEntity, block, pos);
                }
                return;
            } catch (Exception ignore) {
            }
        }
    } else if (metadata <= 12) {
        if (CompatibilityManager.isBCraftTransportLoaded()) {
            if (blockPipeBC != null) {
                try {
                    blockPipeBC.onNeighborBlockChange(world, pos, state, block);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                return;
            }
        }
        super.onNeighborBlockChange(world, pos, state, block);
    } else if (metadata <= EnumEnclosedBlockType.ME_CABLE.getMeta()) {
        super.onNeighborBlockChange(world, pos, state, block);
        if (CompatibilityManager.isAppEngLoaded()) {
            world.markBlockForUpdate(pos);
        }
    } else if (metadata <= EnumEnclosedBlockType.ALUMINUM_WIRE.getMeta()) {
        super.onNeighborBlockChange(world, pos, state, block);
        if (tileEntity instanceof IConductor) {
            ((IConductor) tileEntity).refresh();
        }
    } else if (metadata <= EnumEnclosedBlockType.ALUMINUM_WIRE_HEAVY.getMeta()) {
        super.onNeighborBlockChange(world, pos, state, block);
        if (tileEntity instanceof IConductor) {
            ((IConductor) tileEntity).refresh();
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IConductor(micdoodle8.mods.galacticraft.api.transmission.tile.IConductor) INetworkConnection(micdoodle8.mods.galacticraft.api.transmission.tile.INetworkConnection)

Example 3 with INetworkConnection

use of micdoodle8.mods.galacticraft.api.transmission.tile.INetworkConnection in project Galacticraft by micdoodle8.

the class BlockTransmitter method onNeighborBlockChange.

@Override
public void onNeighborBlockChange(World worldIn, BlockPos pos, IBlockState state, Block neighborBlock) {
    super.onNeighborBlockChange(worldIn, pos, state, neighborBlock);
    TileEntity tile = worldIn.getTileEntity(pos);
    this.setBlockBoundsBasedOnState(worldIn, pos);
    GalacticraftCore.packetPipeline.sendToAllAround(new PacketSimple(EnumSimplePacket.C_UPDATE_WIRE_BOUNDS, GCCoreUtil.getDimensionID(worldIn), new Object[] { pos }), new NetworkRegistry.TargetPoint(GCCoreUtil.getDimensionID(worldIn), pos.getX(), pos.getY(), pos.getZ(), 10.0D));
    TileEntity tileEntity = worldIn.getTileEntity(pos);
    if (tile instanceof INetworkConnection) {
        ((INetworkConnection) tile).refresh();
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) INetworkConnection(micdoodle8.mods.galacticraft.api.transmission.tile.INetworkConnection) NetworkRegistry(net.minecraftforge.fml.common.network.NetworkRegistry) PacketSimple(micdoodle8.mods.galacticraft.core.network.PacketSimple)

Example 4 with INetworkConnection

use of micdoodle8.mods.galacticraft.api.transmission.tile.INetworkConnection 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

INetworkConnection (micdoodle8.mods.galacticraft.api.transmission.tile.INetworkConnection)4 TileEntity (net.minecraft.tileentity.TileEntity)4 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 IConductor (micdoodle8.mods.galacticraft.api.transmission.tile.IConductor)1 INetworkProvider (micdoodle8.mods.galacticraft.api.transmission.tile.INetworkProvider)1 BlockVec3 (micdoodle8.mods.galacticraft.api.vector.BlockVec3)1 PacketSimple (micdoodle8.mods.galacticraft.core.network.PacketSimple)1 FluidStack (net.minecraftforge.fluids.FluidStack)1 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)1 NetworkRegistry (net.minecraftforge.fml.common.network.NetworkRegistry)1