Skip to content

Commit

Permalink
Add hardcoded chunk data
Browse files Browse the repository at this point in the history
  • Loading branch information
ya7on committed Dec 5, 2023
1 parent 29d24a4 commit cb60366
Show file tree
Hide file tree
Showing 3 changed files with 385 additions and 14 deletions.
2 changes: 1 addition & 1 deletion mclib/main/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ pub mod packets {
pub use mclib_protocol::packets::server::status_request::StatusRequest;
}
pub mod client {
pub use mclib_protocol::packets::client::chunk_data_and_update_light::ChunkDataAndUpdateLight;
pub use mclib_protocol::packets::client::finish_configuration::FinishConfigurationClientbound;
pub use mclib_protocol::packets::client::keepalive::ClientboundKeelAlivePlay;
pub use mclib_protocol::packets::client::login_success::{
LoginSuccess, LoginSuccessProperty,
};
pub use mclib_protocol::packets::client::play::{DeathInfo, Play};
pub use mclib_protocol::packets::client::player_abilities::PlayerAbilities;
pub use mclib_protocol::packets::client::registry_data::RegistryData;
pub use mclib_protocol::packets::client::set_default_spawn_position::SetDefaultSpawnPosition;
pub use mclib_protocol::packets::client::status_response::StatusResponse;
Expand Down
189 changes: 189 additions & 0 deletions mclib/protocol/src/packets/client/chunk_data_and_update_light.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
use crate::chunk_format::ChunkData;
use crate::packets::base::MCPacket;
use crate::types::base::MCType;
use crate::types::bitset::MCBitSet;
use crate::types::byte::MCByte;
use crate::types::byte_array::MCByteArray;
use crate::types::int::MCInt;
use crate::types::nbt::MCNBT;
use crate::types::short::MCShort;
use crate::types::varint::MCVarInt;
use mclib_macros::{MCPacket, MCType};
use std::io::Read;

#[derive(MCType, Debug, Clone)]
pub struct BlockEntity {
pub packed_xy: MCByte,
pub y: MCShort,
pub ty: MCVarInt,
pub data: MCNBT,
}

#[derive(MCPacket, Debug, Clone)]
#[packet(packet_id = 0x25)]
pub struct ChunkDataAndUpdateLight {
pub chunk_x: MCInt,
pub chunk_z: MCInt,
pub heightmaps: MCNBT,
pub data: MCByteArray<ChunkData>,
pub block_entities: Vec<BlockEntity>,
pub sky_light_mask: MCBitSet,
pub block_light_mask: MCBitSet,
pub empty_sky_light_mask: MCBitSet,
pub empty_block_light_mask: MCBitSet,
pub sky_lights: Vec<Vec<MCByte>>,
pub block_lights: Vec<Vec<MCByte>>,
}

#[cfg(test)]
mod tests {
use crate::chunk_format::palleted_container::PalletedContainer;
use crate::chunk_format::section::ChunkSection;
use crate::chunk_format::ChunkData;
use crate::nbt::tags::base::IntoNBTTag;
use crate::nbt::NBT;
use crate::packets::base::MCPacket;
use crate::packets::client::chunk_data_and_update_light::ChunkDataAndUpdateLight;
use crate::types::byte_array::MCByteArray;

#[test]
#[ignore]
fn test_chunk_data() {
let reference =
include_bytes!("../../../../../assets/tests/chunk_data_and_update_light.packet");

let heightmap = NBT(
None,
vec![
(
"MOTION_BLOCKING",
vec![
72198606942111748i64,
72198606942111748i64,
72198606942111748i64,
72198606942111748i64,
72198606942111748i64,
72198606942111748i64,
72198606942111748i64,
72198606942111748i64,
72198606942111748i64,
72198606942111748i64,
72198606942111748i64,
72198606942111748i64,
72198606942111748i64,
72198606942111748i64,
72198606942111748i64,
72198606942111748i64,
72198606942111748i64,
72198606942111748i64,
72198606942111748i64,
72198606942111748i64,
72198606942111748i64,
72198606942111748i64,
72198606942111748i64,
72198606942111748i64,
72198606942111748i64,
72198606942111748i64,
72198606942111748i64,
72198606942111748i64,
72198606942111748i64,
72198606942111748i64,
72198606942111748i64,
72198606942111748i64,
72198606942111748i64,
72198606942111748i64,
72198606942111748i64,
72198606942111748i64,
537921540i64,
]
.to_nbt(),
),
(
"WORLD_SURFACE",
vec![
72198606942111748i64,
72198606942111748i64,
72198606942111748i64,
72198606942111748i64,
72198606942111748i64,
72198606942111748i64,
72198606942111748i64,
72198606942111748i64,
72198606942111748i64,
72198606942111748i64,
72198606942111748i64,
72198606942111748i64,
72198606942111748i64,
72198606942111748i64,
72198606942111748i64,
72198606942111748i64,
72198606942111748i64,
72198606942111748i64,
72198606942111748i64,
72198606942111748i64,
72198606942111748i64,
72198606942111748i64,
72198606942111748i64,
72198606942111748i64,
72198606942111748i64,
72198606942111748i64,
72198606942111748i64,
72198606942111748i64,
72198606942111748i64,
72198606942111748i64,
72198606942111748i64,
72198606942111748i64,
72198606942111748i64,
72198606942111748i64,
72198606942111748i64,
72198606942111748i64,
537921540i64,
]
.to_nbt(),
),
]
.to_nbt(),
);

let mut data = Vec::new();
data.extend(vec![1229782938247303441.into(); 16]);
data.extend(vec![2459565876494606882.into(); 32]);
data.extend(vec![3689348814741910323.into(); 16]);
data.extend(vec![0.into(); 192]);
let mut chunks = Vec::new();
chunks.push(ChunkSection {
block_count: 1024.into(),
block_states: PalletedContainer::Indirect {
bits_per_entry: 4.into(),
pallete: vec![0.into(), 79.into(), 10.into(), 9.into()],
data,
},
biomes: PalletedContainer::SingleValued(39.into()),
});
chunks.extend(vec![
ChunkSection {
block_count: 0.into(),
block_states: PalletedContainer::SingleValued(0.into()),
biomes: PalletedContainer::SingleValued(39.into()),
};
23
]);
let chunk_data_and_update_light = ChunkDataAndUpdateLight {
chunk_x: (-1 as i32).into(),
chunk_z: 0.into(),
heightmaps: heightmap.into(),
data: MCByteArray::new(ChunkData(chunks)),
block_entities: vec![],
sky_light_mask: Default::default(),
block_light_mask: Default::default(),
empty_sky_light_mask: Default::default(),
empty_block_light_mask: Default::default(),
sky_lights: vec![],
block_lights: vec![],
};

let packed = &chunk_data_and_update_light.pack()[2..];
assert_eq!(packed[..2899], reference[..2899]);
panic!("{:?}", packed.len());
}
}
Loading

0 comments on commit cb60366

Please sign in to comment.