Seasons api

This commit is contained in:
2026-10-08 13:42:18 -03:00
parent 7e7ac8f6f4
commit dd66d6caa7
16 changed files with 231 additions and 10 deletions
+23
View File
@@ -60,6 +60,7 @@ import type { EffectJson } from "$/common/mod_data.ts";
import { create_entity } from "./entity/entity_types.ts";
import { attribute_type, type AttributeType, MODIFIER_OPERATIONS } from "./entity/attributes.ts";
import { effect_type, EffectInstance, type EffectType } from "./entity/effects.ts";
import { biome_season } from "$/common/worldgen/biomes.ts";
// a list of handlers that can't break each other: one throwing is logged under its mod and the rest still run
export class Signal<T> {
@@ -249,6 +250,8 @@ export class ModRuntime {
get_state: world.get_state,
set_state: world.set_state,
is_face_sturdy: world.is_face_sturdy,
biome_at: world.biome_at,
season_at: world.season_at,
},
components: {
register_block: (id, rules) => {
@@ -502,6 +505,12 @@ export class ModRuntime {
x,
y,
z,
get biome() {
return game.world.biome_at(x, z);
},
get season() {
return biome_season(game.world.biome_at(x, z));
},
get data() {
return game.world.get_tile(x, y, z)?.mod_data;
},
@@ -703,6 +712,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))),
get seed() {
return game().world.seed;
},
@@ -1185,6 +1196,12 @@ function player_api(game: GameServer, player: ServerPlayer): Player {
z: -Math.cos(player.yaw) * cos_pitch,
};
},
get biome() {
return game.world.biome_at(Math.floor(player.x), Math.floor(player.z));
},
get season() {
return biome_season(this.biome);
},
inventory,
get selected_slot() {
return player.selected_slot;
@@ -1312,6 +1329,12 @@ export function entity_ref(entity: Entity): EntityRef {
get position() {
return { x: entity.x, y: entity.y, z: entity.z };
},
get biome() {
return entity.level.biome_at(Math.floor(entity.x), Math.floor(entity.z));
},
get season() {
return biome_season(this.biome);
},
get removed() {
return entity.removed;
},