aboutsummaryrefslogtreecommitdiff
path: root/azalea-client
diff options
context:
space:
mode:
authormat <github@matdoes.dev>2022-05-03 00:33:32 -0500
committermat <github@matdoes.dev>2022-05-03 00:33:32 -0500
commit0bd798045c4328208667df37348e9affb37e384f (patch)
tree241fbc2b738b2a47cd6220bb07beb450c7359ab4 /azalea-client
parent8e42e1c5dfc54314585b564696044780e0407c2f (diff)
downloadazalea-drasl-0bd798045c4328208667df37348e9affb37e384f.tar.xz
more azalea-world stuff
Diffstat (limited to 'azalea-client')
-rwxr-xr-xazalea-client/src/connect.rs48
-rw-r--r--azalea-client/src/player.rs1
2 files changed, 44 insertions, 5 deletions
diff --git a/azalea-client/src/connect.rs b/azalea-client/src/connect.rs
index be268eee..e4d7d7e5 100755
--- a/azalea-client/src/connect.rs
+++ b/azalea-client/src/connect.rs
@@ -1,5 +1,5 @@
use crate::Player;
-use azalea_core::resource_location::ResourceLocation;
+use azalea_core::{resource_location::ResourceLocation, ChunkPos};
use azalea_protocol::{
connect::{GameConnection, HandshakeConnection},
packets::{
@@ -13,8 +13,8 @@ use azalea_protocol::{
},
resolver, ServerAddress,
};
-use azalea_world::Chunk;
-use std::sync::Arc;
+use azalea_world::{Chunk, ChunkStorage, World};
+use std::{fmt::Debug, ops::Deref, sync::Arc};
use tokio::sync::mpsc::{self, UnboundedReceiver, UnboundedSender};
use tokio::sync::Mutex;
@@ -27,8 +27,8 @@ pub struct Account {
#[derive(Default)]
pub struct ClientState {
- // placeholder
pub player: Player,
+ pub world: Option<World>,
}
/// A player that you can control that is currently in a Minecraft server.
@@ -173,8 +173,31 @@ impl Client {
match packet {
GamePacket::ClientboundLoginPacket(p) => {
println!("Got login packet {:?}", p);
+ std::fs::write("login.txt", format!("{:#?}", p)).expect("Unable to write file");
+
+ let mut state = state.lock().await;
+ state.player.entity.id = p.player_id;
+ let dimension_type = p
+ .dimension_type
+ .as_compound()
+ .expect("Dimension type is not compound")
+ .get("")
+ .expect("No \"\" tag")
+ .as_compound()
+ .expect("\"\" tag is not compound");
+ let height = (*dimension_type
+ .get("height")
+ .expect("No height tag")
+ .as_int()
+ .expect("height tag is not int"))
+ .try_into()
+ .expect("height is not a u32");
+
+ state.world = Some(World {
+ height,
+ storage: ChunkStorage::new(16),
+ });
- state.lock().await.player.entity.id = p.player_id;
conn.lock()
.await
.write(
@@ -231,10 +254,25 @@ impl Client {
}
GamePacket::ClientboundSetChunkCacheCenterPacket(p) => {
println!("Got chunk cache center packet {:?}", p);
+ state
+ .lock()
+ .await
+ .world
+ .as_mut()
+ .unwrap()
+ .update_view_center(&ChunkPos::new(p.x, p.z));
}
GamePacket::ClientboundLevelChunkWithLightPacket(p) => {
println!("Got chunk with light packet {} {}", p.x, p.z);
+ let pos = ChunkPos::new(p.x, p.z);
// let chunk = Chunk::read_with_world_height(&mut p.chunk_data);
+ // println("chunk {:?}")
+ state
+ .lock()
+ .await
+ .world
+ .replace_with_packet_data(&pos, &mut p.chunk_data.data.as_slice())
+ .unwrap();
}
GamePacket::ClientboundLightUpdatePacket(p) => {
println!("Got light update packet {:?}", p);
diff --git a/azalea-client/src/player.rs b/azalea-client/src/player.rs
index fc54ff93..70ac1c76 100644
--- a/azalea-client/src/player.rs
+++ b/azalea-client/src/player.rs
@@ -1,4 +1,5 @@
use crate::Entity;
+use azalea_world::World;
#[derive(Default)]
pub struct Player {