Search in sources :

Example 16 with SidedConsumer

use of mcjty.xnet.api.keys.SidedConsumer 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)

Example 17 with SidedConsumer

use of mcjty.xnet.api.keys.SidedConsumer 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 18 with SidedConsumer

use of mcjty.xnet.api.keys.SidedConsumer in project XNet by McJty.

the class TileEntityController method createConnector.

private void createConnector(int channel, SidedPos pos) {
    WorldBlob worldBlob = XNetBlobData.getBlobData(getWorld()).getWorldBlob(getWorld());
    BlockPos consumerPos = pos.getPos().offset(pos.getSide());
    ConsumerId consumerId = worldBlob.getConsumerAt(consumerPos);
    if (consumerId == null) {
        throw new RuntimeException("What?");
    }
    SidedConsumer id = new SidedConsumer(consumerId, pos.getSide().getOpposite());
    boolean advanced = getWorld().getBlockState(consumerPos).getBlock() == NetCableSetup.advancedConnectorBlock;
    channels[channel].createConnector(id, advanced);
    networkDirty();
    markDirtyQuick();
}
Also used : SidedConsumer(mcjty.xnet.api.keys.SidedConsumer) ConsumerId(mcjty.xnet.api.keys.ConsumerId) WorldBlob(mcjty.xnet.multiblock.WorldBlob) BlockPos(net.minecraft.util.math.BlockPos)

Example 19 with SidedConsumer

use of mcjty.xnet.api.keys.SidedConsumer 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)

Example 20 with SidedConsumer

use of mcjty.xnet.api.keys.SidedConsumer in project XNet by McJty.

the class GuiController method refreshConnectorEditor.

private void refreshConnectorEditor() {
    if (!listsReady()) {
        return;
    }
    if (editingConnector != null && !editingConnector.equals(showingConnector)) {
        showingConnector = editingConnector;
        connectorEditPanel.removeChildren();
        ChannelClientInfo info = fromServer_channels.get(editingChannel);
        if (info != null) {
            ConnectorClientInfo clientInfo = findClientInfo(info, editingConnector);
            if (clientInfo != null) {
                EnumFacing side = clientInfo.getPos().getSide();
                SidedConsumer sidedConsumer = new SidedConsumer(clientInfo.getConsumerId(), side.getOpposite());
                ConnectorClientInfo connectorInfo = info.getConnectors().get(sidedConsumer);
                Button remove = new Button(mc, this).setText("x").setTextOffset(0, -1).setTooltips("Remove this connector").setLayoutHint(new PositionalLayout.PositionalHint(151, 1, 9, 10)).addButtonEvent(parent -> removeConnector(editingConnector));
                ConnectorEditorPanel editor = new ConnectorEditorPanel(connectorEditPanel, mc, this, editingChannel, editingConnector);
                connectorInfo.getConnectorSettings().createGui(editor);
                connectorEditPanel.addChild(remove);
                editor.setState(connectorInfo.getConnectorSettings());
            } else {
                Button create = new Button(mc, this).setText("Create").setLayoutHint(new PositionalLayout.PositionalHint(85, 20, 60, 14)).addButtonEvent(parent -> createConnector(editingConnector));
                connectorEditPanel.addChild(create);
            }
        }
    } else if (showingConnector != null && editingConnector == null) {
        showingConnector = null;
        connectorEditPanel.removeChildren();
    }
}
Also used : ChannelClientInfo(mcjty.xnet.clientinfo.ChannelClientInfo) Button(mcjty.lib.gui.widgets.Button) SidedConsumer(mcjty.xnet.api.keys.SidedConsumer) EnumFacing(net.minecraft.util.EnumFacing) ConnectorClientInfo(mcjty.xnet.clientinfo.ConnectorClientInfo)

Aggregations

SidedConsumer (mcjty.xnet.api.keys.SidedConsumer)20 BlockPos (net.minecraft.util.math.BlockPos)14 EnumFacing (net.minecraft.util.EnumFacing)13 TileEntity (net.minecraft.tileentity.TileEntity)10 World (net.minecraft.world.World)8 ConnectorInfo (mcjty.xnet.clientinfo.ConnectorInfo)6 WorldBlob (mcjty.xnet.multiblock.WorldBlob)6 ConsumerId (mcjty.xnet.api.keys.ConsumerId)5 HashMap (java.util.HashMap)4 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)4 Map (java.util.Map)3 Nonnull (javax.annotation.Nonnull)3 ConnectorTileEntity (mcjty.xnet.blocks.cables.ConnectorTileEntity)3 NBTTagList (net.minecraft.nbt.NBTTagList)3 FluidStack (net.minecraftforge.fluids.FluidStack)3 IFluidHandler (net.minecraftforge.fluids.capability.IFluidHandler)3 IItemHandler (net.minecraftforge.items.IItemHandler)3 ArrayList (java.util.ArrayList)2 Argument (mcjty.lib.network.Argument)2 IChannelType (mcjty.xnet.api.channels.IChannelType)2