Worm bin working with both worms and grubs
This commit is contained in:
+5
-2
@@ -35,6 +35,8 @@ export interface MenuSlot {
|
||||
on_take?: (item: ItemStack) => boolean;
|
||||
// drawn in the slot while it's empty
|
||||
icon?: string;
|
||||
// the most it holds of anything, when that's less than a stack, like minecraft's Slot.getMaxStackSize
|
||||
max_count?: number;
|
||||
// one of the player's own inventory slots, this one
|
||||
inventory?: number;
|
||||
}
|
||||
@@ -79,7 +81,7 @@ export class Menu {
|
||||
// the slot doesn't take what the cursor holds
|
||||
return;
|
||||
} else {
|
||||
click_slot(slot.container, slot.index, cursor, button);
|
||||
click_slot(slot.container, slot.index, cursor, button, slot.max_count);
|
||||
}
|
||||
this.on_changed?.();
|
||||
}
|
||||
@@ -138,11 +140,12 @@ export class Menu {
|
||||
}
|
||||
|
||||
slot_info(): MenuSlotInfo[] {
|
||||
return this.slots.map(({ x, y, output, icon }) => ({
|
||||
return this.slots.map(({ x, y, output, icon, max_count }) => ({
|
||||
x,
|
||||
y,
|
||||
...(output ? { output: true } : {}),
|
||||
...(icon ? { icon } : {}),
|
||||
...(max_count !== undefined ? { max_count } : {}),
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
@@ -1154,6 +1154,12 @@ function menu_slot(
|
||||
if (options.output_only) added.output = true;
|
||||
if (on_take) added.on_take = (item) => guarded("an on_take", () => on_take(item_api(item))) === true;
|
||||
if (options.icon) added.icon = String(options.icon);
|
||||
if (options.max_count !== undefined) {
|
||||
if (!Number.isInteger(options.max_count) || options.max_count < 1) {
|
||||
throw new Error(`slot ${slot}'s max_count must be a whole number, at least 1`);
|
||||
}
|
||||
added.max_count = options.max_count;
|
||||
}
|
||||
if (engine === player.inventory) added.inventory = slot;
|
||||
return added;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user