mcdata-rs 0.1.2

Library to access Minecraft data provided by PrismarineJS/minecraft-data
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
use serde::Deserialize;
use std::collections::HashMap;

// Structs related to version information from protocolVersions.json.

#[derive(Deserialize, Debug, Clone, PartialEq, Eq, Hash)]
#[serde(rename_all = "camelCase")]
pub struct ProtocolVersionInfo {
    pub minecraft_version: String,
    pub version: i32,              // Protocol version number
    pub data_version: Option<i32>, // Data version number (used for comparisons)
    pub uses_netty: bool,
    pub major_version: String,
    #[serde(default = "default_release_type")]
    pub release_type: String, // e.g., "release", "snapshot"
}

fn default_release_type() -> String {
    "release".to_string()
}

#[derive(Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct VersionInfo {
    pub version: i32,
    pub minecraft_version: String,
    pub major_version: String,
    #[serde(default = "default_release_type")]
    pub release_type: String,
}

// Structs representing various game data elements loaded from JSON files.

#[derive(Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct Block {
    pub id: u32,
    pub name: String,
    pub display_name: String,
    pub hardness: Option<f32>,
    pub resistance: f32,
    pub stack_size: u32,
    pub diggable: bool,
    pub bounding_box: String, // Typically "block" or "empty"
    pub material: Option<String>,
    #[serde(default)]
    pub harvest_tools: HashMap<String, bool>,
    #[serde(default)]
    pub variations: Option<Vec<BlockVariation>>,
    #[serde(default)]
    pub drops: Vec<BlockDrop>, // Handles simple ID drops or complex drop definitions
    #[serde(default)]
    pub emit_light: u8,
    #[serde(default)]
    pub filter_light: u8,
    #[serde(default)]
    pub transparent: bool,
    #[serde(default)]
    pub states: Vec<BlockStateDefinition>, // Block states (relevant for 1.13+)

    // State IDs might be calculated during indexing if not present in the source JSON.
    #[serde(default = "default_state_id")]
    pub min_state_id: u32,
    #[serde(default = "default_state_id")]
    pub max_state_id: u32,
    #[serde(default = "default_state_id")]
    pub default_state: u32,

    // Internal map added during indexing for quick state ID lookup.
    #[serde(skip)]
    pub state_id_map: Option<HashMap<u32, Block>>,
}

// Default value for state IDs before calculation.
fn default_state_id() -> u32 {
    0
}

#[derive(Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct BlockVariation {
    pub metadata: u32,
    pub display_name: String,
    pub description: Option<String>,
}

#[derive(Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct BlockStateDefinition {
    pub name: String,
    #[serde(rename = "type")]
    pub state_type: String, // e.g., "bool", "enum", "int"
    pub num_values: Option<u32>,
    #[serde(default)]
    pub values: Vec<String>,
}

// Structs for handling block drops, especially in older formats (pre-1.13)
// where drops could be simple item IDs or more complex objects.

#[derive(Deserialize, Debug, Clone)]
pub struct DropItem {
    pub id: u32,
    pub metadata: u32,
}

#[derive(Deserialize, Debug, Clone)]
#[serde(untagged)] // Allows deserializing as either a simple u32 or a DropItem object.
pub enum DropType {
    Id(u32),
    Item(DropItem),
}

#[derive(Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct DropElement {
    pub drop: DropType, // The actual item dropped.
    pub min_count: Option<f32>,
    pub max_count: Option<f32>,
}

#[derive(Deserialize, Debug, Clone)]
#[serde(untagged)] // Allows deserializing as either a simple u32 ID or a DropElement object.
pub enum BlockDrop {
    Id(u32),
    Element(DropElement),
}

#[derive(Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct Item {
    pub id: u32,
    pub name: String,
    pub display_name: String,
    pub stack_size: u32,
    #[serde(default)]
    pub enchant_categories: Option<Vec<String>>,
    #[serde(default)]
    pub repair_with: Option<Vec<String>>,
    #[serde(default)]
    pub max_durability: Option<u32>,
    #[serde(default)]
    pub variations: Option<Vec<ItemVariation>>, // Relevant for older versions with metadata variations.
}

#[derive(Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct ItemVariation {
    pub metadata: u32,
    pub display_name: String,
}

#[derive(Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct Biome {
    pub id: u32,
    pub name: String,
    pub category: String,
    pub temperature: f32,
    pub precipitation: Option<String>, // e.g., "none", "rain", "snow"
    pub dimension: String,             // e.g., "overworld", "nether", "end"
    pub display_name: String,
    pub color: i32,
    pub rainfall: Option<f32>,
    #[serde(default)]
    pub depth: Option<f32>,
    #[serde(default)]
    pub has_precipitation: Option<bool>,
}

#[derive(Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct Effect {
    pub id: u32,
    pub name: String,
    pub display_name: String,
    #[serde(rename = "type")]
    pub effect_type: String, // Typically "good" or "bad"
}

#[derive(Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct Entity {
    pub id: u32,
    pub internal_id: Option<u32>, // Used in some older versions.
    pub name: String,
    pub display_name: String,
    #[serde(rename = "type")]
    pub entity_type: String, // e.g., "mob", "object", "projectile"
    pub width: Option<f32>,
    pub height: Option<f32>,
    pub category: Option<String>,
    #[serde(default)]
    pub metadata_keys: Vec<String>, // Relevant for 1.20.2+
}

// Structs for feature checking from features.json.

#[derive(Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct Feature {
    pub name: String,
    pub description: Option<String>,
    #[serde(default)]
    pub values: Vec<FeatureValue>, // Prioritized if present.
    pub version: Option<String>, // Used if `values` is empty.
    #[serde(default)]
    pub versions: Vec<String>, // Used if `values` and `version` are empty; expected [min, max].
}

#[derive(Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct FeatureValue {
    pub value: serde_json::Value, // The actual feature value (bool, string, number).
    pub version: Option<String>,  // Single version applicability.
    #[serde(default)]
    pub versions: Vec<String>, // Version range applicability [min, max].
}

// Struct for dataPaths.json, mapping versions and keys to file paths.
#[derive(Deserialize, Debug, Clone)]
pub struct DataPaths {
    // Major Version -> Data Key -> Path Suffix
    pub pc: HashMap<String, HashMap<String, String>>,
    pub bedrock: HashMap<String, HashMap<String, String>>,
}

// Other miscellaneous data structs.

#[derive(Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct Sound {
    pub id: u32,
    pub name: String,
}

#[derive(Deserialize, Debug, Clone)]
#[serde(untagged)] // Allows deserializing as a single index or multiple indices.
pub enum BlockShapeRef {
    Single(u32),        // Single shape index for all states.
    Multiple(Vec<u32>), // Shape indices per state/metadata.
}

#[derive(Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct BlockCollisionShapes {
    // Maps block name to its shape reference (single index or list of indices).
    pub blocks: HashMap<String, BlockShapeRef>,
    // Maps shape index (as string key) to an array of bounding boxes ([x1, y1, z1, x2, y2, z2]).
    pub shapes: HashMap<String, Vec<[f64; 6]>>,
}

#[derive(Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct Particle {
    pub id: u32,
    pub name: String,
}

#[derive(Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct Attribute {
    pub name: String,
    pub resource: String, // Namespaced key
    #[serde(default)]
    pub default: f64,
    pub min: f64,
    pub max: f64,
}

#[derive(Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct Instrument {
    pub id: u32,
    pub name: String,
}

#[derive(Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct BlockLoot {
    pub block: String, // Block name
    pub drops: Vec<BlockLootDrop>,
}

#[derive(Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct BlockLootDrop {
    pub item: String, // Item name
    #[serde(default = "default_drop_chance")]
    pub drop_chance: f32,
    #[serde(default = "default_stack_size_range")]
    pub stack_size_range: Vec<Option<i32>>, // Range [min] or [min, max]
    #[serde(default)]
    pub silk_touch: Option<bool>,
    #[serde(default)]
    pub no_silk_touch: Option<bool>,
    #[serde(default)]
    pub block_age: Option<i32>,
}

fn default_drop_chance() -> f32 {
    1.0
}

// Default stack size range is [1].
fn default_stack_size_range() -> Vec<Option<i32>> {
    vec![Some(1)]
}

#[derive(Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct Window {
    pub id: String, // Can be numeric string or namespaced string (e.g., "minecraft:chest")
    pub name: String,
    #[serde(default)]
    pub slots: Vec<WindowSlot>,
    #[serde(default)]
    pub opened_with: Vec<WindowOpenedWith>,
    #[serde(default)]
    pub properties: Vec<String>,
}

#[derive(Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct WindowSlot {
    pub name: String,
    pub index: u32,
    pub size: Option<u32>,
}

#[derive(Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct WindowOpenedWith {
    #[serde(rename = "type")]
    pub opener_type: String, // e.g., "block", "entity"
    pub id: u32,
}

#[derive(Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct EntityLoot {
    pub entity: String, // Entity name
    pub drops: Vec<EntityLootDrop>,
}

#[derive(Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct EntityLootDrop {
    pub item: String, // Item name
    #[serde(default = "default_drop_chance")]
    pub drop_chance: f32,
    #[serde(default = "default_entity_stack_size_range")]
    pub stack_size_range: Vec<u32>, // Range [min] or [min, max]
    #[serde(default)]
    pub player_kill: Option<bool>,
}

// Default stack size range is [1].
fn default_entity_stack_size_range() -> Vec<u32> {
    vec![1]
}

#[derive(Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct Food {
    pub id: u32,
    pub name: String,
    pub display_name: String,
    pub stack_size: u32,
    pub food_points: f32,
    pub saturation: f32,
    pub effective_quality: f32,
    pub saturation_ratio: f32,
    #[serde(default)]
    pub variations: Option<Vec<ItemVariation>>, // Relevant for older versions.
}

#[derive(Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct Enchantment {
    pub id: u32,
    pub name: String,
    pub display_name: String,
    #[serde(rename = "maxLevel")]
    pub max_level: u32,
    #[serde(default)]
    pub min_cost: EnchantmentCost,
    #[serde(default)]
    pub max_cost: EnchantmentCost,
    #[serde(default)]
    pub treasure_only: bool,
    #[serde(default)]
    pub curse: bool,
    #[serde(default)]
    pub exclude: Vec<String>, // Names of mutually exclusive enchantments
    pub category: String, // e.g., "weapon", "armor"
    pub weight: u32,      // Rarity weight
    #[serde(default)]
    pub tradeable: bool,
    #[serde(default)]
    pub discoverable: bool,
}

#[derive(Deserialize, Debug, Clone, Default)]
#[serde(rename_all = "camelCase")]
pub struct EnchantmentCost {
    // Cost calculation parameters: cost = a * level + b
    pub a: i32,
    pub b: i32,
}

#[derive(Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct MapIcon {
    pub id: u32,
    pub name: String,
    pub appearance: Option<String>,
    #[serde(default)]
    pub visible_in_item_frame: bool,
}

#[derive(Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct Tints {
    pub grass: TintData,
    pub foliage: TintData,
    pub water: TintData,
    pub redstone: TintData,
    pub constant: TintData,
}

#[derive(Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct TintData {
    #[serde(default)]
    pub default: Option<i32>, // Default color value
    pub data: Vec<TintDatum>, // List of specific tint rules
}

#[derive(Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct TintDatum {
    // Keys can be biome names (string) or redstone levels (number).
    pub keys: Vec<serde_json::Value>,
    pub color: i32, // The tint color associated with these keys.
}

#[derive(Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct Legacy {
    // Maps legacy numeric IDs (as strings) to modern namespaced IDs.
    pub blocks: HashMap<String, String>,
    pub items: HashMap<String, String>,
}

// Note: Commands and Materials are often loaded as raw `serde_json::Value`
// due to their high variability across versions.