Search in sources :

Example 11 with ConsumerId

use of mcjty.xnet.api.keys.ConsumerId 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 12 with ConsumerId

use of mcjty.xnet.api.keys.ConsumerId 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 13 with ConsumerId

use of mcjty.xnet.api.keys.ConsumerId 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 14 with ConsumerId

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

the class TileEntityController method createConnector.

private void createConnector(int channel, SidedPos pos) {
    WorldBlob worldBlob = XNetBlobData.getBlobData(getWorld()).getWorldBlob(getWorld());
    BlockPos consumerPos = pos.getPos().offset(pos.getSide());
    ConsumerId consumerId = worldBlob.getConsumerAt(consumerPos);
    if (consumerId == null) {
        throw new RuntimeException("What?");
    }
    SidedConsumer id = new SidedConsumer(consumerId, pos.getSide().getOpposite());
    boolean advanced = getWorld().getBlockState(consumerPos).getBlock() == NetCableSetup.advancedConnectorBlock;
    channels[channel].createConnector(id, advanced);
    networkDirty();
    markDirtyQuick();
}
Also used : SidedConsumer(mcjty.xnet.api.keys.SidedConsumer) ConsumerId(mcjty.xnet.api.keys.ConsumerId) WorldBlob(mcjty.xnet.multiblock.WorldBlob) BlockPos(net.minecraft.util.math.BlockPos)

Example 15 with ConsumerId

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

the class TileEntityController method updateConnector.

private void updateConnector(int channel, SidedPos pos, Map<String, Argument> args) {
    WorldBlob worldBlob = XNetBlobData.getBlobData(getWorld()).getWorldBlob(getWorld());
    ConsumerId consumerId = worldBlob.getConsumerAt(pos.getPos().offset(pos.getSide()));
    for (Map.Entry<SidedConsumer, ConnectorInfo> entry : channels[channel].getConnectors().entrySet()) {
        SidedConsumer key = entry.getKey();
        if (key.getConsumerId().equals(consumerId) && key.getSide().getOpposite().equals(pos.getSide())) {
            Map<String, Object> data = new HashMap<>();
            for (Map.Entry<String, Argument> e : args.entrySet()) {
                data.put(e.getKey(), e.getValue().getValue());
            }
            channels[channel].getConnectors().get(key).getConnectorSettings().update(data);
            networkDirty();
            markDirtyQuick();
            return;
        }
    }
}
Also used : ConnectorInfo(mcjty.xnet.clientinfo.ConnectorInfo) Argument(mcjty.lib.network.Argument) SidedConsumer(mcjty.xnet.api.keys.SidedConsumer) ConsumerId(mcjty.xnet.api.keys.ConsumerId) WorldBlob(mcjty.xnet.multiblock.WorldBlob)

Aggregations

ConsumerId (mcjty.xnet.api.keys.ConsumerId)15 WorldBlob (mcjty.xnet.multiblock.WorldBlob)7 NetworkId (mcjty.xnet.api.keys.NetworkId)6 SidedConsumer (mcjty.xnet.api.keys.SidedConsumer)5 ConnectorInfo (mcjty.xnet.clientinfo.ConnectorInfo)3 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)3 XNetBlobData (mcjty.xnet.multiblock.XNetBlobData)2 TileEntity (net.minecraft.tileentity.TileEntity)2 EnumFacing (net.minecraft.util.EnumFacing)2 BlockPos (net.minecraft.util.math.BlockPos)2 World (net.minecraft.world.World)2 Nonnull (javax.annotation.Nonnull)1 Argument (mcjty.lib.network.Argument)1 IChannelType (mcjty.xnet.api.channels.IChannelType)1 ConnectorBlock (mcjty.xnet.blocks.cables.ConnectorBlock)1 ConnectorTileEntity (mcjty.xnet.blocks.cables.ConnectorTileEntity)1 CableColor (mcjty.xnet.blocks.generic.CableColor)1 GenericCableBlock (mcjty.xnet.blocks.generic.GenericCableBlock)1 BlobId (mcjty.xnet.multiblock.BlobId)1 ColorId (mcjty.xnet.multiblock.ColorId)1