This commit is contained in:
2026-11-22 13:21:27 -03:00
parent e751d22c6e
commit ac791b886e
23 changed files with 494 additions and 91 deletions
+3 -1
View File
@@ -3,6 +3,8 @@
"item": {
"id": "dangerous_business:air_horn",
"texture": "dangerous_business:air_horn",
"model": "dangerous_business:air_horn"
"model": "dangerous_business:air_horn",
"entity": "dangerous_business:scrap",
"max_stack": 1
}
}
+2
View File
@@ -4,6 +4,7 @@ import { DOOR, FACILITY_DOOR } from "./shared.ts";
import { Alea } from "@paulaboks/rng";
import { register_coilhead, register_coilhead_animator } from "./coilhead.ts";
import { register_jester, register_jester_animator } from "./jester.ts";
import { register_scrap } from "./scrap.ts";
import {
DOORWAY,
MAIN_TILE,
@@ -26,6 +27,7 @@ export function server(ctx: ServerContext) {
register_commands(ctx);
register_coilhead(ctx);
register_jester(ctx);
register_scrap(ctx);
}
export function client(ctx: ClientContext) {
+22
View File
@@ -0,0 +1,22 @@
import type { ServerContext } from "cubi/server";
// scrap lies around as this entity (see its items' "entity"), holding the item, and is picked up by right clicking it
export const SCRAP = "dangerous_business:scrap";
// the inventory slots scrap can be picked up into, the hotbar for now
const LOOT_SLOTS = [0, 1, 2, 3, 4, 5, 6, 7, 8];
export function register_scrap(ctx: ServerContext) {
ctx.events.before.entity_interact.subscribe((event) => {
if (event.entity.type !== SCRAP) return;
// clicking scrap never uses what's held, picked up or not
event.cancel = true;
const item = event.entity.get_item();
const inventory = event.player.inventory;
const slot = LOOT_SLOTS.find((slot) => inventory.get(slot) === undefined);
// with no free loot slot it stays where it is
if (!item || slot === undefined) return;
inventory.set(slot, item);
event.entity.remove();
});
}