Water flowing
This commit is contained in:
@@ -9,6 +9,7 @@ import {
|
||||
TICKS_PER_SECOND,
|
||||
} from "$/common/constants.ts";
|
||||
import { BlockRegistry, EverythingRegistry, is_liquid_block, ItemRegistry } from "$/common/everything_registry.ts";
|
||||
import { LiquidFlow } from "./liquids.ts";
|
||||
import { Container, ItemData, ItemStack } from "$/common/inventory.ts";
|
||||
import {
|
||||
AIR_ID,
|
||||
@@ -161,6 +162,8 @@ export class GameServer {
|
||||
recipes: RecipeBook;
|
||||
// monsters spawning on their own near players, see natural_spawner.ts
|
||||
spawner: NaturalSpawner;
|
||||
// water and other liquids flowing, see liquids.ts
|
||||
liquids: LiquidFlow;
|
||||
// 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
|
||||
@@ -186,6 +189,20 @@ export class GameServer {
|
||||
);
|
||||
}
|
||||
this.world = new ServerWorld(saved?.seed ?? default_seed, mods.worldgen);
|
||||
this.liquids = new LiquidFlow({
|
||||
value_at: (x, y, z) => {
|
||||
if (y < 0 || y >= CHUNK_HEIGHT) return undefined;
|
||||
const loaded = this.world.has_chunk(Math.floor(x / CHUNK_SIZE), Math.floor(z / CHUNK_SIZE));
|
||||
return loaded ? this.world.get_block_value(x, y, z) : undefined;
|
||||
},
|
||||
block: (nid) => EverythingRegistry.get_by_id<BlockRegistry>("blocks", nid),
|
||||
nid: (id) => this.world.block_ids[id],
|
||||
set_block: (x, y, z, id, state) => {
|
||||
// a level changing is only a state, the block's components don't see it come and go
|
||||
if (id === this.world.get_block_id(x, y, z)) this.set_block_state(x, y, z, state);
|
||||
else this.set_block(x, y, z, id, undefined, state);
|
||||
},
|
||||
});
|
||||
// deno-lint-ignore no-this-alias
|
||||
const game = this;
|
||||
this.entities = new EntityManager({
|
||||
@@ -231,6 +248,7 @@ export class GameServer {
|
||||
|
||||
// players without the chunk get the block with it when they do, like minecraft
|
||||
this.world.on_block_change = (x, y, z, id, state) => {
|
||||
this.liquids.changed(x, y, z, this.#tick);
|
||||
const data = JSON.stringify(
|
||||
(state
|
||||
? { type: "set_block", x, y, z, id, state }
|
||||
@@ -331,6 +349,7 @@ export class GameServer {
|
||||
}
|
||||
|
||||
this.#new_days();
|
||||
this.liquids.tick(this.#tick);
|
||||
this.#tick_vitals();
|
||||
this.#tick_entities();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user