Search in sources :

Example 1 with ColorId

use of mcjty.xnet.multiblock.ColorId 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 ColorId

use of mcjty.xnet.multiblock.ColorId 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 ColorId

use of mcjty.xnet.multiblock.ColorId in project XNet by McJty.

the class GenericCableBlock method createCableSegment.

public void createCableSegment(World world, BlockPos pos, ItemStack stack) {
    XNetBlobData blobData = XNetBlobData.getBlobData(world);
    WorldBlob worldBlob = blobData.getWorldBlob(world);
    CableColor color = world.getBlockState(pos).getValue(COLOR);
    worldBlob.createCableSegment(pos, new ColorId(color.ordinal() + 1));
    blobData.save(world);
}
Also used : XNetBlobData(mcjty.xnet.multiblock.XNetBlobData) WorldBlob(mcjty.xnet.multiblock.WorldBlob) ColorId(mcjty.xnet.multiblock.ColorId)

Example 4 with ColorId

use of mcjty.xnet.multiblock.ColorId 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 5 with ColorId

use of mcjty.xnet.multiblock.ColorId in project XNet by McJty.

the class RouterBlock 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);
    XNetBlobData blobData = XNetBlobData.getBlobData(world);
    WorldBlob worldBlob = blobData.getWorldBlob(world);
    Set<NetworkId> networks = worldBlob.getNetworksAt(data.getPos());
    for (NetworkId networkId : networks) {
        probeInfo.text(TextStyleClass.LABEL + "Network: " + TextStyleClass.INFO + networkId.getId());
        if (mode != ProbeMode.EXTENDED) {
            break;
        }
    }
    TileEntity te = world.getTileEntity(data.getPos());
    if (te instanceof TileEntityRouter) {
        TileEntityRouter router = (TileEntityRouter) te;
        if (router.inError()) {
            probeInfo.text(TextStyleClass.ERROR + "Too many channels on router!");
        } else {
            probeInfo.text(TextStyleClass.LABEL + "Channels: " + TextStyleClass.INFO + router.getChannelCount());
        }
    }
    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) XNetBlobData(mcjty.xnet.multiblock.XNetBlobData) WorldBlob(mcjty.xnet.multiblock.WorldBlob) NetworkId(mcjty.xnet.api.keys.NetworkId) BlobId(mcjty.xnet.multiblock.BlobId) ColorId(mcjty.xnet.multiblock.ColorId)

Aggregations

ColorId (mcjty.xnet.multiblock.ColorId)7 WorldBlob (mcjty.xnet.multiblock.WorldBlob)7 NetworkId (mcjty.xnet.api.keys.NetworkId)5 XNetBlobData (mcjty.xnet.multiblock.XNetBlobData)5 BlobId (mcjty.xnet.multiblock.BlobId)3 TileEntity (net.minecraft.tileentity.TileEntity)3 ConsumerId (mcjty.xnet.api.keys.ConsumerId)1 ConnectorBlock (mcjty.xnet.blocks.cables.ConnectorBlock)1 CableColor (mcjty.xnet.blocks.generic.CableColor)1 EnumFacing (net.minecraft.util.EnumFacing)1