Merge remote-tracking branch 'fork/main'

# Conflicts:
#	src/api/items.rs
#	src/data/mod.rs
pull/5/head
Wyatt Herkamp 2 years ago
commit cd4fa4f3ab

@ -0,0 +1,41 @@
name: Run checks and tests
on:
workflow_dispatch:
push:
branches: [ main, develop, feature/gh-actions ]
pull_request:
branches: [ main, develop ]
env:
CARGO_TERM_COLOR: always
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
if: ${{ !env.ACT }}
with:
submodules: recursive
- name: Cache build data
if: ${{ !env.ACT }}
uses: actions/cache@v2
with:
path: |
target
~/.cargo/
key: ${{ runner.os }}-cargo-${{ hashFiles('Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-
- name: Fetch
run: cargo fetch
- name: Check
run: cargo check --all-features
- name: Lint
run: cargo clippy -- -D warnings
- name: Test
run : cargo test --all-features

@ -1,6 +1,6 @@
[package]
name = "minecraft-data-rs"
version = "0.4.6"
version = "0.4.7"
authors = ["trivernis <trivernis@protonmail.com>"]
edition = "2018"
readme = "README.md"
@ -15,6 +15,11 @@ thiserror = "1.0.31"
serde_json = "1.0.81"
serde_derive = "1.0.137"
serde = "1.0.137"
include_dir = "0.7.2"
itertools = "0.10.3"
lazy_static = "1.4.0"
include_dir = { version = "0.7.2", optional = true }
itertools = { version = "0.10.3", optional = true }
lazy_static = { version = "1.4.0", optional = true }
[features]
default = ["include-data", "api"]
include-data = ["include_dir", "itertools", "lazy_static"]
api = ["include-data"]

@ -4,6 +4,11 @@ This repository is a rust library to access minecraft data.
The data itself hosted in the [minecraft-data](https://github.com/PrismarineJS/minecraft-data) repository
and included into the library at compile time.
### Excluding the minecraft-data at compile time
By adding `default-features=false` to the dependency in your `Cargo.toml` file, you can exclude the minecraft-data from the library.
## Usage
```rust
@ -21,6 +26,13 @@ for food in food {
}
```
## Features
| Feature | Description |
| -------------|------------------------------------------------------------|
| include-data | includes the whole minecraft-data repository in the binary |
| api | enables the api to query minecraft data |
# License
This project is Licensed under MIT.

@ -33,10 +33,6 @@ impl Items {
/// Returns the items indexed by ID
pub fn items(&self) -> DataResult<HashMap<u32, Item>> {
Ok(self
.items_array()?
.into_iter()
.map(|i| (i.id, i))
.collect())
Ok(self.items_array()?.into_iter().map(|i| (i.id, i)).collect())
}
}

@ -1,3 +1,4 @@
#![cfg(feature = "api")]
use crate::api::versions::{available_versions, versions};
use crate::api::Api;
use crate::models::version::Version;

@ -1,3 +1,4 @@
#![cfg(feature = "api")]
mod datapaths;
use crate::data::datapaths::Datapaths;
@ -21,6 +22,7 @@ pub static ITEMS_FILE: &str = "items";
pub static LOGIN_PACKET_FILE: &str = "loginPacket";
#[allow(unused)]
pub static MATERIALS_FILE: &str = "materials";
#[allow(unused)]
pub static PROTOCOL_FILE: &str = "protocol";
pub static RECIPES_FILE: &str = "recipes";
#[allow(unused)]
@ -39,9 +41,9 @@ pub static VERSIONS_FILE: &str = "versions";
pub fn get_common_file(filename: &str) -> DataResult<String> {
MINECRAFT_DATA
.get_file(format!("pc/common/{}.json", filename))
.ok_or_else(||DataError::NotFoundError(filename.to_string()))?
.ok_or_else(|| DataError::NotFoundError(filename.to_string()))?
.contents_utf8()
.ok_or_else(||DataError::InvalidEncodingError(filename.to_string()))
.ok_or_else(|| DataError::InvalidEncodingError(filename.to_string()))
.map(|d| d.to_string())
}
@ -50,12 +52,11 @@ pub fn get_version_specific_file(version: &Version, filename: &str) -> DataResul
let path = get_path(version, filename)?;
MINECRAFT_DATA
.get_file(format!("{}/{}.json", path, filename))
.ok_or_else(||DataError::NotFoundError(format!(
"{}/{}",
version.minecraft_version, filename
)))?
.ok_or_else(|| {
DataError::NotFoundError(format!("{}/{}", version.minecraft_version, filename))
})?
.contents_utf8()
.ok_or_else(||DataError::InvalidEncodingError(filename.to_string()))
.ok_or_else(|| DataError::InvalidEncodingError(filename.to_string()))
.map(|d| d.to_string())
}
@ -67,20 +68,18 @@ pub fn get_path(version: &Version, filename: &str) -> DataResult<String> {
PATHS
.pc
.get(&version.minecraft_version)
.ok_or_else(||DataError::NotFoundError(version.minecraft_version.clone()))?
.ok_or_else(|| DataError::NotFoundError(version.minecraft_version.clone()))?
.get(filename)
.cloned()
.ok_or_else(||DataError::NotFoundError(filename.to_string()))
.ok_or_else(|| DataError::NotFoundError(filename.to_string()))
}
/// Returns the parsed data paths
fn get_datapaths() -> DataResult<Datapaths> {
let content = MINECRAFT_DATA
.get_file("dataPaths.json")
.ok_or_else(||DataError::NotFoundError("dataPaths.json".to_string()))?
.ok_or_else(|| DataError::NotFoundError("dataPaths.json".to_string()))?
.contents_utf8()
.ok_or_else(||DataError::InvalidEncodingError(
"dataPaths.json".to_string(),
))?;
.ok_or_else(|| DataError::InvalidEncodingError("dataPaths.json".to_string()))?;
serde_json::from_str::<Datapaths>(content).map_err(DataError::from)
}

@ -4,12 +4,16 @@
extern crate serde_derive;
/// Provides data access methods
#[cfg(feature = "api")]
pub mod api;
#[cfg(feature = "include-data")]
pub(crate) mod data;
/// Contains the type definitions for the data
pub mod models;
pub(crate) mod utils;
#[cfg(feature = "api")]
pub use api::Api;
pub use utils::error::DataError;
pub use utils::error::DataResult;

Loading…
Cancel
Save