Files
2026-11-22 13:21:27 -03:00

23 lines
892 B
TypeScript

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();
});
}