Merge branch 'Trivernis:main' into path

pull/11/head
Firejoust 1 year ago committed by GitHub
commit be1eac6d44
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,6 +1,6 @@
[package]
name = "minecraft-data-rs"
version = "0.6.0"
version = "0.7.0"
authors = ["trivernis <trivernis@protonmail.com>"]
edition = "2018"
readme = "README.md"
@ -11,10 +11,10 @@ repository = "https://github.com/Trivernis/minecraft-data-rs"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
thiserror = "1.0.37"
serde_json = "1.0.87"
serde_derive = "1.0.147"
serde = "1.0.147"
thiserror = "1.0.38"
serde_json = "1.0.91"
serde_derive = "1.0.151"
serde = "1.0.151"
include_dir = { version = "0.7.3", optional = true }
itertools = { version = "0.10.5", optional = true }
lazy_static = { version = "1.4.0", optional = true }

@ -1 +1 @@
Subproject commit 0953ac6d8a78d6ce612020bd1f9587f346decf90
Subproject commit 971d49da8395def7f54be6393198ffdebb1d94e1

@ -23,11 +23,18 @@ impl Blocks {
Ok(blocks)
}
/// Returns the blocks indexed by ID
pub fn blocks(&self) -> DataResult<HashMap<u32, Block>> {
// Returns the blocks indexed by state ID
pub fn blocks_by_state_id(&self) -> DataResult<HashMap<u32, Block>> {
let blocks = self.blocks_array()?;
let blocks_map = blocks.into_iter().map(|b| (b.id, b)).collect();
let mut blocks_map = HashMap::new();
blocks.iter().for_each(|b| {
let min_state_id = b.min_state_id.unwrap_or(b.id << 4);
let max_state_id = b.max_state_id.unwrap_or(min_state_id + 15);
(min_state_id..max_state_id).for_each(|s| {
blocks_map.insert(s, b.clone());
});
});
Ok(blocks_map)
}
@ -39,6 +46,14 @@ impl Blocks {
Ok(blocks_map)
}
/// Returns the blocks indexed by ID
pub fn blocks(&self) -> DataResult<HashMap<u32, Block>> {
let blocks = self.blocks_array()?;
let blocks_map = blocks.into_iter().map(|b| (b.id, b)).collect();
Ok(blocks_map)
}
/// Returns the block collision shapes object
pub fn block_collision_shapes(&self) -> DataResult<BlockCollisionShapes> {
let content = get_version_specific_file(&self.version, BLOCK_COLLISION_SHAPES_FILE)?;

@ -20,7 +20,7 @@ impl Enchantments {
pub fn enchantments_array(&self) -> DataResult<Vec<Enchantment>> {
let content = get_version_specific_file(&self.version, ENCHANTMENTS_FILE)?;
serde_json::from_str::<Vec<Enchantment>>(&*content).map_err(DataError::from)
serde_json::from_str::<Vec<Enchantment>>(&content).map_err(DataError::from)
}
/// Returns a map of enchantments indexed by ID

@ -19,7 +19,7 @@ impl Items {
pub fn items_array(&self) -> DataResult<Vec<Item>> {
let content = get_version_specific_file(&self.version, ITEMS_FILE)?;
serde_json::from_str::<Vec<Item>>(&*content).map_err(DataError::from)
serde_json::from_str::<Vec<Item>>(&content).map_err(DataError::from)
}
/// Returns the items indexed by name

@ -18,6 +18,6 @@ impl Recipes {
/// Returns a list of recipes indexed by item ID
pub fn recipes(&self) -> DataResult<HashMap<u32, Vec<Recipe>>> {
let content = get_version_specific_file(&self.version, RECIPES_FILE)?;
serde_json::from_str::<HashMap<u32, Vec<Recipe>>>(&*content).map_err(DataError::from)
serde_json::from_str::<HashMap<u32, Vec<Recipe>>>(&content).map_err(DataError::from)
}
}

@ -11,6 +11,17 @@ pub fn test_blocks_array() {
}
}
#[test]
pub fn test_blocks_by_state_id() {
let versions = get_test_versions();
for version in versions {
let api = get_api(version);
let by_state = api.blocks.blocks_by_state_id();
assert!(by_state.is_ok());
}
}
#[test]
pub fn test_blocks_by_name() {
let versions = get_test_versions();

@ -7,7 +7,7 @@ use std::collections::HashMap;
/// Returns the unsorted list of versions
pub fn versions() -> DataResult<Vec<Version>> {
let content = get_common_file(PROTOCOL_VERSIONS_FILE)?;
let versions = serde_json::from_str::<Vec<Version>>(&*content)?;
let versions = serde_json::from_str::<Vec<Version>>(&content)?;
Ok(versions)
}
@ -52,5 +52,5 @@ pub fn latest_stable() -> DataResult<Version> {
/// Returns a list of available version information
pub fn available_versions() -> DataResult<Vec<String>> {
let content = get_common_file(VERSIONS_FILE)?;
serde_json::from_str::<Vec<String>>(&*content).map_err(DataError::from)
serde_json::from_str::<Vec<String>>(&content).map_err(DataError::from)
}

Loading…
Cancel
Save