diff --git a/common/mod_api/shared.ts b/common/mod_api/shared.ts index ea9f4dd..3f846f4 100644 --- a/common/mod_api/shared.ts +++ b/common/mod_api/shared.ts @@ -14,7 +14,7 @@ export interface ItemStack { } // the registries tags are for, see docs/modding/resources/tags.md -export type TagRegistry = "blocks" | "items" | "entities"; +export type TagRegistry = "blocks" | "items" | "entities" | "biomes"; // every mod's tags, the same on the server and every client. tags can be written with or without their # export interface TagApi { diff --git a/common/mod_check.ts b/common/mod_check.ts index 5eab6ab..106fb23 100644 --- a/common/mod_check.ts +++ b/common/mod_check.ts @@ -451,6 +451,7 @@ export function check_references(mods: LoadedMod[], engine_textures: Iterable mod.tags.map(({ file, json }) => ({ mod: mod.id, file, json }))), diff --git a/common/mod_data.ts b/common/mod_data.ts index 9fa6930..0525d92 100644 --- a/common/mod_data.ts +++ b/common/mod_data.ts @@ -28,7 +28,7 @@ export const RESERVED_NAMESPACES = ["bworld", "engine"]; export const TAG_ID_PATTERN = /^[a-z0-9_]+:[a-z0-9_]+(\/[a-z0-9_]+)*$/; // the namespace for tags every mod shares, like neoforge's. no mod owns it export const SHARED_TAG_NAMESPACE = "c"; -export const TAG_REGISTRIES = ["blocks", "items", "entities"] as const; +export const TAG_REGISTRIES = ["blocks", "items", "entities", "biomes"] as const; export type TagRegistry = typeof TAG_REGISTRIES[number]; type BlockTextures = BlockRegistry["textures"]; diff --git a/common/mod_loader.ts b/common/mod_loader.ts index 85236eb..d50475a 100644 --- a/common/mod_loader.ts +++ b/common/mod_loader.ts @@ -92,7 +92,7 @@ export class ModLoadError extends Error { } } -// whether a block, item or entity is registered, for tags. air isn't a registered block, but tags can hold it +// whether a block, item, entity or biome is registered, for tags. air isn't a registered block, but tags can hold it export function is_registered(registry: TagRegistry, id: string): boolean { return (registry === "blocks" && id === "bworld:air") || EverythingRegistry.get(registry, id) !== undefined; } diff --git a/common/tags.ts b/common/tags.ts index fee7033..3dbcf13 100644 --- a/common/tags.ts +++ b/common/tags.ts @@ -1,6 +1,6 @@ -// tags: named lists of blocks, items or entities that mods add to, like neoforge's. see docs/modding/resources/tags.md. +// tags: named lists of blocks, items, entities or biomes that mods add to, like neoforge's. see docs/modding/resources/tags.md. // resolve_tags works them out from every mod's tag files, the same way on the server, clients and in check-mods -import type { TagEntryJson, TagJson, TagRegistry } from "./mod_data.ts"; +import { TAG_REGISTRIES, type TagEntryJson, type TagJson, type TagRegistry } from "./mod_data.ts"; import type { TagApi } from "./mod_api/shared.ts"; export interface TagSource { @@ -38,7 +38,7 @@ function parse_entry(json: TagEntryJson, remove: boolean, source: TagSource): En // merges the tag files, sources in load order, and resolves the tags inside tags. like neoforge, a later file with // replace drops the entries before it, and values and removes apply in order, so a later mod can add back what an // earlier one removed. a tag with a required entry that doesn't exist, or that contains itself, doesn't load and is a -// problem. exists says whether a block, item or entity is registered +// problem. exists says whether a block, item, entity or biome is registered export function resolve_tags( sources: TagSource[], exists: (registry: TagRegistry, id: string) => boolean, @@ -181,10 +181,12 @@ export function expand_items(list: readonly string[]): string[] { // ctx.tags for server and client scripts. everything it returns is a copy export function tag_api(): TagApi { const registry = (name: string): TagRegistry => { - if (name !== "blocks" && name !== "items" && name !== "entities") { - throw new Error(`tags are for "blocks", "items" or "entities", not ${JSON.stringify(name)}`); + if (!TAG_REGISTRIES.includes(name as TagRegistry)) { + throw new Error( + `tags are for ${TAG_REGISTRIES.map((r) => `"${r}"`).join(", ")}, not ${JSON.stringify(name)}`, + ); } - return name; + return name as TagRegistry; }; return { exists: (reg, tag) => Tags.exists(registry(reg), tag), diff --git a/docs/modding/resources/tags.md b/docs/modding/resources/tags.md index cc5171e..d754502 100644 --- a/docs/modding/resources/tags.md +++ b/docs/modding/resources/tags.md @@ -1,7 +1,7 @@ # Tags -A tag is a named list of blocks, items or entities, like every kind of planks. Recipes and blocks can use a tag anywhere -they take an id, and any mod can add to any tag, so a mod's planks can make sticks just by adding them to +A tag is a named list of blocks, items, entities or biomes, like every kind of planks. Recipes and blocks can use a tag +anywhere they take an id, and any mod can add to any tag, so a mod's planks can make sticks just by adding them to `#bworld:planks`. Tags work like [NeoForge's](https://docs.neoforged.net/docs/resources/server/tags). A tag's id starts with `#` where it's used, so `#bworld:planks` is the tag of every kind of planks, and @@ -20,8 +20,8 @@ tags/ my_mod/soft.json # the block tag #my_mod:soft ``` -`` is `blocks`, `items` or `entities`. A block tag and an item tag with the same id are two different tags, so -a block that should be in both, like planks, needs a file for each. +`` is `blocks`, `items`, `entities` or `biomes`. A block tag and an item tag with the same id are two +different tags, so a block that should be in both, like planks, needs a file for each. ```json { diff --git a/docs/modding/worldgen/biomes.md b/docs/modding/worldgen/biomes.md index d29fd30..9810f17 100644 --- a/docs/modding/worldgen/biomes.md +++ b/docs/modding/worldgen/biomes.md @@ -71,6 +71,20 @@ Biome ids are what features' `biome_at` gives and what spawns list. The base gam `/locatebiome ` finds the nearest one. +## Biome Tags + +Biomes have [tags](../resources/tags.md) too, in `tags/biomes/`. The base game's are like Minecraft's: + +| Tag | Biomes | +| --------------------- | ----------------------------------------------------------------------------------------------- | +| `#bworld:is_ocean` | `ocean`, `deep_ocean`, `frozen_ocean`, `deep_frozen_ocean`, `warm_ocean`, `deep_lukewarm_ocean` | +| `#bworld:is_river` | `river`, `frozen_river` | +| `#bworld:is_mountain` | `meadow`, `frozen_peaks`, `jagged_peaks`, `stony_peaks`, `snowy_slopes` | +| `#bworld:is_forest` | `forest`, `dark_forest` | + +A mod's biome joins one by adding itself to the tag's file, like `tags/biomes/bworld/is_forest.json`, and a script +checks a biome with `ctx.tags.has("biomes", "bworld:is_forest", ctx.world.biome_at(x, z))`. + ## Seasons Seasons follow the calendar, 49 days each: days 1 to 49 are spring, 50 to 98 summer, 99 to 147 autumn and 148 to 196 diff --git a/mods/bworld/tags/biomes/bworld/is_forest.json b/mods/bworld/tags/biomes/bworld/is_forest.json new file mode 100644 index 0000000..bbf5c77 --- /dev/null +++ b/mods/bworld/tags/biomes/bworld/is_forest.json @@ -0,0 +1,9 @@ +{ + "format_version": 1, + "tag": { + "values": [ + "bworld:forest", + "bworld:dark_forest" + ] + } +} diff --git a/mods/bworld/tags/biomes/bworld/is_mountain.json b/mods/bworld/tags/biomes/bworld/is_mountain.json new file mode 100644 index 0000000..b6ae468 --- /dev/null +++ b/mods/bworld/tags/biomes/bworld/is_mountain.json @@ -0,0 +1,12 @@ +{ + "format_version": 1, + "tag": { + "values": [ + "bworld:meadow", + "bworld:frozen_peaks", + "bworld:jagged_peaks", + "bworld:stony_peaks", + "bworld:snowy_slopes" + ] + } +} diff --git a/mods/bworld/tags/biomes/bworld/is_ocean.json b/mods/bworld/tags/biomes/bworld/is_ocean.json new file mode 100644 index 0000000..8dadd37 --- /dev/null +++ b/mods/bworld/tags/biomes/bworld/is_ocean.json @@ -0,0 +1,13 @@ +{ + "format_version": 1, + "tag": { + "values": [ + "bworld:ocean", + "bworld:deep_ocean", + "bworld:frozen_ocean", + "bworld:deep_frozen_ocean", + "bworld:warm_ocean", + "bworld:deep_lukewarm_ocean" + ] + } +} diff --git a/mods/bworld/tags/biomes/bworld/is_river.json b/mods/bworld/tags/biomes/bworld/is_river.json new file mode 100644 index 0000000..5b316c4 --- /dev/null +++ b/mods/bworld/tags/biomes/bworld/is_river.json @@ -0,0 +1,9 @@ +{ + "format_version": 1, + "tag": { + "values": [ + "bworld:river", + "bworld:frozen_river" + ] + } +} diff --git a/tests/tags_test.ts b/tests/tags_test.ts index aa929a1..2a99d9d 100644 --- a/tests/tags_test.ts +++ b/tests/tags_test.ts @@ -1,4 +1,4 @@ -// tags: lists of blocks, items or entities that every mod can add to, see docs/modding/resources/tags.md +// tags: lists of blocks, items, entities or biomes that every mod can add to, see docs/modding/resources/tags.md import { assert, assertEquals, assertThrows } from "@std/assert"; import { Container, ItemStack } from "$/common/inventory.ts"; import { CRAFTING_RESULT_SLOT } from "$/common/protocol.ts"; @@ -86,6 +86,11 @@ Deno.test("the base game's tags, from scripts", async () => { assert(tags.has("items", "#bworld:logs", "bworld:cherry_log")); assert(tags.has("blocks", "bworld:leaves", "bworld:birch_leaves")); assert(!tags.has("items", "bworld:planks", "bworld:stone")); + assertEquals(tags.get("biomes", "bworld:is_river"), ["bworld:river", "bworld:frozen_river"]); + assert(tags.has("biomes", "#bworld:is_ocean", "bworld:deep_frozen_ocean")); + assert(tags.has("biomes", "bworld:is_mountain", "bworld:jagged_peaks")); + assert(tags.has("biomes", "bworld:is_forest", "bworld:dark_forest")); + assert(!tags.has("biomes", "bworld:is_forest", "bworld:plains")); assertEquals(tags.get("items", "c:ingots"), [ "bworld:copper_ingot", "bworld:tin_ingot",