Search in sources :

Example 1 with PacketGetInfoFromServer

use of mcjty.lib.network.clientinfo.PacketGetInfoFromServer in project RFTools by McJty.

the class GuiStorageScanner method requestListsIfNeeded.

private void requestListsIfNeeded() {
    listDirty--;
    if (listDirty <= 0) {
        RFToolsMessages.INSTANCE.sendToServer(new PacketGetInfoFromServer(RFTools.MODID, new InventoriesInfoPacketServer(tileEntity.getDimension(), tileEntity.getStorageScannerPos(), false)));
        getInventoryOnServer();
        listDirty = 20;
    }
}
Also used : PacketGetInfoFromServer(mcjty.lib.network.clientinfo.PacketGetInfoFromServer)

Example 2 with PacketGetInfoFromServer

use of mcjty.lib.network.clientinfo.PacketGetInfoFromServer in project RFTools by McJty.

the class GuiStorageScanner method drawGuiContainerBackgroundLayer.

@Override
protected void drawGuiContainerBackgroundLayer(float v, int i, int i2) {
    if (!init) {
        return;
    }
    updateStorageList();
    updateContentsList();
    requestListsIfNeeded();
    String text = radiusLabel.getText();
    if ("0".equals(text)) {
        text = "XNet";
    }
    visibleRadiusLabel.setText(text);
    int selected = storageList.getSelected();
    removeButton.setEnabled(selected != -1);
    if (selected <= 0 || storageList.getChildCount() <= 2) {
        upButton.setEnabled(false);
        downButton.setEnabled(false);
        topButton.setEnabled(false);
        bottomButton.setEnabled(false);
    } else if (selected == 1) {
        topButton.setEnabled(false);
        upButton.setEnabled(false);
        downButton.setEnabled(true);
        bottomButton.setEnabled(true);
    } else if (selected == storageList.getChildCount() - 1) {
        topButton.setEnabled(true);
        upButton.setEnabled(true);
        downButton.setEnabled(false);
        bottomButton.setEnabled(false);
    } else {
        topButton.setEnabled(true);
        upButton.setEnabled(true);
        downButton.setEnabled(true);
        bottomButton.setEnabled(true);
    }
    if (!tileEntity.isDummy()) {
        tileEntity.requestRfFromServer(RFTools.MODID);
        int currentRF = GenericEnergyStorageTileEntity.getCurrentRF();
        energyBar.setValue(currentRF);
        exportToStarred.setCurrentChoice(tileEntity.isExportToCurrent() ? 0 : 1);
    } else {
        if (System.currentTimeMillis() - lastTime > 300) {
            lastTime = System.currentTimeMillis();
            RFToolsMessages.INSTANCE.sendToServer(new PacketGetInfoFromServer(RFTools.MODID, new ScannerInfoPacketServer(tileEntity.getDimension(), tileEntity.getPos())));
        }
        energyBar.setValue(ScannerInfoPacketClient.rfReceived);
        exportToStarred.setCurrentChoice(ScannerInfoPacketClient.exportToCurrentReceived ? 0 : 1);
    }
    drawWindow();
}
Also used : PacketGetInfoFromServer(mcjty.lib.network.clientinfo.PacketGetInfoFromServer)

Example 3 with PacketGetInfoFromServer

use of mcjty.lib.network.clientinfo.PacketGetInfoFromServer in project RFTools by McJty.

the class GuiStorageScanner method initGui.

@Override
public void initGui() {
    super.initGui();
    int maxEnergyStored = tileEntity.getMaxEnergyStored();
    energyBar = new EnergyBar(mc, this).setFilledRectThickness(1).setVertical().setDesiredWidth(10).setDesiredHeight(50).setMaxValue(maxEnergyStored).setShowText(false);
    energyBar.setValue(GenericEnergyStorageTileEntity.getCurrentRF());
    openViewButton = new ToggleButton(mc, this).setCheckMarker(false).setText("V").setTooltips("Toggle wide storage list");
    openViewButton.setPressed(tileEntity.isOpenWideView());
    openViewButton.addButtonEvent(widget -> toggleView());
    upButton = new Button(mc, this).setText("U").setTooltips("Move inventory up").addButtonEvent(widget -> moveUp());
    topButton = new Button(mc, this).setText("T").setTooltips("Move inventory to the top").addButtonEvent(widget -> moveTop());
    downButton = new Button(mc, this).setText("D").setTooltips("Move inventory down").addButtonEvent(widget -> moveDown());
    bottomButton = new Button(mc, this).setText("B").setTooltips("Move inventory to the bottom").addButtonEvent(widget -> moveBottom());
    removeButton = new Button(mc, this).setText("R").setTooltips("Remove inventory from list").addButtonEvent(widget -> removeFromList());
    Panel energyPanel = new Panel(mc, this).setLayout(new VerticalLayout().setVerticalMargin(0).setSpacing(1)).setDesiredWidth(10);
    energyPanel.addChild(openViewButton).addChild(energyBar).addChild(topButton).addChild(upButton).addChild(downButton).addChild(bottomButton).addChild(new Label(mc, this).setText(" ")).addChild(removeButton);
    exportToStarred = new ImageChoiceLabel(mc, this).setLayoutHint(new PositionalLayout.PositionalHint(12, 223, 13, 13)).addChoiceEvent((parent, newChoice) -> changeExportMode());
    exportToStarred.addChoice("No", "Export to current container", guielements, 131, 19);
    exportToStarred.addChoice("Yes", "Export to first routable container", guielements, 115, 19);
    storagePanel = makeStoragePanel(energyPanel);
    itemPanel = makeItemPanel();
    Button scanButton = new Button(mc, this).setText("Scan").setDesiredWidth(50).setDesiredHeight(14).addButtonEvent(parent -> RFToolsMessages.INSTANCE.sendToServer(new PacketGetInfoFromServer(RFTools.MODID, new InventoriesInfoPacketServer(tileEntity.getDimension(), tileEntity.getStorageScannerPos(), true))));
    if (RFTools.instance.xnet) {
        if (StorageScannerConfiguration.xnetRequired) {
            scanButton.setTooltips("Do a scan of all", "storage units connected", "with an active XNet channel");
        } else {
            scanButton.setTooltips("Do a scan of all", "storage units in radius", "Use 'xnet' radius to", "restrict to XNet only");
        }
    } else {
        scanButton.setTooltips("Do a scan of all", "storage units in radius");
    }
    radiusLabel = new ScrollableLabel(mc, this).addValueEvent((parent, newValue) -> changeRadius(newValue)).setRealMinimum(RFTools.instance.xnet ? 0 : 1).setRealMaximum(20);
    radiusLabel.setRealValue(tileEntity.getRadius());
    visibleRadiusLabel = new Label(mc, this);
    visibleRadiusLabel.setDesiredWidth(40);
    searchField = new TextField(mc, this).addTextEvent((parent, newText) -> {
        storageList.clearHilightedRows();
        fromServer_foundInventories.clear();
        startSearch(newText);
    });
    Panel searchPanel = new Panel(mc, this).setLayoutHint(new PositionalLayout.PositionalHint(8, 142, 256 - 11, 18)).setLayout(new HorizontalLayout()).setDesiredHeight(18).addChild(new Label(mc, this).setText("Search:")).addChild(searchField);
    Slider radiusSlider = new Slider(mc, this).setHorizontal().setTooltips("Radius of scan").setMinimumKnobSize(12).setDesiredHeight(14).setScrollable(radiusLabel);
    Panel scanPanel = new Panel(mc, this).setLayoutHint(new PositionalLayout.PositionalHint(8, 162, 74, 54)).setFilledRectThickness(-2).setFilledBackground(StyleConfig.colorListBackground).setLayout(new VerticalLayout().setVerticalMargin(6).setSpacing(1)).addChild(scanButton);
    if (!(RFTools.instance.xnet && StorageScannerConfiguration.xnetRequired)) {
        scanPanel.addChild(radiusSlider);
    }
    scanPanel.addChild(visibleRadiusLabel);
    if (tileEntity.isDummy()) {
        scanButton.setEnabled(false);
        radiusLabel.setVisible(false);
        radiusSlider.setVisible(false);
    }
    Panel toplevel = new Panel(mc, this).setBackground(iconLocation).setLayout(new PositionalLayout()).addChild(storagePanel).addChild(itemPanel).addChild(searchPanel).addChild(scanPanel).addChild(exportToStarred);
    toplevel.setBounds(new Rectangle(guiLeft, guiTop, xSize, ySize));
    window = new Window(this, toplevel);
    Keyboard.enableRepeatEvents(true);
    fromServer_foundInventories.clear();
    fromServer_inventory.clear();
    if (tileEntity.isDummy()) {
        fromServer_inventories.clear();
    } else {
        tileEntity.requestRfFromServer(RFTools.MODID);
    }
    BlockPos pos = tileEntity.getCraftingGridContainerPos();
    craftingGrid.initGui(modBase, network, mc, this, pos, tileEntity.getCraftingGridProvider(), guiLeft, guiTop, xSize, ySize);
    sendServerCommand(RFTools.MODID, CommandHandler.CMD_REQUEST_GRID_SYNC, Arguments.builder().value(pos).build());
    if (StorageScannerConfiguration.hilightStarredOnGuiOpen) {
        storageList.setSelected(0);
    }
    init = true;
}
Also used : GenericGuiContainer(mcjty.lib.container.GenericGuiContainer) RFToolsMessages(mcjty.rftools.network.RFToolsMessages) BlockRenderEvent(mcjty.lib.gui.events.BlockRenderEvent) TextField(mcjty.lib.gui.widgets.TextField) java.util(java.util) mcjty.lib.gui.widgets(mcjty.lib.gui.widgets) HorizontalAlignment(mcjty.lib.gui.layout.HorizontalAlignment) Keyboard(org.lwjgl.input.Keyboard) Label(mcjty.lib.gui.widgets.Label) Arguments(mcjty.lib.network.Arguments) StyleConfig(mcjty.lib.base.StyleConfig) Window(mcjty.lib.gui.Window) BlockPosTools(mcjty.lib.varia.BlockPosTools) ItemStack(net.minecraft.item.ItemStack) HorizontalLayout(mcjty.lib.gui.layout.HorizontalLayout) DefaultSelectionEvent(mcjty.lib.gui.events.DefaultSelectionEvent) Panel(mcjty.lib.gui.widgets.Panel) MutablePair(org.apache.commons.lang3.tuple.MutablePair) Pair(org.apache.commons.lang3.tuple.Pair) Logging(mcjty.lib.varia.Logging) PositionalLayout(mcjty.lib.gui.layout.PositionalLayout) PacketGetInfoFromServer(mcjty.lib.network.clientinfo.PacketGetInfoFromServer) RFTools(mcjty.rftools.RFTools) Predicate(java.util.function.Predicate) GhostOutputSlot(mcjty.lib.container.GhostOutputSlot) TextFormatting(net.minecraft.util.text.TextFormatting) GenericEnergyStorageTileEntity(mcjty.lib.entity.GenericEnergyStorageTileEntity) BlockPos(net.minecraft.util.math.BlockPos) IOException(java.io.IOException) VerticalLayout(mcjty.lib.gui.layout.VerticalLayout) Mouse(org.lwjgl.input.Mouse) java.awt(java.awt) Argument(mcjty.lib.network.Argument) List(java.util.List) Button(mcjty.lib.gui.widgets.Button) Slot(net.minecraft.inventory.Slot) ResourceLocation(net.minecraft.util.ResourceLocation) CommandHandler(mcjty.rftools.CommandHandler) GuiCraftingGrid(mcjty.rftools.craftinggrid.GuiCraftingGrid) Window(mcjty.lib.gui.Window) Label(mcjty.lib.gui.widgets.Label) PositionalLayout(mcjty.lib.gui.layout.PositionalLayout) HorizontalLayout(mcjty.lib.gui.layout.HorizontalLayout) Panel(mcjty.lib.gui.widgets.Panel) PacketGetInfoFromServer(mcjty.lib.network.clientinfo.PacketGetInfoFromServer) Button(mcjty.lib.gui.widgets.Button) VerticalLayout(mcjty.lib.gui.layout.VerticalLayout) TextField(mcjty.lib.gui.widgets.TextField) BlockPos(net.minecraft.util.math.BlockPos)

Example 4 with PacketGetInfoFromServer

use of mcjty.lib.network.clientinfo.PacketGetInfoFromServer in project RFTools by McJty.

the class SpawnerBlock method getWailaBody.

@SideOnly(Side.CLIENT)
@Override
@Optional.Method(modid = "waila")
public List<String> getWailaBody(ItemStack itemStack, List<String> currenttip, IWailaDataAccessor accessor, IWailaConfigHandler config) {
    super.getWailaBody(itemStack, currenttip, accessor, config);
    TileEntity te = accessor.getTileEntity();
    if (te instanceof SpawnerTileEntity) {
        SpawnerTileEntity spawnerTileEntity = (SpawnerTileEntity) te;
        if (System.currentTimeMillis() - lastTime > 500) {
            lastTime = System.currentTimeMillis();
            RFToolsMessages.INSTANCE.sendToServer(new PacketGetInfoFromServer(RFTools.MODID, new SpawnerInfoPacketServer(te.getWorld().provider.getDimension(), te.getPos())));
        }
        float[] matter = SpawnerInfoPacketClient.matterReceived;
        if (matter != null && matter.length == 3) {
            DecimalFormat fmt = new DecimalFormat("#.##");
            fmt.setRoundingMode(RoundingMode.DOWN);
            currenttip.add(TextFormatting.GREEN + "Key Matter: " + fmt.format(matter[0]));
            currenttip.add(TextFormatting.GREEN + "Bulk Matter: " + fmt.format(matter[1]));
            currenttip.add(TextFormatting.GREEN + "Living Matter: " + fmt.format(matter[2]));
        }
    }
    return currenttip;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) PacketGetInfoFromServer(mcjty.lib.network.clientinfo.PacketGetInfoFromServer) DecimalFormat(java.text.DecimalFormat) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 5 with PacketGetInfoFromServer

use of mcjty.lib.network.clientinfo.PacketGetInfoFromServer in project RFTools by McJty.

the class GuiSpawner method showSyringeInfo.

private void showSyringeInfo() {
    for (int i = 0; i < 3; i++) {
        blocks[i].setRenderItem(null);
        labels[i].setText("");
    }
    name.setText("");
    rfTick.setText("");
    ItemStack stack = tileEntity.getStackInSlot(SpawnerContainer.SLOT_SYRINGE);
    if (stack.isEmpty()) {
        return;
    }
    String mobId = SyringeItem.getMobId(stack);
    if (mobId != null) {
        String mobName = SyringeItem.getMobName(stack);
        name.setText(mobName);
        rfTick.setText(SpawnerConfiguration.mobSpawnRf.get(mobId) + "RF");
        int i = 0;
        List<SpawnerConfiguration.MobSpawnAmount> list = SpawnerConfiguration.mobSpawnAmounts.get(mobId);
        if (list != null) {
            if (System.currentTimeMillis() - lastTime > 100) {
                lastTime = System.currentTimeMillis();
                RFToolsMessages.INSTANCE.sendToServer(new PacketGetInfoFromServer(RFTools.MODID, new SpawnerInfoPacketServer(tileEntity.getWorld().provider.getDimension(), tileEntity.getPos())));
            }
            float[] matter = SpawnerInfoPacketClient.matterReceived;
            if (matter == null || matter.length != 3) {
                matter = new float[] { 0, 0, 0 };
            }
            for (SpawnerConfiguration.MobSpawnAmount spawnAmount : list) {
                ItemStack b = spawnAmount.getObject();
                float amount = spawnAmount.getAmount();
                if (b.isEmpty()) {
                    Object[] blocks = { Blocks.LEAVES, Blocks.PUMPKIN, Items.WHEAT, Items.POTATO, Items.BEEF };
                    int index = (int) ((System.currentTimeMillis() / 500) % blocks.length);
                    if (blocks[index] instanceof Block) {
                        this.blocks[i].setRenderItem(new ItemStack((Block) blocks[index], 1, 0));
                    } else {
                        this.blocks[i].setRenderItem(new ItemStack((Item) blocks[index], 1, 0));
                    }
                } else {
                    blocks[i].setRenderItem(b);
                }
                DecimalFormat format = new DecimalFormat("#.##");
                format.setRoundingMode(RoundingMode.DOWN);
                String mf = format.format(matter[i]);
                labels[i].setText(mf + "/" + Float.toString(amount));
                i++;
            }
        }
    }
}
Also used : DecimalFormat(java.text.DecimalFormat) SyringeItem(mcjty.rftools.items.SyringeItem) Item(net.minecraft.item.Item) PacketGetInfoFromServer(mcjty.lib.network.clientinfo.PacketGetInfoFromServer) Block(net.minecraft.block.Block) ItemStack(net.minecraft.item.ItemStack)

Aggregations

PacketGetInfoFromServer (mcjty.lib.network.clientinfo.PacketGetInfoFromServer)8 DecimalFormat (java.text.DecimalFormat)3 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)3 ItemStack (net.minecraft.item.ItemStack)2 TileEntity (net.minecraft.tileentity.TileEntity)2 java.awt (java.awt)1 IOException (java.io.IOException)1 java.util (java.util)1 List (java.util.List)1 Predicate (java.util.function.Predicate)1 StyleConfig (mcjty.lib.base.StyleConfig)1 GenericGuiContainer (mcjty.lib.container.GenericGuiContainer)1 GhostOutputSlot (mcjty.lib.container.GhostOutputSlot)1 GenericEnergyStorageTileEntity (mcjty.lib.entity.GenericEnergyStorageTileEntity)1 Window (mcjty.lib.gui.Window)1 BlockRenderEvent (mcjty.lib.gui.events.BlockRenderEvent)1 DefaultSelectionEvent (mcjty.lib.gui.events.DefaultSelectionEvent)1 HorizontalAlignment (mcjty.lib.gui.layout.HorizontalAlignment)1 HorizontalLayout (mcjty.lib.gui.layout.HorizontalLayout)1 PositionalLayout (mcjty.lib.gui.layout.PositionalLayout)1