Search in sources :

Example 1 with ItemStackKey

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

the class MultiblockInfoRecipeWrapper method initializePattern.

private MBPattern initializePattern(MultiblockShapeInfo shapeInfo, Set<ItemStackKey> blockDrops) {
    Map<BlockPos, BlockInfo> blockMap = new HashMap<>();
    BlockInfo[][][] blocks = shapeInfo.getBlocks();
    for (int z = 0; z < blocks.length; z++) {
        BlockInfo[][] aisle = blocks[z];
        for (int y = 0; y < aisle.length; y++) {
            BlockInfo[] column = aisle[y];
            for (int x = 0; x < column.length; x++) {
                BlockPos blockPos = new BlockPos(x, y, z);
                BlockInfo blockInfo = column[x];
                blockMap.put(blockPos, blockInfo);
            }
        }
    }
    WorldSceneRenderer worldSceneRenderer = new WorldSceneRenderer(blockMap);
    worldSceneRenderer.world.updateEntities();
    HashMap<ItemStackKey, PartInfo> partsMap = new HashMap<>();
    gatherBlockDrops(worldSceneRenderer.world, blockMap, blockDrops, partsMap);
    worldSceneRenderer.setRenderCallback(this);
    worldSceneRenderer.setRenderFilter(this::shouldDisplayBlock);
    ArrayList<PartInfo> partInfos = new ArrayList<>(partsMap.values());
    partInfos.sort((one, two) -> {
        if (one.isController)
            return -1;
        if (two.isController)
            return +1;
        if (one.isTile && !two.isTile)
            return -1;
        if (two.isTile && !one.isTile)
            return +1;
        if (one.blockId != two.blockId)
            return two.blockId - one.blockId;
        return two.amount - one.amount;
    });
    ArrayList<ItemStack> parts = new ArrayList<>();
    for (PartInfo partInfo : partInfos) {
        parts.add(partInfo.getItemStack());
    }
    return new MBPattern(worldSceneRenderer, parts);
}
Also used : WorldSceneRenderer(gregtech.api.render.scene.WorldSceneRenderer) ItemStackKey(gregtech.api.util.ItemStackKey) BlockInfo(gregtech.api.util.BlockInfo) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack)

Example 2 with ItemStackKey

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

the class CoverConveyor method countInventoryItemsByMatchSlot.

protected Map<Object, GroupItemInfo> countInventoryItemsByMatchSlot(IItemHandler inventory) {
    HashMap<Object, GroupItemInfo> 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(transferSlotIndex)) {
            GroupItemInfo itemInfo = new GroupItemInfo(transferSlotIndex, new HashSet<>(), 0);
            itemInfo.itemStackTypes.add(itemStackKey);
            itemInfo.totalCount += itemStack.getCount();
            result.put(transferSlotIndex, itemInfo);
        } else {
            GroupItemInfo itemInfo = result.get(transferSlotIndex);
            itemInfo.itemStackTypes.add(itemStackKey);
            itemInfo.totalCount += itemStack.getCount();
        }
    }
    return result;
}
Also used : ItemStack(net.minecraft.item.ItemStack) ItemStackKey(gregtech.api.util.ItemStackKey)

Example 3 with ItemStackKey

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

the class CoverRoboticArm method doTransferExact.

protected int doTransferExact(IItemHandler itemHandler, IItemHandler myItemHandler, int maxTransferAmount) {
    Map<ItemStackKey, TypeItemInfo> sourceItemAmount = doCountSourceInventoryItemsByType(itemHandler, myItemHandler);
    Iterator<ItemStackKey> iterator = sourceItemAmount.keySet().iterator();
    while (iterator.hasNext()) {
        ItemStackKey key = iterator.next();
        TypeItemInfo sourceInfo = sourceItemAmount.get(key);
        int itemAmount = sourceInfo.totalCount;
        Set<ItemStackKey> matchedItems = Collections.singleton(key);
        int itemToMoveAmount = itemFilterContainer.getSlotTransferLimit(sourceInfo.filterSlot, matchedItems);
        if (itemAmount >= itemToMoveAmount) {
            sourceInfo.totalCount = itemToMoveAmount;
        } else {
            iterator.remove();
        }
    }
    int itemsTransferred = 0;
    int maxTotalTransferAmount = maxTransferAmount + itemsTransferBuffered;
    boolean notEnoughTransferRate = false;
    for (TypeItemInfo itemInfo : sourceItemAmount.values()) {
        if (maxTotalTransferAmount >= itemInfo.totalCount) {
            boolean result = doTransferItemsExact(itemHandler, myItemHandler, itemInfo);
            itemsTransferred += result ? itemInfo.totalCount : 0;
            maxTotalTransferAmount -= result ? itemInfo.totalCount : 0;
        } else {
            notEnoughTransferRate = true;
        }
    }
    // if we didn't transfer anything because of too small transfer rate, buffer it
    if (itemsTransferred == 0 && notEnoughTransferRate) {
        itemsTransferBuffered += maxTransferAmount;
    } else {
        // otherwise, if transfer succeed, empty transfer buffer value
        itemsTransferBuffered = 0;
    }
    return Math.min(itemsTransferred, maxTransferAmount);
}
Also used : ItemStackKey(gregtech.api.util.ItemStackKey)

Example 4 with ItemStackKey

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

the class CachedRecipeData method performRecipe.

public boolean performRecipe(EntityPlayer player) {
    this.lastTickChecked = -1L;
    if (!checkRecipeValid()) {
        return false;
    }
    if (!consumeRecipeItems(false)) {
        this.lastTickChecked = -1L;
        return false;
    }
    ForgeHooks.setCraftingPlayer(player);
    InventoryCrafting deepCopy = InventoryUtils.deepCopyInventoryCrafting(inventory);
    NonNullList<ItemStack> remainingItems = recipe.getRemainingItems(deepCopy);
    ForgeHooks.setCraftingPlayer(null);
    for (ItemStack itemStack : remainingItems) {
        itemStack = itemStack.copy();
        ItemStackKey stackKey = new ItemStackKey(itemStack);
        int remainingAmount = itemStack.getCount() - itemSourceList.insertItem(stackKey, itemStack.getCount(), false, InsertMode.HIGHEST_PRIORITY);
        if (remainingAmount > 0) {
            itemStack.setCount(remainingAmount);
            player.addItemStackToInventory(itemStack);
            if (itemStack.getCount() > 0) {
                player.dropItem(itemStack, false, false);
            }
        }
    }
    this.lastTickChecked = -1L;
    return true;
}
Also used : InventoryCrafting(net.minecraft.inventory.InventoryCrafting) ItemStack(net.minecraft.item.ItemStack) ItemStackKey(gregtech.api.util.ItemStackKey)

Example 5 with ItemStackKey

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

the class ItemSourceList method removeItemHandler.

public void removeItemHandler(ItemSource handlerInfo) {
    if (this.handlerInfoList.remove(handlerInfo)) {
        handlerInfo.setStoredItemsChangeCallback(null);
        handlerInfo.setInvalidationCallback(null);
        for (ItemStackKey itemStackKey : itemInfoMap.keySet()) {
            NetworkItemInfo itemInfo = itemInfoMap.get(itemStackKey);
            itemInfo.removeInventory(handlerInfo);
        }
        removeItemHandlerPost(handlerInfo);
    }
}
Also used : 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