Add Clientbound Chunk Data and Update Light
This commit is contained in:
parent
a45a43397c
commit
f779d31880
@ -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<T>(&mut self, val: impl FnOnce(&mut Self) -> T) -> Option<T> {
|
||||
|
||||
@ -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<u8>,
|
||||
data: Vec<u8>,
|
||||
block_entites: Vec<BlockEntity>,
|
||||
sky_light_mask: BitSet,
|
||||
block_light_mask: BitSet,
|
||||
empty_sky_light_mask: BitSet,
|
||||
sky_lights: Vec<SkyLight>,
|
||||
block_lights: Vec<BlockLight>,
|
||||
}
|
||||
|
||||
impl CChunkDataUpdateLight {
|
||||
pub fn new(
|
||||
chunk_x: i32,
|
||||
chunk_y: i32,
|
||||
heightmaps: Vec<u8>,
|
||||
data: Vec<u8>,
|
||||
block_entites: Vec<BlockEntity>,
|
||||
sky_light_mask: BitSet,
|
||||
block_light_mask: BitSet,
|
||||
empty_sky_light_mask: BitSet,
|
||||
sky_lights: Vec<SkyLight>,
|
||||
block_lights: Vec<BlockLight>,
|
||||
) -> 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::<BlockEntity>(&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::<SkyLight>(&self.sky_lights, |p, v| {
|
||||
p.put_var_int(v.array.len() as VarInt);
|
||||
p.put_slice(&v.array);
|
||||
});
|
||||
bytebuf.put_list::<BlockLight>(&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<u8>,
|
||||
}
|
||||
|
||||
pub struct SkyLight {
|
||||
array: Vec<u8>,
|
||||
}
|
||||
|
||||
pub struct BlockLight {
|
||||
array: Vec<u8>,
|
||||
}
|
||||
|
||||
@ -19,6 +19,11 @@ pub type Identifier = String;
|
||||
pub type VarInt = i32;
|
||||
pub type VarLong = i64;
|
||||
|
||||
pub struct BitSet {
|
||||
length: VarInt,
|
||||
data: Vec<i64>,
|
||||
}
|
||||
|
||||
pub struct VarInt32(pub i32);
|
||||
|
||||
impl VarInt32 {
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
use biomes::Biome;
|
||||
use damage_type::DamageType;
|
||||
use dimensions::Dimension;
|
||||
use fastnbt::SerOpts;
|
||||
use paint::Painting;
|
||||
|
||||
@ -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 {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user