Merge pull request #1 from BGR360/block-states

Parse `"states"` field in blocks.json.
pull/6/head
Julius Riegel 3 years ago committed by GitHub
commit f73a558637
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -29,8 +29,30 @@ pub fn test_blocks_by_id() {
for version in versions {
let api = get_api(version);
let by_name = api.blocks.blocks().unwrap();
assert!(by_name.get(&1).is_some());
assert!(by_name.get(&5).is_some());
let by_id = api.blocks.blocks().unwrap();
assert!(by_id.get(&1).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 min_state_id: Option<u32>,
pub max_state_id: Option<u32>,
pub states: Option<Vec<State>>,
pub default_state: Option<u32>,
#[serde(alias = "resistance")]
pub blast_resistance: Option<f32>,
@ -40,7 +41,8 @@ pub struct Variation {
}
#[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 name: String,
#[serde(alias = "type")]

Loading…
Cancel
Save