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