diff --git a/common/mod_check.ts b/common/mod_check.ts index 116b82c..677e7af 100644 --- a/common/mod_check.ts +++ b/common/mod_check.ts @@ -92,7 +92,8 @@ export function check_references(mods: LoadedMod[], engine_textures: Iterable 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"); diff --git a/common/mod_data.ts b/common/mod_data.ts index 2ef4e73..a649c96 100644 --- a/common/mod_data.ts +++ b/common/mod_data.ts @@ -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; // 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 { + const item: Partial = {}; 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 { diff --git a/common/mod_loader.ts b/common/mod_loader.ts index 74fac74..da564c1 100644 --- a/common/mod_loader.ts +++ b/common/mod_loader.ts @@ -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("items", json.id, item_from_json(json)); + if (json.texture !== undefined) { + EverythingRegistry.register("items", json.id, item_from_json(json)); + continue; + } + const block_item = EverythingRegistry.get("blocks", json.id) && + EverythingRegistry.get("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("entity_models", model.id, model); diff --git a/docs/modding/blocks/index.md b/docs/modding/blocks/index.md index 3bf893a..32215ca 100644 --- a/docs/modding/blocks/index.md +++ b/docs/modding/blocks/index.md @@ -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. | diff --git a/docs/modding/items/index.md b/docs/modding/items/index.md index 35395de..86bd27f 100644 --- a/docs/modding/items/index.md +++ b/docs/modding/items/index.md @@ -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: diff --git a/mods/bworld/items/acacia_leaves.json b/mods/bworld/items/acacia_leaves.json new file mode 100644 index 0000000..8ef0a56 --- /dev/null +++ b/mods/bworld/items/acacia_leaves.json @@ -0,0 +1,7 @@ +{ + "format_version": 1, + "item": { + "id": "bworld:acacia_leaves", + "base_sell_value": 1 + } +} diff --git a/mods/bworld/items/acacia_log.json b/mods/bworld/items/acacia_log.json new file mode 100644 index 0000000..3f389b2 --- /dev/null +++ b/mods/bworld/items/acacia_log.json @@ -0,0 +1,7 @@ +{ + "format_version": 1, + "item": { + "id": "bworld:acacia_log", + "base_sell_value": 8 + } +} diff --git a/mods/bworld/items/acacia_planks.json b/mods/bworld/items/acacia_planks.json new file mode 100644 index 0000000..57f1db4 --- /dev/null +++ b/mods/bworld/items/acacia_planks.json @@ -0,0 +1,7 @@ +{ + "format_version": 1, + "item": { + "id": "bworld:acacia_planks", + "base_sell_value": 2 + } +} diff --git a/mods/bworld/items/birch_leaves.json b/mods/bworld/items/birch_leaves.json new file mode 100644 index 0000000..52b3eda --- /dev/null +++ b/mods/bworld/items/birch_leaves.json @@ -0,0 +1,7 @@ +{ + "format_version": 1, + "item": { + "id": "bworld:birch_leaves", + "base_sell_value": 1 + } +} diff --git a/mods/bworld/items/birch_log.json b/mods/bworld/items/birch_log.json new file mode 100644 index 0000000..ac41f30 --- /dev/null +++ b/mods/bworld/items/birch_log.json @@ -0,0 +1,7 @@ +{ + "format_version": 1, + "item": { + "id": "bworld:birch_log", + "base_sell_value": 8 + } +} diff --git a/mods/bworld/items/birch_planks.json b/mods/bworld/items/birch_planks.json new file mode 100644 index 0000000..eb31c73 --- /dev/null +++ b/mods/bworld/items/birch_planks.json @@ -0,0 +1,7 @@ +{ + "format_version": 1, + "item": { + "id": "bworld:birch_planks", + "base_sell_value": 2 + } +} diff --git a/mods/bworld/items/bone_meal.json b/mods/bworld/items/bone_meal.json index f6f4578..3539cdd 100644 --- a/mods/bworld/items/bone_meal.json +++ b/mods/bworld/items/bone_meal.json @@ -2,6 +2,7 @@ "format_version": 1, "item": { "id": "bworld:bone_meal", - "texture": "bworld:bone_meal" + "texture": "bworld:bone_meal", + "base_sell_value": 4 } } diff --git a/mods/bworld/items/bowl.json b/mods/bworld/items/bowl.json index 8016789..0678a2d 100644 --- a/mods/bworld/items/bowl.json +++ b/mods/bworld/items/bowl.json @@ -2,6 +2,7 @@ "format_version": 1, "item": { "id": "bworld:bowl", - "texture": "bworld:bowl" + "texture": "bworld:bowl", + "base_sell_value": 1 } } diff --git a/mods/bworld/items/brass_coin.json b/mods/bworld/items/brass_coin.json index fe9bc6f..d3d8102 100644 --- a/mods/bworld/items/brass_coin.json +++ b/mods/bworld/items/brass_coin.json @@ -2,6 +2,7 @@ "format_version": 1, "item": { "id": "bworld:brass_coin", - "texture": "bworld:brass_coin" + "texture": "bworld:brass_coin", + "base_sell_value": 64 } } diff --git a/mods/bworld/items/carrot.json b/mods/bworld/items/carrot.json index 7198131..e3c1eb8 100644 --- a/mods/bworld/items/carrot.json +++ b/mods/bworld/items/carrot.json @@ -7,6 +7,7 @@ "nutrition": 3, "saturation_modifier": 0.6 }, - "places": "bworld:carrots" + "places": "bworld:carrots", + "base_sell_value": 12 } } diff --git a/mods/bworld/items/cherry_leaves.json b/mods/bworld/items/cherry_leaves.json new file mode 100644 index 0000000..d911233 --- /dev/null +++ b/mods/bworld/items/cherry_leaves.json @@ -0,0 +1,7 @@ +{ + "format_version": 1, + "item": { + "id": "bworld:cherry_leaves", + "base_sell_value": 1 + } +} diff --git a/mods/bworld/items/cherry_log.json b/mods/bworld/items/cherry_log.json new file mode 100644 index 0000000..7d1044d --- /dev/null +++ b/mods/bworld/items/cherry_log.json @@ -0,0 +1,7 @@ +{ + "format_version": 1, + "item": { + "id": "bworld:cherry_log", + "base_sell_value": 8 + } +} diff --git a/mods/bworld/items/cherry_planks.json b/mods/bworld/items/cherry_planks.json new file mode 100644 index 0000000..77e241a --- /dev/null +++ b/mods/bworld/items/cherry_planks.json @@ -0,0 +1,7 @@ +{ + "format_version": 1, + "item": { + "id": "bworld:cherry_planks", + "base_sell_value": 2 + } +} diff --git a/mods/bworld/items/coal.json b/mods/bworld/items/coal.json index cf6c1ac..564e3e2 100644 --- a/mods/bworld/items/coal.json +++ b/mods/bworld/items/coal.json @@ -2,6 +2,7 @@ "format_version": 1, "item": { "id": "bworld:coal", - "texture": "bworld:coal" + "texture": "bworld:coal", + "base_sell_value": 18 } } diff --git a/mods/bworld/items/cobalt_coin.json b/mods/bworld/items/cobalt_coin.json index 72b48fd..173f129 100644 --- a/mods/bworld/items/cobalt_coin.json +++ b/mods/bworld/items/cobalt_coin.json @@ -2,6 +2,7 @@ "format_version": 1, "item": { "id": "bworld:cobalt_coin", - "texture": "bworld:cobalt_coin" + "texture": "bworld:cobalt_coin", + "base_sell_value": 32768 } } diff --git a/mods/bworld/items/cod.json b/mods/bworld/items/cod.json index 3fd9109..58c5443 100644 --- a/mods/bworld/items/cod.json +++ b/mods/bworld/items/cod.json @@ -6,6 +6,7 @@ "food": { "nutrition": 2, "saturation_modifier": 0.1 - } + }, + "base_sell_value": 30 } } diff --git a/mods/bworld/items/cooked_cod.json b/mods/bworld/items/cooked_cod.json index f8d9018..228dafe 100644 --- a/mods/bworld/items/cooked_cod.json +++ b/mods/bworld/items/cooked_cod.json @@ -6,6 +6,7 @@ "food": { "nutrition": 5, "saturation_modifier": 0.6 - } + }, + "base_sell_value": 32 } } diff --git a/mods/bworld/items/cooked_salmon.json b/mods/bworld/items/cooked_salmon.json index 4ad911c..b5b44b4 100644 --- a/mods/bworld/items/cooked_salmon.json +++ b/mods/bworld/items/cooked_salmon.json @@ -6,6 +6,7 @@ "food": { "nutrition": 6, "saturation_modifier": 0.8 - } + }, + "base_sell_value": 34 } } diff --git a/mods/bworld/items/copper_coin.json b/mods/bworld/items/copper_coin.json index b258d4e..1a7d335 100644 --- a/mods/bworld/items/copper_coin.json +++ b/mods/bworld/items/copper_coin.json @@ -2,6 +2,7 @@ "format_version": 1, "item": { "id": "bworld:copper_coin", - "texture": "bworld:copper_coin" + "texture": "bworld:copper_coin", + "base_sell_value": 1 } } diff --git a/mods/bworld/items/copper_ingot.json b/mods/bworld/items/copper_ingot.json index 5965205..a6db992 100644 --- a/mods/bworld/items/copper_ingot.json +++ b/mods/bworld/items/copper_ingot.json @@ -2,6 +2,7 @@ "format_version": 1, "item": { "id": "bworld:copper_ingot", - "texture": "bworld:copper_ingot" + "texture": "bworld:copper_ingot", + "base_sell_value": 12 } } diff --git a/mods/bworld/items/cracked_stone_bricks.json b/mods/bworld/items/cracked_stone_bricks.json new file mode 100644 index 0000000..ff134be --- /dev/null +++ b/mods/bworld/items/cracked_stone_bricks.json @@ -0,0 +1,7 @@ +{ + "format_version": 1, + "item": { + "id": "bworld:cracked_stone_bricks", + "base_sell_value": 1 + } +} diff --git a/mods/bworld/items/dark_oak_leaves.json b/mods/bworld/items/dark_oak_leaves.json new file mode 100644 index 0000000..3f9945a --- /dev/null +++ b/mods/bworld/items/dark_oak_leaves.json @@ -0,0 +1,7 @@ +{ + "format_version": 1, + "item": { + "id": "bworld:dark_oak_leaves", + "base_sell_value": 1 + } +} diff --git a/mods/bworld/items/dark_oak_log.json b/mods/bworld/items/dark_oak_log.json new file mode 100644 index 0000000..80662cc --- /dev/null +++ b/mods/bworld/items/dark_oak_log.json @@ -0,0 +1,7 @@ +{ + "format_version": 1, + "item": { + "id": "bworld:dark_oak_log", + "base_sell_value": 8 + } +} diff --git a/mods/bworld/items/dark_oak_planks.json b/mods/bworld/items/dark_oak_planks.json new file mode 100644 index 0000000..efa304e --- /dev/null +++ b/mods/bworld/items/dark_oak_planks.json @@ -0,0 +1,7 @@ +{ + "format_version": 1, + "item": { + "id": "bworld:dark_oak_planks", + "base_sell_value": 2 + } +} diff --git a/mods/bworld/items/dirt.json b/mods/bworld/items/dirt.json new file mode 100644 index 0000000..bf09c36 --- /dev/null +++ b/mods/bworld/items/dirt.json @@ -0,0 +1,7 @@ +{ + "format_version": 1, + "item": { + "id": "bworld:dirt", + "base_sell_value": 1 + } +} diff --git a/mods/bworld/items/glass.json b/mods/bworld/items/glass.json new file mode 100644 index 0000000..a95ca2f --- /dev/null +++ b/mods/bworld/items/glass.json @@ -0,0 +1,7 @@ +{ + "format_version": 1, + "item": { + "id": "bworld:glass", + "base_sell_value": 2 + } +} diff --git a/mods/bworld/items/gold_coin.json b/mods/bworld/items/gold_coin.json index 0837166..dcb4b46 100644 --- a/mods/bworld/items/gold_coin.json +++ b/mods/bworld/items/gold_coin.json @@ -2,6 +2,7 @@ "format_version": 1, "item": { "id": "bworld:gold_coin", - "texture": "bworld:gold_coin" + "texture": "bworld:gold_coin", + "base_sell_value": 4096 } } diff --git a/mods/bworld/items/gold_ingot.json b/mods/bworld/items/gold_ingot.json index 4656651..a19499f 100644 --- a/mods/bworld/items/gold_ingot.json +++ b/mods/bworld/items/gold_ingot.json @@ -2,6 +2,7 @@ "format_version": 1, "item": { "id": "bworld:gold_ingot", - "texture": "bworld:gold_ingot" + "texture": "bworld:gold_ingot", + "base_sell_value": 120 } } diff --git a/mods/bworld/items/iron_coin.json b/mods/bworld/items/iron_coin.json index d5d0d8d..5379641 100644 --- a/mods/bworld/items/iron_coin.json +++ b/mods/bworld/items/iron_coin.json @@ -2,6 +2,7 @@ "format_version": 1, "item": { "id": "bworld:iron_coin", - "texture": "bworld:iron_coin" + "texture": "bworld:iron_coin", + "base_sell_value": 512 } } diff --git a/mods/bworld/items/iron_ingot.json b/mods/bworld/items/iron_ingot.json index 028eaad..d719f5a 100644 --- a/mods/bworld/items/iron_ingot.json +++ b/mods/bworld/items/iron_ingot.json @@ -2,6 +2,7 @@ "format_version": 1, "item": { "id": "bworld:iron_ingot", - "texture": "bworld:iron_ingot" + "texture": "bworld:iron_ingot", + "base_sell_value": 60 } } diff --git a/mods/bworld/items/jungle_leaves.json b/mods/bworld/items/jungle_leaves.json new file mode 100644 index 0000000..2fd87e3 --- /dev/null +++ b/mods/bworld/items/jungle_leaves.json @@ -0,0 +1,7 @@ +{ + "format_version": 1, + "item": { + "id": "bworld:jungle_leaves", + "base_sell_value": 1 + } +} diff --git a/mods/bworld/items/jungle_log.json b/mods/bworld/items/jungle_log.json new file mode 100644 index 0000000..ca85a35 --- /dev/null +++ b/mods/bworld/items/jungle_log.json @@ -0,0 +1,7 @@ +{ + "format_version": 1, + "item": { + "id": "bworld:jungle_log", + "base_sell_value": 8 + } +} diff --git a/mods/bworld/items/jungle_planks.json b/mods/bworld/items/jungle_planks.json new file mode 100644 index 0000000..4ece243 --- /dev/null +++ b/mods/bworld/items/jungle_planks.json @@ -0,0 +1,7 @@ +{ + "format_version": 1, + "item": { + "id": "bworld:jungle_planks", + "base_sell_value": 2 + } +} diff --git a/mods/bworld/items/mossy_stone_bricks.json b/mods/bworld/items/mossy_stone_bricks.json new file mode 100644 index 0000000..71f17df --- /dev/null +++ b/mods/bworld/items/mossy_stone_bricks.json @@ -0,0 +1,7 @@ +{ + "format_version": 1, + "item": { + "id": "bworld:mossy_stone_bricks", + "base_sell_value": 2 + } +} diff --git a/mods/bworld/items/nickel_coin.json b/mods/bworld/items/nickel_coin.json index f96a716..66a0457 100644 --- a/mods/bworld/items/nickel_coin.json +++ b/mods/bworld/items/nickel_coin.json @@ -2,6 +2,7 @@ "format_version": 1, "item": { "id": "bworld:nickel_coin", - "texture": "bworld:nickel_coin" + "texture": "bworld:nickel_coin", + "base_sell_value": 8 } } diff --git a/mods/bworld/items/oak_leaves.json b/mods/bworld/items/oak_leaves.json new file mode 100644 index 0000000..f90a02c --- /dev/null +++ b/mods/bworld/items/oak_leaves.json @@ -0,0 +1,7 @@ +{ + "format_version": 1, + "item": { + "id": "bworld:oak_leaves", + "base_sell_value": 1 + } +} diff --git a/mods/bworld/items/oak_log.json b/mods/bworld/items/oak_log.json new file mode 100644 index 0000000..dc4fdb2 --- /dev/null +++ b/mods/bworld/items/oak_log.json @@ -0,0 +1,7 @@ +{ + "format_version": 1, + "item": { + "id": "bworld:oak_log", + "base_sell_value": 8 + } +} diff --git a/mods/bworld/items/oak_planks.json b/mods/bworld/items/oak_planks.json new file mode 100644 index 0000000..153a8ca --- /dev/null +++ b/mods/bworld/items/oak_planks.json @@ -0,0 +1,7 @@ +{ + "format_version": 1, + "item": { + "id": "bworld:oak_planks", + "base_sell_value": 2 + } +} diff --git a/mods/bworld/items/potato.json b/mods/bworld/items/potato.json index 4832374..a5bfd0c 100644 --- a/mods/bworld/items/potato.json +++ b/mods/bworld/items/potato.json @@ -7,6 +7,7 @@ "nutrition": 1, "saturation_modifier": 0.3 }, - "places": "bworld:potatoes" + "places": "bworld:potatoes", + "base_sell_value": 20 } } diff --git a/mods/bworld/items/salmon.json b/mods/bworld/items/salmon.json index 9b72606..62b4543 100644 --- a/mods/bworld/items/salmon.json +++ b/mods/bworld/items/salmon.json @@ -6,6 +6,7 @@ "food": { "nutrition": 2, "saturation_modifier": 0.1 - } + }, + "base_sell_value": 32 } } diff --git a/mods/bworld/items/sand.json b/mods/bworld/items/sand.json new file mode 100644 index 0000000..ae99f31 --- /dev/null +++ b/mods/bworld/items/sand.json @@ -0,0 +1,7 @@ +{ + "format_version": 1, + "item": { + "id": "bworld:sand", + "base_sell_value": 1 + } +} diff --git a/mods/bworld/items/smooth_stone.json b/mods/bworld/items/smooth_stone.json new file mode 100644 index 0000000..8794f5f --- /dev/null +++ b/mods/bworld/items/smooth_stone.json @@ -0,0 +1,7 @@ +{ + "format_version": 1, + "item": { + "id": "bworld:smooth_stone", + "base_sell_value": 2 + } +} diff --git a/mods/bworld/items/spruce_leaves.json b/mods/bworld/items/spruce_leaves.json new file mode 100644 index 0000000..0b9b9fd --- /dev/null +++ b/mods/bworld/items/spruce_leaves.json @@ -0,0 +1,7 @@ +{ + "format_version": 1, + "item": { + "id": "bworld:spruce_leaves", + "base_sell_value": 1 + } +} diff --git a/mods/bworld/items/spruce_log.json b/mods/bworld/items/spruce_log.json new file mode 100644 index 0000000..691d0da --- /dev/null +++ b/mods/bworld/items/spruce_log.json @@ -0,0 +1,7 @@ +{ + "format_version": 1, + "item": { + "id": "bworld:spruce_log", + "base_sell_value": 8 + } +} diff --git a/mods/bworld/items/spruce_planks.json b/mods/bworld/items/spruce_planks.json new file mode 100644 index 0000000..8ff6bcf --- /dev/null +++ b/mods/bworld/items/spruce_planks.json @@ -0,0 +1,7 @@ +{ + "format_version": 1, + "item": { + "id": "bworld:spruce_planks", + "base_sell_value": 2 + } +} diff --git a/mods/bworld/items/stone.json b/mods/bworld/items/stone.json new file mode 100644 index 0000000..954447e --- /dev/null +++ b/mods/bworld/items/stone.json @@ -0,0 +1,7 @@ +{ + "format_version": 1, + "item": { + "id": "bworld:stone", + "base_sell_value": 1 + } +} diff --git a/mods/bworld/items/stone_bricks.json b/mods/bworld/items/stone_bricks.json new file mode 100644 index 0000000..5ab13a7 --- /dev/null +++ b/mods/bworld/items/stone_bricks.json @@ -0,0 +1,7 @@ +{ + "format_version": 1, + "item": { + "id": "bworld:stone_bricks", + "base_sell_value": 1 + } +} diff --git a/mods/bworld/items/tin_ingot.json b/mods/bworld/items/tin_ingot.json index 97d2905..fe338df 100644 --- a/mods/bworld/items/tin_ingot.json +++ b/mods/bworld/items/tin_ingot.json @@ -2,6 +2,7 @@ "format_version": 1, "item": { "id": "bworld:tin_ingot", - "texture": "bworld:tin_ingot" + "texture": "bworld:tin_ingot", + "base_sell_value": 14 } } diff --git a/mods/bworld/items/wheat.json b/mods/bworld/items/wheat.json index 7c1f4b3..2d104a2 100644 --- a/mods/bworld/items/wheat.json +++ b/mods/bworld/items/wheat.json @@ -2,6 +2,7 @@ "format_version": 1, "item": { "id": "bworld:wheat", - "texture": "bworld:wheat" + "texture": "bworld:wheat", + "base_sell_value": 7 } } diff --git a/mods/farmersdelight/items/cabbage.json b/mods/farmersdelight/items/cabbage.json index 36b9301..f61cb7a 100644 --- a/mods/farmersdelight/items/cabbage.json +++ b/mods/farmersdelight/items/cabbage.json @@ -6,6 +6,7 @@ "food": { "nutrition": 2, "saturation_modifier": 0.4 - } + }, + "base_sell_value": 35 } } diff --git a/mods/farmersdelight/items/cabbage_leaf.json b/mods/farmersdelight/items/cabbage_leaf.json index 204c1b6..0f6e9c3 100644 --- a/mods/farmersdelight/items/cabbage_leaf.json +++ b/mods/farmersdelight/items/cabbage_leaf.json @@ -6,6 +6,7 @@ "food": { "nutrition": 1, "saturation_modifier": 0.4 - } + }, + "base_sell_value": 18 } } diff --git a/mods/farmersdelight/items/cabbage_rolls.json b/mods/farmersdelight/items/cabbage_rolls.json index c6b92ec..096169d 100644 --- a/mods/farmersdelight/items/cabbage_rolls.json +++ b/mods/farmersdelight/items/cabbage_rolls.json @@ -6,6 +6,7 @@ "food": { "nutrition": 5, "saturation_modifier": 0.5 - } + }, + "base_sell_value": 50 } } diff --git a/mods/farmersdelight/items/cod_slice.json b/mods/farmersdelight/items/cod_slice.json index 26360aa..fbd41ad 100644 --- a/mods/farmersdelight/items/cod_slice.json +++ b/mods/farmersdelight/items/cod_slice.json @@ -6,6 +6,7 @@ "food": { "nutrition": 1, "saturation_modifier": 0.1 - } + }, + "base_sell_value": 15 } } diff --git a/mods/farmersdelight/items/cooked_rice.json b/mods/farmersdelight/items/cooked_rice.json index 54ff563..f7fd961 100644 --- a/mods/farmersdelight/items/cooked_rice.json +++ b/mods/farmersdelight/items/cooked_rice.json @@ -8,6 +8,7 @@ "nutrition": 6, "saturation_modifier": 0.4, "returns": "bworld:bowl" - } + }, + "base_sell_value": 46 } } diff --git a/mods/farmersdelight/items/onion.json b/mods/farmersdelight/items/onion.json index 072d979..c0c7359 100644 --- a/mods/farmersdelight/items/onion.json +++ b/mods/farmersdelight/items/onion.json @@ -7,6 +7,7 @@ "food": { "nutrition": 2, "saturation_modifier": 0.4 - } + }, + "base_sell_value": 16 } } diff --git a/mods/farmersdelight/items/rice.json b/mods/farmersdelight/items/rice.json index 9bd8e5e..0a175ef 100644 --- a/mods/farmersdelight/items/rice.json +++ b/mods/farmersdelight/items/rice.json @@ -3,6 +3,7 @@ "item": { "id": "farmersdelight:rice", "texture": "farmersdelight:rice", - "places": "farmersdelight:rice" + "places": "farmersdelight:rice", + "base_sell_value": 13 } } diff --git a/mods/farmersdelight/items/rice_panicle.json b/mods/farmersdelight/items/rice_panicle.json index 68f2306..320f94e 100644 --- a/mods/farmersdelight/items/rice_panicle.json +++ b/mods/farmersdelight/items/rice_panicle.json @@ -2,6 +2,7 @@ "format_version": 1, "item": { "id": "farmersdelight:rice_panicle", - "texture": "farmersdelight:rice_panicle" + "texture": "farmersdelight:rice_panicle", + "base_sell_value": 10 } } diff --git a/mods/farmersdelight/items/salmon_slice.json b/mods/farmersdelight/items/salmon_slice.json index e73096a..0c3bda3 100644 --- a/mods/farmersdelight/items/salmon_slice.json +++ b/mods/farmersdelight/items/salmon_slice.json @@ -6,6 +6,7 @@ "food": { "nutrition": 1, "saturation_modifier": 0.1 - } + }, + "base_sell_value": 16 } } diff --git a/mods/farmersdelight/items/tomato.json b/mods/farmersdelight/items/tomato.json index 98ea8c5..0af2493 100644 --- a/mods/farmersdelight/items/tomato.json +++ b/mods/farmersdelight/items/tomato.json @@ -6,6 +6,7 @@ "food": { "nutrition": 1, "saturation_modifier": 0.3 - } + }, + "base_sell_value": 15 } } diff --git a/mods/farmersdelight/items/tomato_sauce.json b/mods/farmersdelight/items/tomato_sauce.json index 5b155e5..60c52ad 100644 --- a/mods/farmersdelight/items/tomato_sauce.json +++ b/mods/farmersdelight/items/tomato_sauce.json @@ -7,6 +7,7 @@ "nutrition": 4, "saturation_modifier": 0.4, "returns": "bworld:bowl" - } + }, + "base_sell_value": 33 } } diff --git a/tests/mod_loading_test.ts b/tests/mod_loading_test.ts index 55b9f31..13201b8 100644 --- a/tests/mod_loading_test.ts +++ b/tests/mod_loading_test.ts @@ -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("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); diff --git a/tests/mod_tools_test.ts b/tests/mod_tools_test.ts index 9dc5706..b04d1cc 100644 --- a/tests/mod_tools_test.ts +++ b/tests/mod_tools_test.ts @@ -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 }); +});