1
2
Fork 0
mirror of https://github.com/mat-1/azalea.git synced 2025-08-02 14:26:04 +00:00

random polish

This commit is contained in:
mat 2022-05-05 23:33:08 -05:00
parent 1b48cad53f
commit e023986565
6 changed files with 41 additions and 3 deletions

1
Cargo.lock generated
View file

@ -191,6 +191,7 @@ name = "bot"
version = "0.1.0"
dependencies = [
"azalea-client",
"azalea-core",
"azalea-protocol",
"tokio",
]

View file

@ -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;

View file

@ -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 }
}
}

View file

@ -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!"

View file

@ -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"

View file

@ -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);
}
}
}