Real ctx.world.is_loaded implementation
This commit is contained in:
@@ -8,7 +8,7 @@ import { Container as EngineContainer, ItemStack as EngineItemStack } from "$/co
|
||||
import { block_states, get_state_value, is_waterlogged, liquid_block, set_state_value } from "$/common/utils.ts";
|
||||
import { LootTables } from "./loot.ts";
|
||||
import { collision_shape_at, covers_face, raycast_blocks, type Shape } from "$/common/block_shapes.ts";
|
||||
import { AIR, faces, ID_MASK } from "$/common/constants.ts";
|
||||
import { AIR, CHUNK_SIZE, faces, ID_MASK } from "$/common/constants.ts";
|
||||
import { physics } from "$/common/physics.ts";
|
||||
import { clock } from "$/common/time.ts";
|
||||
import { BlockRules } from "$/common/block_rules.ts";
|
||||
@@ -848,7 +848,7 @@ export class ModRuntime {
|
||||
// without any -0
|
||||
return { x: fx + 0, y: fy + 0, z: fz + 0 };
|
||||
},
|
||||
is_loaded: () => true,
|
||||
is_loaded: (x, z) => game().world.is_generated(Math.floor(x / CHUNK_SIZE), Math.floor(z / CHUNK_SIZE)),
|
||||
biome_at: (x, z) => game().world.biome_at(Math.floor(x), Math.floor(z)),
|
||||
season_at: (x, z) =>
|
||||
biome_season(game().world.biome_at(Math.floor(x), Math.floor(z)), game().world.time),
|
||||
|
||||
@@ -272,6 +272,13 @@ export class ServerWorld {
|
||||
return this.#chunks.has(chunk_key(chunk_x, chunk_z));
|
||||
}
|
||||
|
||||
// whether the chunk was ever generated: it's kept, or saved, so reading it generates nothing. it may not be in
|
||||
// memory, then reading it decodes it from the save
|
||||
is_generated(chunk_x: number, chunk_z: number) {
|
||||
const key = chunk_key(chunk_x, chunk_z);
|
||||
return this.#chunks.has(key) || this.#is_saved(key);
|
||||
}
|
||||
|
||||
// counts as using the chunk so it's kept longer, if it's there. returns whether it is, see has_chunk
|
||||
keep_chunk(chunk_x: number, chunk_z: number) {
|
||||
return this.#chunks.get(chunk_key(chunk_x, chunk_z)) !== undefined;
|
||||
|
||||
Reference in New Issue
Block a user