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);
+1 -1
View File
@@ -61,7 +61,7 @@ there will be holes in the world behind them.
| `mining.requires_tool` | `false` | Only drops when broken with `mining.tool`. |
| `mining.tier` | `0` | With `requires_tool`, the lowest tool tier it drops for. Iron ore is `1`, so a wood pickaxe gets nothing. |
| `drops` | nothing | The item id it drops when broken. |
| `item` | `true` | Also register an item that places it, with the same id. |
| `item` | `true` | Also register an item that places it, with the same id. To give that item more, see [Block Items](../items/index.md#block-items). |
| `interactive` | `false` | Right clicking it does something, like opening a screen, so clients don't guess that it places a block. |
| `replaceable` | `false` | Placing a block into it replaces it, like water. |
| `place_in` | see meaning | Block ids or [tags](../resources/tags.md) it can be placed into, replacing them, like `["bworld:water"]` for rice. Air and `replaceable` blocks when not set. |
+35 -14
View File
@@ -39,20 +39,20 @@ down to 0 is gone.
## Properties
| Field | Default | Meaning |
| ----------------- | ------------------- | ----------------------------------------------------------------------------- |
| `id` | required | The item's id. |
| `texture` | required | The texture it's drawn with. |
| `name` | from the id | What players see. `copper_tools:copper_ingot` is "Copper Ingot" when not set. |
| `lore` | none | Tooltip text under the name. `\n` starts a new line. |
| `max_stack` | `64`, `1` for tools | How many fit in one slot. |
| `base_sell_value` | none | What one is worth when sold, a whole number of 0 or more. |
| `places` | none | A block it places when used on a block, like seeds. |
| `tool` | none | Makes it a [tool](tools.md). |
| `food` | none | Makes it [edible](food.md). |
| `data_textures` | none | Other textures, picked by the stack's `data`, see below. |
| `worn` | none | How it looks worn on a player, see [below](#worn-models). |
| `components` | none | [Item components](#item-components) and their parameters. |
| Field | Default | Meaning |
| ----------------- | ------------------- | ------------------------------------------------------------------------------------ |
| `id` | required | The item's id. |
| `texture` | required | The texture it's drawn with. Leave it out to [fill in a block's item](#block-items). |
| `name` | from the id | What players see. `copper_tools:copper_ingot` is "Copper Ingot" when not set. |
| `lore` | none | Tooltip text under the name. `\n` starts a new line. |
| `max_stack` | `64`, `1` for tools | How many fit in one slot. |
| `base_sell_value` | none | What one is worth when sold, a whole number of 0 or more. |
| `places` | none | A block it places when used on a block, like seeds. |
| `tool` | none | Makes it a [tool](tools.md). |
| `food` | none | Makes it [edible](food.md). |
| `data_textures` | none | Other textures, picked by the stack's `data`, see below. |
| `worn` | none | How it looks worn on a player, see [below](#worn-models). |
| `components` | none | [Item components](#item-components) and their parameters. |
### Textures From Data
@@ -101,6 +101,27 @@ Things to know when making one:
- **Porting a Java mod's model**, like Artifacts' `ArmsMeshDefinitions`: Java models measure y down from the top of the
head, bedrock up from the feet. Keep x and z, and make each y `24 - y`, with a box's origin at its bottom.
### Block Items
A block's item only has the block's texture and name. To give it anything else, like `lore` or `base_sell_value`, add an
item file with the block's id and no `texture`. What it sets is added to the block's item, and the rest stays as the
block made it.
`items/copper_block.json`:
```json
{
"format_version": 1,
"item": {
"id": "copper_tools:copper_block",
"base_sell_value": 9
}
}
```
The block has to be in the same mod and can't set `"item": false`, or `check-mods` reports an error and the game won't
load the mod.
## Item Components
Like [block components](../blocks/components.md), item components give items behavior. The server script registers them:
+7
View File
@@ -0,0 +1,7 @@
{
"format_version": 1,
"item": {
"id": "bworld:acacia_leaves",
"base_sell_value": 1
}
}
+7
View File
@@ -0,0 +1,7 @@
{
"format_version": 1,
"item": {
"id": "bworld:acacia_log",
"base_sell_value": 8
}
}
+7
View File
@@ -0,0 +1,7 @@
{
"format_version": 1,
"item": {
"id": "bworld:acacia_planks",
"base_sell_value": 2
}
}
+7
View File
@@ -0,0 +1,7 @@
{
"format_version": 1,
"item": {
"id": "bworld:birch_leaves",
"base_sell_value": 1
}
}
+7
View File
@@ -0,0 +1,7 @@
{
"format_version": 1,
"item": {
"id": "bworld:birch_log",
"base_sell_value": 8
}
}
+7
View File
@@ -0,0 +1,7 @@
{
"format_version": 1,
"item": {
"id": "bworld:birch_planks",
"base_sell_value": 2
}
}
+2 -1
View File
@@ -2,6 +2,7 @@
"format_version": 1,
"item": {
"id": "bworld:bone_meal",
"texture": "bworld:bone_meal"
"texture": "bworld:bone_meal",
"base_sell_value": 4
}
}
+2 -1
View File
@@ -2,6 +2,7 @@
"format_version": 1,
"item": {
"id": "bworld:bowl",
"texture": "bworld:bowl"
"texture": "bworld:bowl",
"base_sell_value": 1
}
}
+2 -1
View File
@@ -2,6 +2,7 @@
"format_version": 1,
"item": {
"id": "bworld:brass_coin",
"texture": "bworld:brass_coin"
"texture": "bworld:brass_coin",
"base_sell_value": 64
}
}
+2 -1
View File
@@ -7,6 +7,7 @@
"nutrition": 3,
"saturation_modifier": 0.6
},
"places": "bworld:carrots"
"places": "bworld:carrots",
"base_sell_value": 12
}
}
+7
View File
@@ -0,0 +1,7 @@
{
"format_version": 1,
"item": {
"id": "bworld:cherry_leaves",
"base_sell_value": 1
}
}
+7
View File
@@ -0,0 +1,7 @@
{
"format_version": 1,
"item": {
"id": "bworld:cherry_log",
"base_sell_value": 8
}
}
+7
View File
@@ -0,0 +1,7 @@
{
"format_version": 1,
"item": {
"id": "bworld:cherry_planks",
"base_sell_value": 2
}
}
+2 -1
View File
@@ -2,6 +2,7 @@
"format_version": 1,
"item": {
"id": "bworld:coal",
"texture": "bworld:coal"
"texture": "bworld:coal",
"base_sell_value": 18
}
}
+2 -1
View File
@@ -2,6 +2,7 @@
"format_version": 1,
"item": {
"id": "bworld:cobalt_coin",
"texture": "bworld:cobalt_coin"
"texture": "bworld:cobalt_coin",
"base_sell_value": 32768
}
}
+2 -1
View File
@@ -6,6 +6,7 @@
"food": {
"nutrition": 2,
"saturation_modifier": 0.1
}
},
"base_sell_value": 30
}
}
+2 -1
View File
@@ -6,6 +6,7 @@
"food": {
"nutrition": 5,
"saturation_modifier": 0.6
}
},
"base_sell_value": 32
}
}
+2 -1
View File
@@ -6,6 +6,7 @@
"food": {
"nutrition": 6,
"saturation_modifier": 0.8
}
},
"base_sell_value": 34
}
}
+2 -1
View File
@@ -2,6 +2,7 @@
"format_version": 1,
"item": {
"id": "bworld:copper_coin",
"texture": "bworld:copper_coin"
"texture": "bworld:copper_coin",
"base_sell_value": 1
}
}
+2 -1
View File
@@ -2,6 +2,7 @@
"format_version": 1,
"item": {
"id": "bworld:copper_ingot",
"texture": "bworld:copper_ingot"
"texture": "bworld:copper_ingot",
"base_sell_value": 12
}
}
@@ -0,0 +1,7 @@
{
"format_version": 1,
"item": {
"id": "bworld:cracked_stone_bricks",
"base_sell_value": 1
}
}
+7
View File
@@ -0,0 +1,7 @@
{
"format_version": 1,
"item": {
"id": "bworld:dark_oak_leaves",
"base_sell_value": 1
}
}
+7
View File
@@ -0,0 +1,7 @@
{
"format_version": 1,
"item": {
"id": "bworld:dark_oak_log",
"base_sell_value": 8
}
}
+7
View File
@@ -0,0 +1,7 @@
{
"format_version": 1,
"item": {
"id": "bworld:dark_oak_planks",
"base_sell_value": 2
}
}
+7
View File
@@ -0,0 +1,7 @@
{
"format_version": 1,
"item": {
"id": "bworld:dirt",
"base_sell_value": 1
}
}
+7
View File
@@ -0,0 +1,7 @@
{
"format_version": 1,
"item": {
"id": "bworld:glass",
"base_sell_value": 2
}
}
+2 -1
View File
@@ -2,6 +2,7 @@
"format_version": 1,
"item": {
"id": "bworld:gold_coin",
"texture": "bworld:gold_coin"
"texture": "bworld:gold_coin",
"base_sell_value": 4096
}
}
+2 -1
View File
@@ -2,6 +2,7 @@
"format_version": 1,
"item": {
"id": "bworld:gold_ingot",
"texture": "bworld:gold_ingot"
"texture": "bworld:gold_ingot",
"base_sell_value": 120
}
}
+2 -1
View File
@@ -2,6 +2,7 @@
"format_version": 1,
"item": {
"id": "bworld:iron_coin",
"texture": "bworld:iron_coin"
"texture": "bworld:iron_coin",
"base_sell_value": 512
}
}
+2 -1
View File
@@ -2,6 +2,7 @@
"format_version": 1,
"item": {
"id": "bworld:iron_ingot",
"texture": "bworld:iron_ingot"
"texture": "bworld:iron_ingot",
"base_sell_value": 60
}
}
+7
View File
@@ -0,0 +1,7 @@
{
"format_version": 1,
"item": {
"id": "bworld:jungle_leaves",
"base_sell_value": 1
}
}
+7
View File
@@ -0,0 +1,7 @@
{
"format_version": 1,
"item": {
"id": "bworld:jungle_log",
"base_sell_value": 8
}
}
+7
View File
@@ -0,0 +1,7 @@
{
"format_version": 1,
"item": {
"id": "bworld:jungle_planks",
"base_sell_value": 2
}
}
@@ -0,0 +1,7 @@
{
"format_version": 1,
"item": {
"id": "bworld:mossy_stone_bricks",
"base_sell_value": 2
}
}
+2 -1
View File
@@ -2,6 +2,7 @@
"format_version": 1,
"item": {
"id": "bworld:nickel_coin",
"texture": "bworld:nickel_coin"
"texture": "bworld:nickel_coin",
"base_sell_value": 8
}
}
+7
View File
@@ -0,0 +1,7 @@
{
"format_version": 1,
"item": {
"id": "bworld:oak_leaves",
"base_sell_value": 1
}
}
+7
View File
@@ -0,0 +1,7 @@
{
"format_version": 1,
"item": {
"id": "bworld:oak_log",
"base_sell_value": 8
}
}
+7
View File
@@ -0,0 +1,7 @@
{
"format_version": 1,
"item": {
"id": "bworld:oak_planks",
"base_sell_value": 2
}
}
+2 -1
View File
@@ -7,6 +7,7 @@
"nutrition": 1,
"saturation_modifier": 0.3
},
"places": "bworld:potatoes"
"places": "bworld:potatoes",
"base_sell_value": 20
}
}
+2 -1
View File
@@ -6,6 +6,7 @@
"food": {
"nutrition": 2,
"saturation_modifier": 0.1
}
},
"base_sell_value": 32
}
}
+7
View File
@@ -0,0 +1,7 @@
{
"format_version": 1,
"item": {
"id": "bworld:sand",
"base_sell_value": 1
}
}
+7
View File
@@ -0,0 +1,7 @@
{
"format_version": 1,
"item": {
"id": "bworld:smooth_stone",
"base_sell_value": 2
}
}
+7
View File
@@ -0,0 +1,7 @@
{
"format_version": 1,
"item": {
"id": "bworld:spruce_leaves",
"base_sell_value": 1
}
}
+7
View File
@@ -0,0 +1,7 @@
{
"format_version": 1,
"item": {
"id": "bworld:spruce_log",
"base_sell_value": 8
}
}
+7
View File
@@ -0,0 +1,7 @@
{
"format_version": 1,
"item": {
"id": "bworld:spruce_planks",
"base_sell_value": 2
}
}
+7
View File
@@ -0,0 +1,7 @@
{
"format_version": 1,
"item": {
"id": "bworld:stone",
"base_sell_value": 1
}
}
+7
View File
@@ -0,0 +1,7 @@
{
"format_version": 1,
"item": {
"id": "bworld:stone_bricks",
"base_sell_value": 1
}
}
+2 -1
View File
@@ -2,6 +2,7 @@
"format_version": 1,
"item": {
"id": "bworld:tin_ingot",
"texture": "bworld:tin_ingot"
"texture": "bworld:tin_ingot",
"base_sell_value": 14
}
}
+2 -1
View File
@@ -2,6 +2,7 @@
"format_version": 1,
"item": {
"id": "bworld:wheat",
"texture": "bworld:wheat"
"texture": "bworld:wheat",
"base_sell_value": 7
}
}
+2 -1
View File
@@ -6,6 +6,7 @@
"food": {
"nutrition": 2,
"saturation_modifier": 0.4
}
},
"base_sell_value": 35
}
}
+2 -1
View File
@@ -6,6 +6,7 @@
"food": {
"nutrition": 1,
"saturation_modifier": 0.4
}
},
"base_sell_value": 18
}
}
+2 -1
View File
@@ -6,6 +6,7 @@
"food": {
"nutrition": 5,
"saturation_modifier": 0.5
}
},
"base_sell_value": 50
}
}
+2 -1
View File
@@ -6,6 +6,7 @@
"food": {
"nutrition": 1,
"saturation_modifier": 0.1
}
},
"base_sell_value": 15
}
}
+2 -1
View File
@@ -8,6 +8,7 @@
"nutrition": 6,
"saturation_modifier": 0.4,
"returns": "bworld:bowl"
}
},
"base_sell_value": 46
}
}
+2 -1
View File
@@ -7,6 +7,7 @@
"food": {
"nutrition": 2,
"saturation_modifier": 0.4
}
},
"base_sell_value": 16
}
}
+2 -1
View File
@@ -3,6 +3,7 @@
"item": {
"id": "farmersdelight:rice",
"texture": "farmersdelight:rice",
"places": "farmersdelight:rice"
"places": "farmersdelight:rice",
"base_sell_value": 13
}
}
+2 -1
View File
@@ -2,6 +2,7 @@
"format_version": 1,
"item": {
"id": "farmersdelight:rice_panicle",
"texture": "farmersdelight:rice_panicle"
"texture": "farmersdelight:rice_panicle",
"base_sell_value": 10
}
}
+2 -1
View File
@@ -6,6 +6,7 @@
"food": {
"nutrition": 1,
"saturation_modifier": 0.1
}
},
"base_sell_value": 16
}
}
+2 -1
View File
@@ -6,6 +6,7 @@
"food": {
"nutrition": 1,
"saturation_modifier": 0.3
}
},
"base_sell_value": 15
}
}
+2 -1
View File
@@ -7,6 +7,7 @@
"nutrition": 4,
"saturation_modifier": 0.4,
"returns": "bworld:bowl"
}
},
"base_sell_value": 33
}
}
+17
View File
@@ -45,10 +45,27 @@ Deno.test("mods/bworld json survives going to the registry and back", async () =
}
for (const file of Deno.readDirSync("mods/bworld/items")) {
const { item: json } = JSON.parse(Deno.readTextFileSync(`mods/bworld/items/${file.name}`));
// one without a texture fills in a block's item instead, see the test below
if (json.texture === undefined) continue;
assertEquals(item_to_json(json.id, item_from_json(json)), json, file.name);
}
});
Deno.test("an item file without a texture fills in the item of the block with its id", async () => {
const dir = mods_with_template();
Deno.writeTextFileSync(
`${dir}/copper_tools/items/example_block.json`,
JSON.stringify({ format_version: 1, item: { id: "copper_tools:example_block", base_sell_value: 3 } }),
);
await test_game(dir);
const item = EverythingRegistry.get<ItemRegistry>("items", "copper_tools:example_block")!;
assertEquals(item.base_sell_value, 3);
// and keeps what the block gave it
assertEquals(item.block_id, "copper_tools:example_block");
assertEquals(item.texture_id, "copper_tools:example_block");
Deno.removeSync(dir, { recursive: true });
});
Deno.test("a mod made from the template loads and runs", async () => {
const dir = mods_with_template();
const { game, take, send } = await test_game(dir);
+17
View File
@@ -181,3 +181,20 @@ Deno.test("an item can say how it looks worn, with a model for slim arms too", a
assertEquals(item_to_json("gloves:glove", item_from_json(glove)).worn, worn);
Deno.removeSync(dir, { recursive: true });
});
Deno.test("an item without a texture must be the item of one of the mod's blocks", async () => {
const dir = temp_mods_dir();
create_mod("coins", "Coins", dir);
const mod = `${dir}/coins`;
write_json(`${mod}/items/example_block.json`, {
format_version: 1,
item: { id: "coins:example_block", base_sell_value: 3 },
});
write_json(`${mod}/items/nothing.json`, { format_version: 1, item: { id: "coins:nothing", base_sell_value: 3 } });
const report = (await check_mods(dir)).find((r) => r.id === "coins")!;
assertEquals(report.errors, [
"items/nothing.json: item coins:nothing has no texture, and no block of this mod gives it an item",
]);
Deno.removeSync(dir, { recursive: true });
});