Search in sources :

Example 16 with NetworkId

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

the class LogicTools method getControllerPosForConnector.

@Nullable
public static BlockPos getControllerPosForConnector(@Nonnull World world, @Nonnull BlockPos connectorPos) {
    WorldBlob worldBlob = XNetBlobData.getBlobData(world).getWorldBlob(world);
    NetworkId networkId = worldBlob.getNetworkAt(connectorPos);
    if (networkId == null) {
        return null;
    }
    return worldBlob.getProviderPosition(networkId);
}
Also used : WorldBlob(mcjty.xnet.multiblock.WorldBlob) NetworkId(mcjty.xnet.api.keys.NetworkId) Nullable(javax.annotation.Nullable)

Example 17 with NetworkId

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

the class ChunkBlob method dump.

public void dump() {
    System.out.println("################# Chunk (" + chunkPos.x + "," + chunkPos.z + ") #################");
    System.out.println("Network providers:");
    for (Map.Entry<IntPos, NetworkId> entry : networkProviders.entrySet()) {
        System.out.println("    " + toString(entry.getKey()) + ", network = " + entry.getValue().getId());
    }
    System.out.println("Network consumers:");
    for (Map.Entry<IntPos, ConsumerId> entry : networkConsumers.entrySet()) {
        System.out.println("    " + toString(entry.getKey()) + ", consumer = " + entry.getValue().getId());
    }
    System.out.println("Network mappings:");
    for (Map.Entry<BlobId, Set<NetworkId>> entry : networkMappings.entrySet()) {
        String s = "";
        for (NetworkId networkId : entry.getValue()) {
            s += networkId.getId() + " ";
        }
        System.out.println("    Blob(" + entry.getKey().getId() + "): networks = " + s);
    }
    System.out.println("Blob colors:");
    for (Map.Entry<BlobId, ColorId> entry : blobColors.entrySet()) {
        System.out.println("    Blob(" + entry.getKey().getId() + "): color = " + entry.getValue().getId());
    }
    System.out.println("Allocations:");
    for (Map.Entry<IntPos, BlobId> entry : blobAllocations.entrySet()) {
        System.out.println("    " + toString(entry.getKey()) + ", Blob(" + entry.getValue().getId() + ")");
    }
}
Also used : NetworkId(mcjty.xnet.api.keys.NetworkId) ConsumerId(mcjty.xnet.api.keys.ConsumerId)

Example 18 with NetworkId

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

the class ChunkBlob method getConsumersForNetwork.

@Nonnull
public Set<IntPos> getConsumersForNetwork(NetworkId network) {
    if (cachedConsumers == null) {
        cachedConsumers = new HashMap<>();
        for (Map.Entry<IntPos, ConsumerId> entry : networkConsumers.entrySet()) {
            IntPos pos = entry.getKey();
            BlobId blobId = blobAllocations.get(pos);
            Set<NetworkId> networkIds = networkMappings.get(blobId);
            if (networkIds != null) {
                for (NetworkId net : networkIds) {
                    if (!cachedConsumers.containsKey(net)) {
                        cachedConsumers.put(net, new HashSet<>());
                    }
                    cachedConsumers.get(net).add(pos);
                }
            }
        }
    }
    if (cachedConsumers.containsKey(network)) {
        return cachedConsumers.get(network);
    } else {
        return Collections.emptySet();
    }
}
Also used : ConsumerId(mcjty.xnet.api.keys.ConsumerId) NetworkId(mcjty.xnet.api.keys.NetworkId) Nonnull(javax.annotation.Nonnull)

Example 19 with NetworkId

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

the class ChunkBlob method readFromNBT.

public void readFromNBT(NBTTagCompound compound) {
    networkMappings.clear();
    blobAllocations.clear();
    networkProviders.clear();
    blobColors.clear();
    cachedBorderPositions.clear();
    cachedNetworks = null;
    cachedConsumers = null;
    cachedProviders = null;
    lastBlobId = compound.getInteger("lastBlob");
    // Keep track of blobs we found
    Set<BlobId> foundBlobs = new HashSet<>();
    if (compound.hasKey("allocations")) {
        int[] allocations = compound.getIntArray("allocations");
        int idx = 0;
        while (idx < allocations.length - 1) {
            IntPos pos = new IntPos(allocations[idx]);
            BlobId blob = new BlobId(allocations[idx + 1]);
            blobAllocations.put(pos, blob);
            foundBlobs.add(blob);
            if (pos.isBorder()) {
                cachedBorderPositions.add(pos);
            }
            idx += 2;
        }
    }
    if (compound.hasKey("mappings")) {
        int[] mappings = compound.getIntArray("mappings");
        int idx = 0;
        while (idx < mappings.length - 1) {
            int key = mappings[idx];
            BlobId blob = new BlobId(key);
            Set<NetworkId> ids = new HashSet<>();
            idx++;
            while (idx < mappings.length && mappings[idx] != -1) {
                ids.add(new NetworkId(mappings[idx]));
                idx++;
            }
            if (foundBlobs.contains(blob)) {
                // Only add mappings if we still have allocations for the blob
                networkMappings.put(blob, ids);
            }
            idx++;
        }
    }
    if (compound.hasKey("providers")) {
        int[] providers = compound.getIntArray("providers");
        int idx = 0;
        while (idx < providers.length - 1) {
            networkProviders.put(new IntPos(providers[idx]), new NetworkId(providers[idx + 1]));
            idx += 2;
        }
    }
    if (compound.hasKey("consumers")) {
        int[] consumers = compound.getIntArray("consumers");
        int idx = 0;
        while (idx < consumers.length - 1) {
            IntPos intPos = new IntPos(consumers[idx]);
            ConsumerId consumerId = new ConsumerId(consumers[idx + 1]);
            networkConsumers.put(intPos, consumerId);
            consumerPositions.put(consumerId, intPos);
            idx += 2;
        }
    }
    if (compound.hasKey("colors")) {
        int[] colors = compound.getIntArray("colors");
        int idx = 0;
        while (idx < colors.length - 1) {
            BlobId blob = new BlobId(colors[idx]);
            ColorId color = new ColorId(colors[idx + 1]);
            if (foundBlobs.contains(blob)) {
                // Only add colors if we still have allocations for the blob
                blobColors.put(blob, color);
            }
            idx += 2;
        }
    }
}
Also used : ConsumerId(mcjty.xnet.api.keys.ConsumerId) NetworkId(mcjty.xnet.api.keys.NetworkId)

Example 20 with NetworkId

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

the class NetworkChecker method hash.

private long hash(WorldBlob worldBlob) {
    long h = 0;
    for (NetworkId network : networks) {
        h = Long.rotateLeft(h, 3);
        h ^= worldBlob.getNetworkVersion(network);
    }
    return h;
}
Also used : NetworkId(mcjty.xnet.api.keys.NetworkId)

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