Search in sources :

Example 1 with WorldBlob

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

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

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

the class TileEntityController method removeConnector.

private void removeConnector(int channel, SidedPos pos) {
    WorldBlob worldBlob = XNetBlobData.getBlobData(getWorld()).getWorldBlob(getWorld());
    ConsumerId consumerId = worldBlob.getConsumerAt(pos.getPos().offset(pos.getSide()));
    SidedConsumer toremove = null;
    for (Map.Entry<SidedConsumer, ConnectorInfo> entry : channels[channel].getConnectors().entrySet()) {
        SidedConsumer key = entry.getKey();
        if (key.getSide().getOpposite().equals(pos.getSide())) {
            if (key.getConsumerId().equals(consumerId)) {
                toremove = key;
                break;
            }
        }
    }
    if (toremove != null) {
        channels[channel].getConnectors().remove(toremove);
        networkDirty();
        markDirtyQuick();
    }
}
Also used : ConnectorInfo(mcjty.xnet.clientinfo.ConnectorInfo) SidedConsumer(mcjty.xnet.api.keys.SidedConsumer) ConsumerId(mcjty.xnet.api.keys.ConsumerId) WorldBlob(mcjty.xnet.multiblock.WorldBlob)

Example 4 with WorldBlob

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

the class TileEntityController method findConnectedBlocks.

@Nonnull
private List<ConnectedBlockClientInfo> findConnectedBlocks() {
    WorldBlob worldBlob = XNetBlobData.getBlobData(getWorld()).getWorldBlob(getWorld());
    Set<ConnectedBlockClientInfo> set = new HashSet<>();
    for (BlockPos consumerPos : worldBlob.getConsumers(networkId)) {
        String name = "";
        TileEntity te = getWorld().getTileEntity(consumerPos);
        if (te instanceof ConnectorTileEntity) {
            // Should always be the case. @todo error?
            name = ((ConnectorTileEntity) te).getConnectorName();
        } else {
            XNet.logger.warn("What? The connector at " + BlockPosTools.toString(consumerPos) + " is not a connector?");
        }
        for (EnumFacing facing : EnumFacing.VALUES) {
            if (ConnectorBlock.isConnectable(getWorld(), consumerPos, facing)) {
                BlockPos pos = consumerPos.offset(facing);
                SidedPos sidedPos = new SidedPos(pos, facing.getOpposite());
                IBlockState state = getWorld().getBlockState(pos);
                ItemStack item = state.getBlock().getItem(getWorld(), pos, state);
                ConnectedBlockClientInfo info = new ConnectedBlockClientInfo(sidedPos, item, name);
                set.add(info);
            }
        }
    }
    List<ConnectedBlockClientInfo> list = new ArrayList<>(set);
    list.sort(Comparator.comparing(ConnectedBlockClientInfo::getBlockUnlocName).thenComparing(ConnectedBlockClientInfo::getPos));
    return list;
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) ConnectorTileEntity(mcjty.xnet.blocks.cables.ConnectorTileEntity) EnumFacing(net.minecraft.util.EnumFacing) SPacketUpdateTileEntity(net.minecraft.network.play.server.SPacketUpdateTileEntity) ConnectorTileEntity(mcjty.xnet.blocks.cables.ConnectorTileEntity) GenericEnergyReceiverTileEntity(mcjty.lib.entity.GenericEnergyReceiverTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) ConnectedBlockClientInfo(mcjty.xnet.clientinfo.ConnectedBlockClientInfo) SidedPos(mcjty.xnet.api.keys.SidedPos) WorldBlob(mcjty.xnet.multiblock.WorldBlob) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack) Nonnull(javax.annotation.Nonnull)

Example 5 with WorldBlob

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

the class TileEntityController method update.

@Override
public void update() {
    if (!getWorld().isRemote) {
        WorldBlob worldBlob = XNetBlobData.getBlobData(getWorld()).getWorldBlob(getWorld());
        if (worldBlob.getNetworksAt(getPos()).size() > 1) {
            // Error situation!
            markDirtyClient();
            return;
        }
        checkNetwork(worldBlob);
        if (!checkAndConsumeRF(GeneralConfiguration.controllerRFT)) {
            return;
        }
        boolean dirty = false;
        int newcolors = 0;
        for (int i = 0; i < MAX_CHANNELS; i++) {
            if (channels[i] != null && channels[i].isEnabled()) {
                if (checkAndConsumeRF(GeneralConfiguration.controllerChannelRFT)) {
                    channels[i].getChannelSettings().tick(i, this);
                }
                newcolors |= channels[i].getChannelSettings().getColors();
                dirty = true;
            }
        }
        if (newcolors != colors) {
            dirty = true;
            colors = newcolors;
        }
        if (dirty) {
            markDirtyQuick();
        }
    }
}
Also used : WorldBlob(mcjty.xnet.multiblock.WorldBlob)

Aggregations

WorldBlob (mcjty.xnet.multiblock.WorldBlob)25 XNetBlobData (mcjty.xnet.multiblock.XNetBlobData)11 ConsumerId (mcjty.xnet.api.keys.ConsumerId)8 NetworkId (mcjty.xnet.api.keys.NetworkId)8 ColorId (mcjty.xnet.multiblock.ColorId)7 TileEntity (net.minecraft.tileentity.TileEntity)7 SidedConsumer (mcjty.xnet.api.keys.SidedConsumer)6 EnumFacing (net.minecraft.util.EnumFacing)6 BlockPos (net.minecraft.util.math.BlockPos)6 ConnectorInfo (mcjty.xnet.clientinfo.ConnectorInfo)5 Nonnull (javax.annotation.Nonnull)4 SidedPos (mcjty.xnet.api.keys.SidedPos)4 ConnectorTileEntity (mcjty.xnet.blocks.cables.ConnectorTileEntity)4 GenericEnergyReceiverTileEntity (mcjty.lib.entity.GenericEnergyReceiverTileEntity)3 ConnectorBlock (mcjty.xnet.blocks.cables.ConnectorBlock)3 ConnectedBlockClientInfo (mcjty.xnet.clientinfo.ConnectedBlockClientInfo)3 BlobId (mcjty.xnet.multiblock.BlobId)3 IBlockState (net.minecraft.block.state.IBlockState)3 SPacketUpdateTileEntity (net.minecraft.network.play.server.SPacketUpdateTileEntity)3 Nullable (javax.annotation.Nullable)2