Trait LevelHost
pub trait LevelHost {
Show 19 methods
// Provided methods
fn block_entity_data(
&self,
_entity: BlockEntityRef,
) -> Option<BTreeMap<JavaString, Tag>> { ... }
fn block_state(&self, _pos: [i32; 3]) -> Option<BlockState> { ... }
fn state_block(&self, _state: BlockState) -> Option<&str> { ... }
fn block_state_id(&self, _name: &str) -> Option<BlockState> { ... }
fn block_state_default(&self, _block: BlockKey) -> Option<BlockState> { ... }
fn state_string(&self, _state: BlockState) -> Option<String> { ... }
fn min_y(&self) -> i32 { ... }
fn height(&self) -> i32 { ... }
fn block_in_tag(&self, _block: BlockKey, _tag: &str) -> Option<bool> { ... }
fn tags(&self) -> &dyn Tags { ... }
fn fluid_state(&self, _pos: [i32; 3]) -> Option<FluidState> { ... }
fn state_fluid_state(&self, _state: BlockState) -> Option<FluidState> { ... }
fn fluid_in_tag(&self, _fluid: &str, _tag: &str) -> Option<bool> { ... }
fn state_with_property(
&self,
_state: BlockState,
_key: &str,
_value: &str,
) -> Option<BlockState> { ... }
fn brightness(&self, _layer: LightLayer, _pos: [i32; 3]) -> i32 { ... }
fn raw_brightness(&self, _pos: [i32; 3], _sky_darken: i32) -> i32 { ... }
fn is_loaded(&self, _pos: [i32; 3]) -> bool { ... }
fn is_raining_at(&self, _pos: [i32; 3]) -> bool { ... }
fn enabled_features(&self) -> FeatureFlags { ... }
}Expand description
Read-only level services, like vanilla’s LevelReader.
A level host cannot be used as a game host:
use mod_api::{Host, LevelHost};
fn game(_: &dyn Host) {}
fn level(host: &dyn LevelHost) { game(host); }use mod_api::{ClientHost, LevelHost, ServerHost};
fn server(_: &mut dyn ServerHost) {}
fn client(_: &dyn ClientHost) {}
fn level(host: &mut dyn LevelHost) { server(host); client(host); }A client-side level cannot write:
use mod_api::LevelSide;
fn write(side: LevelSide<'_>) {
if let LevelSide::Client(level) = side { level.set_block_property([0, 0, 0], "a", "b", 0); }
}Provided Methods§
fn block_entity_data(
&self,
_entity: BlockEntityRef,
) -> Option<BTreeMap<JavaString, Tag>>
fn block_entity_data( &self, _entity: BlockEntityRef, ) -> Option<BTreeMap<JavaString, Tag>>
Read a block entity’s saved data without identity metadata from this level. Stale generations and handles from another level or world return None.
fn block_state(&self, _pos: [i32; 3]) -> Option<BlockState>
fn block_state(&self, _pos: [i32; 3]) -> Option<BlockState>
Read an owned block state through the level’s engine read.
Out-of-height or unloaded engine reads retain vanilla’s air as Some(air).
Returns None when the owning state index is unavailable or refuses the state;
this never substitutes an air state for a failed conversion.
fn state_block(&self, _state: BlockState) -> Option<&str>
fn state_block(&self, _state: BlockState) -> Option<&str>
The block state is a state of (BlockState.getBlock()): mymod:shaft. None for an
unknown state.
fn block_state_id(&self, _name: &str) -> Option<BlockState>
fn block_state_id(&self, _name: &str) -> Option<BlockState>
Parse a block name and properties as BlockStateParser.parseForBlock; None for invalid input or unavailable context.
fn block_state_default(&self, _block: BlockKey) -> Option<BlockState>
fn block_state_default(&self, _block: BlockKey) -> Option<BlockState>
The block’s default state (Block.defaultBlockState), or None for an unknown block.
fn state_string(&self, _state: BlockState) -> Option<String>
fn state_string(&self, _state: BlockState) -> Option<String>
The full block state name and properties, as BlockStateParser.serialize; None for an unknown id.
fn block_in_tag(&self, _block: BlockKey, _tag: &str) -> Option<bool>
fn block_in_tag(&self, _block: BlockKey, _tag: &str) -> Option<bool>
BlockState.is(TagKey): numeric membership of the resolved block in the merged block tag.
Unknown tags return false; unavailable authoritative tags or block mappings return None.
The merged-tag service for this level’s owning-thread context. Not on wasm: a frame resource; its methods are the imports.
fn fluid_state(&self, _pos: [i32; 3]) -> Option<FluidState>
fn fluid_state(&self, _pos: [i32; 3]) -> Option<FluidState>
BlockGetter.getFluidState: the fluid at pos, the empty fluid where there is none.
None where the position is not loaded or outside the build height; it never loads a chunk.
fn state_fluid_state(&self, _state: BlockState) -> Option<FluidState>
fn state_fluid_state(&self, _state: BlockState) -> Option<FluidState>
BlockState.getFluidState: the fluid a state holds (water for a waterlogged one). None
for an id no state has.
fn fluid_in_tag(&self, _fluid: &str, _tag: &str) -> Option<bool>
fn fluid_in_tag(&self, _fluid: &str, _tag: &str) -> Option<bool>
FluidState.is(TagKey): whether the fluid registry name is in the merged fluid tag, as block_in_tag reads.
fn state_with_property(
&self,
_state: BlockState,
_key: &str,
_value: &str,
) -> Option<BlockState>
fn state_with_property( &self, _state: BlockState, _key: &str, _value: &str, ) -> Option<BlockState>
BlockState.setValue, through native_state_with_property; None if invalid.
fn brightness(&self, _layer: LightLayer, _pos: [i32; 3]) -> i32
fn brightness(&self, _layer: LightLayer, _pos: [i32; 3]) -> i32
The stored light of one layer at pos (BlockAndLightGetter.getBrightness), 0 to 15.
It reads the game’s own light query: above the build height the sky is 15 and below it 0,
and a chunk that isn’t loaded reads as full sky and no block light. It never loads a chunk.
fn raw_brightness(&self, _pos: [i32; 3], _sky_darken: i32) -> i32
fn raw_brightness(&self, _pos: [i32; 3], _sky_darken: i32) -> i32
BlockAndLightGetter.getRawBrightness(pos, darkening): the brighter of the block light
and the sky light less sky_darken. CropBlock.randomTick asks it with 0.
fn is_loaded(&self, _pos: [i32; 3]) -> bool
fn is_loaded(&self, _pos: [i32; 3]) -> bool
Level.isLoaded: pos is inside the build height and its chunk is loaded. Asking never
loads the chunk.
fn is_raining_at(&self, _pos: [i32; 3]) -> bool
fn is_raining_at(&self, _pos: [i32; 3]) -> bool
Level.isRainingAt: it rains in this level and pos is open to the sky (full sky light,
nothing motion-blocking or fluid above it) in a biome whose precipitation there is rain,
not snow or none. False where pos is not loaded, the chunk is never loaded for it.
fn enabled_features(&self) -> FeatureFlags
fn enabled_features(&self) -> FeatureFlags
LevelReader.enabledFeatures: the feature flags the world enables.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".