diff --git a/pumpkin-protocol/src/bytebuf/mod.rs b/pumpkin-protocol/src/bytebuf/mod.rs index f26785d17..7f4ab6f12 100644 --- a/pumpkin-protocol/src/bytebuf/mod.rs +++ b/pumpkin-protocol/src/bytebuf/mod.rs @@ -3,7 +3,7 @@ use std::io::{self, Error, ErrorKind}; use bytes::{Buf, BufMut, BytesMut}; -use crate::{VarInt, VarLong}; +use crate::{BitSet, VarInt, VarLong}; const SEGMENT_BITS: u8 = 0x7F; const CONTINUE_BIT: u8 = 0x80; @@ -141,6 +141,13 @@ impl ByteBuffer { } } + pub fn put_bit_set(&mut self, set: &BitSet) { + self.put_var_int(set.length); + for b in &set.data { + self.put_i64(*b); + } + } + /// Reads a boolean. If true, the closure is called, and the returned value is /// wrapped in Some. Otherwise, this returns None. pub fn get_option(&mut self, val: impl FnOnce(&mut Self) -> T) -> Option { diff --git a/pumpkin-protocol/src/client/play/mod.rs b/pumpkin-protocol/src/client/play/mod.rs index adf6bb2e8..55d90b8db 100644 --- a/pumpkin-protocol/src/client/play/mod.rs +++ b/pumpkin-protocol/src/client/play/mod.rs @@ -1,4 +1,4 @@ -use crate::{bytebuf::ByteBuffer, ClientPacket, VarInt}; +use crate::{bytebuf::ByteBuffer, BitSet, ClientPacket, VarInt}; pub struct SetHeldItem { slot: i8, @@ -233,3 +233,88 @@ impl ClientPacket for CSyncPlayerPostion { bytebuf.put_var_int(self.teleport_id); } } + +pub struct CChunkDataUpdateLight { + chunk_x: i32, + chunk_y: i32, + heightmaps: Vec, + data: Vec, + block_entites: Vec, + sky_light_mask: BitSet, + block_light_mask: BitSet, + empty_sky_light_mask: BitSet, + sky_lights: Vec, + block_lights: Vec, +} + +impl CChunkDataUpdateLight { + pub fn new( + chunk_x: i32, + chunk_y: i32, + heightmaps: Vec, + data: Vec, + block_entites: Vec, + sky_light_mask: BitSet, + block_light_mask: BitSet, + empty_sky_light_mask: BitSet, + sky_lights: Vec, + block_lights: Vec, + ) -> Self { + Self { + chunk_x, + chunk_y, + heightmaps, + data, + block_entites, + sky_light_mask, + block_light_mask, + empty_sky_light_mask, + sky_lights, + block_lights, + } + } +} + +impl ClientPacket for CChunkDataUpdateLight { + const PACKET_ID: VarInt = 0x27; + + fn write(&self, bytebuf: &mut ByteBuffer) { + bytebuf.put_i32(self.chunk_x); + bytebuf.put_i32(self.chunk_y); + bytebuf.put_slice(&self.heightmaps); + bytebuf.put_var_int(self.data.len() as VarInt); + bytebuf.put_slice(&self.data); + bytebuf.put_list::(&self.block_entites, |p, v| { + p.put_u8(v.packed_xz); + p.put_i16(v.y); + p.put_var_int(v.typee); + p.put_slice(&v.data); + }); + bytebuf.put_bit_set(&self.sky_light_mask); + bytebuf.put_bit_set(&self.block_light_mask); + bytebuf.put_bit_set(&self.empty_sky_light_mask); + bytebuf.put_list::(&self.sky_lights, |p, v| { + p.put_var_int(v.array.len() as VarInt); + p.put_slice(&v.array); + }); + bytebuf.put_list::(&self.block_lights, |p, v| { + p.put_var_int(v.array.len() as VarInt); + p.put_slice(&v.array); + }); + } +} + +pub struct BlockEntity { + packed_xz: u8, + y: i16, + typee: VarInt, + data: Vec, +} + +pub struct SkyLight { + array: Vec, +} + +pub struct BlockLight { + array: Vec, +} diff --git a/pumpkin-protocol/src/lib.rs b/pumpkin-protocol/src/lib.rs index 3008df480..6b1a5c816 100644 --- a/pumpkin-protocol/src/lib.rs +++ b/pumpkin-protocol/src/lib.rs @@ -19,6 +19,11 @@ pub type Identifier = String; pub type VarInt = i32; pub type VarLong = i64; +pub struct BitSet { + length: VarInt, + data: Vec, +} + pub struct VarInt32(pub i32); impl VarInt32 { diff --git a/pumpkin-registry/src/lib.rs b/pumpkin-registry/src/lib.rs index 93fbc3b0c..4569082d3 100644 --- a/pumpkin-registry/src/lib.rs +++ b/pumpkin-registry/src/lib.rs @@ -1,5 +1,4 @@ use biomes::Biome; -use damage_type::DamageType; use dimensions::Dimension; use fastnbt::SerOpts; use paint::Painting; diff --git a/pumpkin/src/server.rs b/pumpkin/src/server.rs index f5e84547f..cf5d84788 100644 --- a/pumpkin/src/server.rs +++ b/pumpkin/src/server.rs @@ -141,7 +141,7 @@ impl Server { } // todo: do this in a world - fn spawn_chunks(player: &Player) {} + fn spawn_test_chunk(client: &Client) {} // move to world pub fn new_entity_id(&self) -> EntityId {