This commit is contained in:
2026-10-28 22:26:42 -03:00
parent b8cccb86ff
commit 5d64b801a3
14 changed files with 480 additions and 12 deletions
+9
View File
@@ -24,6 +24,8 @@ export const MAX_AIR = 300;
const MAX_LOADED_SPEED = 10 * TICKS_PER_SECOND;
// like minecraft
export const MAX_TAGS = 1024;
// how far under its feet the block it stands on is looked for, so standing on top of a block finds that one
const STANDING_DEPTH = 1 / 1024;
// something that can hurt an entity: another entity, or a player
export interface Attacker {
@@ -94,6 +96,8 @@ export interface EntityLevel {
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[];
// 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;
}
// an entity as level.json keeps it, see Entity.save. each kind adds its own fields
@@ -293,6 +297,11 @@ export abstract class Entity {
);
this.on_ground = collisions.y === 1;
this.horizontal_collision = collisions.x !== 0 || collisions.z !== 0;
// the block its feet are on, which can be the one they're in when it's lower than a whole block, like a basin's
// floor
if (this.on_ground) {
this.level.stands_on(this, Math.floor(this.x), Math.floor(this.y - STANDING_DEPTH), Math.floor(this.z));
}
this.update_fall_distance(this.y - from_y);
return collisions;
}
+6
View File
@@ -26,6 +26,8 @@ export interface EntityHost {
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[];
// see EntityLevel.stands_on
stands_on?(entity: Entity, x: number, y: number, z: number): void;
}
// what a client was last told about an entity, so only changes get sent
@@ -172,6 +174,10 @@ export class EntityManager implements EntityLevel {
return this.#host.entity_loot?.(entity, source) ?? [];
}
stands_on(entity: Entity, x: number, y: number, z: number) {
this.#host.stands_on?.(entity, x, y, z);
}
// ticking
// every entity active says should move, with their passengers. entities removed along the way are forgotten
+3 -2
View File
@@ -80,9 +80,10 @@ export class ItemEntity extends Entity {
this.pickup_delay -= 1;
}
// covered by a block placed on it, float out the top instead of being stuck inside
// covered by a block placed on it, float out the top instead of being stuck inside. only inside what it bumps
// into, like minecraft's noCollision, so it can lie in a block with a hollow, like a basin
const level = this.level;
if (level.has_collision(Math.floor(this.x), Math.floor(this.y + this.height / 2), Math.floor(this.z))) {
if (!physics.box_is_free(this, 0, 0, 0, (x, y, z) => level.collision_shape(x, y, z))) {
this.vy = UNSTICK_SPEED;
}