yog_formats/content/item.rs
1//! A `.yitem`'s properties: stacking, food, potions, tools and armor.
2
3use yog_data::Schema;
4use yog_data::with::RefTo;
5
6use yog_registry::ArmorSlot;
7
8use super::refs::{MaterialRef, ToolKindRef};
9use crate::def::{ArmorMaterialKind, ToolMaterialKind};
10
11/// What eating it gives.
12#[derive(Schema, Debug, Clone)]
13pub struct Food {
14 #[data(range = "0..=1000")]
15 pub nutrition: u32,
16 #[data(default, range = "0..=100")]
17 pub saturation: f64,
18 /// Eaten even when not hungry.
19 #[data(default)]
20 pub always_edible: bool,
21}
22
23/// A potion type attached to the item file: the effects the bottle gives.
24#[derive(Schema, Debug, Clone)]
25pub struct PotionProps {
26 /// Translation suffix shared by the bottle variants (optional).
27 pub name: Option<String>,
28 pub effects: Vec<yog_registry::PotionEffect>,
29}
30
31/// An item's properties.
32#[derive(Schema, Debug, Clone, Default)]
33pub struct ItemProps {
34 /// How many stack (1–99; 1 with durability).
35 #[data(range = "1..=99")]
36 pub stack_size: Option<u8>,
37 /// Uses before it breaks (0: none).
38 #[data(range = "0..=1000000000")]
39 pub durability: Option<u32>,
40 /// Survives fire and lava.
41 #[data(default)]
42 pub fire_resistant: bool,
43 /// Ticks it burns in a furnace.
44 #[data(range = "0..=1000000000")]
45 pub fuel_ticks: Option<u32>,
46 pub food: Option<Food>,
47 /// A tool or a weapon: its kind and material.
48 pub tool: Option<ToolProps>,
49 /// A piece of armor: its slot and material.
50 pub armor: Option<ArmorProps>,
51 /// Worn in this slot without being armor (a monocle, a crown):
52 /// right-click and dispensers put it on.
53 pub wearable: Option<ArmorSlot>,
54 /// A potion's effects. Brewing recipes live in `.yrecipe` files.
55 pub potion: Option<PotionProps>,
56 /// Used on a block's side, it hangs there (a painting, a scroll on a wall).
57 pub hangs: Option<HangsProps>,
58}
59
60/// What an item hangs on a wall: an entity of a hanging type that keeps one
61/// of the item and drops it when it breaks.
62#[derive(Schema, Debug, Clone)]
63pub struct HangsProps {
64 /// The entity (`@entity:mymod:wall_scroll`, a `.yentity` of `kind: hanging`).
65 #[data(with = "RefTo<yog_data::kinds::Entity>")]
66 pub entity: String,
67 /// Whole blocks of wall, wide and high; default: the entity type's size.
68 pub size: Option<[u32; 2]>,
69}
70
71/// A block's item form.
72#[derive(Schema, Debug, Clone, Default)]
73pub struct BlockItemProps {
74 /// How many stack (1–99; 64 by default).
75 #[data(range = "1..=99")]
76 pub stack_size: Option<u8>,
77 /// Survives fire and lava.
78 #[data(default)]
79 pub fire_resistant: bool,
80 /// Ticks it burns in a furnace.
81 #[data(range = "0..=1000000000")]
82 pub fuel_ticks: Option<u32>,
83}
84
85/// An item as a tool or weapon.
86#[derive(Schema, Debug, Clone)]
87pub struct ToolProps {
88 /// `pickaxe`, `axe`, `shovel`, `hoe`, `sword`, or a mod's kind of tool
89 /// by the blocks it mines (`@tag:block:mymod:mineable/hammer`).
90 #[data(with = "ToolKindRef")]
91 pub kind: String,
92 /// The game's material (`wood`, `stone`, `iron`, `diamond`, `gold`,
93 /// `netherite`) or a mod's (`@tool_material:mymod:mythril`, a `.ydef`).
94 #[data(with = "MaterialRef<ToolMaterialKind>")]
95 pub material: String,
96 /// Attack damage on top of the material's; by default the game's tool
97 /// of the kind and material has (`yog_registry::ToolMaterial::game_tool`),
98 /// as the running version of the game has it.
99 pub attack_damage: Option<f32>,
100 /// Attack speed change; by default the game's tool's.
101 pub attack_speed: Option<f32>,
102}
103
104/// An item as a piece of armor.
105#[derive(Schema, Debug, Clone)]
106pub struct ArmorProps {
107 pub slot: ArmorSlot,
108 /// The game's material (`leather`, `chainmail`, `iron`, `gold`,
109 /// `diamond`, `turtle`, `netherite`) or a mod's
110 /// (`@armor_material:mymod:mythril`, a `.ydef`).
111 #[data(with = "MaterialRef<ArmorMaterialKind>")]
112 pub material: String,
113}