Search in sources :

Example 1 with ConnectorInfo

use of mcjty.xnet.clientinfo.ConnectorInfo 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 2 with ConnectorInfo

use of mcjty.xnet.clientinfo.ConnectorInfo in project XNet by McJty.

the class ChannelInfo method writeToNBT.

public void writeToNBT(NBTTagCompound tag) {
    channelSettings.writeToNBT(tag);
    tag.setBoolean("enabled", enabled);
    if (channelName != null && !channelName.isEmpty()) {
        tag.setString("name", channelName);
    }
    NBTTagList conlist = new NBTTagList();
    for (Map.Entry<SidedConsumer, ConnectorInfo> entry : connectors.entrySet()) {
        NBTTagCompound tc = new NBTTagCompound();
        ConnectorInfo connectorInfo = entry.getValue();
        connectorInfo.writeToNBT(tc);
        tc.setInteger("consumerId", entry.getKey().getConsumerId().getId());
        tc.setInteger("side", entry.getKey().getSide().ordinal());
        tc.setString("type", connectorInfo.getType().getID());
        tc.setBoolean("advanced", connectorInfo.isAdvanced());
        conlist.appendTag(tc);
    }
    tag.setTag("connectors", conlist);
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) ConnectorInfo(mcjty.xnet.clientinfo.ConnectorInfo) SidedConsumer(mcjty.xnet.api.keys.SidedConsumer) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) HashMap(java.util.HashMap) Map(java.util.Map)

Example 3 with ConnectorInfo

use of mcjty.xnet.clientinfo.ConnectorInfo in project XNet by McJty.

the class ChannelInfo method createConnector.

public ConnectorInfo createConnector(SidedConsumer id, boolean advanced) {
    ConnectorInfo info = new ConnectorInfo(type, id, advanced);
    connectors.put(id, info);
    return info;
}
Also used : ConnectorInfo(mcjty.xnet.clientinfo.ConnectorInfo)

Example 4 with ConnectorInfo

use of mcjty.xnet.clientinfo.ConnectorInfo 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)

Example 5 with ConnectorInfo

use of mcjty.xnet.clientinfo.ConnectorInfo in project XNet by McJty.

the class TileEntityController method getConnectors.

@Override
@Nonnull
public Map<SidedConsumer, IConnectorSettings> getConnectors(int channel) {
    if (cachedConnectors[channel] == null) {
        WorldBlob worldBlob = XNetBlobData.getBlobData(getWorld()).getWorldBlob(getWorld());
        cachedConnectors[channel] = new HashMap<>();
        for (Map.Entry<SidedConsumer, ConnectorInfo> entry : channels[channel].getConnectors().entrySet()) {
            SidedConsumer sidedConsumer = entry.getKey();
            BlockPos pos = findConsumerPosition(sidedConsumer.getConsumerId());
            if (pos != null && worldBlob.getNetworksAt(pos).contains(getNetworkId())) {
                cachedConnectors[channel].put(sidedConsumer, entry.getValue().getConnectorSettings());
            }
        }
    }
    return cachedConnectors[channel];
}
Also used : ConnectorInfo(mcjty.xnet.clientinfo.ConnectorInfo) SidedConsumer(mcjty.xnet.api.keys.SidedConsumer) WorldBlob(mcjty.xnet.multiblock.WorldBlob) BlockPos(net.minecraft.util.math.BlockPos) Nonnull(javax.annotation.Nonnull)

Aggregations

ConnectorInfo (mcjty.xnet.clientinfo.ConnectorInfo)7 SidedConsumer (mcjty.xnet.api.keys.SidedConsumer)6 WorldBlob (mcjty.xnet.multiblock.WorldBlob)4 ConsumerId (mcjty.xnet.api.keys.ConsumerId)3 Nonnull (javax.annotation.Nonnull)2 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)2 NBTTagList (net.minecraft.nbt.NBTTagList)2 BlockPos (net.minecraft.util.math.BlockPos)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Argument (mcjty.lib.network.Argument)1 IChannelType (mcjty.xnet.api.channels.IChannelType)1 SidedPos (mcjty.xnet.api.keys.SidedPos)1 ChannelClientInfo (mcjty.xnet.clientinfo.ChannelClientInfo)1 ConnectorClientInfo (mcjty.xnet.clientinfo.ConnectorClientInfo)1 ChannelInfo (mcjty.xnet.logic.ChannelInfo)1 EnumFacing (net.minecraft.util.EnumFacing)1