online Minecraft written book viewer

chore: appease clippy

kokirigla.de 899c4852 ed63c51e

verified
+64 -81
+5 -2
nara_core/src/book.rs
··· 107 107 fn deserialize_pages<'de, D: Deserializer<'de>>( 108 108 deserializer: D, 109 109 ) -> Result<Vec<Component>, D::Error> { 110 - Vec::<ComponentObject>::deserialize(deserializer) 111 - .map(|objs| objs.into_iter().map(|o| Component::Object(Box::new(o))).collect()) 110 + Vec::<ComponentObject>::deserialize(deserializer).map(|objs| { 111 + objs.into_iter() 112 + .map(|o| Component::Object(Box::new(o))) 113 + .collect() 114 + }) 112 115 } 113 116 114 117 impl BookContent {
+2 -8
nara_core/src/lib.rs
··· 13 13 pub mod uuid; 14 14 15 15 #[serde_as] 16 - #[derive(Debug, Serialize, Deserialize)] 16 + #[derive(Debug, Default, Serialize, Deserialize)] 17 17 pub struct BookContainer { 18 18 #[serde_as(as = "HashMap<Hex, _>")] 19 19 books: HashMap<BookHash, Book>, 20 20 } 21 21 22 22 impl BookContainer { 23 - pub fn new() -> Self { 24 - Self { 25 - books: HashMap::new(), 26 - } 27 - } 28 - 29 23 /// Opens an existing container at `path`, or returns an empty one if the 30 24 /// file does not exist yet. 31 25 pub fn open_or_new<P>(path: P) -> nara_io::Result<BookContainer> ··· 36 30 let buffer = std::fs::read(path)?; 37 31 nara_io::read_json_gz(&buffer) 38 32 } else { 39 - Ok(Self::new()) 33 + Ok(Self::default()) 40 34 } 41 35 } 42 36
+2 -3
nara_mcr/src/lib.rs
··· 42 42 let mut chunks: Vec<Option<C>> = 43 43 (0..CHUNK_COUNT).map(|_| None).collect(); 44 44 45 - for i in 0..CHUNK_COUNT { 45 + for (i, chunk) in chunks.iter_mut().enumerate().take(CHUNK_COUNT) { 46 46 let x = (i % REGION_SIDE) as u8; 47 47 let z = (i / REGION_SIDE) as u8; 48 48 ··· 82 82 83 83 let decompressed = decompress(compressed, compression, x, z)?; 84 84 let mut cursor = Cursor::new(decompressed.as_slice()); 85 - chunks[i] = 86 - Some(crab_nbt::serde::de::from_cursor::<C>(&mut cursor)?); 85 + *chunk = Some(crab_nbt::serde::de::from_cursor::<C>(&mut cursor)?); 87 86 } 88 87 89 88 Ok(Self { chunks })
+40 -42
nara_slurper_1_12_core/src/item.rs
··· 175 175 damage: i16, 176 176 tag: Option<RawTag>, 177 177 ) -> ItemStack { 178 - if id == "minecraft:written_book" { 179 - if let Some(ref t) = tag { 180 - if let (Some(author), Some(title), Some(pages)) = 181 - (t.author.clone(), t.title.clone(), t.pages.clone()) 182 - { 183 - let generation = t 184 - .generation 185 - .and_then(|g| BookGeneration::try_from(g).ok()) 186 - .unwrap_or_default(); 187 - let resolved = t.resolved.map(|b| b != 0).unwrap_or(false); 188 - let display = t.display.clone(); 189 - return ItemStack::WrittenBook(WrittenBookStack { 190 - count, 191 - damage, 192 - id, 193 - tag: WrittenBookTag { 194 - base: BaseTag { display }, 195 - author, 196 - title, 197 - generation, 198 - resolved, 199 - pages: pages 200 - .into_iter() 201 - .map(|s| parse_component_from_str(&s)) 202 - .collect(), 203 - }, 204 - }); 205 - } 206 - } 178 + if id == "minecraft:written_book" 179 + && let Some(ref t) = tag 180 + && let (Some(author), Some(title), Some(pages)) = 181 + (t.author.clone(), t.title.clone(), t.pages.clone()) 182 + { 183 + let generation = t 184 + .generation 185 + .and_then(|g| BookGeneration::try_from(g).ok()) 186 + .unwrap_or_default(); 187 + let resolved = t.resolved.map(|b| b != 0).unwrap_or(false); 188 + let display = t.display.clone(); 189 + return ItemStack::WrittenBook(WrittenBookStack { 190 + count, 191 + damage, 192 + id, 193 + tag: WrittenBookTag { 194 + base: BaseTag { display }, 195 + author, 196 + title, 197 + generation, 198 + resolved, 199 + pages: pages 200 + .into_iter() 201 + .map(|s| parse_component_from_str(&s)) 202 + .collect(), 203 + }, 204 + }); 207 205 } 208 206 209 - if let Some(ref t) = tag { 210 - if let Some(ref be) = t.block_entity { 211 - let display = t.display.clone(); 212 - return ItemStack::BlockEntity(BlockEntityStack { 213 - count, 214 - damage, 215 - id, 216 - tag: BlockEntityTag { 217 - base: BaseTag { display }, 218 - block_entity: be.clone(), 219 - }, 220 - }); 221 - } 207 + if let Some(ref t) = tag 208 + && let Some(ref be) = t.block_entity 209 + { 210 + let display = t.display.clone(); 211 + return ItemStack::BlockEntity(BlockEntityStack { 212 + count, 213 + damage, 214 + id, 215 + tag: BlockEntityTag { 216 + base: BaseTag { display }, 217 + block_entity: be.clone(), 218 + }, 219 + }); 222 220 } 223 221 224 222 ItemStack::Base(BaseItemStack { count, damage, id })
+1 -1
nara_slurper_1_12_infinity/src/lib.rs
··· 19 19 P: AsRef<Path>, 20 20 { 21 21 let buffer = std::fs::read(path)?; 22 - Ok(nara_io::read_nbt(&buffer)?) 22 + nara_io::read_nbt(&buffer) 23 23 } 24 24 25 25 pub fn slurp(&self) -> Vec<Book> {
+2 -3
nara_slurper_1_12_world/src/lib.rs
··· 131 131 for e in &chunk.level.entities { 132 132 match e { 133 133 Entity::ItemHolder(item_holder_entity) => { 134 - let mut fake_inventory = Vec::with_capacity(1); 135 - fake_inventory.push(InventoryItemStack { 134 + let fake_inventory = vec![InventoryItemStack { 136 135 slot: 0, 137 136 item: item_holder_entity.item.clone(), 138 - }); 137 + }]; 139 138 let slurped = extract_books_with_source( 140 139 &fake_inventory, 141 140 None,
+12 -20
nara_slurper_1_12_world/tests/snapshots/data__playerdata.snap
··· 9 9 InventoryItemStack { 10 10 item: WrittenBook( 11 11 WrittenBookStack { 12 - base: BaseItemStack { 13 - count: 1, 14 - damage: 0, 15 - id: "minecraft:written_book", 16 - }, 12 + count: 1, 13 + damage: 0, 14 + id: "minecraft:written_book", 17 15 tag: WrittenBookTag { 18 16 base: BaseTag { 19 17 display: None, ··· 144 142 InventoryItemStack { 145 143 item: BlockEntity( 146 144 BlockEntityStack { 147 - base: BaseItemStack { 148 - count: 1, 149 - damage: 0, 150 - id: "minecraft:pink_shulker_box", 151 - }, 145 + count: 1, 146 + damage: 0, 147 + id: "minecraft:pink_shulker_box", 152 148 tag: BlockEntityTag { 153 149 base: BaseTag { 154 150 display: None, ··· 158 154 InventoryItemStack { 159 155 item: WrittenBook( 160 156 WrittenBookStack { 161 - base: BaseItemStack { 162 - count: 1, 163 - damage: 0, 164 - id: "minecraft:written_book", 165 - }, 157 + count: 1, 158 + damage: 0, 159 + id: "minecraft:written_book", 166 160 tag: WrittenBookTag { 167 161 base: BaseTag { 168 162 display: None, ··· 255 249 InventoryItemStack { 256 250 item: WrittenBook( 257 251 WrittenBookStack { 258 - base: BaseItemStack { 259 - count: 1, 260 - damage: 0, 261 - id: "minecraft:written_book", 262 - }, 252 + count: 1, 253 + damage: 0, 254 + id: "minecraft:written_book", 263 255 tag: WrittenBookTag { 264 256 base: BaseTag { 265 257 display: None,
-2
src/library.rs
··· 8 8 use std::{cell::RefCell, num::NonZeroUsize}; 9 9 use strsim::jaro_winkler; 10 10 11 - 12 11 pub type BookId = usize; 13 12 14 13 /// In-memory index of all books with lookup and fuzzy search helpers. ··· 373 372 pub fn source_for_hash(&self, hash: &BookHash) -> Option<&BookSource> { 374 373 self.source_by_hash.get(hash) 375 374 } 376 - 377 375 } 378 376 379 377 /// Lowercases and normalizes a query string.