···1313pub mod uuid;
14141515#[serde_as]
1616-#[derive(Debug, Serialize, Deserialize)]
1616+#[derive(Debug, Default, Serialize, Deserialize)]
1717pub struct BookContainer {
1818 #[serde_as(as = "HashMap<Hex, _>")]
1919 books: HashMap<BookHash, Book>,
2020}
21212222impl BookContainer {
2323- pub fn new() -> Self {
2424- Self {
2525- books: HashMap::new(),
2626- }
2727- }
2828-2923 /// Opens an existing container at `path`, or returns an empty one if the
3024 /// file does not exist yet.
3125 pub fn open_or_new<P>(path: P) -> nara_io::Result<BookContainer>
···3630 let buffer = std::fs::read(path)?;
3731 nara_io::read_json_gz(&buffer)
3832 } else {
3939- Ok(Self::new())
3333+ Ok(Self::default())
4034 }
4135 }
4236
+2-3
nara_mcr/src/lib.rs
···4242 let mut chunks: Vec<Option<C>> =
4343 (0..CHUNK_COUNT).map(|_| None).collect();
44444545- for i in 0..CHUNK_COUNT {
4545+ for (i, chunk) in chunks.iter_mut().enumerate().take(CHUNK_COUNT) {
4646 let x = (i % REGION_SIDE) as u8;
4747 let z = (i / REGION_SIDE) as u8;
4848···82828383 let decompressed = decompress(compressed, compression, x, z)?;
8484 let mut cursor = Cursor::new(decompressed.as_slice());
8585- chunks[i] =
8686- Some(crab_nbt::serde::de::from_cursor::<C>(&mut cursor)?);
8585+ *chunk = Some(crab_nbt::serde::de::from_cursor::<C>(&mut cursor)?);
8786 }
88878988 Ok(Self { chunks })
+40-42
nara_slurper_1_12_core/src/item.rs
···175175 damage: i16,
176176 tag: Option<RawTag>,
177177) -> ItemStack {
178178- if id == "minecraft:written_book" {
179179- if let Some(ref t) = tag {
180180- if let (Some(author), Some(title), Some(pages)) =
181181- (t.author.clone(), t.title.clone(), t.pages.clone())
182182- {
183183- let generation = t
184184- .generation
185185- .and_then(|g| BookGeneration::try_from(g).ok())
186186- .unwrap_or_default();
187187- let resolved = t.resolved.map(|b| b != 0).unwrap_or(false);
188188- let display = t.display.clone();
189189- return ItemStack::WrittenBook(WrittenBookStack {
190190- count,
191191- damage,
192192- id,
193193- tag: WrittenBookTag {
194194- base: BaseTag { display },
195195- author,
196196- title,
197197- generation,
198198- resolved,
199199- pages: pages
200200- .into_iter()
201201- .map(|s| parse_component_from_str(&s))
202202- .collect(),
203203- },
204204- });
205205- }
206206- }
178178+ if id == "minecraft:written_book"
179179+ && let Some(ref t) = tag
180180+ && let (Some(author), Some(title), Some(pages)) =
181181+ (t.author.clone(), t.title.clone(), t.pages.clone())
182182+ {
183183+ let generation = t
184184+ .generation
185185+ .and_then(|g| BookGeneration::try_from(g).ok())
186186+ .unwrap_or_default();
187187+ let resolved = t.resolved.map(|b| b != 0).unwrap_or(false);
188188+ let display = t.display.clone();
189189+ return ItemStack::WrittenBook(WrittenBookStack {
190190+ count,
191191+ damage,
192192+ id,
193193+ tag: WrittenBookTag {
194194+ base: BaseTag { display },
195195+ author,
196196+ title,
197197+ generation,
198198+ resolved,
199199+ pages: pages
200200+ .into_iter()
201201+ .map(|s| parse_component_from_str(&s))
202202+ .collect(),
203203+ },
204204+ });
207205 }
208206209209- if let Some(ref t) = tag {
210210- if let Some(ref be) = t.block_entity {
211211- let display = t.display.clone();
212212- return ItemStack::BlockEntity(BlockEntityStack {
213213- count,
214214- damage,
215215- id,
216216- tag: BlockEntityTag {
217217- base: BaseTag { display },
218218- block_entity: be.clone(),
219219- },
220220- });
221221- }
207207+ if let Some(ref t) = tag
208208+ && let Some(ref be) = t.block_entity
209209+ {
210210+ let display = t.display.clone();
211211+ return ItemStack::BlockEntity(BlockEntityStack {
212212+ count,
213213+ damage,
214214+ id,
215215+ tag: BlockEntityTag {
216216+ base: BaseTag { display },
217217+ block_entity: be.clone(),
218218+ },
219219+ });
222220 }
223221224222 ItemStack::Base(BaseItemStack { count, damage, id })