Search in sources :

Example 6 with NetworkId

use of mcjty.xnet.api.keys.NetworkId in project XNet by McJty.

the class WorldBlob method removeCableSegment.

public void removeCableSegment(BlockPos pos) {
    ConsumerId consumerId = getConsumerAt(pos);
    if (consumerId != null) {
        consumerPositions.remove(consumerId);
    }
    NetworkId providerId = getNetworkAt(pos);
    if (providerId != null) {
        providerPositions.remove(providerId);
    }
    ChunkBlob blob = getOrCreateBlob(pos);
    blob.removeCableSegment(pos);
    recalculateNetwork();
}
Also used : ConsumerId(mcjty.xnet.api.keys.ConsumerId) NetworkId(mcjty.xnet.api.keys.NetworkId)

Example 7 with NetworkId

use of mcjty.xnet.api.keys.NetworkId in project XNet by McJty.

the class WorldBlob method recalculateNetwork.

private void recalculateNetwork(@Nonnull Set<ChunkBlob> todo, @Nullable Set<ChunkBlob> recalculated) {
    while (!todo.isEmpty()) {
        ChunkBlob blob = todo.iterator().next();
        todo.remove(blob);
        if (recalculated != null) {
            if (!recalculated.contains(blob)) {
                blob.fixNetworkAllocations();
                recalculated.add(blob);
            }
        }
        blob.clearNetworkCache();
        removeCachedNetworksForBlob(blob);
        Set<IntPos> borderPositions = blob.getBorderPositions();
        ChunkPos chunkPos = blob.getChunkPos();
        for (IntPos pos : borderPositions) {
            Set<NetworkId> networks = blob.getOrCreateNetworksForPosition(pos);
            ColorId color = blob.getColorIdForPosition(pos);
            for (EnumFacing facing : EnumFacing.HORIZONTALS) {
                if (pos.isBorder(facing)) {
                    Vec3i vec = facing.getDirectionVec();
                    ChunkBlob adjacent = chunkBlobMap.get(ChunkPos.asLong(chunkPos.x + vec.getX(), chunkPos.z + vec.getZ()));
                    if (adjacent != null) {
                        IntPos connectedPos = pos.otherSide(facing);
                        if (adjacent.getBorderPositions().contains(connectedPos) && adjacent.getColorIdForPosition(connectedPos).equals(color)) {
                            // We have a connection!
                            Set<NetworkId> adjacentNetworks = adjacent.getOrCreateNetworksForPosition(connectedPos);
                            if (networks.addAll(adjacentNetworks)) {
                                // We changed this blob so need to push back on todo
                                todo.add(blob);
                            }
                            if (adjacentNetworks.addAll(networks)) {
                                todo.add(adjacent);
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : Vec3i(net.minecraft.util.math.Vec3i) EnumFacing(net.minecraft.util.EnumFacing) ChunkPos(net.minecraft.util.math.ChunkPos) NetworkId(mcjty.xnet.api.keys.NetworkId)

Example 8 with NetworkId

use of mcjty.xnet.api.keys.NetworkId in project XNet by McJty.

the class WorldBlobTest method main.

public static void main(String[] args) {
    ColorId color1 = new ColorId(111);
    ColorId color2 = new ColorId(222);
    ColorId color3 = new ColorId(333);
    WorldBlob world = new WorldBlob(0);
    BlockPos p1 = new BlockPos(10, 60, 10);
    world.createNetworkProvider(p1, color1, new NetworkId(1000));
    createCableLine(world, p1.east(), EnumFacing.EAST, 20, color1);
    BlockPos p2 = new BlockPos(50, 61, 10);
    world.createNetworkProvider(p2, color2, new NetworkId(2000));
    createCableLine(world, p2.west(), EnumFacing.WEST, 50, color2);
    BlockPos p3 = new BlockPos(50, 30, 1000);
    createCableLine(world, p3, EnumFacing.UP, 5, color3);
    createCableLine(world, p3.east().east(), EnumFacing.UP, 5, color3);
    world.createNetworkProvider(p3.north(), color3, new NetworkId(3000));
    world.createCableSegment(p3.east(), color3);
    world.dump();
    System.out.println("------------------------------------------------------------");
    System.out.println("------------------------------------------------------------");
    System.out.println("------------------------------------------------------------");
    world.removeCableSegment(new BlockPos(30, 61, 10));
    System.out.println("------------------------------------------------------------");
    System.out.println("------------------------------------------------------------");
    System.out.println("------------------------------------------------------------");
    world.dump();
    NBTTagCompound compound = new NBTTagCompound();
    world.writeToNBT(compound);
    world = new WorldBlob(0);
    world.readFromNBT(compound);
    System.out.println("------------------------------------------------------------");
    System.out.println("------------------------------------------------------------");
    System.out.println("------------------------------------------------------------");
    world.dump();
}
Also used : NBTTagCompound(net.minecraft.nbt.NBTTagCompound) BlockPos(net.minecraft.util.math.BlockPos) NetworkId(mcjty.xnet.api.keys.NetworkId)

Example 9 with NetworkId

use of mcjty.xnet.api.keys.NetworkId in project XNet by McJty.

the class TileEntityRouter method addRoutedConnectors.

public void addRoutedConnectors(Map<SidedConsumer, IConnectorSettings> connectors, @Nonnull BlockPos controllerPos, int channel, IChannelType type) {
    if (inError()) {
        // We are in error. Don't do anything
        return;
    }
    LocalChannelId id = new LocalChannelId(controllerPos, channel);
    String publishedName = publishedChannels.get(id);
    if (publishedName != null && !publishedName.isEmpty()) {
        NetworkId networkId = findRoutingNetwork();
        if (networkId != null) {
            LogicTools.consumers(getWorld(), networkId).forEach(consumerPos -> LogicTools.routers(getWorld(), consumerPos).forEach(router -> router.addConnectorsFromConnectedNetworks(connectors, publishedName, type)));
        } else {
            // If there is no routing network that means we have a local network only
            addConnectorsFromConnectedNetworks(connectors, publishedName, type);
        }
    }
}
Also used : GeneralConfiguration(mcjty.xnet.config.GeneralConfiguration) java.util(java.util) SPacketUpdateTileEntity(net.minecraft.network.play.server.SPacketUpdateTileEntity) IConnectorSettings(mcjty.xnet.api.channels.IConnectorSettings) Constants(net.minecraftforge.common.util.Constants) SidedConsumer(mcjty.xnet.api.keys.SidedConsumer) ChannelInfo(mcjty.xnet.logic.ChannelInfo) NetworkManager(net.minecraft.network.NetworkManager) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) BlockPosTools(mcjty.lib.varia.BlockPosTools) NBTTagList(net.minecraft.nbt.NBTTagList) Type(mcjty.typed.Type) ControllerChannelClientInfo(mcjty.xnet.clientinfo.ControllerChannelClientInfo) GenericTileEntity(mcjty.lib.entity.GenericTileEntity) XNetBlobData(mcjty.xnet.multiblock.XNetBlobData) WorldBlob(mcjty.xnet.multiblock.WorldBlob) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) LogicTools(mcjty.xnet.logic.LogicTools) EnumFacing(net.minecraft.util.EnumFacing) BlockPos(net.minecraft.util.math.BlockPos) Argument(mcjty.lib.network.Argument) MAX_CHANNELS(mcjty.xnet.logic.ChannelInfo.MAX_CHANNELS) IChannelType(mcjty.xnet.api.channels.IChannelType) NetworkId(mcjty.xnet.api.keys.NetworkId) NetworkId(mcjty.xnet.api.keys.NetworkId)

Example 10 with NetworkId

use of mcjty.xnet.api.keys.NetworkId in project XNet by McJty.

the class GenericCableBlock method addProbeInfo.

@Override
@Optional.Method(modid = "theoneprobe")
public void addProbeInfo(ProbeMode mode, IProbeInfo probeInfo, EntityPlayer player, World world, IBlockState blockState, IProbeHitData data) {
    WorldBlob worldBlob = XNetBlobData.getBlobData(world).getWorldBlob(world);
    if (mode == ProbeMode.DEBUG) {
        BlobId blobId = worldBlob.getBlobAt(data.getPos());
        if (blobId != null) {
            probeInfo.text(TextStyleClass.LABEL + "Blob: " + TextStyleClass.INFO + blobId.getId());
        }
        ColorId colorId = worldBlob.getColorAt(data.getPos());
        if (colorId != null) {
            probeInfo.text(TextStyleClass.LABEL + "Color: " + TextStyleClass.INFO + colorId.getId());
        }
    }
    Set<NetworkId> networks = worldBlob.getNetworksAt(data.getPos());
    for (NetworkId network : networks) {
        if (mode == ProbeMode.DEBUG) {
            probeInfo.text(TextStyleClass.LABEL + "Network: " + TextStyleClass.INFO + network.getId() + ", V: " + worldBlob.getNetworkVersion(network));
        } else {
            probeInfo.text(TextStyleClass.LABEL + "Network: " + TextStyleClass.INFO + network.getId());
        }
    }
    ConsumerId consumerId = worldBlob.getConsumerAt(data.getPos());
    if (consumerId != null) {
        probeInfo.text(TextStyleClass.LABEL + "Consumer: " + TextStyleClass.INFO + consumerId.getId());
    }
}
Also used : ConsumerId(mcjty.xnet.api.keys.ConsumerId) WorldBlob(mcjty.xnet.multiblock.WorldBlob) NetworkId(mcjty.xnet.api.keys.NetworkId) BlobId(mcjty.xnet.multiblock.BlobId) ColorId(mcjty.xnet.multiblock.ColorId)

Aggregations

NetworkId (mcjty.xnet.api.keys.NetworkId)21 WorldBlob (mcjty.xnet.multiblock.WorldBlob)10 ConsumerId (mcjty.xnet.api.keys.ConsumerId)7 XNetBlobData (mcjty.xnet.multiblock.XNetBlobData)6 EnumFacing (net.minecraft.util.EnumFacing)6 ColorId (mcjty.xnet.multiblock.ColorId)5 Nonnull (javax.annotation.Nonnull)4 Nullable (javax.annotation.Nullable)4 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)4 TileEntity (net.minecraft.tileentity.TileEntity)4 BlockPos (net.minecraft.util.math.BlockPos)4 java.util (java.util)3 Argument (mcjty.lib.network.Argument)3 BlockPosTools (mcjty.lib.varia.BlockPosTools)3 Type (mcjty.typed.Type)3 IChannelType (mcjty.xnet.api.channels.IChannelType)3 IConnectorSettings (mcjty.xnet.api.channels.IConnectorSettings)3 SidedConsumer (mcjty.xnet.api.keys.SidedConsumer)3 GeneralConfiguration (mcjty.xnet.config.GeneralConfiguration)3 ChannelInfo (mcjty.xnet.logic.ChannelInfo)3