aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormat <github@matdoes.dev>2022-05-08 23:45:15 -0500
committermat <github@matdoes.dev>2022-05-08 23:45:15 -0500
commit345cecf7afa84df2d5ecf075ecfb499e3fd10a55 (patch)
tree4657aebf820aab0e934cc501fcbb822d5ef2c84f
parent122693a654b0c851bbb9e134c539961419175bef (diff)
downloadazalea-drasl-345cecf7afa84df2d5ecf075ecfb499e3fd10a55.tar.xz
add more stuff
-rw-r--r--.gitignore2
-rwxr-xr-xazalea-client/src/connect.rs1
-rw-r--r--azalea-core/src/position.rs25
-rw-r--r--azalea-world/src/bit_storage.rs12
-rw-r--r--azalea-world/src/lib.rs9
-rw-r--r--azalea-world/src/palette.rs14
-rw-r--r--bot/src/main.rs23
7 files changed, 67 insertions, 19 deletions
diff --git a/.gitignore b/.gitignore
index dc2a59d1..53141060 100644
--- a/.gitignore
+++ b/.gitignore
@@ -4,8 +4,6 @@ flamegraph.svg
perf.data
perf.data.old
-# TODO: remove this after chunk-decoding is merged
-/login.txt
code-generator/Burger
code-generator/client.jar
diff --git a/azalea-client/src/connect.rs b/azalea-client/src/connect.rs
index 2f38b305..522d7d48 100755
--- a/azalea-client/src/connect.rs
+++ b/azalea-client/src/connect.rs
@@ -177,7 +177,6 @@ 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;
diff --git a/azalea-core/src/position.rs b/azalea-core/src/position.rs
index a57f5c0b..a2292651 100644
--- a/azalea-core/src/position.rs
+++ b/azalea-core/src/position.rs
@@ -23,6 +23,15 @@ impl ChunkPos {
}
}
+impl From<BlockPos> for ChunkPos {
+ fn from(pos: BlockPos) -> Self {
+ ChunkPos {
+ x: pos.x / 16,
+ z: pos.z / 16,
+ }
+ }
+}
+
#[derive(Clone, Copy, Debug, Default)]
pub struct ChunkSectionPos {
pub x: i32,
@@ -35,3 +44,19 @@ impl ChunkSectionPos {
ChunkSectionPos { x, y, z }
}
}
+
+impl From<BlockPos> for ChunkSectionPos {
+ fn from(pos: BlockPos) -> Self {
+ ChunkSectionPos {
+ x: pos.x / 16,
+ y: pos.y / 16,
+ z: pos.z / 16,
+ }
+ }
+}
+
+impl From<ChunkSectionPos> for ChunkPos {
+ fn from(pos: ChunkSectionPos) -> Self {
+ ChunkPos { x: pos.x, z: pos.z }
+ }
+}
diff --git a/azalea-world/src/bit_storage.rs b/azalea-world/src/bit_storage.rs
index 9cc3a053..211a4a04 100644
--- a/azalea-world/src/bit_storage.rs
+++ b/azalea-world/src/bit_storage.rs
@@ -70,9 +70,9 @@ const MAGIC: [(i32, i32, i32); 64] = [
];
/// A compact list of integers with the given number of bits per entry.
-#[derive(Clone)]
+#[derive(Clone, Debug, Default)]
pub struct BitStorage {
- data: Vec<u64>,
+ pub data: Vec<u64>,
bits: usize,
mask: u64,
size: usize,
@@ -103,9 +103,17 @@ impl BitStorage {
/// Create a new BitStorage with the given number of bits per entry.
/// `size` is the number of entries in the BitStorage.
pub fn new(bits: usize, size: usize, data: Option<Vec<u64>>) -> Result<Self, BitStorageError> {
+ if let Some(data) = &data {
+ if data.len() == 0 {
+ // TODO: make 0 bit storage actually work
+ return Ok(BitStorage::default());
+ }
+ }
+
let values_per_long = 64 / bits;
let magic_index = values_per_long - 1;
let (divide_mul, divide_add, divide_shift) = MAGIC[magic_index as usize];
+ println!("values_per_long: {}, size: {}", values_per_long, size);
let calculated_length = (size + values_per_long - 1) / values_per_long;
let mask = (1 << bits) - 1;
diff --git a/azalea-world/src/lib.rs b/azalea-world/src/lib.rs
index 4b8c21e9..4da2fb0f 100644
--- a/azalea-world/src/lib.rs
+++ b/azalea-world/src/lib.rs
@@ -67,6 +67,15 @@ impl IndexMut<&ChunkPos> for World {
&mut self.storage[pos]
}
}
+// impl Index<&BlockPos> for World {
+// type Output = Option<Arc<Mutex<Chunk>>>;
+
+// fn index(&self, pos: &BlockPos) -> &Self::Output {
+// let chunk = &self[ChunkPos::from(pos)];
+// // chunk.
+
+// }
+// }
pub struct ChunkStorage {
view_center: ChunkPos,
diff --git a/azalea-world/src/palette.rs b/azalea-world/src/palette.rs
index db722a5b..c33992b1 100644
--- a/azalea-world/src/palette.rs
+++ b/azalea-world/src/palette.rs
@@ -1,6 +1,8 @@
use azalea_protocol::mc_buf::{McBufReadable, McBufVarReadable, McBufWritable, Readable, Writable};
use std::io::{Read, Write};
+use crate::BitStorage;
+
#[derive(Clone, Debug, Copy)]
pub enum PalettedContainerType {
Biomes,
@@ -12,7 +14,7 @@ pub struct PalettedContainer {
pub bits_per_entry: u8,
pub palette: Palette,
/// Compacted list of indices pointing to entry IDs in the Palette.
- pub data: Vec<u64>,
+ pub storage: BitStorage,
}
impl PalettedContainer {
@@ -29,17 +31,23 @@ impl PalettedContainer {
Palette::biomes_read_with_bits_per_entry(buf, bits_per_entry)?
}
};
+ let size = match type_ {
+ PalettedContainerType::BlockStates => 4096,
+ PalettedContainerType::Biomes => 64,
+ };
let data = Vec::<u64>::read_into(buf)?;
debug_assert!(
bits_per_entry != 0 || data.is_empty(),
"Bits per entry is 0 but data is not empty."
);
+ println!("data: {:?}", data);
+ let storage = BitStorage::new(bits_per_entry.into(), size, Some(data)).unwrap();
Ok(PalettedContainer {
bits_per_entry,
palette,
- data,
+ storage,
})
}
}
@@ -47,7 +55,7 @@ impl McBufWritable for PalettedContainer {
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
buf.write_byte(self.bits_per_entry)?;
self.palette.write_into(buf)?;
- self.data.write_into(buf)?;
+ self.storage.data.write_into(buf)?;
Ok(())
}
}
diff --git a/bot/src/main.rs b/bot/src/main.rs
index 075bfa44..2686636b 100644
--- a/bot/src/main.rs
+++ b/bot/src/main.rs
@@ -1,5 +1,5 @@
use azalea_client::{Account, Event};
-use azalea_core::ChunkPos;
+use azalea_core::{BlockPos, ChunkPos};
#[tokio::main]
async fn main() {
@@ -19,18 +19,19 @@ async fn main() {
while let Some(e) = client.next().await {
match e {
// 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);
- }
+ Event::Login => {}
Event::Chat(p) => {
println!("{}", p.message.to_ansi(None));
+ if p.message.to_ansi(None) == "<py5> ok" {
+ let state = client.state.lock().await;
+ let world = state.world.as_ref().unwrap();
+ // let c = world[&BlockPos::new(5, 78, -2)]
+ // .as_ref()
+ // .unwrap()
+ // .lock()
+ // .unwrap();
+ // println!("{:?}", c);
+ }
}
}
}