mor echunk stuff

This commit is contained in:
mat 2022-05-03 18:03:10 +00:00
parent 0bd798045c
commit 477c367fc4
3 changed files with 9 additions and 25 deletions

View file

@ -271,6 +271,8 @@ impl Client {
.lock()
.await
.world
.as_mut()
.expect("World doesn't exist! We should've gotten a login packet by now.")
.replace_with_packet_data(&pos, &mut p.chunk_data.data.as_slice())
.unwrap();
}

View file

@ -2,8 +2,8 @@
Sent and receive Minecraft packets. You should probably use `azalea` or `azalea-client` instead.
The goal is to **only** support the latest Minecraft version in order to ease development.
The goal is to only support the latest Minecraft version in order to ease development.
This is not yet complete, search for `TODO` in the code for things that need to be done.
Unfortunately, compiling the crate requires Rust nightly because specialization is not stable yet.
Unfortunately, using azalea-protocol requires Rust nightly because [specialization](https://github.com/rust-lang/rust/issues/31844) is not stable yet. Use `rustup default nightly` to enable it.

View file

@ -38,17 +38,11 @@ impl World {
);
return Ok(());
}
let existing_chunk = &self.storage[pos];
if let Some(existing_chunk) = existing_chunk {
existing_chunk
.lock()
.expect("Couldn't get lock on existing chunk")
.replace_with_packet_data(data)?;
} else {
let chunk = Arc::new(Mutex::new(Chunk::read_with_world(data, self)?));
println!("Loaded chunk {:?}", chunk);
self.storage[pos] = Some(chunk);
}
// let existing_chunk = &self.storage[pos];
let chunk = Arc::new(Mutex::new(Chunk::read_with_world(data, self)?));
println!("Loaded chunk {:?}", chunk);
self.storage[pos] = Some(chunk);
Ok(())
}
@ -131,18 +125,6 @@ impl Chunk {
}
Ok(Chunk { sections })
}
fn replace_with_packet_data(&mut self, data: &mut impl Read) -> Result<(), String> {
let section_count = self.sections.len();
// this should also replace block entities and set the heightmap
for i in 0..section_count {
self.sections[i] = Section::read_into(data)?;
}
Ok(())
}
}
impl McBufWritable for Chunk {