Loot tables

This commit is contained in:
2026-10-08 00:54:45 -03:00
parent 757ee74bc7
commit ec2b53c02a
45 changed files with 1733 additions and 150 deletions
+2
View File
@@ -84,6 +84,8 @@ export interface EntityLevel {
entity_event(entity: Entity, event: EntityEvent): void;
// it died, after dropping its things
on_death(entity: Entity, source: DamageSource): void;
// what it drops when it dies, from its type's loot table
entity_loot(entity: Entity, source: DamageSource): ItemStack[];
}
// an entity as level.json keeps it, see Entity.save. each kind adds its own fields
+6
View File
@@ -20,6 +20,8 @@ export interface EntityHost {
send(player: ServerPlayer, message: ServerMessage): void;
hurt_player(player: ServerPlayer, amount: number, source: DamageSource): boolean;
on_entity_death?(entity: Entity, source: DamageSource): void;
// what it drops when it dies, from its loot table
entity_loot?(entity: Entity, source: DamageSource): ItemStack[];
}
// what a client was last told about an entity, so only changes get sent
@@ -154,6 +156,10 @@ export class EntityManager implements EntityLevel {
this.#host.on_entity_death?.(entity, source);
}
entity_loot(entity: Entity, source: DamageSource): ItemStack[] {
return this.#host.entity_loot?.(entity, source) ?? [];
}
// ticking
// every entity active says should move, with their passengers. entities removed along the way are forgotten
+5 -2
View File
@@ -374,8 +374,11 @@ export abstract class LivingEntity extends Entity {
this.level.on_death(this, source);
}
// what it drops when it dies, each kind decides. spawn_at_location drops something where it is
drop_loot(_source: DamageSource) {}
// what it drops when it dies: its type's loot table, see EntityJson.loot_table. spawn_at_location drops
// something where it is
drop_loot(source: DamageSource) {
for (const stack of this.level.entity_loot(this, source)) this.spawn_at_location(stack);
}
// mobs drop their equipment, see Mob
drop_equipment(_source: DamageSource) {}