Compare commits

...

3 Commits
v0.7.2 ... main

17
.github/stale.yml vendored

@ -1,17 +0,0 @@
# Number of days of inactivity before an issue becomes stale
daysUntilStale: 14
# Number of days of inactivity before a stale issue is closed
daysUntilClose: 7
# Issues with these labels will never be considered stale
exemptLabels:
- pinned
- security
# Label to use when marking an issue as stale
staleLabel: wontfix
# Comment to post when marking an issue as stale. Set to `false` to disable
markComment: >
This issue has been automatically marked as stale because it has not had
recent activity. It will be closed if no further activity occurs. Thank you
for your contributions.
# Comment to post when closing a stale issue. Set to `false` to disable
closeComment: false

1
.gitignore vendored

@ -2,3 +2,4 @@
Cargo.lock
.idea
jtd-codegen
minecraft-data

3
.gitmodules vendored

@ -1,3 +0,0 @@
[submodule "minecraft-data"]
path = minecraft-data
url = git@github.com:PrismarineJS/minecraft-data.git

@ -1,14 +1,16 @@
[package]
name = "minecraft-data-rs"
version = "0.7.2"
version = "0.8.1"
authors = ["trivernis <trivernis@protonmail.com>"]
edition = "2018"
edition = "2021"
readme = "README.md"
license = "MIT"
description = "A wrapper for minecraft-data"
repository = "https://github.com/Trivernis/minecraft-data-rs"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[package.metadata]
minecraft_data_repo = "https://github.com/PrismarineJS/minecraft-data.git"
minecraft_data_commit = "46b78398b6f351958e02fbd266424f0ee0ab138b"
[dependencies]
thiserror = "1.0.38"
@ -19,7 +21,14 @@ include_dir = { version = "0.7.3", optional = true }
itertools = { version = "0.10.5", optional = true }
lazy_static = { version = "1.4.0", optional = true }
[build-dependencies]
git2 = {version = "0.18.2", optional = true}
dirs = {version = "5.0.1", optional = true}
cargo_toml = {version = "0.19.1", optional = true}
serde = { version = "1.0.151", features = ["derive"], optional = true }
[features]
default = ["include-data", "api"]
include-data = ["include_dir", "itertools", "lazy_static"]
include-data = ["include_dir", "itertools", "lazy_static", "git2", "dirs", "cargo_toml", "serde/derive"]
api = ["include-data"]

@ -0,0 +1,73 @@
#[cfg(not(feature = "include-data"))]
fn main() {}
#[cfg(feature = "include-data")]
fn main() {
data_repo::init_repo();
}
#[cfg(feature = "include-data")]
mod data_repo {
use std::{env, fs, path::PathBuf};
use cargo_toml::Manifest;
use git2::{Oid, Repository};
use serde::Deserialize;
#[derive(Clone, Debug, Deserialize)]
struct Metadata {
minecraft_data_repo: String,
minecraft_data_commit: String,
}
pub fn init_repo() {
println!("cargo:rerun-if-env-changed=MINECRAFT_DATA_REPO_PATH");
println!("cargo:rerun-if-changed=Cargo.toml");
let manifest = Manifest::<Metadata>::from_path_with_metadata(PathBuf::from("Cargo.toml"))
.expect("Failed to read manifest (Cargo.toml)");
let metadata = manifest
.package
.expect("missing package info in Cargo.toml")
.metadata
.expect("missing package.metadata in Cargo.toml");
let repo_path = env::var("MINECRAFT_DATA_REPO_PATH")
.map(PathBuf::from)
.ok()
.or_else(|| dirs::cache_dir().map(|p| p.join("minecraft-data")))
.unwrap_or_else(|| PathBuf::from("minecraft-data"));
println!(
"cargo:rustc-env=MINECRAFT_DATA_PATH_INTERNAL={}",
repo_path.to_string_lossy()
);
let version_oid = Oid::from_str(&metadata.minecraft_data_commit).expect("invalid oid");
let repo = if repo_path.exists() {
let repo = Repository::open(&repo_path).expect("failed to open git repo");
let head_oid = repo
.head()
.expect("no head found in repo")
.peel_to_commit()
.expect("head is not a commit")
.as_object()
.id();
if head_oid != version_oid {
fs::remove_dir_all(&repo_path).expect("could not delete repository");
Repository::clone(&metadata.minecraft_data_repo, repo_path)
.expect("failed to clone repo")
} else {
repo
}
} else {
Repository::clone(&metadata.minecraft_data_repo, repo_path)
.expect("failed to clone repo")
};
repo.set_head_detached(version_oid)
.expect("failed set head");
repo.checkout_head(None).expect("failed checkout index")
}
}

@ -1 +0,0 @@
Subproject commit 971d49da8395def7f54be6393198ffdebb1d94e1

@ -1,12 +1,11 @@
use crate::api::biomes::Biomes;
use crate::api::blocks::Blocks;
use crate::api::enchantments::Enchantments;
use crate::api::entities::Entities;
use crate::api::foods::Foods;
use crate::api::items::Items;
use crate::api::loot::Loot;
use crate::api::recipes::Recipes;
use crate::api::versions::latest_stable;
pub use crate::api::biomes::Biomes;
pub use crate::api::blocks::Blocks;
pub use crate::api::enchantments::Enchantments;
pub use crate::api::entities::Entities;
pub use crate::api::foods::Foods;
pub use crate::api::items::Items;
pub use crate::api::loot::Loot;
pub use crate::api::recipes::Recipes;
use crate::models::version::Version;
use crate::DataResult;
use std::sync::Arc;
@ -26,14 +25,6 @@ mod recipes;
mod versions;
use crate::api::protocol::Protocol;
pub use biomes::*;
pub use blocks::*;
pub use enchantments::*;
pub use entities::*;
pub use foods::*;
pub use items::*;
pub use loot::*;
pub use recipes::*;
pub use versions::*;
/// A type wrapping access to all the metadata

@ -31,7 +31,7 @@ pub fn test_blocks_by_name() {
let by_name = api.blocks.blocks_by_name().unwrap();
assert!(by_name.get("dirt").is_some());
assert!(by_name.get("stone").is_some());
assert_eq!(by_name.get("grass").unwrap().stack_size, 64)
assert_eq!(by_name.get("grass_block").unwrap().stack_size, 64)
}
}

@ -43,8 +43,7 @@ pub fn latest_stable() -> DataResult<Version> {
})
.map(|(v, _, _, _)| v)
.filter_map(|v| versions_by_minecraft_version().ok()?.remove(&v))
.rev()
.next();
.next_back();
latest.ok_or_else(|| DataError::NotFoundError(String::from("latest version")))
}

@ -6,7 +6,7 @@ use crate::models::version::Version;
use crate::{DataError, DataResult};
use include_dir::Dir;
pub static MINECRAFT_DATA: Dir = include_dir::include_dir!("minecraft-data/data");
pub static MINECRAFT_DATA: Dir = include_dir::include_dir!("$MINECRAFT_DATA_PATH_INTERNAL/data");
pub static BIOMES_FILE: &str = "biomes";
pub static BLOCK_LOOT_FILE: &str = "blockLoot";
@ -69,11 +69,7 @@ pub fn get_path(version: &Version, filename: &str) -> DataResult<String> {
.pc
.get(&version.minecraft_version)
// fallback to major version
.or_else(||
PATHS
.pc
.get(&version.major_version)
)
.or_else(|| PATHS.pc.get(&version.major_version))
.ok_or_else(|| DataError::NotFoundError(version.minecraft_version.clone()))?
.get(filename)
.cloned()

@ -5,10 +5,10 @@ pub struct Biome {
pub name: String,
pub category: String,
pub temperature: f32,
pub precipitation: String,
pub precipitation: Option<String>,
pub depth: Option<f32>,
pub dimension: String,
pub display_name: String,
pub color: u32,
pub rainfall: f32,
pub rainfall: Option<f32>,
}

Loading…
Cancel
Save