Tooltip api

This commit is contained in:
2026-11-05 23:06:37 -03:00
parent 9bc8fd992a
commit 34f001285d
15 changed files with 264 additions and 81 deletions
+6 -4
View File
@@ -5,7 +5,8 @@ import { ID_MASK, STATE_SHIFT } from "./constants.ts";
import { BlockRegistry, EverythingRegistry, fluid_height, ItemRegistry } from "./everything_registry.ts";
import { block_item_texture, cube_face_texture } from "./block_models.ts";
import { FULL_SHAPE, type Shape } from "./block_shapes.ts";
import type { ItemStack } from "./inventory.ts";
import type { FluidRules } from "./fluids.ts";
import { type ItemStack, sell_value } from "./inventory.ts";
import type { SharedContext } from "./mod_api/shared.ts";
import type { FluidInCell } from "./physics.ts";
import { list_matches } from "./tags.ts";
@@ -87,8 +88,9 @@ export function display_name(item_id: string): string {
return EverythingRegistry.get<ItemRegistry>("items", item_id)?.name || name_from_id(item_id);
}
// ctx.items for shared scripts, and the part of the client's that's the same
export function shared_items_api(mod: string): SharedContext["items"] {
// ctx.items for shared scripts, and the part of the client's that's the same. fluids are this side's rules, which
// price full fluid containers
export function shared_items_api(mod: string, fluids: FluidRules): SharedContext["items"] {
const known = (id: string) => {
const item = EverythingRegistry.get<ItemRegistry>("items", id);
if (!item) throw new Error(`[${mod}] unknown item ${id}`);
@@ -99,7 +101,7 @@ export function shared_items_api(mod: string): SharedContext["items"] {
exists: (id) => EverythingRegistry.get("items", id) !== undefined,
name: (id) => (known(id), display_name(id)),
components: (id) => structuredClone(known(id).components ?? {}),
sell_value: (id) => known(id).base_sell_value,
sell_value: (id, data) => (known(id), sell_value(id, data, fluids)),
};
}