mirror of
https://github.com/mat-1/azalea.git
synced 2025-08-02 14:26:04 +00:00
make azalea-registry crate
This commit is contained in:
parent
029ae0e567
commit
ae64d316e3
3 changed files with 44 additions and 0 deletions
8
azalea-registry/Cargo.toml
Normal file
8
azalea-registry/Cargo.toml
Normal file
|
@ -0,0 +1,8 @@
|
|||
[package]
|
||||
name = "azalea-registry"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
3
azalea-registry/README.md
Normal file
3
azalea-registry/README.md
Normal file
|
@ -0,0 +1,3 @@
|
|||
# Azalea Registry
|
||||
|
||||
Minecraft has a concept called "registries", which are primarily used to determine ids in the protocol. The contents of this crate are automatically generated using Minecraft's built-in data generator.
|
33
azalea-registry/src/lib.rs
Normal file
33
azalea-registry/src/lib.rs
Normal file
|
@ -0,0 +1,33 @@
|
|||
enum Block {
|
||||
Air = 0,
|
||||
Stone,
|
||||
}
|
||||
|
||||
impl Block {
|
||||
/// Transmutes a u32 to a Block.
|
||||
///
|
||||
/// # Safety
|
||||
/// The `id` should be less than {}.
|
||||
#[inline]
|
||||
pub unsafe fn from_u32_unchecked(id: u32) -> Self {
|
||||
mem::transmute::<u32, Block>(id)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn is_valid_id(id: u32) -> bool {
|
||||
id <= 100
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<u32> for Block {
|
||||
type Error = ();
|
||||
|
||||
/// Safely converts a state id to a block state.
|
||||
fn try_from(id: u32) -> Result<Self, Self::Error> {
|
||||
if Self::is_valid_state(state_id) {
|
||||
Ok(unsafe { Self::from_u32_unsafe(state_id) })
|
||||
} else {
|
||||
Err(())
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue