aboutsummaryrefslogtreecommitdiff
path: root/azalea-world/src
diff options
context:
space:
mode:
authormat <github@matdoes.dev>2022-12-08 18:39:35 -0600
committermat <github@matdoes.dev>2022-12-08 18:39:35 -0600
commit70e2dfed16da8d5130460ea15b47701e622f4a9f (patch)
tree41f670baf3a05ed180880ec2a11d8e5f6a1a1599 /azalea-world/src
parentf2076daba5cfcce81399b075ba9258fbdc2012fa (diff)
downloadazalea-drasl-70e2dfed16da8d5130460ea15b47701e622f4a9f.tar.xz
wrap_comments = true
Diffstat (limited to 'azalea-world/src')
-rwxr-xr-xazalea-world/src/chunk_storage.rs6
-rw-r--r--azalea-world/src/entity/mod.rs16
-rwxr-xr-xazalea-world/src/entity_storage.rs36
-rwxr-xr-xazalea-world/src/palette.rs9
-rw-r--r--azalea-world/src/world.rs6
5 files changed, 46 insertions, 27 deletions
diff --git a/azalea-world/src/chunk_storage.rs b/azalea-world/src/chunk_storage.rs
index 6a8a995e..7d4486e4 100755
--- a/azalea-world/src/chunk_storage.rs
+++ b/azalea-world/src/chunk_storage.rs
@@ -50,9 +50,9 @@ pub struct ChunkStorage {
pub chunks: HashMap<ChunkPos, Arc<Mutex<Chunk>>>,
}
-/// A single chunk in a world (16*?*16 blocks). This only contains the blocks and biomes. You
-/// can derive the height of the chunk from the number of sections, but you
-/// need a [`ChunkStorage`] to get the minimum Y coordinate.
+/// A single chunk in a world (16*?*16 blocks). This only contains the blocks
+/// and biomes. You can derive the height of the chunk from the number of
+/// sections, but you need a [`ChunkStorage`] to get the minimum Y coordinate.
#[derive(Debug)]
pub struct Chunk {
pub sections: Vec<Section>,
diff --git a/azalea-world/src/entity/mod.rs b/azalea-world/src/entity/mod.rs
index dbf7e665..814ef6d2 100644
--- a/azalea-world/src/entity/mod.rs
+++ b/azalea-world/src/entity/mod.rs
@@ -53,7 +53,8 @@ impl<'d, D: DerefMut<Target = World>> Entity<'d, D> {
pub fn set_rotation(&mut self, y_rot: f32, x_rot: f32) {
self.y_rot = y_rot % 360.0;
self.x_rot = x_rot.clamp(-90.0, 90.0) % 360.0;
- // TODO: minecraft also sets yRotO and xRotO to xRot and yRot ... but idk what they're used for so
+ // TODO: minecraft also sets yRotO and xRotO to xRot and yRot ... but
+ // idk what they're used for so
}
pub fn move_relative(&mut self, speed: f32, acceleration: &Vec3) {
@@ -116,8 +117,8 @@ impl<'d, D: Deref<Target = World>> Entity<'d, D> {
// if (this.level.getBlockState(var5).isAir()) {
// BlockPos var6 = var5.below();
// BlockState var7 = this.level.getBlockState(var6);
- // if (var7.is(BlockTags.FENCES) || var7.is(BlockTags.WALLS) || var7.getBlock() instanceof FenceGateBlock) {
- // return var6;
+ // if (var7.is(BlockTags.FENCES) || var7.is(BlockTags.WALLS) ||
+ // var7.getBlock() instanceof FenceGateBlock) { return var6;
// }
// }
// return var5;
@@ -181,7 +182,8 @@ impl<D: Deref<Target = World>> Deref for Entity<'_, D> {
pub struct EntityData {
pub uuid: Uuid,
/// The position of the entity right now.
- /// This can be changde with unsafe_move, but the correct way is with world.move_entity
+ /// This can be changde with unsafe_move, but the correct way is with
+ /// world.move_entity
pos: Vec3,
/// The position of the entity last tick.
pub last_pos: Vec3,
@@ -205,7 +207,8 @@ pub struct EntityData {
/// The width and height of the entity.
pub dimensions: EntityDimensions,
- /// The bounding box of the entity. This is more than just width and height, unlike dimensions.
+ /// The bounding box of the entity. This is more than just width and height,
+ /// unlike dimensions.
pub bounding_box: AABB,
/// Whether the entity will try to jump every tick
@@ -258,7 +261,8 @@ impl EntityData {
metadata,
attributes: AttributeModifiers {
- // TODO: do the correct defaults for everything, some entities have different defaults
+ // TODO: do the correct defaults for everything, some entities have different
+ // defaults
speed: AttributeInstance::new(0.1),
},
}
diff --git a/azalea-world/src/entity_storage.rs b/azalea-world/src/entity_storage.rs
index 4826abdb..0e8fc0b5 100755
--- a/azalea-world/src/entity_storage.rs
+++ b/azalea-world/src/entity_storage.rs
@@ -11,13 +11,20 @@ use uuid::Uuid;
// How entity updates are processed (to avoid issues with shared worlds)
// - each bot contains a map of { entity id: updates received }
-// - the shared world also contains a canonical "true" updates received for each entity
-// - when a client loads an entity, its "updates received" is set to the same as the global "updates received"
-// - when the shared world sees an entity for the first time, the "updates received" is set to 1.
-// - clients can force the shared "updates received" to 0 to make it so certain entities (i.e. other bots in our swarm) don't get confused and updated by other bots
-// - when a client gets an update to an entity, we check if our "updates received" is the same as the shared world's "updates received":
-// if it is, then process the update and increment the client's and shared world's "updates received"
-// if not, then we simply increment our local "updates received" and do nothing else
+// - the shared world also contains a canonical "true" updates received for each
+// entity
+// - when a client loads an entity, its "updates received" is set to the same as
+// the global "updates received"
+// - when the shared world sees an entity for the first time, the "updates
+// received" is set to 1.
+// - clients can force the shared "updates received" to 0 to make it so certain
+// entities (i.e. other bots in our swarm) don't get confused and updated by
+// other bots
+// - when a client gets an update to an entity, we check if our "updates
+// received" is the same as the shared world's "updates received": if it is,
+// then process the update and increment the client's and shared world's
+// "updates received" if not, then we simply increment our local "updates
+// received" and do nothing else
/// Store a map of entities by ID. To get an iterator over all entities, use
/// `storage.shared.read().entities` [`WeakEntityStorage::entities`].
@@ -125,7 +132,8 @@ impl PartialEntityStorage {
self.shared.read().data_by_id.contains_key(id)
}
- /// Get a reference to an entity by its id, if it's being loaded by this storage.
+ /// Get a reference to an entity by its id, if it's being loaded by this
+ /// storage.
#[inline]
pub fn limited_get_by_id(&self, id: u32) -> Option<&Arc<EntityData>> {
self.data_by_id.get(&id)
@@ -138,10 +146,11 @@ impl PartialEntityStorage {
self.data_by_id.get_mut(&id)
}
- /// Returns whether we're allowed to update this entity (to prevent two clients in
- /// a shared world updating it twice), and acknowleges that we WILL update
- /// it if it's true. Don't call this unless you actually got an entity
- /// update that all other clients within render distance will get too.
+ /// Returns whether we're allowed to update this entity (to prevent two
+ /// clients in a shared world updating it twice), and acknowleges that
+ /// we WILL update it if it's true. Don't call this unless you actually
+ /// got an entity update that all other clients within render distance
+ /// will get too.
pub fn maybe_update(&mut self, id: u32) -> bool {
let this_client_updates_received = self.updates_received.get(&id).copied();
let shared_updates_received = self.shared.read().updates_received.get(&id).copied();
@@ -302,7 +311,8 @@ impl WeakEntityStorage {
);
}
if self.updates_received.remove(&id).is_none() {
- // if this happens it means we weren't tracking the updates_received for the client (bad)
+ // if this happens it means we weren't tracking the updates_received for the
+ // client (bad)
warn!(
"Tried to remove entity with id {id} from updates_received but it was not found."
);
diff --git a/azalea-world/src/palette.rs b/azalea-world/src/palette.rs
index e359e7bc..f78b2082 100755
--- a/azalea-world/src/palette.rs
+++ b/azalea-world/src/palette.rs
@@ -83,7 +83,8 @@ impl PalettedContainer {
.get_and_set(self.get_index(x, y, z), paletted_value as u64) as u32
}
- /// Sets the id at the given index and return the previous id. You probably want `.set` instead.
+ /// Sets the id at the given index and return the previous id. You probably
+ /// want `.set` instead.
pub fn set_at_index(&mut self, index: usize, value: u32) {
let paletted_value = self.id_for(value);
self.storage.set(index, paletted_value as u64)
@@ -110,7 +111,8 @@ impl PalettedContainer {
// sanity check
debug_assert_eq!(storage.size(), self.container_type.size());
- // let palette = new_palette_type.as_empty_palette(1usize << (bits_per_entry as usize));
+ // let palette = new_palette_type.as_empty_palette(1usize << (bits_per_entry as
+ // usize));
let palette = new_palette_type.as_empty_palette();
PalettedContainer {
bits_per_entry,
@@ -197,7 +199,8 @@ pub enum PaletteType {
pub enum Palette {
/// ID of the corresponding entry in its global palette
SingleValue(u32),
- // in vanilla this keeps a `size` field that might be less than the length, but i'm not sure it's actually needed?
+ // in vanilla this keeps a `size` field that might be less than the length, but i'm not sure
+ // it's actually needed?
Linear(Vec<u32>),
Hashmap(Vec<u32>),
Global,
diff --git a/azalea-world/src/world.rs b/azalea-world/src/world.rs
index 257d9eb6..65d001c3 100644
--- a/azalea-world/src/world.rs
+++ b/azalea-world/src/world.rs
@@ -11,7 +11,8 @@ use std::{backtrace::Backtrace, fmt::Debug};
use std::{fmt::Formatter, io::Cursor, sync::Arc};
use uuid::Uuid;
-/// A world is a collection of chunks and entities. They're called "levels" in Minecraft's source code.
+/// A world is a collection of chunks and entities. They're called "levels" in
+/// Minecraft's source code.
#[derive(Default)]
pub struct World {
// we just need to keep a strong reference to `shared` so it doesn't get
@@ -22,7 +23,8 @@ pub struct World {
pub entity_storage: PartialEntityStorage,
}
-/// A world where the chunks are stored as weak pointers. This is used for shared worlds.
+/// A world where the chunks are stored as weak pointers. This is used for
+/// shared worlds.
#[derive(Default)]
pub struct WeakWorld {
pub chunk_storage: Arc<RwLock<WeakChunkStorage>>,