This commit is contained in:
2026-11-22 13:21:27 -03:00
parent e751d22c6e
commit ac791b886e
23 changed files with 494 additions and 91 deletions
+13 -2
View File
@@ -16,7 +16,9 @@ import { sound_range, sound_to_play } from "@/common/mod_data.ts";
import type { ServerPlayer } from "../player.ts";
import type { ServerWorld } from "../world.ts";
import type { DamageSource, Entity, EntityLevel, SavedEntity } from "./entity.ts";
import { load_entity } from "./entity_types.ts";
import { create_entity, load_entity } from "./entity_types.ts";
import { ObjectEntity } from "./mod_entity.ts";
import { EverythingRegistry, type ItemRegistry } from "@/common/everything_registry.ts";
import { ItemEntity } from "./item_entity.ts";
import { MOBS_PATH_THROUGH } from "./pathfinding.ts";
import type { LivingEntity } from "./living_entity.ts";
@@ -180,7 +182,16 @@ export class EntityManager implements EntityLevel {
this.#host.after_hurt(entity, amount, source);
}
spawn_item(x: number, y: number, z: number, stack: ItemStack, pickup_delay = 0): ItemEntity {
// a cubi:item, or the entity the item lies around as instead, holding it (see ItemRegistry.entity)
spawn_item(x: number, y: number, z: number, stack: ItemStack, pickup_delay = 0): Entity {
const type = EverythingRegistry.get<ItemRegistry>("items", stack.type_id)?.entity;
const object = type === undefined ? undefined : create_entity(this, type);
if (object instanceof ObjectEntity) {
object.item = stack;
object.set_position(x, y, z);
this.add_entity(object);
return object;
}
const entity = new ItemEntity(this, stack, x, y, z, pickup_delay);
this.add_entity(entity);
return entity;