aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormat <github@matdoes.dev>2022-05-05 23:33:08 -0500
committermat <github@matdoes.dev>2022-05-05 23:33:08 -0500
commite0239865659b2f2750edda7556548f6a2b8d4127 (patch)
tree1a2ddf3499ae37bfed4255bf996fef6fd9f1bc84
parent1b48cad53ffba45463be41dafb4dfbcab0f46c09 (diff)
downloadazalea-drasl-e0239865659b2f2750edda7556548f6a2b8d4127.tar.xz
random polish
-rwxr-xr-xCargo.lock1
-rwxr-xr-xazalea-core/src/lib.rs2
-rw-r--r--azalea-core/src/position.rs13
-rw-r--r--azalea-world/src/lib.rs14
-rwxr-xr-xbot/Cargo.toml1
-rw-r--r--bot/src/main.rs13
6 files changed, 41 insertions, 3 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 73a8dafd..e5b6a112 100755
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -191,6 +191,7 @@ name = "bot"
version = "0.1.0"
dependencies = [
"azalea-client",
+ "azalea-core",
"azalea-protocol",
"tokio",
]
diff --git a/azalea-core/src/lib.rs b/azalea-core/src/lib.rs
index 6f0c25cc..0053dc9b 100755
--- a/azalea-core/src/lib.rs
+++ b/azalea-core/src/lib.rs
@@ -9,7 +9,7 @@ mod slot;
pub use slot::{Slot, SlotData};
mod position;
-pub use position::{BlockPos, ChunkPos};
+pub use position::{BlockPos, ChunkPos, ChunkSectionPos};
mod direction;
pub use direction::Direction;
diff --git a/azalea-core/src/position.rs b/azalea-core/src/position.rs
index aa82c1f9..a57f5c0b 100644
--- a/azalea-core/src/position.rs
+++ b/azalea-core/src/position.rs
@@ -22,3 +22,16 @@ impl ChunkPos {
ChunkPos { x, z }
}
}
+
+#[derive(Clone, Copy, Debug, Default)]
+pub struct ChunkSectionPos {
+ pub x: i32,
+ pub y: i32,
+ pub z: i32,
+}
+
+impl ChunkSectionPos {
+ pub fn new(x: i32, y: i32, z: i32) -> Self {
+ ChunkSectionPos { x, y, z }
+ }
+}
diff --git a/azalea-world/src/lib.rs b/azalea-world/src/lib.rs
index 36bbceac..4b8c21e9 100644
--- a/azalea-world/src/lib.rs
+++ b/azalea-world/src/lib.rs
@@ -55,6 +55,18 @@ impl World {
self.storage.view_center = *pos;
}
}
+impl Index<&ChunkPos> for World {
+ type Output = Option<Arc<Mutex<Chunk>>>;
+
+ fn index(&self, pos: &ChunkPos) -> &Self::Output {
+ &self.storage[pos]
+ }
+}
+impl IndexMut<&ChunkPos> for World {
+ fn index_mut<'a>(&'a mut self, pos: &ChunkPos) -> &'a mut Self::Output {
+ &mut self.storage[pos]
+ }
+}
pub struct ChunkStorage {
view_center: ChunkPos,
@@ -150,7 +162,7 @@ pub struct Section {
impl McBufReadable for Section {
fn read_into(buf: &mut impl Read) -> Result<Self, String> {
let block_count = u16::read_into(buf)?;
- // this is commented out because apparently the vanilla server just gives us an incorrect block count sometimes
+ // this is commented out because the vanilla server is wrong
// assert!(
// block_count <= 16 * 16 * 16,
// "A section has more blocks than what should be possible. This is a bug!"
diff --git a/bot/Cargo.toml b/bot/Cargo.toml
index fd6ad067..e55f6c3d 100755
--- a/bot/Cargo.toml
+++ b/bot/Cargo.toml
@@ -7,5 +7,6 @@ version = "0.1.0"
[dependencies]
azalea-client = {path = "../azalea-client"}
+azalea-core = {path = "../azalea-core"}
azalea-protocol = {path = "../azalea-protocol"}
tokio = "^1.14.0"
diff --git a/bot/src/main.rs b/bot/src/main.rs
index 7cf056bf..657d1adb 100644
--- a/bot/src/main.rs
+++ b/bot/src/main.rs
@@ -1,4 +1,5 @@
use azalea_client::{Account, Event};
+use azalea_core::ChunkPos;
#[tokio::main]
async fn main() {
@@ -17,7 +18,17 @@ async fn main() {
while let Some(e) = client.next().await {
match e {
- Event::Login => {}
+ // TODO: have a "loaded" or "ready" event that fires when all chunks are loaded
+ Event::Login => {
+ // let state = client.state.lock().await;
+ // let world = state.world.as_ref().unwrap();
+ // let c = world[&ChunkPos::new(-1, -4)]
+ // .as_ref()
+ // .unwrap()
+ // .lock()
+ // .unwrap();
+ // println!("{:?}", c);
+ }
}
}