Parse `"states"` field in blocks.json.

pull/1/head
Ben Reeves 3 years ago
parent cc69c314df
commit ba404ffbbf

@ -29,8 +29,30 @@ pub fn test_blocks_by_id() {
for version in versions { for version in versions {
let api = get_api(version); let api = get_api(version);
let by_name = api.blocks.blocks().unwrap(); let by_id = api.blocks.blocks().unwrap();
assert!(by_name.get(&1).is_some()); assert!(by_id.get(&1).is_some());
assert!(by_name.get(&5).is_some()); assert!(by_id.get(&5).is_some());
}
}
#[test]
pub fn test_block_states() {
let versions = get_test_versions();
for version in versions {
let api = get_api(version);
let by_name = api.blocks.blocks_by_name().unwrap();
let air = by_name.get("air").unwrap();
if let Some(states) = &air.states {
// Air has no states.
assert_eq!(states.len(), 0);
}
let water = by_name.get("water").unwrap();
if let Some(states) = &water.states {
// Water has states.
assert_ne!(states.len(), 0);
}
} }
} }

@ -19,6 +19,7 @@ pub struct Block {
pub filter_light: u8, pub filter_light: u8,
pub min_state_id: Option<u32>, pub min_state_id: Option<u32>,
pub max_state_id: Option<u32>, pub max_state_id: Option<u32>,
pub states: Option<Vec<State>>,
pub default_state: Option<u32>, pub default_state: Option<u32>,
#[serde(alias = "resistance")] #[serde(alias = "resistance")]
pub blast_resistance: Option<f32>, pub blast_resistance: Option<f32>,
@ -40,7 +41,8 @@ pub struct Variation {
} }
#[derive(Deserialize, Debug, Clone)] #[derive(Deserialize, Debug, Clone)]
#[serde(rename_all(deserialize = "camelCase", serialize = "snake_case"))] // The fields in this part of the schema are not camelCase.
#[serde(rename_all(serialize = "snake_case"))]
pub struct State { pub struct State {
pub name: String, pub name: String,
#[serde(alias = "type")] #[serde(alias = "type")]

Loading…
Cancel
Save