aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--azalea-client/src/client.rs7
-rw-r--r--azalea-core/src/position.rs16
-rwxr-xr-xazalea-core/src/resource_location.rs2
-rw-r--r--azalea-protocol/src/packets/game/clientbound_section_blocks_update_packet.rs10
-rw-r--r--azalea-protocol/src/read.rs2
5 files changed, 28 insertions, 9 deletions
diff --git a/azalea-client/src/client.rs b/azalea-client/src/client.rs
index 0e13415c..aaaa0308 100644
--- a/azalea-client/src/client.rs
+++ b/azalea-client/src/client.rs
@@ -1,7 +1,7 @@
use crate::{movement::MoveDirection, Account, Player};
use azalea_auth::game_profile::GameProfile;
use azalea_chat::component::Component;
-use azalea_core::{ChunkPos, ResourceLocation, Vec3};
+use azalea_core::{BlockPos, ChunkPos, ResourceLocation, Vec3};
use azalea_protocol::{
connect::{Connection, ConnectionError, ReadConnection, WriteConnection},
packets::{
@@ -631,7 +631,10 @@ impl Client {
}
ClientboundGamePacket::SectionBlocksUpdate(p) => {
debug!("Got section blocks update packet {:?}", p);
- // TODO: update world
+ let mut dimension = client.dimension.lock();
+ for state in &p.states {
+ dimension.set_block_state(&(p.section_pos + state.pos), state.state);
+ }
}
ClientboundGamePacket::GameEvent(p) => {
debug!("Got game event packet {:?}", p);
diff --git a/azalea-core/src/position.rs b/azalea-core/src/position.rs
index d408d817..83472b61 100644
--- a/azalea-core/src/position.rs
+++ b/azalea-core/src/position.rs
@@ -172,6 +172,18 @@ impl ChunkSectionBlockPos {
}
}
+impl Add<ChunkSectionBlockPos> for ChunkSectionPos {
+ type Output = BlockPos;
+
+ fn add(self, rhs: ChunkSectionBlockPos) -> Self::Output {
+ BlockPos {
+ x: self.x * 16 + rhs.x as i32,
+ y: self.y * 16 + rhs.y as i32,
+ z: self.z * 16 + rhs.z as i32,
+ }
+ }
+}
+
/// A block pos with an attached dimension
#[derive(Debug, Clone)]
pub struct GlobalPos {
@@ -403,8 +415,8 @@ mod tests {
fn test_read_blockpos_from() {
let mut buf = Vec::new();
13743895338965u64.write_into(&mut buf).unwrap();
- let buf = &mut &buf[..];
- let block_pos = BlockPos::read_from(buf).unwrap();
+ let mut buf = Cursor::new(&buf[..]);
+ let block_pos = BlockPos::read_from(&mut buf).unwrap();
assert_eq!(block_pos, BlockPos::new(49, -43, -3));
}
}
diff --git a/azalea-core/src/resource_location.rs b/azalea-core/src/resource_location.rs
index 5f8dcea1..e810b96e 100755
--- a/azalea-core/src/resource_location.rs
+++ b/azalea-core/src/resource_location.rs
@@ -94,7 +94,7 @@ mod tests {
.write_into(&mut buf)
.unwrap();
- let mut buf = &mut &buf[..];
+ let mut buf = Cursor::new(&buf[..]);
assert_eq!(
ResourceLocation::read_from(&mut buf).unwrap(),
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 357a30f6..f9b1cd1e 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
@@ -1,5 +1,7 @@
-use azalea_buf::{BufReadError, McBuf};
-use azalea_buf::{McBufReadable, McBufVarReadable, McBufVarWritable, McBufWritable};
+use azalea_block::BlockState;
+use azalea_buf::{
+ BufReadError, McBuf, McBufReadable, McBufVarReadable, McBufVarWritable, McBufWritable,
+};
use azalea_core::{ChunkSectionBlockPos, ChunkSectionPos};
use azalea_protocol_macros::ClientboundGamePacket;
use std::io::{Cursor, Write};
@@ -14,7 +16,7 @@ pub struct ClientboundSectionBlocksUpdatePacket {
#[derive(Clone, Debug)]
pub struct BlockStateWithPosition {
pub pos: ChunkSectionBlockPos,
- pub state: u32,
+ pub state: BlockState,
}
impl McBufReadable for BlockStateWithPosition {
@@ -22,6 +24,8 @@ impl McBufReadable for BlockStateWithPosition {
let data = u64::var_read_from(buf)?;
let position_part = data & 4095;
let state = (data >> 12) as u32;
+ let state = BlockState::try_from(state)
+ .map_err(|_| BufReadError::UnexpectedEnumVariant { id: state as i32 })?;
let pos = ChunkSectionBlockPos {
x: (position_part >> 8 & 15) as u8,
y: (position_part & 15) as u8,
diff --git a/azalea-protocol/src/read.rs b/azalea-protocol/src/read.rs
index 2f0391b9..61d5d914 100644
--- a/azalea-protocol/src/read.rs
+++ b/azalea-protocol/src/read.rs
@@ -12,7 +12,7 @@ use std::{
io::{Cursor, Read},
};
use thiserror::Error;
-use tokio::io::{AsyncRead, AsyncReadExt};
+use tokio::io::AsyncRead;
use tokio_util::codec::{BytesCodec, FramedRead};
#[derive(Error, Debug)]