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;
}
}
}
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;
}
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();
}
}
}
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;
}
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;
}
Aggregations