Q to drop
This commit is contained in:
@@ -138,6 +138,9 @@ export class Client {
|
||||
this.pop_screen();
|
||||
}
|
||||
}
|
||||
if (InputManager.is_key_pressed(options.key_drop)) {
|
||||
this.#handle_drop();
|
||||
}
|
||||
if (InputManager.is_key_pressed(options.key_chat) && !this.screen) {
|
||||
this.push_screen(new GuiChat(this));
|
||||
}
|
||||
@@ -165,6 +168,24 @@ export class Client {
|
||||
}
|
||||
}
|
||||
|
||||
// the held item while playing, the slot under the mouse in an inventory (only with nothing on the cursor)
|
||||
#handle_drop() {
|
||||
const all = InputManager.is_key_down("ControlLeft") || InputManager.is_key_down("ControlRight");
|
||||
const inventories = this.player.inventories;
|
||||
const screen = this.screen;
|
||||
if (!screen) {
|
||||
this.game_mode.drop_item(inventories.inventory, "inventory", inventories.hotbar_selected, all);
|
||||
return;
|
||||
}
|
||||
const slot = screen instanceof GuiInventoryScreen ? screen.hovering : undefined;
|
||||
const container = slot && screen instanceof GuiInventoryScreen
|
||||
? screen.get_container(slot.container)
|
||||
: undefined;
|
||||
if (slot && container && !slot.output && !inventories.cursor.item) {
|
||||
this.game_mode.drop_item(container, slot.container, slot.index, all);
|
||||
}
|
||||
}
|
||||
|
||||
// clicks happen right away, holding to break advances in tick()
|
||||
#handle_block_interaction() {
|
||||
const hit = this.hit_result;
|
||||
|
||||
@@ -2,6 +2,8 @@ import { BlockRegistry, EverythingRegistry, ItemRegistry } from "$/common/everyt
|
||||
import { AIR, FACE_OFFSETS, TICK_DELTA } from "$/common/constants.ts";
|
||||
import type { Client } from "./client.ts";
|
||||
import type { BlockHitResult } from "./level/client_level.ts";
|
||||
import type { Container } from "$/common/inventory.ts";
|
||||
import type { ContainerKey } from "$/common/protocol.ts";
|
||||
|
||||
// breaking and using blocks against a server, like minecraft's MultiPlayerGameMode. the client times breaking
|
||||
// and guesses the results so they feel instant, the server decides what really happens
|
||||
@@ -68,6 +70,17 @@ export class MultiPlayerGameMode {
|
||||
}
|
||||
}
|
||||
|
||||
// q on a slot: throws one, or the whole stack. the server spawns the item, this only takes it out right away
|
||||
drop_item(container: Container, key: ContainerKey, index: number, all: boolean) {
|
||||
const item = container.get_item(index);
|
||||
if (!item) {
|
||||
return;
|
||||
}
|
||||
this.client.connection.send({ type: "drop_item", container: key, index, all });
|
||||
item.amount = all ? 0 : item.amount - 1;
|
||||
container.set_item(index, item.amount > 0 ? item : undefined);
|
||||
}
|
||||
|
||||
// right click on nothing
|
||||
use_item() {
|
||||
this.client.connection.send({ type: "use_item" });
|
||||
|
||||
@@ -11,6 +11,8 @@ export class Options {
|
||||
key_jump: KeyCode = "Space";
|
||||
key_sprint: KeyCode = "ShiftLeft";
|
||||
key_inventory: KeyCode = "KeyE";
|
||||
// with ctrl it drops the whole stack
|
||||
key_drop: KeyCode = "KeyQ";
|
||||
key_chat: KeyCode = "KeyT";
|
||||
key_debug: KeyCode = "F3";
|
||||
key_fullscreen: KeyCode = "F11";
|
||||
|
||||
Reference in New Issue
Block a user