Removed lazy_static!{} in favor of LazyLock
This commit is contained in:
parent
e4fd015265
commit
8a2e7cada8
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -2018,7 +2018,6 @@ dependencies = [
|
|||||||
"flate2",
|
"flate2",
|
||||||
"futures",
|
"futures",
|
||||||
"itertools 0.13.0",
|
"itertools 0.13.0",
|
||||||
"lazy_static",
|
|
||||||
"log",
|
"log",
|
||||||
"num-derive",
|
"num-derive",
|
||||||
"num-traits",
|
"num-traits",
|
||||||
|
|||||||
@ -15,7 +15,6 @@ thiserror = "1.0.63"
|
|||||||
futures = "0.3.30"
|
futures = "0.3.30"
|
||||||
flate2 = "1.0.33"
|
flate2 = "1.0.33"
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
lazy_static = "1.5.0"
|
|
||||||
serde_json = "1.0"
|
serde_json = "1.0"
|
||||||
static_assertions = "1.1.0"
|
static_assertions = "1.1.0"
|
||||||
log.workspace = true
|
log.workspace = true
|
||||||
|
|||||||
@ -1,15 +1,13 @@
|
|||||||
use std::collections::HashMap;
|
use std::{collections::HashMap, sync::LazyLock};
|
||||||
|
|
||||||
use lazy_static::lazy_static;
|
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
|
||||||
use super::block_id::BlockId;
|
use super::block_id::BlockId;
|
||||||
|
|
||||||
lazy_static! {
|
pub static BLOCKS: LazyLock<HashMap<String, RegistryBlockType>> = LazyLock::new(|| {
|
||||||
pub static ref BLOCKS: HashMap<String, RegistryBlockType> =
|
serde_json::from_str(include_str!("../../assets/blocks.json"))
|
||||||
serde_json::from_str(include_str!("../../assets/blocks.json"))
|
.expect("Could not parse block.json registry.")
|
||||||
.expect("Could not parse block.json registry.");
|
});
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Deserialize, Debug, Clone, PartialEq, Eq)]
|
#[derive(Deserialize, Debug, Clone, PartialEq, Eq)]
|
||||||
pub struct RegistryBlockDefinition {
|
pub struct RegistryBlockDefinition {
|
||||||
|
|||||||
@ -1,6 +1,4 @@
|
|||||||
use std::collections::HashMap;
|
use std::{collections::HashMap, sync::LazyLock};
|
||||||
|
|
||||||
use lazy_static::lazy_static;
|
|
||||||
|
|
||||||
pub const ITEM_REGISTRY: &str = "minecraft:item";
|
pub const ITEM_REGISTRY: &str = "minecraft:item";
|
||||||
|
|
||||||
@ -12,10 +10,9 @@ pub struct RegistryElement {
|
|||||||
pub entries: HashMap<String, HashMap<String, u32>>,
|
pub entries: HashMap<String, HashMap<String, u32>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
lazy_static! {
|
pub static REGISTRY: LazyLock<HashMap<String, RegistryElement>> = LazyLock::new(|| {
|
||||||
pub static ref REGISTRY: HashMap<String, RegistryElement> =
|
serde_json::from_str(REGISTRY_JSON).expect("Could not parse registry.json registry.")
|
||||||
serde_json::from_str(REGISTRY_JSON).expect("Could not parse registry.json registry.");
|
});
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_protocol_id(category: &str, entry: &str) -> u32 {
|
pub fn get_protocol_id(category: &str, entry: &str) -> u32 {
|
||||||
*REGISTRY
|
*REGISTRY
|
||||||
|
|||||||
@ -1,13 +1,14 @@
|
|||||||
use std::collections::HashMap;
|
use std::{collections::HashMap, sync::LazyLock};
|
||||||
|
|
||||||
use lazy_static::lazy_static;
|
|
||||||
|
|
||||||
use crate::global_registry::{self, ITEM_REGISTRY};
|
|
||||||
|
|
||||||
use super::Rarity;
|
use super::Rarity;
|
||||||
|
use crate::global_registry::{self, ITEM_REGISTRY};
|
||||||
|
|
||||||
const ITEMS_JSON: &str = include_str!("../../assets/items.json");
|
const ITEMS_JSON: &str = include_str!("../../assets/items.json");
|
||||||
|
|
||||||
|
pub static ITEMS: LazyLock<HashMap<String, ItemElement>> = LazyLock::new(|| {
|
||||||
|
serde_json::from_str(ITEMS_JSON).expect("Could not parse items.json registry.")
|
||||||
|
});
|
||||||
|
|
||||||
#[derive(serde::Deserialize, Debug, Clone, PartialEq, Eq)]
|
#[derive(serde::Deserialize, Debug, Clone, PartialEq, Eq)]
|
||||||
pub struct ItemComponents {
|
pub struct ItemComponents {
|
||||||
// TODO: attribute_modifiers
|
// TODO: attribute_modifiers
|
||||||
@ -27,11 +28,6 @@ pub struct ItemElement {
|
|||||||
components: ItemComponents,
|
components: ItemComponents,
|
||||||
}
|
}
|
||||||
|
|
||||||
lazy_static! {
|
|
||||||
pub static ref ITEMS: HashMap<String, ItemElement> =
|
|
||||||
serde_json::from_str(ITEMS_JSON).expect("Could not parse items.json registry.");
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
pub fn get_item_element(item_id: &str) -> &ItemComponents {
|
pub fn get_item_element(item_id: &str) -> &ItemComponents {
|
||||||
&ITEMS.get(item_id).expect("Item not found").components
|
&ITEMS.get(item_id).expect("Item not found").components
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user