aboutsummaryrefslogtreecommitdiff
path: root/azalea-world/src
diff options
context:
space:
mode:
authormat <git@matdoes.dev>2023-09-18 19:29:14 -0500
committermat <git@matdoes.dev>2023-09-18 19:29:14 -0500
commite6941b6a24deed617d09c6e08ba65278bb3bcf25 (patch)
treea647ca131cd87d7d6cdb463dd50f497f4320656b /azalea-world/src
parent856a3252f693421df519cbc4d9bc03cfc0f0c212 (diff)
downloadazalea-drasl-e6941b6a24deed617d09c6e08ba65278bb3bcf25.tar.xz
instanceloadedevent and a few fixes
Diffstat (limited to 'azalea-world/src')
-rwxr-xr-xazalea-world/src/bit_storage.rs26
-rw-r--r--azalea-world/src/container.rs12
-rw-r--r--azalea-world/src/heightmap.rs19
3 files changed, 50 insertions, 7 deletions
diff --git a/azalea-world/src/bit_storage.rs b/azalea-world/src/bit_storage.rs
index 9f9b7abf..13fa0698 100755
--- a/azalea-world/src/bit_storage.rs
+++ b/azalea-world/src/bit_storage.rs
@@ -218,6 +218,32 @@ impl BitStorage {
pub fn size(&self) -> usize {
self.size
}
+
+ pub fn iter(&self) -> BitStorageIter {
+ BitStorageIter {
+ storage: self,
+ index: 0,
+ }
+ }
+}
+
+pub struct BitStorageIter<'a> {
+ storage: &'a BitStorage,
+ index: usize,
+}
+
+impl<'a> Iterator for BitStorageIter<'a> {
+ type Item = u64;
+
+ fn next(&mut self) -> Option<Self::Item> {
+ if self.index >= self.storage.size {
+ return None;
+ }
+
+ let value = self.storage.get(self.index);
+ self.index += 1;
+ Some(value)
+ }
}
#[cfg(test)]
diff --git a/azalea-world/src/container.rs b/azalea-world/src/container.rs
index 866ac157..79cf2105 100644
--- a/azalea-world/src/container.rs
+++ b/azalea-world/src/container.rs
@@ -27,20 +27,18 @@ pub struct InstanceContainer {
// telling them apart. We hope most servers are nice and don't do that though. It's only an
// issue when there's multiple clients with the same WorldContainer in different worlds
// anyways.
- pub worlds: HashMap<ResourceLocation, Weak<RwLock<Instance>>>,
+ pub instances: HashMap<ResourceLocation, Weak<RwLock<Instance>>>,
}
impl InstanceContainer {
pub fn new() -> Self {
- InstanceContainer {
- worlds: HashMap::new(),
- }
+ InstanceContainer::default()
}
/// Get a world from the container. Returns `None` if none of the clients
/// are in this world.
pub fn get(&self, name: &InstanceName) -> Option<Arc<RwLock<Instance>>> {
- self.worlds.get(name).and_then(|world| world.upgrade())
+ self.instances.get(name).and_then(|world| world.upgrade())
}
/// Add an empty world to the container (or not if it already exists) and
@@ -52,7 +50,7 @@ impl InstanceContainer {
height: u32,
min_y: i32,
) -> Arc<RwLock<Instance>> {
- if let Some(existing_lock) = self.worlds.get(&name).and_then(|world| world.upgrade()) {
+ if let Some(existing_lock) = self.instances.get(&name).and_then(|world| world.upgrade()) {
let existing = existing_lock.read();
if existing.chunks.height != height {
error!(
@@ -73,7 +71,7 @@ impl InstanceContainer {
entities_by_chunk: HashMap::new(),
entity_by_id: IntMap::default(),
}));
- self.worlds.insert(name, Arc::downgrade(&world));
+ self.instances.insert(name, Arc::downgrade(&world));
world
}
}
diff --git a/azalea-world/src/heightmap.rs b/azalea-world/src/heightmap.rs
index ec73adf9..81aeb1e2 100644
--- a/azalea-world/src/heightmap.rs
+++ b/azalea-world/src/heightmap.rs
@@ -119,6 +119,25 @@ impl Heightmap {
false
}
+
+ /// Get an iterator over the top available block positions in this
+ /// heightmap.
+ pub fn iter_first_available<'a>(&'a self) -> impl Iterator<Item = ChunkBlockPos> + 'a {
+ self.data.iter().enumerate().map(move |(index, height)| {
+ let x = (index % 16) as u8;
+ let z = (index / 16) as u8;
+ ChunkBlockPos::new(x, height as i32 + self.min_y, z)
+ })
+ }
+
+ /// Get an iterator over the top block positions in this heightmap.
+ pub fn iter_highest_taken<'a>(&'a self) -> impl Iterator<Item = ChunkBlockPos> + 'a {
+ self.data.iter().enumerate().map(move |(index, height)| {
+ let x = (index % 16) as u8;
+ let z = (index / 16) as u8;
+ ChunkBlockPos::new(x, height as i32 + self.min_y - 1, z)
+ })
+ }
}
impl FromStr for HeightmapKind {