diff options
author | nea <nea@nea.moe> | 2023-03-27 23:57:20 +0200 |
---|---|---|
committer | nea <nea@nea.moe> | 2023-03-27 23:57:20 +0200 |
commit | d4e040403ba047c02a7106b97f712d2c565f4389 (patch) | |
tree | 6d3a4ed3cec220d18686fbe16e075fa2cc4dcbbd /src/world.rs | |
parent | e20255889940ab3b16d5103e07f4555ab5d8730c (diff) | |
download | mgasi-d4e040403ba047c02a7106b97f712d2c565f4389.tar.gz mgasi-d4e040403ba047c02a7106b97f712d2c565f4389.tar.bz2 mgasi-d4e040403ba047c02a7106b97f712d2c565f4389.zip |
Standalone world
Diffstat (limited to 'src/world.rs')
-rw-r--r-- | src/world.rs | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/src/world.rs b/src/world.rs new file mode 100644 index 0000000..a1c7e11 --- /dev/null +++ b/src/world.rs @@ -0,0 +1,74 @@ +use std::sync::Arc; + +use anyhow::Result; +use async_trait::async_trait; +use mcproto_rs::nbt::Tag; +use mcproto_rs::Serializer; +use mcproto_rs::types::{BytesSerializer, NamedNbtTag}; +use mcproto_rs::v1_19_3::{BitSet, BlobArray, ChunkDataAndUpdateLightSpec, ChunkDataSpec, ChunkSection, LightDataSpec, Packet761, PalettedContainer}; + +use crate::convention::Universe; +use crate::nbt; +use crate::player::Player; + +#[async_trait] +pub trait World { + async fn send_chunk(&self, observer: &Player, chunk_x: i32, chunk_z: i32) -> Result<()>; +} + +pub struct DebugWorld { + universe: Arc<Universe>, +} + +impl DebugWorld { + pub fn new(universe: Arc<Universe>) -> DebugWorld { + DebugWorld { universe } + } +} + +#[async_trait] +impl World for DebugWorld { + async fn send_chunk(&self, observer: &Player, chunk_x: i32, chunk_z: i32) -> Result<()> { + let mut heightmap = BlobArray::new(9); + for cx in 0..(16 * 16) { + heightmap.set_entry(cx, 2) + } + let mut chunk_dat_serializer = BytesSerializer::default(); + for i in 0..(self.universe.max_world_section - self.universe.min_world_section) { + let section = ChunkSection { + block_count: if i < 4 { 16 * 16 * 16 } else { 0 }, + block_state: PalettedContainer { singular_value: if i < 4 { 1.into() } else { 0.into() } }, + biomes: PalettedContainer { singular_value: 0.into() }, + }; + chunk_dat_serializer.serialize_other(§ion)?; + } + let chunk_column_bytes = chunk_dat_serializer.into_bytes(); + observer.send_packet(Packet761::ChunkDataAndUpdateLight(ChunkDataAndUpdateLightSpec { + chunk_x, + chunk_z, + chunk_data: ChunkDataSpec { + heightmaps: NamedNbtTag { + root: nbt! { + "MOTION_BLOCKING" :: (Tag::LongArray(heightmap.data.iter().map(|n| n.to_owned() as _).collect())), + "WORLD_SURFACE" :: (Tag::LongArray(heightmap.data.iter().map(|n| n.to_owned() as _).collect())), + }.with_name("root") + }, + buffer: chunk_column_bytes.into(), + block_entities: vec![].into(), + }, + light_data: LightDataSpec { + trust_edges: true, + sky_y_mask: BitSet::empty(), + block_y_mask: BitSet::empty(), + empty_sky_y_mask: BitSet::empty(), + empty_block_y_mask: BitSet::empty(), + sky_updates: vec![].into(), + block_updates: vec![].into(), + }, + }))?; + Ok(()) + } +} + + + |