Skip to main content

World

Struct World 

Source
pub struct World {
    pub chunks: ChunkStorage,
    pub entities_by_chunk: HashMap<ChunkPos, HashSet<Entity>>,
    pub entity_by_id: IntMap<MinecraftEntityId, Entity>,
    pub registries: RegistryHolder,
}
Expand description

A Minecraft world, sometimes referred to as a dimension.

This is the most commonly used type to interact with the world that a client is in. In here, all chunks are stored as weak pointers, which means that clients in different areas of the same world can share the same World instance.

Also see PartialWorld.

Note that this is distinct from Bevy’s World type, which contains all of the data for every client. When referring to the Bevy World within Azalea, the term “ECS” is generally used instead.

Fields§

§chunks: ChunkStorage§entities_by_chunk: HashMap<ChunkPos, HashSet<Entity>>

An index of all the entities we know are in the chunks of the world

§entity_by_id: IntMap<MinecraftEntityId, Entity>

An index of Minecraft entity IDs to Azalea ECS entities.

You should avoid using this (particularly if you’re using swarms) and instead use azalea_entity::EntityIdIndex, since some servers may give different entity IDs for the same entities to different players.

§registries: RegistryHolder

Implementations§

Source§

impl World

Source

pub fn find_block( &self, nearest_to: impl Into<BlockPos>, block_states: &BlockStates, ) -> Option<BlockPos>

Find the coordinates of a block in the world.

Note that this is sorted by x+y+z and not x^2+y^2+z^2 for performance purposes.

let pos = world.find_block(position, &BlockKind::Chest.into());
Source

pub fn find_blocks<'a>( &'a self, nearest_to: impl Into<BlockPos>, block_states: &'a BlockStates, ) -> FindBlocks<'a>

Find all the coordinates of a block in the world.

This returns an iterator that yields the BlockPoss of blocks that are in the given block states.

Note that this is sorted by x+y+z and not x^2+y^2+z^2 for performance purposes.

Source§

impl World

Source

pub fn get_block_state(&self, pos: BlockPos) -> Option<BlockState>

Get the block at the given position, or None if it’s outside of the world that we have loaded.

Source

pub fn get_fluid_state(&self, pos: BlockPos) -> Option<FluidState>

Similar to Self::get_block_state, but returns data about the fluid at the position, including for waterlogged blocks.

Source

pub fn get_biome(&self, pos: BlockPos) -> Option<Biome>

Get the biome at the given position.

You can then use Client::with_resolved_registry to get the name and data from the biome.

Note that biomes are internally stored as 4x4x4 blocks, so if you’re writing code that searches for a specific biome it’ll probably be more efficient to avoid scanning every single block.

Source

pub fn set_block_state( &self, pos: BlockPos, state: BlockState, ) -> Option<BlockState>

Trait Implementations§

Source§

impl Debug for World

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for World

Source§

fn default() -> World

Returns the “default value” for a type. Read more
Source§

impl From<ChunkStorage> for World

Source§

fn from(chunks: ChunkStorage) -> Self

Make an empty world from this ChunkStorage. This is meant to be a convenience function for tests.

Auto Trait Implementations§

§

impl Freeze for World

§

impl !RefUnwindSafe for World

§

impl Send for World

§

impl Sync for World

§

impl Unpin for World

§

impl UnsafeUnpin 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> FromWorld for T
where T: Default,

Source§

fn from_world(_world: &mut World) -> T

Creates Self using default().

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoResult<T> for T

Source§

fn into_result(self) -> Result<T, RunSystemError>

Converts this type into the system output type.
Source§

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

Source§

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>,

Source§

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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ConditionalSend for T
where T: Send,