Skip to main content

yog_formats/content/
mod.rs

1//! The `.yitem` and `.yblock` formats in Yog Data: an item or a block, its
2//! model (a template or elements) and properties. `yog build` turns them
3//! into the game's models, block states, loot tables and the Rust glue.
4
5use yog_data::with::Opt;
6use yog_data::{Schema, Text};
7
8mod block;
9mod item;
10mod kind;
11mod model;
12mod refs;
13pub mod vocab;
14
15pub use block::{BlockProps, BlockShape, DropCount, DropItem, Drops, RenderLayer, TriggeredBy};
16pub use item::{ArmorProps, BlockItemProps, Food, HangsProps, ItemProps, PotionProps, ToolProps};
17pub use kind::{BlockKind, KIND_FIELDS, KindModel, KindPart, KindRef};
18pub use model::{
19    Axis, Connect, Display, Element, ElementRotation, Face, Faces, Facing, GuiLight, Model,
20    ModelNames, Placement, Rotation, SLOT_MARK, States, Texture, Transform,
21};
22pub use refs::{
23    BlockTag, LevelRef, MaterialKind, MaterialRef, OneOrMany, SoundRef, ToolKindRef, ToolTag,
24};
25
26/// Registered by `yog_api::content!()` (`auto`), or by the mod's code.
27#[derive(Schema, Debug, Clone, Copy, PartialEq, Eq, Default)]
28pub enum Register {
29    #[default]
30    Auto,
31    Manual,
32}
33
34/// A schema enum's name as written.
35pub fn word<T: Schema>(v: &T) -> String {
36    v.write().as_str().unwrap_or_default().to_string()
37}
38
39/// A `.yitem`.
40#[derive(Schema, Debug, Clone)]
41pub struct ItemFile {
42    /// The file format; 1.
43    pub format: Option<u32>,
44    /// Its id; the file's name in the mod's namespace by default.
45    pub id: Option<String>,
46    pub name: Option<Text>,
47    pub tooltip: Option<Text>,
48    pub register: Option<Register>,
49    /// Mods it needs — Yog or Java mod ids (`pehkui`): without every one of
50    /// them loaded it isn't there (an optional integration).
51    #[data(default)]
52    pub requires: Vec<String>,
53    /// Item tags it's in: Yog's common tags (`yog:planks`, `yog:ingots/iron`
54    /// — the game's or each loader's tag of that meaning), the game's
55    /// (`minecraft:planks`), or the mod's own (a bare name).
56    #[data(default)]
57    pub tags: Vec<String>,
58    /// Items need a model; potion-only `.yitem` files don't register one.
59    pub model: Option<Model>,
60    pub item: Option<ItemProps>,
61}
62
63/// A `.yblock` — the block and its item form.
64#[derive(Schema, Debug, Clone)]
65pub struct BlockFile {
66    pub format: Option<u32>,
67    pub id: Option<String>,
68    pub name: Option<Text>,
69    pub tooltip: Option<Text>,
70    pub register: Option<Register>,
71    /// Mods it needs — Yog or Java mod ids (`pehkui`): without every one of
72    /// them loaded it isn't there (an optional integration).
73    #[data(default)]
74    pub requires: Vec<String>,
75    /// Tags it's in (`yog:logs` — Yog's common tags, `minecraft:logs`,
76    /// `edified_logs` — a bare name is the mod's own): the block tag, and the
77    /// item tag of the same name for its item form, as the game pairs them.
78    /// A tag of blocks only is a `.ydef`.
79    #[data(default)]
80    pub tags: Vec<String>,
81    /// One of the game's kinds of block — `stairs`, `slab`, `door`,
82    /// `trapdoor`, `button`, `pressure_plate`, `fence`, `fence_gate`: it
83    /// behaves as the game's, its states and models are the kind's, and
84    /// `model` gives only `textures` (the kind's slots).
85    #[data(with = "Opt<KindRef>")]
86    pub kind: Option<String>,
87    pub model: Model,
88    /// The item form's model; the block's by default.
89    pub item_model: Option<Model>,
90    /// The item form: how many stack, whether it survives fire, how long it
91    /// burns as fuel.
92    pub item: Option<BlockItemProps>,
93    pub block: Option<BlockProps>,
94    pub states: Option<States>,
95}