Add Item registry
This commit is contained in:
parent
9d3ee1de9b
commit
d6fb4ed121
20161
pumpkin-world/assets/items.json
Normal file
20161
pumpkin-world/assets/items.json
Normal file
File diff suppressed because it is too large
Load Diff
17877
pumpkin-world/assets/registries.json
Normal file
17877
pumpkin-world/assets/registries.json
Normal file
File diff suppressed because it is too large
Load Diff
35
pumpkin-world/src/global_registry.rs
Normal file
35
pumpkin-world/src/global_registry.rs
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
use std::collections::HashMap;
|
||||||
|
|
||||||
|
use lazy_static::lazy_static;
|
||||||
|
|
||||||
|
pub const ITEM_REGISTRY: &str = "minecraft:item";
|
||||||
|
|
||||||
|
const REGISTRY_JSON: &str = include_str!("../assets/registries.json");
|
||||||
|
|
||||||
|
#[derive(serde::Deserialize, Debug, Clone, PartialEq, Eq)]
|
||||||
|
pub struct RegistryElement {
|
||||||
|
default: Option<String>,
|
||||||
|
entries: HashMap<String, u32>,
|
||||||
|
}
|
||||||
|
|
||||||
|
lazy_static! {
|
||||||
|
static ref REGISTRY: HashMap<String, RegistryElement> =
|
||||||
|
serde_json::from_str(REGISTRY_JSON).expect("Could not parse items.json registry.");
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_protocol_id(category: &str, entry: &str) -> u32 {
|
||||||
|
*REGISTRY
|
||||||
|
.get(category)
|
||||||
|
.expect("Invalid Category in registry")
|
||||||
|
.entries
|
||||||
|
.get(entry)
|
||||||
|
.expect("No Entry found")
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_default<'a>(category: &str) -> Option<&'a str> {
|
||||||
|
REGISTRY
|
||||||
|
.get(category)
|
||||||
|
.expect("Invalid Category in registry")
|
||||||
|
.default
|
||||||
|
.as_deref()
|
||||||
|
}
|
||||||
41
pumpkin-world/src/item/item_registry.rs
Normal file
41
pumpkin-world/src/item/item_registry.rs
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
use std::collections::HashMap;
|
||||||
|
|
||||||
|
use lazy_static::lazy_static;
|
||||||
|
|
||||||
|
use crate::global_registry::{self, ITEM_REGISTRY};
|
||||||
|
|
||||||
|
use super::Raritiy;
|
||||||
|
|
||||||
|
const ITEMS_JSON: &str = include_str!("../../assets/items.json");
|
||||||
|
|
||||||
|
#[derive(serde::Deserialize, Debug, Clone, PartialEq, Eq)]
|
||||||
|
pub struct ItemComponents {
|
||||||
|
// TODO: attribute_modifiers
|
||||||
|
// TODO: enchantments: HashMap<>
|
||||||
|
#[serde(rename = "minecraft:lore")]
|
||||||
|
lore: Vec<String>,
|
||||||
|
#[serde(rename = "minecraft:max_stack_size")]
|
||||||
|
max_stack_size: u32,
|
||||||
|
#[serde(rename = "minecraft:rarity")]
|
||||||
|
rarity: Raritiy,
|
||||||
|
#[serde(rename = "minecraft:repair_cost")]
|
||||||
|
repair_cost: u32,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(serde::Deserialize, Debug, Clone, PartialEq, Eq)]
|
||||||
|
struct ItemElement {
|
||||||
|
components: ItemComponents,
|
||||||
|
}
|
||||||
|
|
||||||
|
lazy_static! {
|
||||||
|
static ref ITEMS: HashMap<String, ItemElement> =
|
||||||
|
serde_json::from_str(ITEMS_JSON).expect("Could not parse items.json registry.");
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_item_element(item_id: &str) -> &ItemComponents {
|
||||||
|
&ITEMS.get(item_id).expect("Item not found").components
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_item_protocol_id(item_id: &str) -> u32 {
|
||||||
|
global_registry::get_protocol_id(ITEM_REGISTRY, item_id)
|
||||||
|
}
|
||||||
11
pumpkin-world/src/item/mod.rs
Normal file
11
pumpkin-world/src/item/mod.rs
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
mod item_registry;
|
||||||
|
|
||||||
|
#[derive(serde::Deserialize, Debug, Clone, PartialEq, Eq)]
|
||||||
|
#[serde(rename_all = "lowercase")]
|
||||||
|
/// Item Raritiy
|
||||||
|
pub enum Raritiy {
|
||||||
|
Common,
|
||||||
|
UnCommon,
|
||||||
|
Rare,
|
||||||
|
Epic,
|
||||||
|
}
|
||||||
@ -4,5 +4,7 @@ pub const WORLD_HEIGHT: usize = 384;
|
|||||||
pub const WORLD_Y_START_AT: i32 = -64;
|
pub const WORLD_Y_START_AT: i32 = -64;
|
||||||
pub const DIRECT_PALETTE_BITS: u32 = 15;
|
pub const DIRECT_PALETTE_BITS: u32 = 15;
|
||||||
mod block;
|
mod block;
|
||||||
|
mod global_registry;
|
||||||
|
mod item;
|
||||||
pub mod radial_chunk_iterator;
|
pub mod radial_chunk_iterator;
|
||||||
mod world;
|
mod world;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user