Search in sources :

Example 1 with SidedPos

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

the class TileEntityController method findConnectedBlocks.

@Nonnull
private List<ConnectedBlockClientInfo> findConnectedBlocks() {
    WorldBlob worldBlob = XNetBlobData.getBlobData(getWorld()).getWorldBlob(getWorld());
    Set<ConnectedBlockClientInfo> set = new HashSet<>();
    for (BlockPos consumerPos : worldBlob.getConsumers(networkId)) {
        String name = "";
        TileEntity te = getWorld().getTileEntity(consumerPos);
        if (te instanceof ConnectorTileEntity) {
            // Should always be the case. @todo error?
            name = ((ConnectorTileEntity) te).getConnectorName();
        } else {
            XNet.logger.warn("What? The connector at " + BlockPosTools.toString(consumerPos) + " is not a connector?");
        }
        for (EnumFacing facing : EnumFacing.VALUES) {
            if (ConnectorBlock.isConnectable(getWorld(), consumerPos, facing)) {
                BlockPos pos = consumerPos.offset(facing);
                SidedPos sidedPos = new SidedPos(pos, facing.getOpposite());
                IBlockState state = getWorld().getBlockState(pos);
                ItemStack item = state.getBlock().getItem(getWorld(), pos, state);
                ConnectedBlockClientInfo info = new ConnectedBlockClientInfo(sidedPos, item, name);
                set.add(info);
            }
        }
    }
    List<ConnectedBlockClientInfo> list = new ArrayList<>(set);
    list.sort(Comparator.comparing(ConnectedBlockClientInfo::getBlockUnlocName).thenComparing(ConnectedBlockClientInfo::getPos));
    return list;
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) ConnectorTileEntity(mcjty.xnet.blocks.cables.ConnectorTileEntity) EnumFacing(net.minecraft.util.EnumFacing) SPacketUpdateTileEntity(net.minecraft.network.play.server.SPacketUpdateTileEntity) ConnectorTileEntity(mcjty.xnet.blocks.cables.ConnectorTileEntity) GenericEnergyReceiverTileEntity(mcjty.lib.entity.GenericEnergyReceiverTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) ConnectedBlockClientInfo(mcjty.xnet.clientinfo.ConnectedBlockClientInfo) SidedPos(mcjty.xnet.api.keys.SidedPos) WorldBlob(mcjty.xnet.multiblock.WorldBlob) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack) Nonnull(javax.annotation.Nonnull)

Example 2 with SidedPos

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

the class TileEntityController method getConnectedBlockPositions.

@Override
public List<SidedPos> getConnectedBlockPositions() {
    WorldBlob worldBlob = XNetBlobData.getBlobData(getWorld()).getWorldBlob(getWorld());
    List<SidedPos> result = new ArrayList<>();
    Set<ConnectedBlockClientInfo> set = new HashSet<>();
    for (BlockPos consumerPos : worldBlob.getConsumers(networkId)) {
        String name = "";
        TileEntity te = getWorld().getTileEntity(consumerPos);
        if (te instanceof ConnectorTileEntity) {
            // Should always be the case. @todo error?
            name = ((ConnectorTileEntity) te).getConnectorName();
        } else {
            XNet.logger.warn("What? The connector at " + BlockPosTools.toString(consumerPos) + " is not a connector?");
        }
        for (EnumFacing facing : EnumFacing.VALUES) {
            if (ConnectorBlock.isConnectable(getWorld(), consumerPos, facing)) {
                BlockPos pos = consumerPos.offset(facing);
                SidedPos sidedPos = new SidedPos(pos, facing.getOpposite());
                result.add(sidedPos);
            }
        }
    }
    return result;
}
Also used : SPacketUpdateTileEntity(net.minecraft.network.play.server.SPacketUpdateTileEntity) ConnectorTileEntity(mcjty.xnet.blocks.cables.ConnectorTileEntity) GenericEnergyReceiverTileEntity(mcjty.lib.entity.GenericEnergyReceiverTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) ConnectedBlockClientInfo(mcjty.xnet.clientinfo.ConnectedBlockClientInfo) SidedPos(mcjty.xnet.api.keys.SidedPos) ConnectorTileEntity(mcjty.xnet.blocks.cables.ConnectorTileEntity) EnumFacing(net.minecraft.util.EnumFacing) WorldBlob(mcjty.xnet.multiblock.WorldBlob) BlockPos(net.minecraft.util.math.BlockPos)

Example 3 with SidedPos

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

the class TileEntityController method execute.

@Override
public boolean execute(EntityPlayerMP playerMP, String command, Map<String, Argument> args) {
    boolean rc = super.execute(playerMP, command, args);
    if (rc) {
        return true;
    }
    if (CMD_CREATECHANNEL.equals(command)) {
        int index = args.get("index").getInteger();
        String typeId = args.get("type").getString();
        createChannel(index, typeId);
        return true;
    } else if (CMD_CREATECONNECTOR.equals(command)) {
        int channel = args.get("channel").getInteger();
        SidedPos pos = new SidedPos(args.get("pos").getCoordinate(), EnumFacing.VALUES[args.get("side").getInteger()]);
        createConnector(channel, pos);
        return true;
    } else if (CMD_REMOVECHANNEL.equals(command)) {
        int index = args.get("index").getInteger();
        removeChannel(index);
        return true;
    } else if (CMD_REMOVECONNECTOR.equals(command)) {
        SidedPos pos = new SidedPos(args.get("pos").getCoordinate(), EnumFacing.VALUES[args.get("side").getInteger()]);
        int channel = args.get("channel").getInteger();
        removeConnector(channel, pos);
        return true;
    } else if (CMD_UPDATECONNECTOR.equals(command)) {
        SidedPos pos = new SidedPos(args.get("pos").getCoordinate(), EnumFacing.VALUES[args.get("side").getInteger()]);
        int channel = args.get("channel").getInteger();
        updateConnector(channel, pos, args);
        return true;
    } else if (CMD_UPDATECHANNEL.equals(command)) {
        int channel = args.get("channel").getInteger();
        updateChannel(channel, args);
        return true;
    }
    return false;
}
Also used : SidedPos(mcjty.xnet.api.keys.SidedPos)

Example 4 with SidedPos

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

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

the class GuiController method populateList.

private void populateList() {
    if (!listsReady()) {
        return;
    }
    if (!needsRefresh) {
        return;
    }
    needsRefresh = false;
    connectorList.removeChildren();
    int sel = connectorList.getSelected();
    BlockPos prevPos = null;
    String selectedText = searchBar.getText().trim().toLowerCase();
    for (ConnectedBlockClientInfo connectedBlock : fromServer_connectedBlocks) {
        SidedPos sidedPos = connectedBlock.getPos();
        BlockPos coordinate = sidedPos.getPos();
        String name = connectedBlock.getName();
        String blockUnlocName = connectedBlock.getBlockUnlocName();
        String blockName = I18n.format(blockUnlocName).trim();
        int color = StyleConfig.colorTextInListNormal;
        Panel panel = new Panel(mc, this).setLayout(new HorizontalLayout().setHorizontalMargin(0).setSpacing(0));
        if (!selectedText.isEmpty()) {
            if (blockName.toLowerCase().contains(selectedText)) {
                panel.setFilledBackground(0xffddeeaa);
            }
        }
        BlockRender br;
        if (coordinate.equals(prevPos)) {
            br = new BlockRender(mc, this);
        } else {
            br = new BlockRender(mc, this).setRenderItem(connectedBlock.getConnectedBlock());
            prevPos = coordinate;
        }
        br.setUserObject("block");
        panel.addChild(br);
        if (!name.isEmpty()) {
            br.setTooltips(TextFormatting.GREEN + "Connector: " + TextFormatting.WHITE + name, TextFormatting.GREEN + "Block: " + TextFormatting.WHITE + blockName, TextFormatting.GREEN + "Position: " + TextFormatting.WHITE + BlockPosTools.toString(coordinate), TextFormatting.WHITE + "(doubleclick to highlight)");
        } else {
            br.setTooltips(TextFormatting.GREEN + "Block: " + TextFormatting.WHITE + blockName, TextFormatting.GREEN + "Position: " + TextFormatting.WHITE + BlockPosTools.toString(coordinate), TextFormatting.WHITE + "(doubleclick to highlight)");
        }
        panel.addChild(new Label(mc, this).setText(sidedPos.getSide().getName().substring(0, 1).toUpperCase()).setColor(color).setDesiredWidth(18));
        for (int i = 0; i < MAX_CHANNELS; i++) {
            Button but = new Button(mc, this).setDesiredWidth(14);
            ChannelClientInfo info = fromServer_channels.get(i);
            if (info != null) {
                ConnectorClientInfo clientInfo = findClientInfo(info, sidedPos);
                if (clientInfo != null) {
                    IndicatorIcon icon = clientInfo.getConnectorSettings().getIndicatorIcon();
                    if (icon != null) {
                        but.setImage(icon.getImage(), icon.getU(), icon.getV(), icon.getIw(), icon.getIh());
                    }
                    String indicator = clientInfo.getConnectorSettings().getIndicator();
                    but.setText(indicator != null ? indicator : "");
                }
            }
            int finalI = i;
            but.addButtonEvent(parent -> {
                selectConnectorEditor(sidedPos, finalI);
            });
            panel.addChild(but);
        }
        connectorList.addChild(panel);
    }
    connectorList.setSelected(sel);
}
Also used : Label(mcjty.lib.gui.widgets.Label) HorizontalLayout(mcjty.lib.gui.layout.HorizontalLayout) Panel(mcjty.lib.gui.widgets.Panel) ConnectedBlockClientInfo(mcjty.xnet.clientinfo.ConnectedBlockClientInfo) ChannelClientInfo(mcjty.xnet.clientinfo.ChannelClientInfo) SidedPos(mcjty.xnet.api.keys.SidedPos) Button(mcjty.lib.gui.widgets.Button) BlockPos(net.minecraft.util.math.BlockPos) IndicatorIcon(mcjty.xnet.api.gui.IndicatorIcon) ConnectorClientInfo(mcjty.xnet.clientinfo.ConnectorClientInfo)

Aggregations

SidedPos (mcjty.xnet.api.keys.SidedPos)5 BlockPos (net.minecraft.util.math.BlockPos)4 ConnectedBlockClientInfo (mcjty.xnet.clientinfo.ConnectedBlockClientInfo)3 WorldBlob (mcjty.xnet.multiblock.WorldBlob)3 Nonnull (javax.annotation.Nonnull)2 GenericEnergyReceiverTileEntity (mcjty.lib.entity.GenericEnergyReceiverTileEntity)2 ConnectorTileEntity (mcjty.xnet.blocks.cables.ConnectorTileEntity)2 ChannelClientInfo (mcjty.xnet.clientinfo.ChannelClientInfo)2 ConnectorClientInfo (mcjty.xnet.clientinfo.ConnectorClientInfo)2 SPacketUpdateTileEntity (net.minecraft.network.play.server.SPacketUpdateTileEntity)2 TileEntity (net.minecraft.tileentity.TileEntity)2 EnumFacing (net.minecraft.util.EnumFacing)2 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 IndicatorIcon (mcjty.xnet.api.gui.IndicatorIcon)1 SidedConsumer (mcjty.xnet.api.keys.SidedConsumer)1 ConnectorInfo (mcjty.xnet.clientinfo.ConnectorInfo)1 ChannelInfo (mcjty.xnet.logic.ChannelInfo)1