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