Add natural mob spawning for rotwalker
This commit is contained in:
@@ -74,6 +74,7 @@ import {
|
||||
import { Mob } from "./entity/mob.ts";
|
||||
import { LivingEntity } from "./entity/living_entity.ts";
|
||||
import { EntityManager } from "./entity/entity_manager.ts";
|
||||
import { NaturalSpawner } from "./natural_spawner.ts";
|
||||
import { create_entity, entity_type_ids } from "./entity/entity_types.ts";
|
||||
import { DAMAGE, type DamageSource, type SavedEntity } from "./entity/entity.ts";
|
||||
import { ATTRIBUTES } from "./entity/attributes.ts";
|
||||
@@ -170,6 +171,10 @@ export class GameServer {
|
||||
entities: EntityManager;
|
||||
mods: ModRuntime;
|
||||
recipes: RecipeBook;
|
||||
// monsters spawning on their own near players, see natural_spawner.ts
|
||||
spawner: NaturalSpawner;
|
||||
// minecraft's doMobSpawning game rule. tests turn it off so nothing turns up they didn't put there
|
||||
do_mob_spawning = true;
|
||||
// what runs tick(), for /tps. tests call tick() themselves
|
||||
loop?: GameLoop;
|
||||
// how long a tick can spend building chunks for players. tests lift it so what gets sent doesn't depend on speed
|
||||
@@ -180,6 +185,7 @@ export class GameServer {
|
||||
this.#mods = mods;
|
||||
this.mods = mods.runtime;
|
||||
this.recipes = mods.recipes;
|
||||
this.spawner = new NaturalSpawner(mods.recipes.spawns);
|
||||
|
||||
const saved: SavedLevel | SavedLevelV4 | undefined = save?.level ? JSON.parse(save.level) : undefined;
|
||||
if (saved && saved.version !== 5 && saved.version !== 4) {
|
||||
@@ -1517,6 +1523,7 @@ export class GameServer {
|
||||
|
||||
// like minecraft: entities only move near players, and players pick up items by walking into them
|
||||
#tick_entities() {
|
||||
if (this.do_mob_spawning) this.spawner.tick(this, SIMULATION_DISTANCE);
|
||||
this.entities.tick((entity) => this.#near_any_player(entity.x, entity.z));
|
||||
const items = this.item_entities();
|
||||
for (const player of this.#players.values()) {
|
||||
|
||||
Reference in New Issue
Block a user