Shift clicking

This commit is contained in:
2026-09-30 00:30:33 -03:00
parent 7dc78aac76
commit 88659bb7af
6 changed files with 227 additions and 10 deletions
+43
View File
@@ -299,6 +299,49 @@ function right_click(container: Container, index: number, cursor: Cursor) {
slot.amount = half;
}
// shift clicking, like minecraft's moveItemStackTo: tops up stacks of the same item in these slots, in order, then
// fills empty ones. what doesn't fit stays in the item
export function move_into(
item: ItemStack,
container: Container,
slots: number[],
accepts: (index: number) => boolean = () => true,
) {
for (const index of slots) {
const there = container.get_item(index);
if (item.amount <= 0) return;
if (there && there !== item && there.type_id === item.type_id && accepts(index)) {
const moving = Math.min(there.max_amount - there.amount, item.amount);
there.amount += moving;
item.amount -= moving;
}
}
for (const index of slots) {
if (item.amount <= 0) return;
if (!container.get_item(index) && accepts(index)) {
container.set_item(index, item.clone());
item.amount = 0;
}
}
}
// how many of the item move_into could put in these slots
export function room_for(
item: ItemStack,
container: Container,
slots: number[],
accepts: (index: number) => boolean = () => true,
): number {
let room = 0;
for (const index of slots) {
const there = container.get_item(index);
if (!accepts(index)) continue;
if (!there) room += item.max_amount;
else if (there.type_id === item.type_id) room += there.max_amount - there.amount;
}
return room;
}
// whether take_output would take it
export function can_take_output(item: ItemStack, cursor: Cursor): boolean {
const holding = cursor.item;
+2 -1
View File
@@ -92,7 +92,8 @@ export type ClientMessage =
// right click on a block: interact with it, or place the held block against `face`
| { type: "use_block"; x: number; y: number; z: number; face: Faces }
| { type: "select_slot"; slot: number }
| { type: "click"; container: ContainerKey; index: number; button: number }
// shift moves the stack to the other part of the screen instead, like minecraft's quick move
| { type: "click"; container: ContainerKey; index: number; button: number; shift?: boolean }
// q on a slot (the held one when no screen is open) throws one item, or the whole stack with ctrl
| { type: "drop_item"; container: ContainerKey; index: number; all: boolean }
// closes the open screen, including the player's own inventory screen