Search in sources :

Example 1 with SimpleItemInfo

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

the class ItemListGridWidget method readUpdateInfo.

@Override
public void readUpdateInfo(int id, PacketBuffer buffer) {
    super.readUpdateInfo(id, buffer);
    if (id == 2) {
        int slotsToAdd = buffer.readVarInt();
        modifySlotRows(slotsToAdd);
    }
    if (id == 3) {
        try {
            int itemsRemoved = buffer.readVarInt();
            for (int i = 0; i < itemsRemoved; i++) {
                ItemStackKey itemStack = new ItemStackKey(buffer.readItemStack());
                this.displayItemList.removeIf(it -> it.getItemStackKey().equals(itemStack));
            }
            int itemsChanged = buffer.readVarInt();
            for (int i = 0; i < itemsChanged; i++) {
                ItemStackKey itemStack = new ItemStackKey(buffer.readItemStack());
                int newTotalAmount = buffer.readVarInt();
                SimpleItemInfo itemInfo = displayItemList.stream().filter(it -> it.getItemStackKey().equals(itemStack)).findAny().orElse(null);
                if (itemInfo == null) {
                    itemInfo = new SimpleItemInfo(itemStack);
                    this.displayItemList.add(itemInfo);
                }
                itemInfo.setTotalItemAmount(newTotalAmount);
            }
            this.displayItemList.sort(comparator);
        } catch (IOException ex) {
            throw new RuntimeException(ex);
        }
    }
}
Also used : SimpleItemInfo(gregtech.common.inventory.SimpleItemInfo) IOException(java.io.IOException) ItemStackKey(gregtech.api.util.ItemStackKey)

Example 2 with SimpleItemInfo

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

the class ItemListGridWidget method checkItemListForChanges.

private void checkItemListForChanges() {
    Iterator<ItemStackKey> iterator = cachedItemList.keySet().iterator();
    while (iterator.hasNext()) {
        ItemStackKey itemStack = iterator.next();
        if (!itemList.hasItemStored(itemStack)) {
            iterator.remove();
            itemsRemoved.add(itemStack);
        }
    }
    for (ItemStackKey itemStack : itemList.getStoredItems()) {
        IItemInfo itemInfo = itemList.getItemInfo(itemStack);
        if (itemInfo == null)
            continue;
        if (!cachedItemList.containsKey(itemStack)) {
            SimpleItemInfo lookupInfo = new SimpleItemInfo(itemStack);
            int totalAmount = itemInfo.getTotalItemAmount();
            if (totalAmount == 0) {
                itemsRemoved.add(itemStack);
            } else {
                lookupInfo.setTotalItemAmount(totalAmount);
                cachedItemList.put(itemStack, lookupInfo);
                itemsChanged.add(lookupInfo);
            }
        } else {
            SimpleItemInfo cachedItemInfo = cachedItemList.get(itemStack);
            if (cachedItemInfo.getTotalItemAmount() != itemInfo.getTotalItemAmount()) {
                cachedItemInfo.setTotalItemAmount(itemInfo.getTotalItemAmount());
                itemsChanged.add(cachedItemInfo);
            }
        }
    }
}
Also used : IItemInfo(gregtech.common.inventory.IItemInfo) SimpleItemInfo(gregtech.common.inventory.SimpleItemInfo) ItemStackKey(gregtech.api.util.ItemStackKey)

Example 3 with SimpleItemInfo

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

the class ItemListGridWidget method detectAndSendChanges.

@Override
public void detectAndSendChanges() {
    super.detectAndSendChanges();
    if (itemList == null)
        return;
    int amountOfItemTypes = itemList.getStoredItems().size();
    int slotRowsRequired = Math.max(slotAmountY, (int) Math.ceil(amountOfItemTypes / (slotAmountX * 1.0)));
    if (slotRowsAmount != slotRowsRequired) {
        int slotsToAdd = slotRowsRequired - slotRowsAmount;
        this.slotRowsAmount = slotRowsRequired;
        writeUpdateInfo(2, buf -> buf.writeVarInt(slotsToAdd));
        modifySlotRows(slotsToAdd);
    }
    this.itemsChanged.clear();
    this.itemsRemoved.clear();
    checkItemListForChanges();
    if (!itemsChanged.isEmpty() || !itemsRemoved.isEmpty()) {
        writeUpdateInfo(3, buf -> {
            buf.writeVarInt(itemsRemoved.size());
            for (ItemStackKey itemStackKey : itemsRemoved) {
                buf.writeItemStack(itemStackKey.getItemStackRaw());
            }
            buf.writeVarInt(itemsChanged.size());
            for (SimpleItemInfo itemInfo : itemsChanged) {
                buf.writeItemStack(itemInfo.getItemStackKey().getItemStackRaw());
                buf.writeVarInt(itemInfo.getTotalItemAmount());
            }
        });
    }
}
Also used : SimpleItemInfo(gregtech.common.inventory.SimpleItemInfo) ItemStackKey(gregtech.api.util.ItemStackKey)

Aggregations

ItemStackKey (gregtech.api.util.ItemStackKey)3 SimpleItemInfo (gregtech.common.inventory.SimpleItemInfo)3 IItemInfo (gregtech.common.inventory.IItemInfo)1 IOException (java.io.IOException)1