Seasons api
This commit is contained in:
@@ -52,6 +52,8 @@ export interface Chunk {
|
||||
max_y: number;
|
||||
// only for translucent meshes that have to be sorted again as the camera moves
|
||||
translucent_sort?: TranslucentSort;
|
||||
// each column's biome id, x then z
|
||||
biomes: string[];
|
||||
// each column's biome grass color, x then z, then each column's foliage color, then water color
|
||||
biome_colors: Uint32Array;
|
||||
// from its last mesh, see get_light. undefined until it's been meshed
|
||||
@@ -189,6 +191,7 @@ export class ClientLevel {
|
||||
if (chunk) {
|
||||
// its old mesh stays up until the new one is ready
|
||||
chunk.blocks = blocks;
|
||||
chunk.biomes = biomes;
|
||||
chunk.biome_colors = biome_colors;
|
||||
this.#mark_dirty(chunk);
|
||||
} else {
|
||||
@@ -196,6 +199,7 @@ export class ClientLevel {
|
||||
x,
|
||||
z,
|
||||
blocks,
|
||||
biomes,
|
||||
biome_colors,
|
||||
dirty: true,
|
||||
mesh_version: 0,
|
||||
@@ -330,6 +334,14 @@ export class ClientLevel {
|
||||
return block ? collision_shape_at(block, value) : true;
|
||||
}
|
||||
|
||||
// the column's biome, undefined in unloaded chunks
|
||||
biome_at(x: number, z: number): string | undefined {
|
||||
const chunk_x = Math.floor(x / CHUNK_SIZE);
|
||||
const chunk_z = Math.floor(z / CHUNK_SIZE);
|
||||
return this.get_chunk(chunk_x, chunk_z)
|
||||
?.biomes[(z - chunk_z * CHUNK_SIZE) * CHUNK_SIZE + (x - chunk_x * CHUNK_SIZE)];
|
||||
}
|
||||
|
||||
// the biome's water color at a column as 0xRRGGBB, see "tint". plains' in unloaded chunks
|
||||
water_color(x: number, z: number) {
|
||||
const chunk_x = Math.floor(x / CHUNK_SIZE);
|
||||
|
||||
@@ -17,6 +17,7 @@ import { GuiModScreen } from "./gui/gui_mod_screens.ts";
|
||||
import { clear_hooks, expose_engine, loading_mod } from "$/common/hooks.ts";
|
||||
import { common_engine } from "$/common/engine_modules.ts";
|
||||
import { client_engine } from "./engine_modules.ts";
|
||||
import { biome_season } from "$/common/worldgen/biomes.ts";
|
||||
|
||||
// each loaded mod's credits file, for the credits screen
|
||||
export const mod_credits: { name: string; version: string; text: string }[] = [];
|
||||
@@ -89,6 +90,11 @@ const rules_world: SharedWorld = {
|
||||
const shape = client?.level.collision_shape(x, y, z) ?? false;
|
||||
return covers_face(shape === true ? FULL_SHAPE : shape === false ? EMPTY_SHAPE : shape, face);
|
||||
},
|
||||
biome_at: (x, z) => client?.level.biome_at(Math.floor(x), Math.floor(z)),
|
||||
season_at(x, z) {
|
||||
const biome = this.biome_at(x, z);
|
||||
return biome === undefined ? undefined : biome_season(biome);
|
||||
},
|
||||
};
|
||||
|
||||
// this client changed the block at x y z ahead of the server, the blocks beside it change with it the way they will
|
||||
@@ -267,6 +273,14 @@ function client_context(listing: ModListing): ClientContext {
|
||||
const { x, y, z } = need_client().player;
|
||||
return { x, y, z };
|
||||
},
|
||||
get biome() {
|
||||
const { x, z } = need_client().player;
|
||||
return rules_world.biome_at(x, z);
|
||||
},
|
||||
get season() {
|
||||
const { x, z } = need_client().player;
|
||||
return rules_world.season_at(x, z);
|
||||
},
|
||||
is_swimming: () => need_client().player.swimming,
|
||||
},
|
||||
world: {
|
||||
@@ -275,6 +289,8 @@ function client_context(listing: ModListing): ClientContext {
|
||||
if (nid === AIR) return AIR_ID;
|
||||
return EverythingRegistry.get_by_id<BlockRegistry>("blocks", nid)?.id;
|
||||
},
|
||||
biome_at: (x, z) => rules_world.biome_at(x, z),
|
||||
season_at: (x, z) => rules_world.season_at(x, z),
|
||||
get time() {
|
||||
return need_client().level.time;
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user