Search in sources :

Example 6 with ConnectorInfo

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

Example 7 with ConnectorInfo

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

the class TileEntityController method updateConnector.

private void updateConnector(int channel, SidedPos pos, Map<String, Argument> args) {
    WorldBlob worldBlob = XNetBlobData.getBlobData(getWorld()).getWorldBlob(getWorld());
    ConsumerId consumerId = worldBlob.getConsumerAt(pos.getPos().offset(pos.getSide()));
    for (Map.Entry<SidedConsumer, ConnectorInfo> entry : channels[channel].getConnectors().entrySet()) {
        SidedConsumer key = entry.getKey();
        if (key.getConsumerId().equals(consumerId) && key.getSide().getOpposite().equals(pos.getSide())) {
            Map<String, Object> data = new HashMap<>();
            for (Map.Entry<String, Argument> e : args.entrySet()) {
                data.put(e.getKey(), e.getValue().getValue());
            }
            channels[channel].getConnectors().get(key).getConnectorSettings().update(data);
            networkDirty();
            markDirtyQuick();
            return;
        }
    }
}
Also used : ConnectorInfo(mcjty.xnet.clientinfo.ConnectorInfo) Argument(mcjty.lib.network.Argument) SidedConsumer(mcjty.xnet.api.keys.SidedConsumer) ConsumerId(mcjty.xnet.api.keys.ConsumerId) WorldBlob(mcjty.xnet.multiblock.WorldBlob)

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