Search in sources :

Example 1 with InventoryDatabaseClient

use of crazypants.enderio.machine.invpanel.client.InventoryDatabaseClient in project EnderIO by SleepyTrousers.

the class GuiInventoryPanel method mouseWheel.

@Override
protected void mouseWheel(int x, int y, int delta) {
    super.mouseWheel(x, y, delta);
    if (draggingScrollbar == null) {
        x -= guiLeft;
        y -= guiTop;
        boolean shift = isShiftKeyDown();
        if (inventoryArea.contains(x, y)) {
            GhostSlot hovered = getGhostSlotHandler().getGhostSlotAt(this, x, y);
            if (!shift) {
                scrollbar.scrollBy(-Integer.signum(delta));
            } else if (hovered instanceof InvSlot) {
                InvSlot invSlot = (InvSlot) hovered;
                InventoryDatabaseClient db = getDatabase();
                if (invSlot.getStack() != null && invSlot.entry != null && db != null) {
                    ItemStack itemStack = mc.player.inventory.getItemStack();
                    if (itemStack.isEmpty() || ItemUtil.areStackMergable(itemStack, invSlot.getStack())) {
                        PacketHandler.INSTANCE.sendToServer(new PacketFetchItem(db.getGeneration(), invSlot.entry, -1, 1));
                    }
                }
            }
        }
    }
}
Also used : ItemStack(net.minecraft.item.ItemStack) GhostSlot(com.enderio.core.client.gui.widget.GhostSlot) InventoryDatabaseClient(crazypants.enderio.machine.invpanel.client.InventoryDatabaseClient)

Example 2 with InventoryDatabaseClient

use of crazypants.enderio.machine.invpanel.client.InventoryDatabaseClient in project EnderIO by SleepyTrousers.

the class GuiInventoryPanel method ghostSlotClicked.

protected void ghostSlotClicked(GhostSlot slot, int x, int y, int button) {
    if (slot instanceof InvSlot) {
        InvSlot invSlot = (InvSlot) slot;
        InventoryDatabaseClient db = getDatabase();
        if (invSlot.entry != null && invSlot.getStack() != null && db != null) {
            int targetSlot;
            int count = Math.min(invSlot.getStack().getCount(), invSlot.getStack().getMaxStackSize());
            if (button == 0) {
                if (isShiftKeyDown()) {
                    InventoryPlayer playerInv = mc.player.inventory;
                    targetSlot = playerInv.getFirstEmptyStack();
                    if (targetSlot >= 0) {
                        targetSlot = getContainer().getSlotIndex(playerInv, targetSlot);
                    }
                    if (targetSlot < 0) {
                        return;
                    }
                } else {
                    targetSlot = -1;
                }
            } else if (button == 1) {
                targetSlot = -1;
                if (isCtrlKeyDown()) {
                    count = 1;
                } else {
                    count = (count + 1) / 2;
                }
            } else {
                return;
            }
            PacketHandler.INSTANCE.sendToServer(new PacketFetchItem(db.getGeneration(), invSlot.entry, targetSlot, count));
        }
    } else if (slot instanceof RecipeSlot) {
        RecipeSlot recipeSlot = (RecipeSlot) slot;
        if (recipeSlot.isVisible()) {
            if (button == 0) {
                fillFromStoredRecipe(recipeSlot.index, isShiftKeyDown());
            } else if (button == 1) {
                getTileEntity().removeStoredCraftingRecipe(recipeSlot.index);
            }
        }
    }
}
Also used : InventoryPlayer(net.minecraft.entity.player.InventoryPlayer) InventoryDatabaseClient(crazypants.enderio.machine.invpanel.client.InventoryDatabaseClient)

Aggregations

InventoryDatabaseClient (crazypants.enderio.machine.invpanel.client.InventoryDatabaseClient)2 GhostSlot (com.enderio.core.client.gui.widget.GhostSlot)1 InventoryPlayer (net.minecraft.entity.player.InventoryPlayer)1 ItemStack (net.minecraft.item.ItemStack)1