pub struct LootContext<'a, R: Rng> {Show 16 fields
pub rng: &'a mut R,
pub luck: f32,
pub block_state: Option<BlockStateId>,
pub tool: Option<&'a ItemStack>,
pub explosion_radius: Option<f32>,
pub killed_by_player: bool,
pub origin: Option<(f64, f64, f64)>,
pub game_time: Option<i64>,
pub weather: Option<WeatherState>,
pub this_entity: Option<EntityRef<'a>>,
pub killer_entity: Option<EntityRef<'a>>,
pub direct_killer_entity: Option<EntityRef<'a>>,
pub last_damage_player: Option<EntityRef<'a>>,
pub damage_source: Option<DamageSourceInfo<'a>>,
pub block_entity: Option<BlockEntityRef<'a>>,
pub interacting_entity: Option<EntityRef<'a>>,
}Expand description
Context for loot table evaluation, containing all relevant game state.
This mirrors vanilla’s LootContext / LootParams system.
Fields§
§rng: &'a mut RRandom number generator.
luck: f32Luck value (e.g., from Luck of the Sea enchantment).
block_state: Option<BlockStateId>The block state being broken (for block loot tables).
tool: Option<&'a ItemStack>The tool used to break the block.
explosion_radius: Option<f32>Explosion radius if caused by an explosion.
killed_by_player: boolWhether the entity was killed by a player.
origin: Option<(f64, f64, f64)>World position where the loot is generated (block position or entity death location).
game_time: Option<i64>Current game time in ticks (for TimeCheck condition).
weather: Option<WeatherState>Current weather state.
this_entity: Option<EntityRef<'a>>The entity being looted (the killed mob, block entity owner, etc.). This is a type-erased pointer; actual entity data depends on game implementation.
killer_entity: Option<EntityRef<'a>>The entity that killed this_entity (for mob loot tables).
direct_killer_entity: Option<EntityRef<'a>>The direct attacker entity (e.g., arrow, not the player who shot it).
last_damage_player: Option<EntityRef<'a>>The player who dealt the final damage (may be different from killer).
damage_source: Option<DamageSourceInfo<'a>>Damage source information for entity deaths.
block_entity: Option<BlockEntityRef<'a>>Block entity reference for container/block loot.
interacting_entity: Option<EntityRef<'a>>The entity interacting with a block/entity (e.g., player opening a chest).
Implementations§
Source§impl<'a, R: Rng> LootContext<'a, R>
impl<'a, R: Rng> LootContext<'a, R>
Sourcepub const fn with_block_state(self, state: BlockStateId) -> Self
pub const fn with_block_state(self, state: BlockStateId) -> Self
Set the block state.
Sourcepub const fn with_explosion(self, radius: f32) -> Self
pub const fn with_explosion(self, radius: f32) -> Self
Set the explosion radius.
Sourcepub const fn with_killed_by_player(self, killed: bool) -> Self
pub const fn with_killed_by_player(self, killed: bool) -> Self
Set whether killed by player.
Sourcepub const fn with_origin(self, x: f64, y: f64, z: f64) -> Self
pub const fn with_origin(self, x: f64, y: f64, z: f64) -> Self
Set the world origin position.
Sourcepub const fn with_game_time(self, time: i64) -> Self
pub const fn with_game_time(self, time: i64) -> Self
Set the game time.
Sourcepub const fn with_weather(self, weather: WeatherState) -> Self
pub const fn with_weather(self, weather: WeatherState) -> Self
Set the weather state.
Sourcepub const fn with_this_entity(self, entity: EntityRef<'a>) -> Self
pub const fn with_this_entity(self, entity: EntityRef<'a>) -> Self
Set the entity being looted.
Sourcepub const fn with_killer_entity(self, entity: EntityRef<'a>) -> Self
pub const fn with_killer_entity(self, entity: EntityRef<'a>) -> Self
Set the killer entity.
Sourcepub const fn with_direct_killer_entity(self, entity: EntityRef<'a>) -> Self
pub const fn with_direct_killer_entity(self, entity: EntityRef<'a>) -> Self
Set the direct killer entity (e.g., projectile).
Sourcepub const fn with_last_damage_player(self, entity: EntityRef<'a>) -> Self
pub const fn with_last_damage_player(self, entity: EntityRef<'a>) -> Self
Set the player who dealt the final damage.
Sourcepub const fn with_damage_source(
self,
damage_source: DamageSourceInfo<'a>,
) -> Self
pub const fn with_damage_source( self, damage_source: DamageSourceInfo<'a>, ) -> Self
Set the damage source information.
Sourcepub const fn with_block_entity(self, block_entity: BlockEntityRef<'a>) -> Self
pub const fn with_block_entity(self, block_entity: BlockEntityRef<'a>) -> Self
Set the block entity reference.
Sourcepub const fn with_interacting_entity(self, entity: EntityRef<'a>) -> Self
pub const fn with_interacting_entity(self, entity: EntityRef<'a>) -> Self
Set the interacting entity (e.g., player opening a chest).
Sourcepub fn get_enchantment_level_by_id(&self, enchantment: &Identifier) -> i32
pub fn get_enchantment_level_by_id(&self, enchantment: &Identifier) -> i32
Get the level of an enchantment on the tool by identifier.
Sourcepub const fn get_entity(
&self,
target: LootContextEntity,
) -> Option<EntityRef<'a>>
pub const fn get_entity( &self, target: LootContextEntity, ) -> Option<EntityRef<'a>>
Get an entity reference by target.
Auto Trait Implementations§
impl<'a, R> !RefUnwindSafe for LootContext<'a, R>
impl<'a, R> !UnwindSafe for LootContext<'a, R>
impl<'a, R> Freeze for LootContext<'a, R>
impl<'a, R> Send for LootContext<'a, R>where
R: Send,
impl<'a, R> Sync for LootContext<'a, R>where
R: Sync,
impl<'a, R> Unpin for LootContext<'a, R>
impl<'a, R> UnsafeUnpin for LootContext<'a, R>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreArc<SyncMutex<>>