Skip to main content

yog_cli/content/
vocab.rs

1//! The words content files are written in: directions, display slots,
2//! render layers, model templates.
3
4use yog_ids::texture_slot as slot;
5use yog_ids::word::GUI;
6
7/// A block's faces, in the game's order.
8pub const DIRECTIONS: &[&str] = yog_ids::direction::ALL_VALUES;
9/// Where an item's model is shown: its `display` transforms.
10pub const DISPLAY_SLOTS: [&str; 8] = [
11    "thirdperson_righthand",
12    "thirdperson_lefthand",
13    "firstperson_righthand",
14    "firstperson_lefthand",
15    GUI,
16    "head",
17    "ground",
18    "fixed",
19];
20/// How a block's model is drawn.
21pub const RENDER_LAYERS: [&str; 4] = ["solid", "cutout", "cutout_mipped", "translucent"];
22
23/// A model template — `"parent": "cube_all"` — and the texture slots it takes.
24pub struct Template {
25    pub name: &'static str,
26    /// The vanilla model it compiles to.
27    pub parent: &'static str,
28    /// Its texture slots; for item sprites, `layer0` (more layers allowed).
29    pub slots: &'static [&'static str],
30    /// An item sprite template (`generated`, `handheld`) — item models only.
31    pub sprite: bool,
32    /// The parent model defines `particle` itself.
33    pub has_particle: bool,
34}
35
36/// A template named as the game's model it compiles to, `<dir><name>`.
37macro_rules! template {
38    ($dir:ident, $name:expr, $slots:expr, sprite: $sprite:expr, particle: $particle:expr) => {
39        Template {
40            name: $name,
41            parent: yog_ids::id!(
42                yog_ids::ns::MINECRAFT,
43                yog_ids::concatcp!(yog_ids::res::$dir, $name)
44            ),
45            slots: $slots,
46            sprite: $sprite,
47            has_particle: $particle,
48        }
49    };
50}
51
52/// A sprite item's slots: its first layer.
53const SPRITE_SLOTS: &[&str] = &[yog_ids::model::LAYER0];
54
55pub const TEMPLATES: &[Template] = &[
56    template!(BLOCK_DIR, "cube_all", &[slot::ALL], sprite: false, particle: true),
57    template!(BLOCK_DIR, "cube_column", &[slot::END, slot::SIDE], sprite: false, particle: true),
58    template!(BLOCK_DIR, "cube_bottom_top", &[slot::TOP, slot::BOTTOM, slot::SIDE], sprite: false, particle: true),
59    template!(BLOCK_DIR, "cube", &DIRECTIONS, sprite: false, particle: false),
60    template!(BLOCK_DIR, "orientable", &[slot::FRONT, slot::SIDE, slot::TOP], sprite: false, particle: true),
61    template!(BLOCK_DIR, "cross", &["cross"], sprite: false, particle: true),
62    template!(ITEM_DIR, "generated", SPRITE_SLOTS, sprite: true, particle: true),
63    template!(ITEM_DIR, "handheld", SPRITE_SLOTS, sprite: true, particle: true),
64];
65
66/// The template named `name`.
67pub fn template(name: &str) -> Option<&'static Template> {
68    TEMPLATES.iter().find(|t| t.name == name)
69}