Java Code Examples for net.minecraft.client.gui.inventory.GuiContainer#getGuiTop()

The following examples show how to use net.minecraft.client.gui.inventory.GuiContainer#getGuiTop() . 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: NEIController.java    From NotEnoughItems with MIT License 4 votes vote down vote up
@Override
public boolean mouseClicked(GuiScreen screen, int mouseX, int mouseY, int button) {

    if (!(screen instanceof GuiContainer) || !NEIClientConfig.isEnabled() || isSpreading(((GuiContainer) screen))) {
        return false;
    }
    GuiContainer gui = ((GuiContainer) screen);
    Slot slot = GuiHelper.getSlotMouseOver(gui);
    int slotID = -1;

    boolean outsideGui = (mouseX < gui.getGuiLeft() || mouseY < gui.getGuiTop() || mouseX >= gui.getGuiLeft() + gui.getXSize() || mouseY >= gui.getGuiTop() + gui.getYSize()) && slot == null;

    if (slot != null) {
        slotID = slot.slotNumber;
    }

    if (outsideGui) {
        slotID = -999;
    }


    //Shift / Click delete.
    if (deleteMode && slot != null && slot.slotNumber >= 0) {
        if (NEIClientUtils.shiftKey() && button == 0) {
            ItemStack itemstack1 = slot.getStack();
            if (!itemstack1.isEmpty()) {
                NEIClientUtils.deleteItemsOfType(itemstack1);
            }

        } else if (button == 1) {
            NEIClientUtils.decreaseSlotStack(slot.slotNumber);
        } else {
            NEIClientUtils.deleteSlotStack(slot.slotNumber);
        }
        return true;
    }

    //Creative click the slot 64 times because mojang.
    //Seems to already be a thing.. Gonna leave this here and wipe it in a cleanup pass.
    //if (button == 1 && slot instanceof SlotCrafting)//right click
    //{
    //    for (int i1 = 0; i1 < 64; i1++)//click this slot 64 times
    //    {
    //        manager.handleSlotClick(slot.slotNumber, button, ClickType.PICKUP);
    //    }
    //    return true;
    //}

    //Control click slot = give me an item.
    if (NEIClientUtils.controlKey() && slot != null && !slot.getStack().isEmpty() && slot.isItemValid(slot.getStack())) {
        NEIClientUtils.cheatItem(slot.getStack(), button, 1);
        return true;
    }

    //Custom slots or container? No thanx, bia!
    if (GuiInfo.hasCustomSlots(gui) || ItemInfo.fastTransferContainerExemptions.contains(gui.getClass())) {
        return false;
    }
    //Disabled for now.
    //if (slotID >= 0 && NEIClientUtils.shiftKey() && !NEIClientUtils.getHeldItem().isEmpty() && !slot.getHasStack()) {
    //    ItemStack held = NEIClientUtils.getHeldItem();
    //    GuiHelper.clickSlot(container, slot.slotNumber, button, ClickType.PICKUP);
    //    if (slot.isItemValid(held)) {
    //        fastTransferManager.performMassTransfer(container, pickedUpFromSlot, slot.slotNumber, held);
    //    }
    //
    //    return true;
    //}

    if (slotID == -999 && NEIClientUtils.shiftKey() && button == 0 && !NEIClientUtils.getHeldItem().isEmpty()) {
        fastTransferManager.throwAll(gui, pickedUpFromSlot);
        return true;
    }

    return false;
}
 
Example 2
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;
}