ctx.items.damage and player_death event moved to bworld

This commit is contained in:
2026-11-14 00:09:55 -03:00
parent 9bf6b98953
commit 6c6be61dd0
7 changed files with 34 additions and 14 deletions
+16
View File
@@ -39,6 +39,22 @@ export function setup(ctx: ServerContext) {
register_stove(ctx);
register_cooking_pot(ctx);
register_cutting_board(ctx);
register_death_drops(ctx);
}
// everything a player carried falls out where they died. tools lose 1 durability first, and ones that run out break
// instead of dropping
function register_death_drops(ctx: ServerContext) {
ctx.events.after.player_death.subscribe(({ player }) => {
const { x, y, z } = player.position;
for (let i = 0; i < player.inventory.size; i++) {
const item = player.inventory.get(i);
if (!item) continue;
player.inventory.set(i, undefined);
if (ctx.items.damage(item, 1)) continue;
ctx.world.drop_item(Math.floor(x), Math.floor(Math.max(y, 0)), Math.floor(z), item);
}
});
}
// right clicking with a type of tool turns the block into another, like any hoe on grass