Search in sources :

Example 1 with IItemList

use of gregtech.common.inventory.IItemList in project GregTech by GregTechCE.

the class ItemListSlotWidget method extractItemStack.

private void extractItemStack(ItemStackKey itemStackKey, int amount, boolean isClient) {
    InventoryPlayer inventory = gui.entityPlayer.inventory;
    if (inventory.getItemStack().isEmpty()) {
        if (!isClient) {
            // on server, we try to extract from the network
            IItemList itemList = gridWidget.getItemList();
            int amountExtracted = itemList.extractItem(itemStackKey, amount, false);
            if (amountExtracted > 0) {
                ItemStack resultStack = itemStackKey.getItemStack();
                resultStack.setCount(amountExtracted);
                inventory.setItemStack(resultStack);
            }
            uiAccess.sendHeldItemUpdate();
        } else {
            // on client we assume we can extract as much items as user wishes
            ItemStack itemStack = itemStackKey.getItemStack();
            itemStack.setCount(amount);
            inventory.setItemStack(itemStack);
        }
    }
}
Also used : InventoryPlayer(net.minecraft.entity.player.InventoryPlayer) IItemList(gregtech.common.inventory.IItemList) ItemStack(net.minecraft.item.ItemStack)

Example 2 with IItemList

use of gregtech.common.inventory.IItemList in project GregTech by GregTechCE.

the class ItemListSlotWidget method insertHeldItemStack.

// returns true if something actually happened
private boolean insertHeldItemStack(int button, boolean isClient) {
    InventoryPlayer inventory = gui.entityPlayer.inventory;
    int amountToInsert = button == 1 ? 1 : Integer.MAX_VALUE;
    if (!inventory.getItemStack().isEmpty()) {
        if (!isClient) {
            // on server, we lookup item list to see how much we can actually insert
            ItemStack heldItemStack = inventory.getItemStack();
            IItemList itemList = gridWidget.getItemList();
            int amountInserted = itemList.insertItem(new ItemStackKey(heldItemStack), Math.min(heldItemStack.getCount(), amountToInsert), false, InsertMode.LOWEST_PRIORITY);
            heldItemStack.shrink(amountInserted);
            uiAccess.sendHeldItemUpdate();
            gui.entityPlayer.openContainer.detectAndSendChanges();
            return amountInserted > 0;
        } else {
            // on client we assume we can insert full stack into the network
            inventory.getItemStack().shrink(amountToInsert);
            return true;
        }
    }
    return false;
}
Also used : InventoryPlayer(net.minecraft.entity.player.InventoryPlayer) IItemList(gregtech.common.inventory.IItemList) ItemStack(net.minecraft.item.ItemStack) ItemStackKey(gregtech.api.util.ItemStackKey)

Example 3 with IItemList

use of gregtech.common.inventory.IItemList in project GregTech by GregTechCE.

the class MetaTileEntityWorkbench method createItemListTab.

private AbstractWidgetGroup createItemListTab() {
    WidgetGroup widgetGroup = new WidgetGroup();
    widgetGroup.addWidget(new LabelWidget(5, 20, "gregtech.machine.workbench.storage_note_1"));
    widgetGroup.addWidget(new LabelWidget(5, 30, "gregtech.machine.workbench.storage_note_2"));
    CraftingRecipeResolver recipeResolver = getRecipeResolver();
    IItemList itemList = recipeResolver == null ? null : recipeResolver.getItemSourceList();
    widgetGroup.addWidget(new ItemListGridWidget(2, 45, 9, 5, itemList));
    return widgetGroup;
}
Also used : IItemList(gregtech.common.inventory.IItemList) ItemListGridWidget(gregtech.common.gui.widget.ItemListGridWidget)

Aggregations

IItemList (gregtech.common.inventory.IItemList)3 InventoryPlayer (net.minecraft.entity.player.InventoryPlayer)2 ItemStack (net.minecraft.item.ItemStack)2 ItemStackKey (gregtech.api.util.ItemStackKey)1 ItemListGridWidget (gregtech.common.gui.widget.ItemListGridWidget)1