Loot tables
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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) {}
|
||||
|
||||
Reference in New Issue
Block a user