Search in sources :

Example 6 with ItemStackKey

use of gregtech.api.util.ItemStackKey in project GregTech by GregTechCE.

the class ItemSourceList method updateStoredItems.

void updateStoredItems(ItemSource handlerInfo, Map<ItemStackKey, Integer> itemAmount, Set<ItemStackKey> removedItems) {
    boolean updatedItemAmount = false;
    for (ItemStackKey itemStackKey : itemAmount.keySet()) {
        int extractedAmount = handlerInfo.extractItem(itemStackKey, 1, true);
        if (extractedAmount > 0) {
            NetworkItemInfo itemInfo = itemInfoMap.get(itemStackKey);
            if (itemInfo == null) {
                itemInfo = new NetworkItemInfo(itemStackKey);
                this.itemInfoMap.put(itemStackKey, itemInfo);
            }
            updatedItemAmount |= itemInfo.addInventory(handlerInfo, itemAmount.get(itemStackKey));
        }
    }
    for (ItemStackKey removedItem : removedItems) {
        NetworkItemInfo itemInfo = itemInfoMap.get(removedItem);
        if (itemInfo != null) {
            updatedItemAmount |= itemInfo.removeInventory(handlerInfo);
            if (itemInfo.getTotalItemAmount() == 0) {
                this.itemInfoMap.remove(removedItem);
            }
        }
    }
    if (updatedItemAmount && itemListChangeCallback != null) {
        if (!disableCallback) {
            itemListChangeCallback.run();
        } else {
            this.callbackWasCalled = true;
        }
    }
}
Also used : ItemStackKey(gregtech.api.util.ItemStackKey)

Example 7 with ItemStackKey

use of gregtech.api.util.ItemStackKey in project GregTech by GregTechCE.

the class InventoryItemSource method recomputeItemStackCount.

private boolean recomputeItemStackCount() {
    if (!checkItemHandlerValid(false)) {
        return false;
    }
    this.lastStoredItemListUpdateTick = world.getTotalWorldTime();
    HashMap<ItemStackKey, Integer> amountMap = new HashMap<>();
    for (int i = 0; i < itemHandler.getSlots(); i++) {
        ItemStack itemStack = itemHandler.getStackInSlot(i);
        if (itemStack.isEmpty())
            continue;
        ItemStackKey stackKey = new ItemStackKey(itemStack);
        amountMap.put(stackKey, amountMap.getOrDefault(stackKey, 0) + itemStack.getCount());
    }
    if (amountMap.equals(itemStackByAmountMap)) {
        return false;
    }
    HashSet<ItemStackKey> removedItems = new HashSet<>(itemStackByAmountMap.keySet());
    removedItems.removeAll(amountMap.keySet());
    this.itemStackByAmountMap = amountMap;
    if (changeCallback != null) {
        changeCallback.onStoredItemsUpdated(amountMap, removedItems);
    }
    return true;
}
Also used : HashMap(java.util.HashMap) ItemStack(net.minecraft.item.ItemStack) ItemStackKey(gregtech.api.util.ItemStackKey) HashSet(java.util.HashSet)

Example 8 with ItemStackKey

use of gregtech.api.util.ItemStackKey in project GregTech by GregTechCE.

the class ItemListGridWidget method handleSlotShiftClick.

private void handleSlotShiftClick(INativeWidget clickedSlot) {
    ItemStack itemStack = clickedSlot.getHandle().getStack();
    if (clickedSlot.getHandle().canTakeStack(gui.entityPlayer) && !itemStack.isEmpty()) {
        itemStack = clickedSlot.onItemTake(gui.entityPlayer, itemStack, true);
        int amountInserted = getItemList().insertItem(new ItemStackKey(itemStack), itemStack.getCount(), false, InsertMode.LOWEST_PRIORITY);
        if (amountInserted > 0) {
            clickedSlot.onItemTake(gui.entityPlayer, itemStack, false);
            itemStack.shrink(amountInserted);
            if (!clickedSlot.canMergeSlot(itemStack)) {
                gui.entityPlayer.dropItem(itemStack.copy(), false, false);
                itemStack.setCount(0);
            }
            clickedSlot.getHandle().onSlotChanged();
            uiAccess.sendSlotUpdate(clickedSlot);
            gui.entityPlayer.openContainer.detectAndSendChanges();
        }
    }
}
Also used : ItemStack(net.minecraft.item.ItemStack) ItemStackKey(gregtech.api.util.ItemStackKey)

Example 9 with ItemStackKey

use of gregtech.api.util.ItemStackKey in project GregTech by GregTechCE.

the class CachedRecipeData method getIngredientEquivalent.

private boolean getIngredientEquivalent(int slot) {
    ItemStack currentStack = inventory.getStackInSlot(slot);
    if (currentStack.isEmpty()) {
        // stack is empty, nothing to return
        return true;
    }
    ItemStackKey currentStackKey = new ItemStackKey(currentStack);
    if (simulateExtractItem(currentStackKey)) {
        // so just return it without searching equivalent
        return true;
    }
    // iterate stored items to find equivalent
    for (ItemStackKey itemStackKey : itemSourceList.getStoredItems()) {
        ItemStack itemStack = itemStackKey.getItemStack();
        // update item in slot, and check that recipe matches and output item is equal to the expected one
        inventory.setInventorySlotContents(slot, itemStack);
        if (recipe.matches(inventory, itemSourceList.getWorld()) && ItemStack.areItemStacksEqual(expectedOutput, recipe.getCraftingResult(inventory))) {
            // ingredient matched, attempt to extract it and return if successful
            if (simulateExtractItem(itemStackKey)) {
                return true;
            }
        }
    }
    // nothing matched, so return null
    return false;
}
Also used : ItemStack(net.minecraft.item.ItemStack) ItemStackKey(gregtech.api.util.ItemStackKey)

Example 10 with ItemStackKey

use of gregtech.api.util.ItemStackKey in project GregTech by GregTechCE.

the class CoverConveyor method countInventoryItemsByType.

protected Map<ItemStackKey, TypeItemInfo> countInventoryItemsByType(IItemHandler inventory) {
    Map<ItemStackKey, TypeItemInfo> result = new HashMap<>();
    for (int srcIndex = 0; srcIndex < inventory.getSlots(); srcIndex++) {
        ItemStack itemStack = inventory.getStackInSlot(srcIndex);
        if (itemStack.isEmpty()) {
            continue;
        }
        Object transferSlotIndex = itemFilterContainer.matchItemStack(itemStack);
        if (transferSlotIndex == null) {
            continue;
        }
        ItemStackKey itemStackKey = new ItemStackKey(itemStack);
        if (!result.containsKey(itemStackKey)) {
            TypeItemInfo itemInfo = new TypeItemInfo(itemStack.copy(), transferSlotIndex, new TIntArrayList(), 0);
            itemInfo.totalCount += itemStack.getCount();
            itemInfo.slots.add(srcIndex);
            result.put(itemStackKey, itemInfo);
        } else {
            TypeItemInfo itemInfo = result.get(itemStackKey);
            itemInfo.totalCount += itemStack.getCount();
            itemInfo.slots.add(srcIndex);
        }
    }
    return result;
}
Also used : ItemStack(net.minecraft.item.ItemStack) TIntArrayList(gnu.trove.list.array.TIntArrayList) ItemStackKey(gregtech.api.util.ItemStackKey)

Aggregations

ItemStackKey (gregtech.api.util.ItemStackKey)16 ItemStack (net.minecraft.item.ItemStack)10 SimpleItemInfo (gregtech.common.inventory.SimpleItemInfo)3 BlockInfo (gregtech.api.util.BlockInfo)2 IItemInfo (gregtech.common.inventory.IItemInfo)2 IOException (java.io.IOException)2 BlockPos (net.minecraft.util.math.BlockPos)2 TIntArrayList (gnu.trove.list.array.TIntArrayList)1 WorldSceneRenderer (gregtech.api.render.scene.WorldSceneRenderer)1 IItemList (gregtech.common.inventory.IItemList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 IBlockState (net.minecraft.block.state.IBlockState)1 InventoryPlayer (net.minecraft.entity.player.InventoryPlayer)1 InventoryCrafting (net.minecraft.inventory.InventoryCrafting)1