diff options
| author | mat <github@matdoes.dev> | 2022-06-19 22:01:54 -0500 |
|---|---|---|
| committer | mat <github@matdoes.dev> | 2022-06-19 22:01:54 -0500 |
| commit | c9a070f711a6fdaf505f522cb8809749c9190e38 (patch) | |
| tree | c64f5d6aaa4f489538d2e81814b31b5abca71a9e /azalea-world/src | |
| parent | d674633e856f0ac1683172ad5655ff7026c6eae6 (diff) | |
| download | azalea-drasl-c9a070f711a6fdaf505f522cb8809749c9190e38.tar.xz | |
Fix some clippy warnings
Diffstat (limited to 'azalea-world/src')
| -rw-r--r-- | azalea-world/src/bit_storage.rs | 6 | ||||
| -rw-r--r-- | azalea-world/src/chunk.rs | 10 | ||||
| -rw-r--r-- | azalea-world/src/entity.rs | 8 | ||||
| -rw-r--r-- | azalea-world/src/lib.rs | 7 |
4 files changed, 17 insertions, 14 deletions
diff --git a/azalea-world/src/bit_storage.rs b/azalea-world/src/bit_storage.rs index 0dc81f9a..fcb3f8f9 100644 --- a/azalea-world/src/bit_storage.rs +++ b/azalea-world/src/bit_storage.rs @@ -107,7 +107,7 @@ impl BitStorage { // assert!(bits >= 1 && bits <= 32); if let Some(data) = &data { - if data.len() == 0 { + if data.is_empty() { // TODO: make 0 bit storage actually work return Ok(BitStorage::default()); } @@ -162,7 +162,7 @@ impl BitStorage { // return (int)(var3 >> var5 & this.mask); assert!( - index <= self.size - 1, + index < self.size, "Index {} out of bounds (max is {})", index, self.size - 1 @@ -181,7 +181,7 @@ impl BitStorage { // int var6 = (var1 - var3 * this.valuesPerLong) * this.bits; // this.data[var3] = var4 & ~(this.mask << var6) | ((long)var2 & this.mask) << var6; - assert!(index <= self.size - 1); + assert!(index < self.size); assert!(value <= self.mask); let cell_index = self.cell_index(index as u64); let cell = &mut self.data[cell_index as usize]; diff --git a/azalea-world/src/chunk.rs b/azalea-world/src/chunk.rs index 5de39e52..77fa8786 100644 --- a/azalea-world/src/chunk.rs +++ b/azalea-world/src/chunk.rs @@ -60,10 +60,9 @@ impl ChunkStorage { let chunk_pos = ChunkPos::from(pos); println!("chunk_pos {:?} block_pos {:?}", chunk_pos, pos); let chunk = &self[&chunk_pos]; - match chunk { - Some(chunk) => Some(chunk.lock().unwrap().get(&ChunkBlockPos::from(pos), min_y)), - None => None, - } + chunk + .as_ref() + .map(|chunk| chunk.lock().unwrap().get(&ChunkBlockPos::from(pos), min_y)) } pub fn replace_with_packet_data( @@ -137,8 +136,7 @@ impl Chunk { // TODO: make sure the section exists let section = &self.sections[section_index as usize]; let chunk_section_pos = ChunkSectionBlockPos::from(pos); - let block_state = section.get(chunk_section_pos); - block_state + section.get(chunk_section_pos) } } diff --git a/azalea-world/src/entity.rs b/azalea-world/src/entity.rs index 7077d0c4..2409995c 100644 --- a/azalea-world/src/entity.rs +++ b/azalea-world/src/entity.rs @@ -34,7 +34,7 @@ impl EntityStorage { pub fn remove_by_id(&mut self, id: u32) { if let Some(entity) = self.by_id.remove(&id) { let entity_chunk = ChunkPos::from(entity.pos()); - if let None = self.by_chunk.remove(&entity_chunk) { + if self.by_chunk.remove(&entity_chunk).is_none() { warn!("Tried to remove entity with id {id} from chunk {entity_chunk:?} but it was not found."); } } else { @@ -80,3 +80,9 @@ impl EntityStorage { .insert(entity_id); } } + +impl Default for EntityStorage { + fn default() -> Self { + Self::new() + } +} diff --git a/azalea-world/src/lib.rs b/azalea-world/src/lib.rs index 746143c7..dc538618 100644 --- a/azalea-world/src/lib.rs +++ b/azalea-world/src/lib.rs @@ -6,14 +6,13 @@ mod entity; mod palette; use azalea_block::BlockState; -use azalea_core::{BlockPos, ChunkBlockPos, ChunkPos, ChunkSectionBlockPos, EntityPos}; +use azalea_core::{BlockPos, ChunkPos, EntityPos}; use azalea_entity::Entity; -use azalea_protocol::mc_buf::{McBufReadable, McBufWritable}; pub use bit_storage::BitStorage; pub use chunk::{Chunk, ChunkStorage}; pub use entity::EntityStorage; use std::{ - io::{Read, Write}, + io::Read, ops::{Index, IndexMut}, sync::{Arc, Mutex}, }; @@ -61,7 +60,7 @@ impl World { let entity = self .entity_storage .get_mut_by_id(entity_id) - .ok_or("Moving entity that doesn't exist".to_string())?; + .ok_or_else(|| "Moving entity that doesn't exist".to_string())?; let old_chunk = ChunkPos::from(entity.pos()); let new_chunk = ChunkPos::from(&new_pos); // this is fine because we update the chunk below |
