Search in sources :

Example 1 with BlockRenderEvent

use of mcjty.lib.gui.events.BlockRenderEvent in project RFTools by McJty.

the class GuiStorageScanner method addItemToList.

private Pair<Panel, Integer> addItemToList(ItemStack item, WidgetList itemList, Pair<Panel, Integer> currentPos, int numcolumns, int spacing) {
    Panel panel = currentPos.getKey();
    if (panel == null || currentPos.getValue() >= numcolumns) {
        panel = new Panel(mc, this).setLayout(new HorizontalLayout().setSpacing(spacing).setHorizontalMargin(1)).setDesiredHeight(12).setUserObject(new Integer(-1)).setDesiredHeight(16);
        currentPos = MutablePair.of(panel, 0);
        itemList.addChild(panel);
    }
    BlockRender blockRender = new BlockRender(mc, this).setRenderItem(item).setUserObject(// Mark as a special stack in the renderer (for tooltip)
    1).setOffsetX(-1).setOffsetY(-1).setHilightOnHover(true);
    blockRender.addSelectionEvent(new BlockRenderEvent() {

        @Override
        public void select(Widget widget) {
            BlockRender br = (BlockRender) widget;
            Object item = br.getRenderItem();
            if (item != null) {
                boolean shift = Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_RSHIFT);
                requestItem((ItemStack) item, shift ? 1 : -1);
            }
        }

        @Override
        public void doubleClick(Widget widget) {
        }
    });
    panel.addChild(blockRender);
    currentPos.setValue(currentPos.getValue() + 1);
    return currentPos;
}
Also used : Panel(mcjty.lib.gui.widgets.Panel) BlockRenderEvent(mcjty.lib.gui.events.BlockRenderEvent) ItemStack(net.minecraft.item.ItemStack) HorizontalLayout(mcjty.lib.gui.layout.HorizontalLayout)

Example 2 with BlockRenderEvent

use of mcjty.lib.gui.events.BlockRenderEvent in project RFToolsControl by McJty.

the class GuiCraftingStation method updateRecipeList.

private void updateRecipeList() {
    String filterText = searchField.getText().toLowerCase().trim();
    fromServer_craftables.sort((r1, r2) -> {
        return r1.getDisplayName().compareTo(r2.getDisplayName());
    });
    recipeList.removeChildren();
    Panel panel = null;
    int index = 0;
    for (ItemStack stack : fromServer_craftables) {
        String displayName = stack.getDisplayName();
        if ((!filterText.isEmpty()) && !displayName.toLowerCase().contains(filterText)) {
            continue;
        }
        if (panel == null || panel.getChildCount() >= 6) {
            panel = new Panel(mc, this).setLayout(new HorizontalLayout().setSpacing(3).setHorizontalMargin(1)).setDesiredHeight(16);
            recipeList.addChild(panel);
        }
        BlockRender blockRender = new BlockRender(mc, this) {

            @Override
            public List<String> getTooltips() {
                ITooltipFlag flag = this.mc.gameSettings.advancedItemTooltips ? ITooltipFlag.TooltipFlags.ADVANCED : ITooltipFlag.TooltipFlags.NORMAL;
                List<String> list = stack.getTooltip(this.mc.player, flag);
                for (int i = 0; i < list.size(); ++i) {
                    if (i == 0) {
                        list.set(i, stack.getRarity().rarityColor + list.get(i));
                    } else {
                        list.set(i, TextFormatting.GRAY + list.get(i));
                    }
                }
                List<String> newlist = new ArrayList<>();
                newlist.add(TextFormatting.GREEN + "Click: " + TextFormatting.WHITE + "craft single");
                newlist.add(TextFormatting.GREEN + "Shift + click: " + TextFormatting.WHITE + "craft amount");
                newlist.add("");
                newlist.addAll(list);
                return newlist;
            }
        }.setRenderItem(stack).setHilightOnHover(true).setOffsetX(-1).setOffsetY(-1).setUserObject(index);
        index++;
        blockRender.addSelectionEvent(new BlockRenderEvent() {

            @Override
            public void select(Widget widget) {
                BlockRender br = (BlockRender) widget;
                Object item = br.getRenderItem();
                if (item != null) {
                    boolean shift = Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_RSHIFT);
                    Object index = br.getUserObject();
                    if (shift) {
                        askAmountToCraft(stack);
                    } else {
                        requestItem(stack, 1);
                    }
                }
            }

            @Override
            public void doubleClick(Widget widget) {
            }
        });
        panel.addChild(blockRender);
    }
}
Also used : ITooltipFlag(net.minecraft.client.util.ITooltipFlag) BlockRenderEvent(mcjty.lib.gui.events.BlockRenderEvent) HorizontalLayout(mcjty.lib.gui.layout.HorizontalLayout) Panel(mcjty.lib.gui.widgets.Panel) ArrayList(java.util.ArrayList) List(java.util.List) ItemStack(net.minecraft.item.ItemStack)

Example 3 with BlockRenderEvent

use of mcjty.lib.gui.events.BlockRenderEvent in project RFToolsControl by McJty.

the class FluidEditor method build.

@Override
public void build(Minecraft mc, Gui gui, Panel panel, ParameterEditorCallback callback) {
    Panel constantPanel = new Panel(mc, gui).setLayout(new HorizontalLayout());
    Label<?> label = new Label(mc, gui).setText("Drop bucket:");
    constantPanel.addChild(label);
    blockRender = new BlockRender(mc, gui).setDesiredWidth(18 + 100).setDesiredHeight(18).setFilledRectThickness(1).setFilledBackground(0xff555555).setShowLabel(true);
    constantPanel.addChild(blockRender);
    blockRender.addSelectionEvent(new BlockRenderEvent() {

        @Override
        public void select(Widget widget) {
            ItemStack holding = Minecraft.getMinecraft().player.inventory.getItemStack();
            if (holding.isEmpty()) {
                blockRender.setRenderItem(null);
            } else {
                blockRender.setRenderItem(stackToFluid(holding));
            }
            callback.valueChanged(readValue());
        }

        @Override
        public void doubleClick(Widget widget) {
        }
    });
    createEditorPanel(mc, gui, panel, callback, constantPanel, ParameterType.PAR_FLUID);
}
Also used : Panel(mcjty.lib.gui.widgets.Panel) Label(mcjty.lib.gui.widgets.Label) Widget(mcjty.lib.gui.widgets.Widget) BlockRenderEvent(mcjty.lib.gui.events.BlockRenderEvent) ItemStack(net.minecraft.item.ItemStack) BlockRender(mcjty.lib.gui.widgets.BlockRender) HorizontalLayout(mcjty.lib.gui.layout.HorizontalLayout)

Example 4 with BlockRenderEvent

use of mcjty.lib.gui.events.BlockRenderEvent in project RFTools by McJty.

the class ScreenModuleGuiBuilder method ghostStack.

@Override
public IModuleGuiBuilder ghostStack(String tagname) {
    ItemStack stack = ItemStack.EMPTY;
    if (currentData.hasKey(tagname)) {
        stack = new ItemStack(currentData.getCompoundTag(tagname));
    }
    BlockRender blockRender = new BlockRender(mc, gui).setRenderItem(stack).setDesiredWidth(18).setDesiredHeight(18).setFilledRectThickness(1).setFilledBackground(0xff555555);
    row.add(blockRender);
    blockRender.addSelectionEvent(new BlockRenderEvent() {

        @Override
        public void select(Widget widget) {
            ItemStack holding = Minecraft.getMinecraft().player.inventory.getItemStack();
            if (holding.isEmpty()) {
                currentData.removeTag(tagname);
                blockRender.setRenderItem(null);
            } else {
                ItemStack copy = holding.copy();
                copy.setCount(1);
                blockRender.setRenderItem(copy);
                NBTTagCompound tc = new NBTTagCompound();
                copy.writeToNBT(tc);
                currentData.setTag(tagname, tc);
            }
            moduleGuiChanged.updateData();
        }

        @Override
        public void doubleClick(Widget widget) {
        }
    });
    return this;
}
Also used : NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ItemStack(net.minecraft.item.ItemStack) BlockRenderEvent(mcjty.lib.gui.events.BlockRenderEvent)

Example 5 with BlockRenderEvent

use of mcjty.lib.gui.events.BlockRenderEvent in project RFToolsControl by McJty.

the class GuiCraftingCard method createSelectionEvent.

private BlockRenderEvent createSelectionEvent(final int idx) {
    return new BlockRenderEvent() {

        @Override
        public void select(Widget parent) {
            ItemStack itemstack = mc.player.inventory.getItemStack();
            slots[idx].setRenderItem(itemstack);
            ItemStackList stacks = getStacks();
            if (!stacks.isEmpty()) {
                stacks.set(idx, itemstack);
                ItemStack cardItem = mc.player.getHeldItem(EnumHand.MAIN_HAND);
                CraftingCardItem.putStacksInItem(cardItem, stacks);
                RFToolsCtrlMessages.INSTANCE.sendToServer(new PacketItemNBTToServer(cardItem.getTagCompound()));
            }
        }

        @Override
        public void doubleClick(Widget parent) {
        }
    };
}
Also used : ItemStackList(mcjty.lib.varia.ItemStackList) BlockRenderEvent(mcjty.lib.gui.events.BlockRenderEvent) ItemStack(net.minecraft.item.ItemStack) PacketItemNBTToServer(mcjty.rftoolscontrol.network.PacketItemNBTToServer)

Aggregations

BlockRenderEvent (mcjty.lib.gui.events.BlockRenderEvent)7 ItemStack (net.minecraft.item.ItemStack)7 HorizontalLayout (mcjty.lib.gui.layout.HorizontalLayout)4 Panel (mcjty.lib.gui.widgets.Panel)4 BlockRender (mcjty.lib.gui.widgets.BlockRender)2 Label (mcjty.lib.gui.widgets.Label)2 Widget (mcjty.lib.gui.widgets.Widget)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 PositionalLayout (mcjty.lib.gui.layout.PositionalLayout)1 ItemStackList (mcjty.lib.varia.ItemStackList)1 PacketItemNBTToServer (mcjty.rftoolscontrol.network.PacketItemNBTToServer)1 ITooltipFlag (net.minecraft.client.util.ITooltipFlag)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1