Search in sources :

Example 1 with IItemInfo

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

the class ItemListSlotWidget method drawInBackground.

@Override
public void drawInBackground(int mouseX, int mouseY, IRenderContext context) {
    super.drawInBackground(mouseX, mouseY, context);
    Position position = getPosition();
    GuiTextures.SLOT.draw(position.x, position.y, 18, 18);
    IItemInfo itemInfo = gridWidget.getItemInfoAt(index);
    int stackX = position.x + 1;
    int stackY = position.y + 1;
    if (itemInfo != null) {
        ItemStack itemStack = itemInfo.getItemStackKey().getItemStackRaw();
        String itemAmountStr = formatItemAmount(itemInfo.getTotalItemAmount());
        drawItemStack(itemStack, stackX, stackY, null);
        drawStringFixedCorner(itemAmountStr, stackX + 17, stackY + 17, 16777215, true, 0.5f);
    }
    if (isMouseOverElement(mouseX, mouseY)) {
        drawSelectionOverlay(stackX, stackY, 16, 16);
    }
}
Also used : IItemInfo(gregtech.common.inventory.IItemInfo) Position(gregtech.api.util.Position) ItemStack(net.minecraft.item.ItemStack)

Example 2 with IItemInfo

use of gregtech.common.inventory.IItemInfo 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 IItemInfo

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

the class ItemListSlotWidget method drawInForeground.

@Override
public void drawInForeground(int mouseX, int mouseY) {
    super.drawInForeground(mouseX, mouseY);
    IItemInfo itemInfo = gridWidget.getItemInfoAt(index);
    if (itemInfo != null && isMouseOverElement(mouseX, mouseY)) {
        ItemStack itemStack = itemInfo.getItemStackKey().getItemStackRaw();
        List<String> tooltip = getItemToolTip(itemStack);
        int totalItemStored = itemInfo.getTotalItemAmount();
        String itemStoredText = I18n.format("gregtech.item_list.item_stored", totalItemStored);
        tooltip.add(TextFormatting.GRAY + itemStoredText);
        drawHoveringText(itemStack, tooltip, -1, mouseX, mouseY);
    }
}
Also used : IItemInfo(gregtech.common.inventory.IItemInfo) ItemStack(net.minecraft.item.ItemStack)

Example 4 with IItemInfo

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

the class ItemListSlotWidget method handleClientAction.

@Override
public void handleClientAction(int id, PacketBuffer buffer) {
    super.handleClientAction(id, buffer);
    if (id == 1) {
        try {
            ItemStack itemStack = buffer.readItemStack();
            int button = buffer.readVarInt();
            IItemInfo itemInfo = itemStack.isEmpty() ? null : gridWidget.getItemList().getItemInfo(new ItemStackKey(itemStack));
            handleMouseClick(itemInfo, button, false);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    } else if (id == 2) {
        try {
            ItemStack itemStack = buffer.readItemStack();
            IItemInfo itemInfo = gridWidget.getItemList().getItemInfo(new ItemStackKey(itemStack));
            if (itemInfo != null) {
                handleSelfShiftClick(itemInfo);
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
Also used : IItemInfo(gregtech.common.inventory.IItemInfo) IOException(java.io.IOException) ItemStack(net.minecraft.item.ItemStack) ItemStackKey(gregtech.api.util.ItemStackKey)

Example 5 with IItemInfo

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

the class ItemListSlotWidget method dispatchMouseClick.

private void dispatchMouseClick(int button) {
    IItemInfo itemInfo = gridWidget.getItemInfoAt(index);
    handleMouseClick(itemInfo, button, true);
    ItemStack itemStack = itemInfo == null ? ItemStack.EMPTY : itemInfo.getItemStackKey().getItemStack();
    writeClientAction(1, buf -> {
        buf.writeItemStack(itemStack);
        buf.writeVarInt(button);
    });
}
Also used : IItemInfo(gregtech.common.inventory.IItemInfo) ItemStack(net.minecraft.item.ItemStack)

Aggregations

IItemInfo (gregtech.common.inventory.IItemInfo)5 ItemStack (net.minecraft.item.ItemStack)4 ItemStackKey (gregtech.api.util.ItemStackKey)2 Position (gregtech.api.util.Position)1 SimpleItemInfo (gregtech.common.inventory.SimpleItemInfo)1 IOException (java.io.IOException)1