World shape for dimension
This commit is contained in:
@@ -17,8 +17,8 @@ import type { EntityData, EntityEvent, EntityInfo } from "@/common/protocol.ts";
|
||||
import type { ServerPlayer } from "../player.ts";
|
||||
import type { LivingEntity } from "./living_entity.ts";
|
||||
|
||||
// below this, entities have fallen out of the world
|
||||
export const VOID_Y = -64;
|
||||
// this far below the bottom of the world, entities have fallen out of it
|
||||
export const VOID_DEPTH = 64;
|
||||
// the most air most things hold, 15 seconds
|
||||
export const MAX_AIR = 300;
|
||||
// motion faster than minecraft's 10 blocks a tick is reset when loading
|
||||
@@ -69,6 +69,8 @@ export function damage_source(cause: string): DamageSource {
|
||||
// what entities can see and do in the world, the entity manager is one
|
||||
export interface EntityLevel {
|
||||
readonly current_tick: number;
|
||||
// the bottom of the world, see WorldShape
|
||||
readonly min_y: number;
|
||||
has_collision(x: number, y: number, z: number): boolean;
|
||||
// what it bumps into at a block, see common/physics.ts
|
||||
collision_shape(x: number, y: number, z: number): boolean | Shape;
|
||||
@@ -269,7 +271,7 @@ export abstract class Entity {
|
||||
}
|
||||
}
|
||||
|
||||
if (this.y < VOID_Y) {
|
||||
if (this.y < this.level.min_y - VOID_DEPTH) {
|
||||
this.on_below_world();
|
||||
}
|
||||
}
|
||||
@@ -344,7 +346,7 @@ export abstract class Entity {
|
||||
return (this.invulnerable || this.invulnerable_time > 0) && !source.bypasses_invulnerability;
|
||||
}
|
||||
|
||||
// y is below VOID_Y. things that can't die just go away
|
||||
// y is VOID_DEPTH below the bottom of the world. things that can't die just go away
|
||||
on_below_world() {
|
||||
this.remove();
|
||||
}
|
||||
|
||||
@@ -62,6 +62,10 @@ export class EntityManager implements EntityLevel {
|
||||
return this.#host.current_tick;
|
||||
}
|
||||
|
||||
get min_y() {
|
||||
return this.#host.world.shape.min_y;
|
||||
}
|
||||
|
||||
get count() {
|
||||
return this.#entities.size;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user