Skip to content

Commit

Permalink
fix clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
user622628252416 committed Dec 1, 2024
1 parent 490c82f commit cdf2498
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
23 changes: 16 additions & 7 deletions pumpkin-macros/src/block.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use std::collections::HashMap;
use std::str::FromStr;
use std::sync::LazyLock;

use proc_macro::TokenStream;
Expand Down Expand Up @@ -43,8 +42,12 @@ pub(super) fn block_id_impl(item: TokenStream) -> TokenStream {
.get(&identifier)
.expect(&format!("block {identifier:?} does not exist"));

// integer literal without type information
TokenStream::from_str(&format!("{id}")).unwrap()
let id = *id as u16;

quote::quote! {
#id
}
.into()
}

pub(super) fn block_state_id_impl(item: TokenStream) -> TokenStream {
Expand All @@ -57,8 +60,10 @@ pub(super) fn block_state_id_impl(item: TokenStream) -> TokenStream {
let block = &BLOCKS[*block_id];
let id = block.default_state_id;

// integer literal without type information
TokenStream::from_str(&format!("{id}")).unwrap()
quote::quote! {
#id
}
.into()
}

pub(super) fn block_entity_id_impl(item: TokenStream) -> TokenStream {
Expand All @@ -68,6 +73,10 @@ pub(super) fn block_entity_id_impl(item: TokenStream) -> TokenStream {
.get(&identifier)
.expect(&format!("block enitity {identifier:?} does not exist"));

// integer literal without type information
TokenStream::from_str(&format!("{id}")).unwrap()
let id = *id as u32;

quote::quote! {
#id
}
.into()
}
2 changes: 1 addition & 1 deletion pumpkin-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ pub fn block_entity_id(item: TokenStream) -> TokenStream {
use std::hash::{DefaultHasher, Hash, Hasher};
let mut hasher = DefaultHasher::new();
item.to_string().hash(&mut hasher);
let id = hasher.finish() as u16;
let id = hasher.finish() as u32;
quote::quote! { #id }.into()
}

Expand Down
2 changes: 0 additions & 2 deletions pumpkin-world/src/block/block_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,6 @@ pub fn get_shapes_by_block_state(block_state_id: u16) -> Option<Vec<&'static Sha

#[cfg(test)]
mod tests {
use std::u16;

use pumpkin_macros::block_entity_id;
use pumpkin_macros::block_id;
use pumpkin_macros::block_state_id;
Expand Down

0 comments on commit cdf2498

Please sign in to comment.