Item grids & terminals
GaldurItemGrid shows thousands of items with their amounts, like a storage network terminal, without creating real menu slots.
Not real slots
A GaldurItemGrid only shows a list of entries and reports clicks. It moves no item and does not talk to the server. Your mod:
- keeps the list up to date (from server packets, for instance),
- filters and sorts it,
- sends the server what the player wants to do with a click.
The list is read every frame: it can change at any time without rebuilding the widget.
Create a grid
List<GaldurItemGrid.Entry> contents = ...; // kept up to date by the modGaldurItemGrid grid = GaldurItemGrid.of(9, 6, () -> contents) .onClick((index, entry, button, shift) -> askServer(entry, button, shift));of(columns, rows, entries) creates a grid of columns × rows visible cells, scrollbar included. Each Entry is an ItemStack and a long amount, so amounts can go far past 64.
Put it in a terminal screen
The test mod's terminal places a grid of every item above the player inventory, in a GaldurContainerScreen:
public class TestTerminalScreen extends GaldurContainerScreen<TestTerminalMenu> { private int scrollRow; @Override protected void init() { super.init(); GaldurItemGrid grid = GaldurItemGrid.of(9, TestTerminalMenu.GRID_ROWS, () -> entries) .onClick((index, entry, button, shift) -> LOGGER.info("{} x {}", entry.stack(), entry.amount())); // Grid cells line up with the inventory slots: frame at x - 1. grid.setPosition(leftPos + 7, topPos + TestTerminalMenu.GRID_Y - 1); grid.setScrollRow(scrollRow); addRenderableWidget(grid.onScroll(row -> scrollRow = row)); }}The matching menu only adds the player inventory, below the grid:
static final int GRID_Y = 18;static final int GRID_ROWS = 6;static final int INVENTORY_Y = GRID_Y + GRID_ROWS * SLOT_SIZE + 14;// in the constructor:addPlayerInventory(inventory, 8, INVENTORY_Y);Minecraft calls init() again on every resize. Save the first visible row with onScroll and restore it with setScrollRow, as above.
What the grid does
| Behaviour | |
|---|---|
| Rendering | Only the visible rows are drawn (columns × rows cells), whatever the list size. |
| Amounts | Short form in the cell: "64", "1,2k", "64k" (GaldurFormat.amount). |
| Scrolling | By whole rows, with the wheel (one row per notch) or the scrollbar, which can be dragged. The scrollbar only shows when the items do not fit. |
| Hover | accent_hover outline, accent veil and the item tooltip, with the exact amount above 1,000. |
| Click | Left or right, with the Shift state, on an occupied cell. |
| Disabled | active = false: muted amounts, no click or hover; scrolling still works for browsing. |
| JEI / EMI | Hovering an item and pressing R or U shows its recipes (in a GaldurContainerScreen). |
A cell is 18 × 18 pixels, like a vanilla slot (CELL_SIZE). The scrollbar width comes from the theme (spacing.scrollbar_width).
A single cell
For one item instead of a grid, GaldurItemSlot is a display cell usable in vanilla layouts:
GaldurItemSlot iron = GaldurItemSlot.of(() -> new ItemStack(Items.IRON_INGOT), () -> network.amount(iron)) .onPress(button -> button == 0 ? takeStack() : takeHalf());The amount is hidden when it is 1, as in vanilla. Left click is 0, right click is 1; Enter and Space count as a left click.