ctx.items.damage and player_death event moved to bworld
This commit is contained in:
@@ -1969,20 +1969,11 @@ export class GameServer {
|
||||
player.heal(amount);
|
||||
}
|
||||
|
||||
// like minecraft: everything they carried falls out where they died, and they start over at spawn. tools lose 1
|
||||
// durability first, and ones that run out break instead of dropping
|
||||
// they start over at spawn. what happens to what they carried is up to mods' player_death, which runs while
|
||||
// they're still where they died
|
||||
#kill(player: ServerPlayer, source: DamageSource) {
|
||||
const cause = source.cause;
|
||||
const { x, y, z } = player;
|
||||
this.close_menu(player);
|
||||
for (let i = 0; i < player.inventory.size; i++) {
|
||||
const item = player.inventory.get_item(i);
|
||||
if (item) {
|
||||
player.inventory.set_item(i, undefined);
|
||||
if (item.damage(1)) continue;
|
||||
this.pop_item(Math.floor(x), Math.floor(Math.max(y, 0)), Math.floor(z), item);
|
||||
}
|
||||
}
|
||||
this.mods.after.player_death.emit({ player: this.mods.player(player), cause });
|
||||
this.#broadcast({ type: "chat", text: death_message(player.name, source) });
|
||||
player.vitals.reset();
|
||||
|
||||
@@ -1002,6 +1002,12 @@ export class ModRuntime {
|
||||
if (!item) throw new Error(`unknown item ${id}`);
|
||||
return item.tool?.type;
|
||||
},
|
||||
damage: (item, amount) => {
|
||||
const stack = EngineItemStack.from_data(item);
|
||||
const used_up = stack.damage(amount);
|
||||
item.data = stack.data;
|
||||
return used_up;
|
||||
},
|
||||
sell_value: shared_items_api(mod, this.fluid_rules).sell_value,
|
||||
components: (id) => {
|
||||
const item = EverythingRegistry.get<ItemRegistry>("items", id);
|
||||
|
||||
Reference in New Issue
Block a user