Biome tags

This commit is contained in:
2026-10-11 12:13:07 -03:00
parent 1623b91ddf
commit fa969e0a96
12 changed files with 79 additions and 14 deletions
+1 -1
View File
@@ -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 {
+1
View File
@@ -451,6 +451,7 @@ export function check_references(mods: LoadedMod[], engine_textures: Iterable<st
blocks: block_owners,
items: item_owners,
entities: entity_owners,
biomes: biome_owners,
};
const { problems } = resolve_tags(
ordered.flatMap((mod) => mod.tags.map(({ file, json }) => ({ mod: mod.id, file, json }))),
+1 -1
View File
@@ -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"];
+1 -1
View File
@@ -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;
}
+8 -6
View File
@@ -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),
+4 -4
View File
@@ -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
```
`<registry>` 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.
`<registry>` 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
{
+14
View File
@@ -71,6 +71,20 @@ Biome ids are what features' `biome_at` gives and what spawns list. The base gam
`/locatebiome <id>` 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
@@ -0,0 +1,9 @@
{
"format_version": 1,
"tag": {
"values": [
"bworld:forest",
"bworld:dark_forest"
]
}
}
@@ -0,0 +1,12 @@
{
"format_version": 1,
"tag": {
"values": [
"bworld:meadow",
"bworld:frozen_peaks",
"bworld:jagged_peaks",
"bworld:stony_peaks",
"bworld:snowy_slopes"
]
}
}
@@ -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"
]
}
}
@@ -0,0 +1,9 @@
{
"format_version": 1,
"tag": {
"values": [
"bworld:river",
"bworld:frozen_river"
]
}
}
+6 -1
View File
@@ -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",