Implement tags !

This commit is contained in:
2026-09-30 13:41:29 -03:00
parent dc70ada7c4
commit 342b45d593
51 changed files with 978 additions and 219 deletions
+4 -2
View File
@@ -1,7 +1,7 @@
// what client scripts get, see docs/modding/gui/index.md
import type { Id, ItemStack, KeyCode, ModInfo, Position } from "./shared.ts";
import type { Id, ItemStack, KeyCode, ModInfo, Position, TagApi } from "./shared.ts";
export type { Id, ItemStack, KeyCode, ModInfo, Position } from "./shared.ts";
export type { Id, ItemStack, KeyCode, ModInfo, Position, TagApi, TagRegistry } from "./shared.ts";
export interface ClientContext {
mod: ModInfo;
@@ -30,6 +30,8 @@ export interface ClientContext {
// deno-lint-ignore no-explicit-any
list(type?: Id): any[];
};
// every mod's block, item and entity tags
tags: TagApi;
log(...args: unknown[]): void;
}
+3 -2
View File
@@ -1,10 +1,10 @@
// what server scripts get, see docs/modding/
import type { EventSignal, Face, Id, ItemStack, ModInfo, Position } from "./shared.ts";
import type { EventSignal, Face, Id, ItemStack, ModInfo, Position, TagApi } from "./shared.ts";
import type { ArgumentType, CommandNode } from "../commands.ts";
export type { ArgumentType, CommandContext, CommandNode, Suggestion } from "../commands.ts";
export type { EventSignal, Face, Id, ItemStack, ModInfo, Position } from "./shared.ts";
export type { EventSignal, Face, Id, ItemStack, ModInfo, Position, TagApi, TagRegistry } from "./shared.ts";
export interface ServerContext {
mod: ModInfo;
@@ -17,6 +17,7 @@ export interface ServerContext {
containers: ContainerApi;
items: ItemApi;
recipes: RecipeApi;
tags: TagApi;
ui: ServerUi;
net: ServerNet;
storage: ModStorage;
+17
View File
@@ -10,6 +10,23 @@ export interface ItemStack {
data?: unknown;
}
// the registries tags are for, see docs/modding/resources/tags.md
export type TagRegistry = "blocks" | "items" | "entities";
// every mod's tags, the same on the server and every client. tags can be written with or without their #
export interface TagApi {
// whether any mod defines the tag and it loaded
exists(registry: TagRegistry, tag: Id): boolean;
// whether id is in the tag, like has("items", "bworld:planks", "bworld:birch_planks"). false for a tag nobody defines
has(registry: TagRegistry, tag: Id, id: Id): boolean;
// every id in the tag, including its tags' ids, in the order they were added. empty for a tag nobody defines
get(registry: TagRegistry, tag: Id): Id[];
// every tag id is in
of(registry: TagRegistry, id: Id): Id[];
// the items a recipe's item choice stands for, once each: an item id or "#tag", or a list of those
expand(choice: Id | Id[]): Id[];
}
export interface ModInfo {
readonly id: string;
readonly version: string;