Search in sources :

Example 1 with IChannelType

use of mcjty.xnet.api.channels.IChannelType 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 IChannelType

use of mcjty.xnet.api.channels.IChannelType 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 IChannelType

use of mcjty.xnet.api.channels.IChannelType in project XNet by McJty.

the class GuiRouter method makeChannelLine.

private Panel makeChannelLine(ControllerChannelClientInfo channel, boolean local) {
    String name = channel.getChannelName();
    String publishedName = channel.getPublishedName();
    BlockPos controllerPos = channel.getPos();
    IChannelType type = channel.getChannelType();
    int index = channel.getIndex();
    Panel panel = new Panel(mc, this).setLayout(new PositionalLayout()).setDesiredHeight(30);
    Panel panel1 = new Panel(mc, this).setLayout(new HorizontalLayout().setHorizontalMargin(0).setSpacing(0)).setLayoutHint(new PositionalLayout.PositionalHint(0, 0, 160, 13));
    panel1.addChild(new Label<>(mc, this).setText("Ch").setColor(0xff2244aa));
    panel1.addChild(new Label<>(mc, this).setText(name));
    panel1.addChild(new Label<>(mc, this).setText(">").setColor(0xff2244aa));
    if (local) {
        TextField pubName = new TextField(mc, this).setText(publishedName).setDesiredWidth(50).setDesiredHeight(13).addTextEvent((parent, newText) -> updatePublish(controllerPos, index, newText));
        panel1.addChild(pubName);
    } else {
        panel1.addChild(new Label<>(mc, this).setText(publishedName).setColor(0xff33ff00));
    }
    Panel panel2 = new Panel(mc, this).setLayout(new HorizontalLayout().setHorizontalMargin(0).setSpacing(0)).setLayoutHint(new PositionalLayout.PositionalHint(0, 13, 160, 13));
    panel2.addChild(new Label<>(mc, this).setText("Pos").setColor(0xff2244aa));
    panel2.addChild(new Label<>(mc, this).setText(BlockPosTools.toString(controllerPos)));
    Panel panel3 = new Panel(mc, this).setLayout(new HorizontalLayout().setHorizontalMargin(0).setSpacing(0)).setLayoutHint(new PositionalLayout.PositionalHint(0, 26, 160, 13));
    panel3.addChild(new Label<>(mc, this).setText("Index").setColor(0xff2244aa));
    panel3.addChild(new Label<>(mc, this).setText(index + " (" + type.getName() + ")"));
    panel.addChild(panel1).addChild(panel2).addChild(panel3);
    return panel;
}
Also used : Panel(mcjty.lib.gui.widgets.Panel) PositionalLayout(mcjty.lib.gui.layout.PositionalLayout) Label(mcjty.lib.gui.widgets.Label) TextField(mcjty.lib.gui.widgets.TextField) BlockPos(net.minecraft.util.math.BlockPos) IChannelType(mcjty.xnet.api.channels.IChannelType) HorizontalLayout(mcjty.lib.gui.layout.HorizontalLayout)

Example 4 with IChannelType

use of mcjty.xnet.api.channels.IChannelType in project XNet by McJty.

the class TileEntityRouter method addRoutedConnectors.

public void addRoutedConnectors(Map<SidedConsumer, IConnectorSettings> connectors, @Nonnull BlockPos controllerPos, int channel, IChannelType type) {
    if (inError()) {
        // We are in error. Don't do anything
        return;
    }
    LocalChannelId id = new LocalChannelId(controllerPos, channel);
    String publishedName = publishedChannels.get(id);
    if (publishedName != null && !publishedName.isEmpty()) {
        NetworkId networkId = findRoutingNetwork();
        if (networkId != null) {
            LogicTools.consumers(getWorld(), networkId).forEach(consumerPos -> LogicTools.routers(getWorld(), consumerPos).forEach(router -> router.addConnectorsFromConnectedNetworks(connectors, publishedName, type)));
        } else {
            // If there is no routing network that means we have a local network only
            addConnectorsFromConnectedNetworks(connectors, publishedName, type);
        }
    }
}
Also used : GeneralConfiguration(mcjty.xnet.config.GeneralConfiguration) java.util(java.util) SPacketUpdateTileEntity(net.minecraft.network.play.server.SPacketUpdateTileEntity) IConnectorSettings(mcjty.xnet.api.channels.IConnectorSettings) Constants(net.minecraftforge.common.util.Constants) SidedConsumer(mcjty.xnet.api.keys.SidedConsumer) ChannelInfo(mcjty.xnet.logic.ChannelInfo) NetworkManager(net.minecraft.network.NetworkManager) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) BlockPosTools(mcjty.lib.varia.BlockPosTools) NBTTagList(net.minecraft.nbt.NBTTagList) Type(mcjty.typed.Type) ControllerChannelClientInfo(mcjty.xnet.clientinfo.ControllerChannelClientInfo) GenericTileEntity(mcjty.lib.entity.GenericTileEntity) XNetBlobData(mcjty.xnet.multiblock.XNetBlobData) WorldBlob(mcjty.xnet.multiblock.WorldBlob) Nonnull(javax.annotation.Nonnull) Nullable(javax.annotation.Nullable) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) LogicTools(mcjty.xnet.logic.LogicTools) EnumFacing(net.minecraft.util.EnumFacing) BlockPos(net.minecraft.util.math.BlockPos) Argument(mcjty.lib.network.Argument) MAX_CHANNELS(mcjty.xnet.logic.ChannelInfo.MAX_CHANNELS) IChannelType(mcjty.xnet.api.channels.IChannelType) NetworkId(mcjty.xnet.api.keys.NetworkId) NetworkId(mcjty.xnet.api.keys.NetworkId)

Example 5 with IChannelType

use of mcjty.xnet.api.channels.IChannelType 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

IChannelType (mcjty.xnet.api.channels.IChannelType)6 ChannelInfo (mcjty.xnet.logic.ChannelInfo)3 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)3 PositionalLayout (mcjty.lib.gui.layout.PositionalLayout)2 SidedConsumer (mcjty.xnet.api.keys.SidedConsumer)2 NBTTagList (net.minecraft.nbt.NBTTagList)2 EnumFacing (net.minecraft.util.EnumFacing)2 BlockPos (net.minecraft.util.math.BlockPos)2 java.util (java.util)1 Nonnull (javax.annotation.Nonnull)1 Nullable (javax.annotation.Nullable)1 GenericTileEntity (mcjty.lib.entity.GenericTileEntity)1 HorizontalLayout (mcjty.lib.gui.layout.HorizontalLayout)1 Button (mcjty.lib.gui.widgets.Button)1 Label (mcjty.lib.gui.widgets.Label)1 Panel (mcjty.lib.gui.widgets.Panel)1 TextField (mcjty.lib.gui.widgets.TextField)1 Argument (mcjty.lib.network.Argument)1 BlockPosTools (mcjty.lib.varia.BlockPosTools)1 Type (mcjty.typed.Type)1