aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormat <github@matdoes.dev>2022-06-25 14:24:56 -0500
committermat <github@matdoes.dev>2022-06-25 14:24:56 -0500
commit77980f0018eca3a192994021b76ad5d05bff88ea (patch)
tree8a7ad1337f21542f1dbe098057b1e4e156df976c
parentcd9a05e5a62190b3d4a2a733bf637d6324aec5fd (diff)
downloadazalea-drasl-77980f0018eca3a192994021b76ad5d05bff88ea.tar.xz
rename World to dimension
A world is a collection of dimensions
-rw-r--r--azalea-client/src/client.rs22
-rw-r--r--azalea-client/src/player.rs4
-rw-r--r--azalea-world/src/chunk.rs15
-rw-r--r--azalea-world/src/lib.rs11
4 files changed, 29 insertions, 23 deletions
diff --git a/azalea-client/src/client.rs b/azalea-client/src/client.rs
index dfefe4ad..2bc73551 100644
--- a/azalea-client/src/client.rs
+++ b/azalea-client/src/client.rs
@@ -23,7 +23,7 @@ use azalea_protocol::{
},
resolver, ServerAddress,
};
-use azalea_world::World;
+use azalea_world::Dimension;
use owning_ref::OwningRef;
use std::{
fmt::Debug,
@@ -37,7 +37,7 @@ use tokio::{
#[derive(Default)]
pub struct ClientState {
pub player: Player,
- pub world: Option<World>,
+ pub world: Option<Dimension>,
}
#[derive(Debug, Clone)]
@@ -294,13 +294,15 @@ impl Client {
// the 16 here is our render distance
// i'll make this an actual setting later
- state_lock.world = Some(World::new(16, height, min_y));
+ state_lock.world = Some(Dimension::new(16, height, min_y));
let entity = Entity::new(p.player_id, game_profile.uuid, EntityPos::default());
state_lock
.world
.as_mut()
- .expect("World doesn't exist! We should've gotten a login packet by now.")
+ .expect(
+ "Dimension doesn't exist! We should've gotten a login packet by now.",
+ )
.add_entity(entity);
state_lock.player.set_entity_id(p.player_id);
@@ -461,7 +463,7 @@ impl Client {
.lock()?
.world
.as_mut()
- .expect("World doesn't exist! We should've gotten a login packet by now.")
+ .expect("Dimension doesn't exist! We should've gotten a login packet by now.")
.replace_with_packet_data(&pos, &mut p.chunk_data.data.as_slice())
.unwrap();
}
@@ -475,7 +477,7 @@ impl Client {
.lock()?
.world
.as_mut()
- .expect("World doesn't exist! We should've gotten a login packet by now.")
+ .expect("Dimension doesn't exist! We should've gotten a login packet by now.")
.add_entity(entity);
}
GamePacket::ClientboundSetEntityDataPacket(_p) => {
@@ -497,7 +499,7 @@ impl Client {
.lock()?
.world
.as_mut()
- .expect("World doesn't exist! We should've gotten a login packet by now.")
+ .expect("Dimension doesn't exist! We should've gotten a login packet by now.")
.add_entity(entity);
}
GamePacket::ClientboundInitializeBorderPacket(p) => {
@@ -640,14 +642,14 @@ impl Client {
tx.send(Event::GameTick).unwrap();
}
- /// Gets the `World` the client is in.
+ /// Gets the `Dimension` the client is in.
///
/// This is basically a shortcut for `client.state.lock().unwrap().world.as_ref().unwrap()`.
/// If the client hasn't received a login packet yet, this will panic.
- pub fn world(&self) -> OwningRef<std::sync::MutexGuard<ClientState>, World> {
+ pub fn world(&self) -> OwningRef<std::sync::MutexGuard<ClientState>, Dimension> {
let state_lock: std::sync::MutexGuard<ClientState> = self.state.lock().unwrap();
let state_lock_ref = OwningRef::new(state_lock);
- state_lock_ref.map(|state| state.world.as_ref().expect("World doesn't exist!"))
+ state_lock_ref.map(|state| state.world.as_ref().expect("Dimension doesn't exist!"))
}
/// Gets the `Player` struct for our player.
diff --git a/azalea-client/src/player.rs b/azalea-client/src/player.rs
index ee0b9718..7501eede 100644
--- a/azalea-client/src/player.rs
+++ b/azalea-client/src/player.rs
@@ -1,5 +1,5 @@
use azalea_entity::Entity;
-use azalea_world::World;
+use azalea_world::Dimension;
use uuid::Uuid;
#[derive(Default, Debug)]
@@ -12,7 +12,7 @@ pub struct Player {
impl Player {
/// Get the entity of the player in the world.
- pub fn entity<'a>(&self, world: &'a World) -> Option<&'a Entity> {
+ pub fn entity<'a>(&self, world: &'a Dimension) -> Option<&'a Entity> {
// world.entity_by_uuid(&self.uuid)
world.entity_by_id(self.entity_id)
}
diff --git a/azalea-world/src/chunk.rs b/azalea-world/src/chunk.rs
index a19ece8c..e4893ace 100644
--- a/azalea-world/src/chunk.rs
+++ b/azalea-world/src/chunk.rs
@@ -1,6 +1,6 @@
use crate::palette::PalettedContainer;
use crate::palette::PalettedContainerType;
-use crate::World;
+use crate::Dimension;
use azalea_block::BlockState;
use azalea_buf::{McBufReadable, McBufWritable};
use azalea_core::{BlockPos, ChunkBlockPos, ChunkPos, ChunkSectionBlockPos};
@@ -78,7 +78,7 @@ impl ChunkStorage {
return Ok(());
}
- let chunk = Arc::new(Mutex::new(Chunk::read_with_world_height(
+ let chunk = Arc::new(Mutex::new(Chunk::read_with_dimension_height(
data,
self.height,
)?));
@@ -109,12 +109,15 @@ pub struct Chunk {
}
impl Chunk {
- pub fn read_with_world(buf: &mut impl Read, data: &World) -> Result<Self, String> {
- Self::read_with_world_height(buf, data.height())
+ pub fn read_with_dimension(buf: &mut impl Read, data: &Dimension) -> Result<Self, String> {
+ Self::read_with_dimension_height(buf, data.height())
}
- pub fn read_with_world_height(buf: &mut impl Read, world_height: u32) -> Result<Self, String> {
- let section_count = world_height / SECTION_HEIGHT;
+ pub fn read_with_dimension_height(
+ buf: &mut impl Read,
+ dimension_height: u32,
+ ) -> Result<Self, String> {
+ let section_count = dimension_height / SECTION_HEIGHT;
let mut sections = Vec::with_capacity(section_count as usize);
for _ in 0..section_count {
let section = Section::read_from(buf)?;
diff --git a/azalea-world/src/lib.rs b/azalea-world/src/lib.rs
index 3afa4fee..7822dcc4 100644
--- a/azalea-world/src/lib.rs
+++ b/azalea-world/src/lib.rs
@@ -27,15 +27,16 @@ mod tests {
}
}
+/// A dimension is a collection of chunks and entities.
#[derive(Debug)]
-pub struct World {
+pub struct Dimension {
chunk_storage: ChunkStorage,
entity_storage: EntityStorage,
}
-impl World {
+impl Dimension {
pub fn new(chunk_radius: u32, height: u32, min_y: i32) -> Self {
- World {
+ Dimension {
chunk_storage: ChunkStorage::new(chunk_radius, height, min_y),
entity_storage: EntityStorage::new(),
}
@@ -135,14 +136,14 @@ impl World {
}
}
-impl Index<&ChunkPos> for World {
+impl Index<&ChunkPos> for Dimension {
type Output = Option<Arc<Mutex<Chunk>>>;
fn index(&self, pos: &ChunkPos) -> &Self::Output {
&self.chunk_storage[pos]
}
}
-impl IndexMut<&ChunkPos> for World {
+impl IndexMut<&ChunkPos> for Dimension {
fn index_mut<'a>(&'a mut self, pos: &ChunkPos) -> &'a mut Self::Output {
&mut self.chunk_storage[pos]
}