Skip to main content

yog_event/content/
host.rs

1//! What the hosts register, as the runtime hands it to them in one blob:
2//! items and blocks with what they name resolved (materials and sound
3//! groups whole), inventories laid out, recipes, dimensions, fonts, and
4//! the mods' entity types, attributes, effects and potions as declared.
5//! The hosts' Java reads it through the records generated from these; its
6//! counts are `i32`, the `int`s the game's Java takes them as.
7
8use yog_data::Schema;
9use yog_data::Value;
10use yog_data::with::Raw;
11use yog_registry::{
12    ArmorMaterial, ArmorSlot, AttributeDef, BiomeFeature, BlockProperty, EffectDef, EntityDef,
13    Facing, FoodDef, GameTool, ParticleDef, Placement, PotionDef, SoundGroup, ToolMaterial,
14};
15
16/// Everything the hosts register.
17#[derive(Debug, Clone, Default, Schema)]
18pub struct Content {
19    pub items: Vec<Item>,
20    /// Blocks made from another (stairs from planks) after the ones they're made from.
21    pub blocks: Vec<Block>,
22    pub inventories: Vec<Inventory>,
23    pub recipes: Vec<Recipe>,
24    /// For the hosts that add features to biomes in code (Fabric).
25    pub biome_features: Vec<BiomeFeature>,
26    pub entities: Vec<EntityDef>,
27    pub dimensions: Vec<Dimension>,
28    pub fonts: Vec<Font>,
29    pub attributes: Vec<AttributeDef>,
30    pub effects: Vec<EffectDef>,
31    pub potions: Vec<PotionDef>,
32    /// The mods' particles: the hosts register and draw each.
33    #[data(default)]
34    pub particles: Vec<ParticleDef>,
35}
36
37/// An item: its stack, durability, fuel, food, tool or armor (materials
38/// whole), what it's worn as or hangs, and whether it opens a book.
39#[derive(Debug, Clone, Schema)]
40pub struct Item {
41    pub id: String,
42    pub max_stack: i32,
43    /// Empty: the game's name of its id.
44    pub name: String,
45    /// Empty: none.
46    pub tooltip: String,
47    pub max_damage: i32,
48    pub fire_resistant: bool,
49    pub fuel_ticks: i32,
50    pub food: Option<FoodDef>,
51    /// A book registered under the item's id: the item opens it.
52    pub book: bool,
53    pub tool: Option<Tool>,
54    pub armor: Option<Armor>,
55    /// The slot it's worn in without being armor.
56    pub wearable: Option<ArmorSlot>,
57    pub hangs: Option<Hangs>,
58}
59
60/// A tool: its kind (`pickaxe`…, or a mineable tag id), its material, and
61/// its own attack where it gives one — else the game's tool it attacks as
62/// (`game_tool`), which the host reads the game's numbers off.
63#[derive(Debug, Clone, Schema)]
64pub struct Tool {
65    pub kind: String,
66    /// On top of the material's.
67    pub attack_damage: Option<f32>,
68    pub attack_speed: Option<f32>,
69    pub material: ToolMaterial,
70    pub game_tool: Option<GameTool>,
71}
72
73/// A piece of armor: its slot and material, whole.
74#[derive(Debug, Clone, Schema)]
75pub struct Armor {
76    pub slot: ArmorSlot,
77    pub material: ArmorMaterial,
78}
79
80/// What an item hangs on a block's side: an entity of a hanging type,
81/// `width`×`height` blocks.
82#[derive(Debug, Clone, Schema)]
83pub struct Hangs {
84    pub entity: String,
85    pub width: i32,
86    pub height: i32,
87}
88
89/// A block: its properties, shape, sound group (whole), states, kind.
90#[derive(Debug, Clone, Schema)]
91pub struct Block {
92    pub id: String,
93    pub hardness: f32,
94    pub resistance: f32,
95    /// Empty: the game's name of its id.
96    pub name: String,
97    /// `x1, y1, z1, x2, y2, z2` in pixels.
98    pub shape: Option<Vec<f32>>,
99    pub light: i32,
100    pub sound: Option<SoundGroup>,
101    pub requires_tool: bool,
102    pub no_collision: bool,
103    pub slipperiness: f32,
104    pub connects: bool,
105    pub connect_groups: Vec<String>,
106    /// The inventory it holds, by id.
107    pub inventory: Option<String>,
108    /// It's a redstone source.
109    pub redstone: bool,
110    /// Which ways it turns; `None`: it doesn't.
111    pub facing: Option<Facing>,
112    pub placement: Placement,
113    pub attach: bool,
114    pub waterlogged: bool,
115    /// Its own properties: their values, the first the default.
116    pub properties: Vec<BlockProperty>,
117    pub powered: Option<String>,
118    pub comparator: Option<String>,
119    pub accepts_items: bool,
120    pub no_occlusion: bool,
121    /// One of the game's kinds of block (`stairs`, `door`…) or empty.
122    pub kind: String,
123    /// The block it's made from.
124    pub base: Option<String>,
125    /// A block set or wood type by name.
126    pub set: Option<String>,
127    pub press_ticks: i32,
128    pub mobs_only: bool,
129}
130
131/// An inventory: its slots where its layout puts them, its background,
132/// and — a machine's — its ingredients' and result's slots.
133#[derive(Debug, Clone, Schema)]
134pub struct Inventory {
135    pub id: String,
136    pub slot_count: i32,
137    pub slots: Vec<InventorySlot>,
138    pub include_player_inventory: bool,
139    /// Where the player's inventory goes: `x, y`.
140    pub player_inv: Vec<f32>,
141    pub background_texture: Option<String>,
142    pub title: String,
143    /// `width, height`.
144    pub background_size: Option<Vec<f32>>,
145    pub machine: Option<Machine>,
146}
147
148/// A slot: where it is (`x, y`), and the item ids and `#tags` it takes (none: anything).
149#[derive(Debug, Clone, Schema)]
150pub struct InventorySlot {
151    pub at: Vec<f32>,
152    pub accepts: Vec<String>,
153}
154
155/// A machine's ingredients' slots and its result's (the recipe is the runtime's to find).
156#[derive(Debug, Clone, Schema)]
157pub struct Machine {
158    pub places: Vec<i32>,
159    pub result: i32,
160}
161
162/// A recipe in Yog's own format.
163#[derive(Debug, Clone, Schema)]
164pub struct Recipe {
165    pub namespace: String,
166    pub name: String,
167    pub recipe: Value,
168}
169
170/// A dimension: its id and definition (`yog-dimensions`).
171#[derive(Debug, Clone, Schema)]
172pub struct Dimension {
173    pub id: String,
174    pub def: Value,
175}
176
177/// A Yog font as the game's text takes it: one cell per character, `rows`
178/// of them in the PNG, its baseline `ascent` GUI pixels down a cell `height` high.
179#[derive(Debug, Clone, Schema)]
180pub struct Font {
181    pub id: String,
182    #[data(with = "Raw")]
183    pub png: Vec<u8>,
184    /// Each row's characters, cell by cell.
185    pub rows: Vec<String>,
186    /// GUI pixels from the top of a cell to the baseline, and a cell's height.
187    pub ascent: i32,
188    pub height: i32,
189}