codechicken.nei.api.INEIGuiHandler Java Examples

The following examples show how to use codechicken.nei.api.INEIGuiHandler. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JEIProxy.java    From NotEnoughItems with MIT License 6 votes vote down vote up
public JEIProxy() {
    MinecraftForge.EVENT_BUS.register(new EventHandler());
    API.registerNEIGuiHandler(new INEIGuiHandler() {
        @Override
        public boolean hideItemPanelSlot(GuiContainer gui, int x, int y, int w, int h) {
            if (extraAreasCache == null) {
                extraAreasCache = getExtraAreas(gui);
            }
            for (Rectangle rectangle : extraAreasCache) {
                if (rectangle.intersects(x, y, w, h)) {
                    return true;
                }
            }
            return false;
        }
    });
}
 
Example #2
Source File: LayoutManager.java    From NotEnoughItems with MIT License 6 votes vote down vote up
public static void layout(GuiContainer gui) {
    VisibilityData visiblity = new VisibilityData();
    if (isHidden()) {
        //showItemPanel = false;
        visiblity.showNEI = false;
    }
    if (gui.height - gui.getYSize() <= 40) {
        visiblity.showSearchSection = false;
    }
    if (gui.getGuiLeft() - 4 < 76) {
        visiblity.showWidgets = false;
    }

    for (INEIGuiHandler handler : GuiInfo.guiHandlers) {
        handler.modifyVisibility(gui, visiblity);
    }

    visiblity.translateDependencies();

    getLayoutStyle().layout(gui, visiblity);

    updateWidgetVisiblities(gui, visiblity);
}
 
Example #3
Source File: NEIController.java    From NotEnoughItems with MIT License 5 votes vote down vote up
public static void load(GuiContainer gui) {
    deleteMode = false;
    GuiInfo.clearGuiHandlers();
    fastTransferManager = null;
    if (!NEIClientConfig.isEnabled()) {
        return;
    }

    fastTransferManager = new FastTransferManager();
    if (gui instanceof INEIGuiHandler) {
        API.registerNEIGuiHandler((INEIGuiHandler) gui);
    }
}
 
Example #4
Source File: ItemPanel.java    From NotEnoughItems with MIT License 5 votes vote down vote up
private boolean slotValid(GuiContainer gui, int i) {
    Rectangle4i rect = getSlotRect(i);
    for (INEIGuiHandler handler : GuiInfo.guiHandlers) {
        if (handler.hideItemPanelSlot(gui, rect.x, rect.y, rect.w, rect.h)) {
            return false;
        }
    }
    return true;
}
 
Example #5
Source File: ItemPanel.java    From NotEnoughItems with MIT License 5 votes vote down vote up
@Override
public boolean contains(int px, int py) {
    GuiContainer gui = NEIClientUtils.getGuiContainer();
    Rectangle4i rect = new Rectangle4i(px, py, 1, 1);
    for (INEIGuiHandler handler : GuiInfo.guiHandlers) {
        if (handler.hideItemPanelSlot(gui, rect.x, rect.y, rect.w, rect.h)) {
            return false;
        }
    }

    return super.contains(px, py);
}
 
Example #6
Source File: ItemPanel.java    From NotEnoughItems with MIT License 5 votes vote down vote up
private boolean slotValid(GuiContainer gui, int i) {
    Rectangle4i rect = getSlotRect(i);
    for (INEIGuiHandler handler : GuiInfo.guiHandlers)
        if (handler.hideItemPanelSlot(gui, rect.x, rect.y, rect.w, rect.h))
            return false;
    return true;
}
 
Example #7
Source File: ItemPanel.java    From NotEnoughItems with MIT License 5 votes vote down vote up
@Override
public boolean handleClick(int mousex, int mousey, int button) {
    if (handleDraggedClick(mousex, mousey, button))
        return true;

    if (NEIClientUtils.getHeldItem() != null) {
        for (INEIGuiHandler handler : GuiInfo.guiHandlers)
            if (handler.hideItemPanelSlot(NEIClientUtils.getGuiContainer(), mousex, mousey, 1, 1))
                return false;

        if (NEIClientConfig.canPerformAction("delete") && NEIClientConfig.canPerformAction("item"))
            if (button == 1)
                NEIClientUtils.decreaseSlotStack(-999);
            else
                NEIClientUtils.deleteHeldItem();
        else
            NEIClientUtils.dropHeldItem();

        return true;
    }

    ItemPanelSlot hoverSlot = getSlotMouseOver(mousex, mousey);
    if (hoverSlot != null) {
        if (button == 2) {
            ItemStack stack = hoverSlot.item;
            if (stack != null) {
                int amount = NEIClientConfig.getItemQuantity();
                if (amount == 0)
                    amount = stack.getMaxStackSize();

                draggedStack = NEIServerUtils.copyStack(stack, amount);
            }
        } else {
            mouseDownSlot = hoverSlot.slotIndex;
        }
        return true;
    }
    return false;
}
 
Example #8
Source File: ItemPanel.java    From NotEnoughItems with MIT License 5 votes vote down vote up
@Override
public boolean contains(int px, int py) {
    GuiContainer gui = NEIClientUtils.getGuiContainer();
    Rectangle4i rect = new Rectangle4i(px, py, 1, 1);
    for (INEIGuiHandler handler : GuiInfo.guiHandlers)
        if (handler.hideItemPanelSlot(gui, rect.x, rect.y, rect.w, rect.h))
            return false;

    return super.contains(px, py);
}
 
Example #9
Source File: ItemPanel.java    From NotEnoughItems with MIT License 4 votes vote down vote up
@Override
public boolean handleClick(int mousex, int mousey, int button) {
    if (handleDraggedClick(mousex, mousey, button)) {
        return true;
    }

    if (!NEIClientUtils.getHeldItem().isEmpty()) {
        for (INEIGuiHandler handler : GuiInfo.guiHandlers) {
            if (handler.hideItemPanelSlot(NEIClientUtils.getGuiContainer(), mousex, mousey, 1, 1)) {
                return false;
            }
        }

        if (NEIClientConfig.canPerformAction("delete") && NEIClientConfig.canPerformAction("item")) {
            if (button == 1) {
                NEIClientUtils.decreaseSlotStack(-999);
            } else {
                NEIClientUtils.deleteHeldItem();
            }
        } else {
            NEIClientUtils.dropHeldItem();
        }

        return true;
    }

    ItemPanelSlot hoverSlot = getSlotMouseOver(mousex, mousey);
    if (hoverSlot != null) {
        if (button == 2) {
            ItemStack stack = hoverSlot.item;
            if (!stack.isEmpty()) {
                int amount = NEIClientConfig.getItemQuantity();
                if (amount == 0) {
                    amount = stack.getMaxStackSize();
                }

                draggedStack = NEIServerUtils.copyStack(stack, amount);
            }
        } else {
            mouseDownSlot = hoverSlot.slotIndex;
        }
        return true;
    }
    return false;
}
 
Example #10
Source File: ItemPanel.java    From NotEnoughItems with MIT License 4 votes vote down vote up
private boolean handleDraggedClick(int mousex, int mousey, int button) {
    if (draggedStack.isEmpty()) {
        return false;
    }

    GuiContainer gui = NEIClientUtils.getGuiContainer();
    boolean handled = false;
    for (INEIGuiHandler handler : GuiInfo.guiHandlers) {
        if (handler.handleDragNDrop(gui, mousex, mousey, draggedStack, button)) {
            handled = true;
            if (draggedStack.getCount() == 0) {
                draggedStack = ItemStack.EMPTY;
                return true;
            }
        }
    }

    if (handled) {
        return true;
    }

    Slot overSlot = gui.getSlotAtPosition(mousex, mousey);
    if (overSlot != null && overSlot.isItemValid(draggedStack)) {
        if (NEIClientConfig.canCheatItem(draggedStack)) {
            int contents = overSlot.getHasStack() ? overSlot.getStack().getCount() : 0;
            int add = button == 0 ? draggedStack.getCount() : 1;
            if (overSlot.getHasStack() && !NEIServerUtils.areStacksSameType(draggedStack, overSlot.getStack())) {
                contents = 0;
            }
            int total = Math.min(contents + add, Math.min(overSlot.getSlotStackLimit(), draggedStack.getMaxStackSize()));

            if (total > contents) {
                int slotNumber = overSlot.slotNumber;
                if (gui instanceof GuiContainerCreative) {
                    //Because Mojang..
                    slotNumber = slotNumber - gui.inventorySlots.inventorySlots.size() + 9 + 36;
                }
                NEIClientUtils.setSlotContents(slotNumber, NEIServerUtils.copyStack(draggedStack, total), true);
                NEIClientPacketHandler.sendGiveItem(NEIServerUtils.copyStack(draggedStack, total), false, false);
                draggedStack.shrink(total - contents);
            }
            if (draggedStack.getCount() == 0) {
                draggedStack = ItemStack.EMPTY;
            }
        } else {
            draggedStack = ItemStack.EMPTY;
        }
    } else if (mousex < gui.getGuiLeft() || mousey < gui.getGuiTop() || mousex >= gui.getGuiLeft() + gui.getXSize() || mousey >= gui.getGuiTop() + gui.getYSize()) {
        draggedStack = ItemStack.EMPTY;
    }

    return true;
}
 
Example #11
Source File: ItemPanel.java    From NotEnoughItems with MIT License 4 votes vote down vote up
private boolean handleDraggedClick(int mousex, int mousey, int button) {
    if (draggedStack == null)
        return false;

    GuiContainer gui = NEIClientUtils.getGuiContainer();
    boolean handled = false;
    for (INEIGuiHandler handler : GuiInfo.guiHandlers)
        if (handler.handleDragNDrop(gui, mousex, mousey, draggedStack, button)) {
            handled = true;
            if (draggedStack.stackSize == 0) {
                draggedStack = null;
                return true;
            }
        }

    if (handled)
        return true;

    Slot overSlot = gui.getSlotAtPosition(mousex, mousey);
    if (overSlot != null && overSlot.isItemValid(draggedStack)) {
        if (NEIClientConfig.canCheatItem(draggedStack)) {
            int contents = overSlot.getHasStack() ? overSlot.getStack().stackSize : 0;
            int add = button == 0 ? draggedStack.stackSize : 1;
            if (overSlot.getHasStack() && !NEIServerUtils.areStacksSameType(draggedStack, overSlot.getStack()))
                contents = 0;
            int total = Math.min(contents + add, Math.min(overSlot.getSlotStackLimit(), draggedStack.getMaxStackSize()));

            if (total > contents) {
                NEIClientUtils.setSlotContents(overSlot.slotNumber, NEIServerUtils.copyStack(draggedStack, total), true);
                NEICPH.sendGiveItem(NEIServerUtils.copyStack(draggedStack, total), false, false);
                draggedStack.stackSize -= total - contents;
            }
            if (draggedStack.stackSize == 0)
                draggedStack = null;
        } else {
            draggedStack = null;
        }
    } else if (mousex < gui.guiLeft || mousey < gui.guiTop || mousex >= gui.guiLeft + gui.xSize || mousey >= gui.guiTop + gui.ySize) {
        draggedStack = null;
    }

    return true;
}