Seasons api
This commit is contained in:
@@ -70,6 +70,8 @@ export interface EntityLevel {
|
||||
// the liquid there and how high it is, for liquids pushing things along
|
||||
liquid_at(x: number, y: number, z: number): LiquidInCell | undefined;
|
||||
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;
|
||||
add_entity(entity: Entity): void;
|
||||
get_entity(id: string): Entity | undefined;
|
||||
// entities whose feet are within the box around x, y, z
|
||||
|
||||
@@ -104,6 +104,10 @@ export class EntityManager implements EntityLevel {
|
||||
return this.#host.world.get_block_info(x, y, z);
|
||||
}
|
||||
|
||||
biome_at(x: number, z: number) {
|
||||
return this.#host.world.biome_at(x, z);
|
||||
}
|
||||
|
||||
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));
|
||||
|
||||
@@ -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;
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user