Add sell value for every block and item in the game, crazy

This commit is contained in:
2026-10-04 01:09:31 -03:00
parent 67c84e3504
commit 6a6abae0d5
67 changed files with 365 additions and 52 deletions
+6 -2
View File
@@ -92,7 +92,8 @@ export function check_references(mods: LoadedMod[], engine_textures: Iterable<st
add(block_owners, json.id, mod.id);
if (json.item !== false) add(item_owners, json.id, mod.id);
}
for (const { json } of mod.items) add(item_owners, json.id, mod.id);
// one without a texture is the item of the mod's block, which is already counted
for (const { json } of mod.items) if (json.texture !== undefined) add(item_owners, json.id, mod.id);
for (const { json } of mod.models) add(model_owners, json.id, mod.id);
for (const { json } of mod.entities) {
add(entity_owners, json.id, mod.id);
@@ -182,7 +183,10 @@ export function check_references(mods: LoadedMod[], engine_textures: Iterable<st
if ((item_owners.get(json.id)?.length ?? 0) > 1) {
errors.push(`${file}: item ${json.id} is also defined by ${item_owners.get(json.id)!.join(", ")}`);
}
uses(file, json.texture, "texture");
if (json.texture !== undefined) uses(file, json.texture, "texture");
else if (!mod.blocks.some((block) => block.json.id === json.id && block.json.item !== false)) {
errors.push(`${file}: item ${json.id} has no texture, and no block of this mod gives it an item`);
}
for (const texture of Object.values(json.data_textures ?? {})) uses(file, texture, "texture");
if (json.places) uses(file, json.places, "block");
if (json.food?.returns) uses(file, json.food.returns, "item");
+15 -3
View File
@@ -98,7 +98,8 @@ export interface SpawnJson {
export interface ItemJson {
id: string;
texture: string;
// without one it isn't a new item, it fills in the item of the mod's block with this id, see add_to_block_item
texture?: string;
// data key -> texture, see ItemRegistry.data_textures
data_textures?: Record<string, string>;
// tier and speed default to 0 and 2
@@ -352,7 +353,18 @@ export function item_to_json(id: string, item: ItemRegistry): ItemJson {
}
export function item_from_json(json: ItemJson): ItemRegistry {
const item: ItemRegistry = { texture_id: json.texture };
if (json.texture === undefined) throw new Error(`${json.id} has no texture and isn't a block's item`);
return { texture_id: json.texture, ...item_fields(json) };
}
// an item json without a texture: what it sets replaces what the block's item has, the rest stays
export function add_to_block_item(json: ItemJson, item: ItemRegistry) {
Object.assign(item, item_fields(json));
}
// everything but the texture
function item_fields(json: ItemJson): Partial<ItemRegistry> {
const item: Partial<ItemRegistry> = {};
if (json.data_textures !== undefined) item.data_textures = json.data_textures;
if (json.tool !== undefined) item.tool = { tier: 0, speed: 2, ...json.tool };
if (json.places !== undefined) item.block_id = json.places;
@@ -700,7 +712,7 @@ function is_whole(value: unknown): value is number {
export function validate_item(json: unknown): Problems {
if (!is_object(json)) return ["item must be an object"];
const problems = validate_id(json.id, "id");
problems.push(...validate_id(json.texture, "texture"));
if (json.texture !== undefined) problems.push(...validate_id(json.texture, "texture"));
if (json.data_textures !== undefined) {
if (!is_object(json.data_textures)) problems.push("data_textures must be { data key: texture id }");
else {
+9 -1
View File
@@ -1,6 +1,7 @@
// registers mods' data, the same way on the server and on clients
import { BlockRegistry, EverythingRegistry, ItemRegistry } from "./everything_registry.ts";
import {
add_to_block_item,
block_from_json,
BlockJson,
choice_ids,
@@ -96,7 +97,14 @@ export function register_mod_data(mods: { id: string; data: ModData }[]): Recipe
}
}
for (const json of data.items) {
EverythingRegistry.register<ItemRegistry>("items", json.id, item_from_json(json));
if (json.texture !== undefined) {
EverythingRegistry.register<ItemRegistry>("items", json.id, item_from_json(json));
continue;
}
const block_item = EverythingRegistry.get<BlockRegistry>("blocks", json.id) &&
EverythingRegistry.get<ItemRegistry>("items", json.id);
if (!block_item) throw new Error(`item ${json.id} has no texture and isn't a block's item`);
add_to_block_item(json, block_item);
}
for (const model of data.entity_models) {
EverythingRegistry.register<EntityModelJson>("entity_models", model.id, model);