Seasons based on a calendar

This commit is contained in:
2026-10-09 22:09:21 -03:00
parent 4d5700f0bf
commit 7fe9c15b67
12 changed files with 88 additions and 33 deletions
+3
View File
@@ -8,6 +8,7 @@ import { TICKS_PER_SECOND } from "$/common/constants.ts";
import type { BlockRegistry } from "$/common/everything_registry.ts";
import type { ItemStack } from "$/common/inventory.ts";
import type { Shape } from "$/common/block_shapes.ts";
import type { Season } from "$/common/worldgen/biomes.ts";
import { type Collisions, type LiquidInCell, physics } from "$/common/physics.ts";
import type { EntityData, EntityEvent, EntityInfo } from "$/common/protocol.ts";
import type { ServerPlayer } from "../player.ts";
@@ -72,6 +73,8 @@ export interface EntityLevel {
get_block_info(x: number, y: number, z: number): BlockRegistry | undefined;
// the column's biome, like "bworld:plains"
biome_at(x: number, z: number): string;
// that biome's season now, see biome_season in common/worldgen/biomes.ts
season_at(x: number, z: number): Season;
add_entity(entity: Entity): void;
get_entity(id: string): Entity | undefined;
// entities whose feet are within the box around x, y, z
+5
View File
@@ -4,6 +4,7 @@
import { CHUNK_SIZE } from "$/common/constants.ts";
import { is_within_view } from "$/common/chunk_streaming.ts";
import { liquid_block, liquid_in_cell } from "$/common/utils.ts";
import { biome_season } from "$/common/worldgen/biomes.ts";
import type { ItemStack } from "$/common/inventory.ts";
import type { EntityEvent, EntityInfo, ServerMessage } from "$/common/protocol.ts";
import type { ServerPlayer } from "../player.ts";
@@ -108,6 +109,10 @@ export class EntityManager implements EntityLevel {
return this.#host.world.biome_at(x, z);
}
season_at(x: number, z: number) {
return biome_season(this.biome_at(x, z), this.#host.world.time);
}
liquid_at(x: number, y: number, z: number) {
const world = this.#host.world;
return liquid_in_cell(world.get_block_value(x, y, z), world.get_block_info(x, y, z));
+5 -4
View File
@@ -510,7 +510,7 @@ export class ModRuntime {
return game.world.biome_at(x, z);
},
get season() {
return biome_season(game.world.biome_at(x, z));
return biome_season(game.world.biome_at(x, z), game.world.time);
},
get data() {
return game.world.get_tile(x, y, z)?.mod_data;
@@ -714,7 +714,8 @@ export class ModRuntime {
},
is_loaded: () => true,
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))),
season_at: (x, z) =>
biome_season(game().world.biome_at(Math.floor(x), Math.floor(z)), game().world.time),
get seed() {
return game().world.seed;
},
@@ -1205,7 +1206,7 @@ function player_api(game: GameServer, player: ServerPlayer): Player {
return game.world.biome_at(Math.floor(player.x), Math.floor(player.z));
},
get season() {
return biome_season(this.biome);
return biome_season(this.biome, game.world.time);
},
inventory,
get selected_slot() {
@@ -1338,7 +1339,7 @@ export function entity_ref(entity: Entity): EntityRef {
return entity.level.biome_at(Math.floor(entity.x), Math.floor(entity.z));
},
get season() {
return biome_season(this.biome);
return entity.level.season_at(Math.floor(entity.x), Math.floor(entity.z));
},
get removed() {
return entity.removed;
+3 -3
View File
@@ -10,7 +10,7 @@ import { AIR_ID, BlockChange } from "$/common/protocol.ts";
import { block_value, chunk_key, default_block_value } from "$/common/utils.ts";
import { LruMap } from "./lru.ts";
import { collision_shape_at, EMPTY_SHAPE, type Shape } from "$/common/block_shapes.ts";
import { CYCLE_TICKS } from "$/common/time.ts";
import { farming_day } from "$/common/time.ts";
import { encode_level_chunk } from "$/common/chunk_streaming.ts";
import type { ItemData } from "$/common/inventory.ts";
import { CHUNK_VOLUME, ChunkBlocks, decode_chunk, encode_chunk, is_changed, SavedChunk } from "./saves.ts";
@@ -74,9 +74,9 @@ export class ServerWorld {
// ticks since 06:00 of day 1, see common/time.ts
time = 0;
// days since the world started, going up at 06:00. the farming day, unlike the clock's day that starts at midnight
// days since the world started, see farming_day in common/time.ts
get day() {
return Math.floor(this.time / CYCLE_TICKS);
return farming_day(this.time);
}
// set when anything that gets saved changes