Search in sources :

Example 6 with ConsumerId

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

the class ChunkBlob method writeToNBT.

public NBTTagCompound writeToNBT(NBTTagCompound compound) {
    compound.setInteger("lastBlob", lastBlobId);
    List<Integer> m = new ArrayList<>();
    for (Map.Entry<BlobId, Set<NetworkId>> entry : networkMappings.entrySet()) {
        m.add(entry.getKey().getId());
        for (NetworkId v : entry.getValue()) {
            m.add(v.getId());
        }
        m.add(-1);
    }
    NBTTagIntArray mappings = new NBTTagIntArray(m.stream().mapToInt(i -> i).toArray());
    compound.setTag("mappings", mappings);
    m.clear();
    for (Map.Entry<IntPos, BlobId> entry : blobAllocations.entrySet()) {
        m.add(entry.getKey().getPos());
        m.add(entry.getValue().getId());
    }
    NBTTagIntArray allocations = new NBTTagIntArray(m.stream().mapToInt(i -> i).toArray());
    compound.setTag("allocations", allocations);
    m.clear();
    for (Map.Entry<IntPos, NetworkId> entry : networkProviders.entrySet()) {
        m.add(entry.getKey().getPos());
        m.add(entry.getValue().getId());
    }
    NBTTagIntArray providers = new NBTTagIntArray(m.stream().mapToInt(i -> i).toArray());
    compound.setTag("providers", providers);
    m.clear();
    for (Map.Entry<IntPos, ConsumerId> entry : networkConsumers.entrySet()) {
        m.add(entry.getKey().getPos());
        m.add(entry.getValue().getId());
    }
    NBTTagIntArray consumers = new NBTTagIntArray(m.stream().mapToInt(i -> i).toArray());
    compound.setTag("consumers", consumers);
    m.clear();
    for (Map.Entry<BlobId, ColorId> entry : blobColors.entrySet()) {
        m.add(entry.getKey().getId());
        m.add(entry.getValue().getId());
    }
    NBTTagIntArray colors = new NBTTagIntArray(m.stream().mapToInt(i -> i).toArray());
    compound.setTag("colors", colors);
    return compound;
}
Also used : NetworkId(mcjty.xnet.api.keys.NetworkId) NBTTagIntArray(net.minecraft.nbt.NBTTagIntArray) ConsumerId(mcjty.xnet.api.keys.ConsumerId)

Example 7 with ConsumerId

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

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

Example 9 with ConsumerId

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

the class ConnectorBlock method createCableSegment.

@Override
public void createCableSegment(World world, BlockPos pos, ItemStack stack) {
    ConsumerId consumer;
    if (!stack.isEmpty() && stack.hasTagCompound() && stack.getTagCompound().hasKey("consumerId")) {
        consumer = new ConsumerId(stack.getTagCompound().getInteger("consumerId"));
    } else {
        XNetBlobData blobData = XNetBlobData.getBlobData(world);
        WorldBlob worldBlob = blobData.getWorldBlob(world);
        consumer = worldBlob.newConsumer();
    }
    createCableSegment(world, pos, consumer);
}
Also used : XNetBlobData(mcjty.xnet.multiblock.XNetBlobData) ConsumerId(mcjty.xnet.api.keys.ConsumerId) WorldBlob(mcjty.xnet.multiblock.WorldBlob)

Example 10 with ConsumerId

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

the class ChannelInfo method readFromNBT.

public void readFromNBT(NBTTagCompound tag) {
    channelSettings.readFromNBT(tag);
    enabled = tag.getBoolean("enabled");
    if (tag.hasKey("name")) {
        channelName = tag.getString("name");
    } else {
        channelName = null;
    }
    NBTTagList conlist = tag.getTagList("connectors", Constants.NBT.TAG_COMPOUND);
    for (int i = 0; i < conlist.tagCount(); i++) {
        NBTTagCompound tc = conlist.getCompoundTagAt(i);
        String id = tc.getString("type");
        IChannelType type = XNet.xNetApi.findType(id);
        if (type == null) {
            XNet.logger.warn("Unsupported type " + id + "!");
            continue;
        }
        if (!getType().equals(type)) {
            XNet.logger.warn("Trying to load a connector with non-matching type " + type + "!");
            continue;
        }
        ConsumerId consumerId = new ConsumerId(tc.getInteger("consumerId"));
        EnumFacing side = EnumFacing.VALUES[tc.getInteger("side")];
        SidedConsumer key = new SidedConsumer(consumerId, side);
        boolean advanced = tc.getBoolean("advanced");
        ConnectorInfo connectorInfo = new ConnectorInfo(type, key, advanced);
        connectorInfo.readFromNBT(tc);
        connectors.put(key, connectorInfo);
    }
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) ConnectorInfo(mcjty.xnet.clientinfo.ConnectorInfo) SidedConsumer(mcjty.xnet.api.keys.SidedConsumer) EnumFacing(net.minecraft.util.EnumFacing) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ConsumerId(mcjty.xnet.api.keys.ConsumerId) IChannelType(mcjty.xnet.api.channels.IChannelType)

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