Struct memory_management::world::World

source ·
pub struct World { /* private fields */ }
Expand description

A struct to manage a world

Implementations§

source§

impl World

source

pub fn new(region_file_location: &'static str) -> Self

Creates a new instance of World.

This function initializes a new World with empty players, a new generator, and a ChunkHolder initialized with the provided region file location.

§Arguments
  • region_file_location - A static string slice that specifies the location of the region file to be used by the ChunkHolder.
§Returns
  • A new instance of World.
§Example
use std::collections::HashMap;
use memory_management::world::Generator;
use memory_management::world::chunks::ChunkHolder;
use memory_management::world::World;

fn main() {
    // Specify the region file location
    let region_file_location = "../../../nbt_lib/test_data/test_world/region/";

    // Create a new World instance
    let world = World::new(region_file_location);

    // Use the World instance
    println!("New world created with region file: {}", region_file_location);
}
§See Also
source

pub fn get_chunk(&mut self, x: i64, z: i64) -> Result<Rc<ChunkData>, ()>

Retrieves a chunk at the specified coordinates (x, z).

This function first attempts to get an existing chunk from the internal storage. If the chunk is found and its generation status is GenerationStatus::Full, it is returned wrapped in Ok.

If the chunk is not found or its generation status is not Full, a new chunk is generated for the specified coordinates. After generation, the chunk is inserted into the internal storage. If the insertion is successful, the generated chunk is returned wrapped in Ok.

If both retrieving and generating the chunk fail, the function returns Err.

§Arguments
  • x - The x-coordinate of the chunk.
  • z - The z-coordinate of the chunk.
§Returns
  • Ok(Rc<ChunkData>) - If the chunk is found and has a Full generation status or is successfully generated.
  • Err(()) - If the chunk cannot be retrieved or generated.
§Errors

This function returns Err(()) if the chunk cannot be retrieved or generated, or if the retrieved chunk’s generation status is not Full.

§Example
use memory_management::world::World;
use level_lib::anvil::region::chunk::chunk_data::ChunkData;
let mut world = World::new("../../../nbt_lib/test_data/test_world/region/");
let chunk = world.get_chunk(1000, 1000).expect("This should not fail, because a chunks is getting
generated, if the read chunk does not exist or is incomplete");
assert!(matches!(chunk.as_ref(), &ChunkData { .. }));

Auto Trait Implementations§

§

impl !Freeze for World

§

impl RefUnwindSafe for World

§

impl !Send for World

§

impl !Sync for World

§

impl Unpin for World

§

impl UnwindSafe for World

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.