Search in sources :

Example 1 with ChannelInfo

use of mcjty.xnet.logic.ChannelInfo in project XNet by McJty.

the class TileEntityController method readRestorableFromNBT.

@Override
public void readRestorableFromNBT(NBTTagCompound tagCompound) {
    super.readRestorableFromNBT(tagCompound);
    colors = tagCompound.getInteger("colors");
    for (int i = 0; i < MAX_CHANNELS; i++) {
        if (tagCompound.hasKey("channel" + i)) {
            NBTTagCompound tc = (NBTTagCompound) tagCompound.getTag("channel" + i);
            String id = tc.getString("type");
            IChannelType type = XNet.xNetApi.findType(id);
            if (type == null) {
                XNet.logger.warn("Unsupported type " + id + "!");
                continue;
            }
            channels[i] = new ChannelInfo(type);
            channels[i].readFromNBT(tc);
        } else {
            channels[i] = null;
        }
    }
}
Also used : NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ChannelInfo(mcjty.xnet.logic.ChannelInfo) IChannelType(mcjty.xnet.api.channels.IChannelType)

Example 2 with ChannelInfo

use of mcjty.xnet.logic.ChannelInfo in project XNet by McJty.

the class TileEntityController method createChannel.

private void createChannel(int channel, String typeId) {
    IChannelType type = XNet.xNetApi.findType(typeId);
    channels[channel] = new ChannelInfo(type);
    networkDirty();
    markDirtyQuick();
}
Also used : ChannelInfo(mcjty.xnet.logic.ChannelInfo) IChannelType(mcjty.xnet.api.channels.IChannelType)

Example 3 with ChannelInfo

use of mcjty.xnet.logic.ChannelInfo in project XNet by McJty.

the class TileEntityRouter method findLocalChannelInfo.

@Nonnull
private List<ControllerChannelClientInfo> findLocalChannelInfo(boolean onlyPublished) {
    List<ControllerChannelClientInfo> list = new ArrayList<>();
    LogicTools.connectors(getWorld(), getPos()).map(connectorPos -> LogicTools.getControllerForConnector(getWorld(), connectorPos)).filter(Objects::nonNull).forEach(controller -> {
        for (int i = 0; i < MAX_CHANNELS; i++) {
            ChannelInfo channelInfo = controller.getChannels()[i];
            if (channelInfo != null && !channelInfo.getChannelName().isEmpty()) {
                LocalChannelId id = new LocalChannelId(controller.getPos(), i);
                String publishedName = publishedChannels.get(id);
                if (publishedName == null) {
                    publishedName = "";
                }
                if ((!onlyPublished) || !publishedName.isEmpty()) {
                    ControllerChannelClientInfo ci = new ControllerChannelClientInfo(channelInfo.getChannelName(), publishedName, controller.getPos(), channelInfo.getType(), i);
                    list.add(ci);
                }
            }
        }
    });
    return list;
}
Also used : ControllerChannelClientInfo(mcjty.xnet.clientinfo.ControllerChannelClientInfo) ChannelInfo(mcjty.xnet.logic.ChannelInfo) Nonnull(javax.annotation.Nonnull)

Example 4 with ChannelInfo

use of mcjty.xnet.logic.ChannelInfo in project XNet by McJty.

the class TileEntityController method findChannelInfo.

@Nonnull
private List<ChannelClientInfo> findChannelInfo() {
    WorldBlob worldBlob = XNetBlobData.getBlobData(getWorld()).getWorldBlob(getWorld());
    List<ChannelClientInfo> chanList = new ArrayList<>();
    for (ChannelInfo channel : channels) {
        if (channel != null) {
            ChannelClientInfo clientInfo = new ChannelClientInfo(channel.getChannelName(), channel.getType(), channel.getChannelSettings(), channel.isEnabled());
            for (Map.Entry<SidedConsumer, ConnectorInfo> entry : channel.getConnectors().entrySet()) {
                SidedConsumer sidedConsumer = entry.getKey();
                ConnectorInfo info = entry.getValue();
                if (info.getConnectorSettings() != null) {
                    BlockPos consumerPos = findConsumerPosition(worldBlob, sidedConsumer.getConsumerId());
                    if (consumerPos != null) {
                        SidedPos pos = new SidedPos(consumerPos.offset(sidedConsumer.getSide()), sidedConsumer.getSide().getOpposite());
                        boolean advanced = getWorld().getBlockState(consumerPos).getBlock() == NetCableSetup.advancedConnectorBlock;
                        ConnectorClientInfo ci = new ConnectorClientInfo(pos, sidedConsumer.getConsumerId(), channel.getType(), info.getConnectorSettings());
                        clientInfo.getConnectors().put(sidedConsumer, ci);
                    } else {
                    // Consumer was possibly removed. We might want to remove the entry from our list here?
                    // @todo
                    }
                }
            }
            chanList.add(clientInfo);
        } else {
            chanList.add(null);
        }
    }
    return chanList;
}
Also used : ConnectorInfo(mcjty.xnet.clientinfo.ConnectorInfo) SidedConsumer(mcjty.xnet.api.keys.SidedConsumer) ChannelInfo(mcjty.xnet.logic.ChannelInfo) ChannelClientInfo(mcjty.xnet.clientinfo.ChannelClientInfo) SidedPos(mcjty.xnet.api.keys.SidedPos) WorldBlob(mcjty.xnet.multiblock.WorldBlob) BlockPos(net.minecraft.util.math.BlockPos) ConnectorClientInfo(mcjty.xnet.clientinfo.ConnectorClientInfo) Nonnull(javax.annotation.Nonnull)

Aggregations

ChannelInfo (mcjty.xnet.logic.ChannelInfo)4 Nonnull (javax.annotation.Nonnull)2 IChannelType (mcjty.xnet.api.channels.IChannelType)2 SidedConsumer (mcjty.xnet.api.keys.SidedConsumer)1 SidedPos (mcjty.xnet.api.keys.SidedPos)1 ChannelClientInfo (mcjty.xnet.clientinfo.ChannelClientInfo)1 ConnectorClientInfo (mcjty.xnet.clientinfo.ConnectorClientInfo)1 ConnectorInfo (mcjty.xnet.clientinfo.ConnectorInfo)1 ControllerChannelClientInfo (mcjty.xnet.clientinfo.ControllerChannelClientInfo)1 WorldBlob (mcjty.xnet.multiblock.WorldBlob)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1 BlockPos (net.minecraft.util.math.BlockPos)1