Death
This commit is contained in:
@@ -104,6 +104,8 @@ export interface EntityLevel {
|
||||
entity_loot(entity: Entity, source: DamageSource): ItemStack[];
|
||||
// it's standing on the block at x y z after moving, for the block's components, see on_entity_stand
|
||||
stands_on(entity: Entity, x: number, y: number, z: number): void;
|
||||
// it moved, for the components of the blocks its box is in, see on_entity_inside
|
||||
inside_blocks(entity: Entity): void;
|
||||
}
|
||||
|
||||
// an entity as level.json keeps it, see Entity.save. each kind adds its own fields
|
||||
@@ -308,6 +310,7 @@ export abstract class Entity {
|
||||
if (this.on_ground) {
|
||||
this.level.stands_on(this, Math.floor(this.x), Math.floor(this.y - STANDING_DEPTH), Math.floor(this.z));
|
||||
}
|
||||
this.level.inside_blocks(this);
|
||||
this.update_fall_distance(this.y - from_y);
|
||||
return collisions;
|
||||
}
|
||||
@@ -362,6 +365,12 @@ export abstract class Entity {
|
||||
this.fire = 0;
|
||||
}
|
||||
|
||||
// like minecraft's Entity.kill: ones that can die do, even when invulnerable, the rest go away. cause is for events
|
||||
// and the death message
|
||||
kill(_cause: string) {
|
||||
this.remove();
|
||||
}
|
||||
|
||||
// takes it out of the world. the entity manager tells clients and forgets it
|
||||
remove() {
|
||||
if (this.removed) return;
|
||||
|
||||
@@ -30,6 +30,8 @@ export interface EntityHost {
|
||||
entity_loot?(entity: Entity, source: DamageSource): ItemStack[];
|
||||
// see EntityLevel.stands_on
|
||||
stands_on?(entity: Entity, x: number, y: number, z: number): void;
|
||||
// see EntityLevel.inside_blocks
|
||||
inside_blocks?(entity: Entity): void;
|
||||
}
|
||||
|
||||
// what a client was last told about an entity, so only changes get sent
|
||||
@@ -188,6 +190,10 @@ export class EntityManager implements EntityLevel {
|
||||
this.#host.stands_on?.(entity, x, y, z);
|
||||
}
|
||||
|
||||
inside_blocks(entity: Entity) {
|
||||
this.#host.inside_blocks?.(entity);
|
||||
}
|
||||
|
||||
// ticking
|
||||
|
||||
// every entity active says should move, with their passengers. entities removed along the way are forgotten
|
||||
|
||||
@@ -313,6 +313,11 @@ export abstract class LivingEntity extends Entity {
|
||||
return true;
|
||||
}
|
||||
|
||||
// mods can still cancel it, like any damage
|
||||
override kill(cause: string) {
|
||||
this.hurt(Number.MAX_VALUE, { cause, type: "absolute", bypasses_invulnerability: true });
|
||||
}
|
||||
|
||||
// after mods and the hurt cooldown
|
||||
actually_hurt(amount: number, source: DamageSource) {
|
||||
// absolute damage, take it and theres no counterplay
|
||||
|
||||
Reference in New Issue
Block a user