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),