aboutsummaryrefslogtreecommitdiff
path: root/azalea-block
diff options
context:
space:
mode:
authormat <27899617+mat-1@users.noreply.github.com>2022-07-07 05:58:44 +0000
committerGitHub <noreply@github.com>2022-07-07 05:58:44 +0000
commit31e5629ce1c8267802bbcb9d03b60a299d474e59 (patch)
tree5968b48af9b0c30149e908b043966c41dda0a61d /azalea-block
parent27edd4f578e7b64fdaacefa26f691e2148707a8c (diff)
parent37d854c799236650da3deb025d8b32693531a27f (diff)
downloadazalea-drasl-31e5629ce1c8267802bbcb9d03b60a299d474e59.tar.xz
Merge branch 'main' into 1.19.1
Diffstat (limited to 'azalea-block')
-rw-r--r--azalea-block/block-macros/src/lib.rs20
-rw-r--r--azalea-block/block-macros/src/utils.rs15
-rw-r--r--azalea-block/src/lib.rs6
3 files changed, 18 insertions, 23 deletions
diff --git a/azalea-block/block-macros/src/lib.rs b/azalea-block/block-macros/src/lib.rs
index 6206bb65..01ce556d 100644
--- a/azalea-block/block-macros/src/lib.rs
+++ b/azalea-block/block-macros/src/lib.rs
@@ -36,7 +36,7 @@ struct BlockDefinition {
properties_and_defaults: Vec<PropertyAndDefault>,
}
impl PropertyAndDefault {
- fn into_property_with_name_and_default(&self, name: String) -> PropertyWithNameAndDefault {
+ fn as_property_with_name_and_default(&self, name: String) -> PropertyWithNameAndDefault {
PropertyWithNameAndDefault {
name,
struct_name: self.struct_name.clone(),
@@ -110,11 +110,7 @@ impl Parse for BlockDefinition {
let mut properties_and_defaults = Vec::new();
- loop {
- let property = match content.parse() {
- Ok(property) => property,
- Err(_) => break,
- };
+ while let Ok(property) = content.parse() {
content.parse::<Token![=]>()?;
let property_default = content.parse()?;
properties_and_defaults.push(PropertyAndDefault {
@@ -248,7 +244,7 @@ pub fn make_block_states(input: TokenStream) -> TokenStream {
for property_name in block_property_names {
let property_variants = properties_map
.get(property_name)
- .expect(format!("Property '{}' not found", property_name).as_str())
+ .unwrap_or_else(|| panic!("Property '{}' not found", property_name))
.clone();
block_properties_vec.push(property_variants);
}
@@ -274,13 +270,13 @@ pub fn make_block_states(input: TokenStream) -> TokenStream {
};
let mut property_name = property_struct_names_to_names
.get(&property.struct_name.to_string())
- .expect(format!("Property '{}' is bad", property.struct_name).as_str())
+ .unwrap_or_else(|| panic!("Property '{}' is bad", property.struct_name))
.clone();
if let Some(index) = index {
property_name.push_str(&format!("_{}", &index.to_string()));
}
properties_with_name
- .push(property.into_property_with_name_and_default(property_name.clone()));
+ .push(property.as_property_with_name_and_default(property_name.clone()));
}
// pub face: properties::Face,
@@ -297,7 +293,7 @@ pub fn make_block_states(input: TokenStream) -> TokenStream {
{
// let property_name_snake =
// Ident::new(&property.to_string(), proc_macro2::Span::call_site());
- let name_ident = Ident::new(&name, proc_macro2::Span::call_site());
+ let name_ident = Ident::new(name, proc_macro2::Span::call_site());
block_struct_fields.extend(quote! {
pub #name_ident: #struct_name,
})
@@ -317,7 +313,7 @@ pub fn make_block_states(input: TokenStream) -> TokenStream {
let first_state_id = state_id;
// if there's no properties, then the block is just a single state
- if block_properties_vec.len() == 0 {
+ if block_properties_vec.is_empty() {
block_state_enum_variants.extend(quote! {
#block_name_pascal_case,
});
@@ -418,7 +414,7 @@ pub fn make_block_states(input: TokenStream) -> TokenStream {
let block_behavior = &block.behavior;
let block_id = block.name.to_string();
- let from_block_to_state_match = if block.properties_and_defaults.len() > 0 {
+ let from_block_to_state_match = if !block.properties_and_defaults.is_empty() {
quote! {
match b {
#from_block_to_state_match_inner
diff --git a/azalea-block/block-macros/src/utils.rs b/azalea-block/block-macros/src/utils.rs
index 019fd60f..82095d86 100644
--- a/azalea-block/block-macros/src/utils.rs
+++ b/azalea-block/block-macros/src/utils.rs
@@ -1,6 +1,6 @@
pub fn combinations_of<T: Clone>(items: &[Vec<T>]) -> Vec<Vec<T>> {
let mut combinations = Vec::new();
- if items.len() == 0 {
+ if items.is_empty() {
return combinations;
};
if items.len() == 1 {
@@ -13,8 +13,7 @@ pub fn combinations_of<T: Clone>(items: &[Vec<T>]) -> Vec<Vec<T>> {
for i in 0..items[0].len() {
let item = &items[0][i];
for other_combinations in combinations_of(&items[1..]) {
- let mut combination = Vec::new();
- combination.push(item.clone());
+ let mut combination = vec![item.clone()];
combination.extend(other_combinations);
combinations.push(combination);
}
@@ -29,13 +28,11 @@ pub fn to_pascal_case(s: &str) -> String {
for c in s.chars() {
if c == '_' {
prev_was_underscore = true;
+ } else if prev_was_underscore {
+ result.push(c.to_ascii_uppercase());
+ prev_was_underscore = false;
} else {
- if prev_was_underscore {
- result.push(c.to_ascii_uppercase());
- prev_was_underscore = false;
- } else {
- result.push(c);
- }
+ result.push(c);
}
}
result
diff --git a/azalea-block/src/lib.rs b/azalea-block/src/lib.rs
index a6de1e92..f07b1bce 100644
--- a/azalea-block/src/lib.rs
+++ b/azalea-block/src/lib.rs
@@ -7,8 +7,10 @@ pub use blocks::*;
use std::mem;
impl BlockState {
- /// Transmutes a u32 to a block state. UB if the value is not a valid block
- /// state.
+ /// Transmutes a u32 to a block state.
+ ///
+ /// # Safety
+ /// The `state_id` should be a valid block state.
#[inline]
pub unsafe fn from_u32_unsafe(state_id: u32) -> Self {
mem::transmute::<u32, BlockState>(state_id)