ctx.items.damage and player_death event moved to bworld
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user