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

rename World to dimension

A world is a collection of dimensions
This commit is contained in:
mat 2022-06-25 14:24:56 -05:00
parent cd9a05e5a6
commit 77980f0018
4 changed files with 29 additions and 23 deletions

View file

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

View file

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

View file

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

View file

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