aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormat <github@matdoes.dev>2022-06-25 17:37:29 -0500
committermat <github@matdoes.dev>2022-06-25 17:37:29 -0500
commite8deda5d2e45eb634700614009cbcc5b35949e26 (patch)
treedab321d33c66e20e8b558d9777550a3d27cd4b59
parent978880b756aa052226f77c21e8e9de9b40070152 (diff)
downloadazalea-drasl-e8deda5d2e45eb634700614009cbcc5b35949e26.tar.xz
clippo
-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
-rw-r--r--azalea-buf/src/read.rs2
-rw-r--r--azalea-buf/src/write.rs2
-rwxr-xr-xazalea-chat/src/translatable_component.rs2
-rw-r--r--azalea-client/src/client.rs6
-rw-r--r--azalea-client/src/movement.rs22
-rw-r--r--azalea-core/src/position.rs12
-rw-r--r--azalea-protocol/src/packets/game/clientbound_section_blocks_update_packet.rs9
-rwxr-xr-xazalea-protocol/src/packets/mod.rs6
-rw-r--r--bot/src/main.rs2
12 files changed, 48 insertions, 56 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)
diff --git a/azalea-buf/src/read.rs b/azalea-buf/src/read.rs
index 92c4d79b..684404bc 100644
--- a/azalea-buf/src/read.rs
+++ b/azalea-buf/src/read.rs
@@ -231,7 +231,7 @@ impl McBufVarReadable for i64 {
for i in 0..8 {
buf.read_exact(&mut buffer)
.map_err(|_| "Invalid VarLong".to_string())?;
- ans |= ((buffer[0] & 0b0111_1111) as i64) << 7 * i;
+ ans |= ((buffer[0] & 0b0111_1111) as i64) << (7 * i);
if buffer[0] & 0b1000_0000 == 0 {
break;
}
diff --git a/azalea-buf/src/write.rs b/azalea-buf/src/write.rs
index 38ddcf49..df7f56e0 100644
--- a/azalea-buf/src/write.rs
+++ b/azalea-buf/src/write.rs
@@ -191,7 +191,7 @@ impl McBufVarWritable for i64 {
}
// this only writes a single byte, so write_all isn't necessary
// the let _ = is so clippy doesn't complain
- let _ = buf.write(&mut buffer)?;
+ let _ = buf.write(&buffer)?;
}
Ok(())
}
diff --git a/azalea-chat/src/translatable_component.rs b/azalea-chat/src/translatable_component.rs
index fdef6465..6ffc5ccf 100755
--- a/azalea-chat/src/translatable_component.rs
+++ b/azalea-chat/src/translatable_component.rs
@@ -25,7 +25,7 @@ impl TranslatableComponent {
}
pub fn read(&self) -> Result<String, fmt::Error> {
- let template = azalea_language::get(&self.key).unwrap_or_else(|| &self.key);
+ let template = azalea_language::get(&self.key).unwrap_or(&self.key);
// decode the % things
let mut result = String::new();
diff --git a/azalea-client/src/client.rs b/azalea-client/src/client.rs
index 9b3f7cdf..e2967a10 100644
--- a/azalea-client/src/client.rs
+++ b/azalea-client/src/client.rs
@@ -155,8 +155,8 @@ impl Client {
// we got the GameConnection, so the server is now connected :)
let client = Client {
- game_profile: game_profile.clone(),
- conn: conn.clone(),
+ game_profile,
+ conn,
player: Arc::new(Mutex::new(Player::default())),
dimension: Arc::new(Mutex::new(None)),
};
@@ -167,7 +167,7 @@ impl Client {
// read the error to see where the issue is
// you might be able to just drop the lock or put it in its own scope to fix
tokio::spawn(Self::protocol_loop(client.clone(), tx.clone()));
- tokio::spawn(Self::game_tick_loop(client.clone(), tx.clone()));
+ tokio::spawn(Self::game_tick_loop(client.clone(), tx));
Ok((client, rx))
}
diff --git a/azalea-client/src/movement.rs b/azalea-client/src/movement.rs
index 5247e0f0..4f99984f 100644
--- a/azalea-client/src/movement.rs
+++ b/azalea-client/src/movement.rs
@@ -5,20 +5,20 @@ use azalea_protocol::packets::game::serverbound_move_player_packet_pos_rot::Serv
impl Client {
/// Set the client's position to the given coordinates.
pub async fn move_to(&mut self, new_pos: EntityPos) -> Result<(), String> {
- let mut dimension_lock = self.dimension.lock().unwrap();
- let dimension = dimension_lock.as_mut().unwrap();
+ {
+ let mut dimension_lock = self.dimension.lock().unwrap();
+ let dimension = dimension_lock.as_mut().unwrap();
- let player_lock = self.player.lock().unwrap();
+ let player_lock = self.player.lock().unwrap();
- let player_id = if let Some(player_lock) = player_lock.entity(dimension) {
- player_lock.id
- } else {
- return Err("Player entity not found".to_string());
- };
+ let player_id = if let Some(player_lock) = player_lock.entity(dimension) {
+ player_lock.id
+ } else {
+ return Err("Player entity not found".to_string());
+ };
- dimension.move_entity(player_id, new_pos)?;
- drop(dimension_lock);
- drop(player_lock);
+ dimension.move_entity(player_id, new_pos)?;
+ }
self.conn
.lock()
diff --git a/azalea-core/src/position.rs b/azalea-core/src/position.rs
index 195558e8..64075aa7 100644
--- a/azalea-core/src/position.rs
+++ b/azalea-core/src/position.rs
@@ -182,9 +182,9 @@ impl From<ChunkSectionPos> for ChunkPos {
impl From<&BlockPos> for ChunkBlockPos {
fn from(pos: &BlockPos) -> Self {
ChunkBlockPos {
- x: pos.x.rem_euclid(16).abs() as u8,
+ x: pos.x.rem_euclid(16).unsigned_abs() as u8,
y: pos.y,
- z: pos.z.rem_euclid(16).abs() as u8,
+ z: pos.z.rem_euclid(16).unsigned_abs() as u8,
}
}
}
@@ -192,9 +192,9 @@ impl From<&BlockPos> for ChunkBlockPos {
impl From<&BlockPos> for ChunkSectionBlockPos {
fn from(pos: &BlockPos) -> Self {
ChunkSectionBlockPos {
- x: pos.x.rem(16).abs() as u8,
- y: pos.y.rem(16).abs() as u8,
- z: pos.z.rem(16).abs() as u8,
+ x: pos.x.rem(16).unsigned_abs() as u8,
+ y: pos.y.rem(16).unsigned_abs() as u8,
+ z: pos.z.rem(16).unsigned_abs() as u8,
}
}
}
@@ -203,7 +203,7 @@ impl From<&ChunkBlockPos> for ChunkSectionBlockPos {
fn from(pos: &ChunkBlockPos) -> Self {
ChunkSectionBlockPos {
x: pos.x,
- y: pos.y.rem(16).abs() as u8,
+ y: pos.y.rem(16).unsigned_abs() as u8,
z: pos.z,
}
}
diff --git a/azalea-protocol/src/packets/game/clientbound_section_blocks_update_packet.rs b/azalea-protocol/src/packets/game/clientbound_section_blocks_update_packet.rs
index 60ebe26c..24f34f6e 100644
--- a/azalea-protocol/src/packets/game/clientbound_section_blocks_update_packet.rs
+++ b/azalea-protocol/src/packets/game/clientbound_section_blocks_update_packet.rs
@@ -22,15 +22,12 @@ impl McBufReadable for BlockStateWithPosition {
let data = u64::var_read_from(buf)?;
let position_part = data & 4095;
let state = (data >> 12) as u32;
- let position = ChunkSectionBlockPos {
+ let pos = ChunkSectionBlockPos {
x: (position_part >> 8 & 15) as u8,
- y: (position_part >> 0 & 15) as u8,
+ y: (position_part & 15) as u8,
z: (position_part >> 4 & 15) as u8,
};
- Ok(BlockStateWithPosition {
- pos: position,
- state: state,
- })
+ Ok(BlockStateWithPosition { pos, state })
}
}
diff --git a/azalea-protocol/src/packets/mod.rs b/azalea-protocol/src/packets/mod.rs
index 2f439cd5..cf405e98 100755
--- a/azalea-protocol/src/packets/mod.rs
+++ b/azalea-protocol/src/packets/mod.rs
@@ -31,9 +31,9 @@ impl ConnectionProtocol {
#[derive(Clone, Debug)]
pub enum Packet {
- Game(game::GamePacket),
- Handshake(handshake::HandshakePacket),
- Login(login::LoginPacket),
+ Game(Box<game::GamePacket>),
+ Handshake(Box<handshake::HandshakePacket>),
+ Login(Box<login::LoginPacket>),
Status(Box<status::StatusPacket>),
}
diff --git a/bot/src/main.rs b/bot/src/main.rs
index 948ca1d6..3ff30908 100644
--- a/bot/src/main.rs
+++ b/bot/src/main.rs
@@ -44,7 +44,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let dimension = dimension_lock.as_ref().unwrap();
let player = client.player.lock().unwrap();
let entity = player
- .entity(&dimension)
+ .entity(dimension)
.expect("Player entity is not in world");
entity.pos().add_y(0.5)
};