Search in sources :

Example 1 with NetworkId

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

the class ControllerBlock method findNeighbourConnector.

// Check neighbour blocks for a connector and inherit the color from that
private void findNeighbourConnector(World world, BlockPos pos) {
    XNetBlobData blobData = XNetBlobData.getBlobData(world);
    WorldBlob worldBlob = blobData.getWorldBlob(world);
    ColorId oldColor = worldBlob.getColorAt(pos);
    ColorId newColor = null;
    for (EnumFacing facing : EnumFacing.VALUES) {
        if (world.getBlockState(pos.offset(facing)).getBlock() instanceof ConnectorBlock) {
            ColorId color = worldBlob.getColorAt(pos.offset(facing));
            if (color != null) {
                if (color == oldColor) {
                    // Nothing to do
                    return;
                }
                newColor = color;
            }
        }
    }
    if (newColor != null) {
        if (worldBlob.getBlobAt(pos) != null) {
            worldBlob.removeCableSegment(pos);
        }
        NetworkId networkId = worldBlob.newNetwork();
        worldBlob.createNetworkProvider(pos, newColor, networkId);
        blobData.save(world);
        TileEntity te = world.getTileEntity(pos);
        if (te instanceof TileEntityController) {
            ((TileEntityController) te).setNetworkId(networkId);
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) XNetBlobData(mcjty.xnet.multiblock.XNetBlobData) EnumFacing(net.minecraft.util.EnumFacing) WorldBlob(mcjty.xnet.multiblock.WorldBlob) NetworkId(mcjty.xnet.api.keys.NetworkId) ColorId(mcjty.xnet.multiblock.ColorId) ConnectorBlock(mcjty.xnet.blocks.cables.ConnectorBlock)

Example 2 with NetworkId

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

the class ControllerBlock method addProbeInfo.

@Override
@Optional.Method(modid = "theoneprobe")
public void addProbeInfo(ProbeMode mode, IProbeInfo probeInfo, EntityPlayer player, World world, IBlockState blockState, IProbeHitData data) {
    super.addProbeInfo(mode, probeInfo, player, world, blockState, data);
    TileEntity te = world.getTileEntity(data.getPos());
    WorldBlob worldBlob = XNetBlobData.getBlobData(world).getWorldBlob(world);
    if (te instanceof TileEntityController) {
        TileEntityController controller = (TileEntityController) te;
        NetworkId networkId = controller.getNetworkId();
        if (networkId != null) {
            if (mode == ProbeMode.DEBUG) {
                probeInfo.text(TextStyleClass.LABEL + "Network: " + TextStyleClass.INFO + networkId.getId() + ", V: " + worldBlob.getNetworkVersion(networkId));
            } else {
                probeInfo.text(TextStyleClass.LABEL + "Network: " + TextStyleClass.INFO + networkId.getId());
            }
        }
        if (mode == ProbeMode.DEBUG) {
            String s = "";
            for (NetworkId id : controller.getNetworkChecker().getAffectedNetworks()) {
                s += id.getId() + " ";
                if (s.length() > 15) {
                    probeInfo.text(TextStyleClass.LABEL + "InfNet: " + TextStyleClass.INFO + s);
                    s = "";
                }
            }
            if (!s.isEmpty()) {
                probeInfo.text(TextStyleClass.LABEL + "InfNet: " + TextStyleClass.INFO + s);
            }
        }
        if (controller.inError()) {
            probeInfo.text(TextStyleClass.ERROR + "Too many controllers on network!");
        }
    }
    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());
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) WorldBlob(mcjty.xnet.multiblock.WorldBlob) NetworkId(mcjty.xnet.api.keys.NetworkId) BlobId(mcjty.xnet.multiblock.BlobId) ColorId(mcjty.xnet.multiblock.ColorId)

Example 3 with NetworkId

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

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

the class WorldBlob method dump.

private void dump(String prefix, Set<NetworkId> networks) {
    String s = prefix + ": ";
    for (NetworkId network : networks) {
        s += network.getId() + " ";
    }
    System.out.println("s = " + s);
}
Also used : NetworkId(mcjty.xnet.api.keys.NetworkId)

Example 5 with NetworkId

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

the class WorldBlob method removeCachedNetworksForBlob.

private void removeCachedNetworksForBlob(ChunkBlob blob) {
    for (NetworkId id : blob.getNetworks()) {
        consumersOnNetwork.remove(id);
        incNetworkVersion(id);
    }
}
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