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 fn with_block_state(self, state: BlockStateId) -> Self
pub fn with_block_state(self, state: BlockStateId) -> Self
Set the block state.
Sourcepub fn with_explosion(self, radius: f32) -> Self
pub fn with_explosion(self, radius: f32) -> Self
Set the explosion radius.
Sourcepub fn with_killed_by_player(self, killed: bool) -> Self
pub fn with_killed_by_player(self, killed: bool) -> Self
Set whether killed by player.
Sourcepub fn with_origin(self, x: f64, y: f64, z: f64) -> Self
pub fn with_origin(self, x: f64, y: f64, z: f64) -> Self
Set the world origin position.
Sourcepub fn with_game_time(self, time: i64) -> Self
pub fn with_game_time(self, time: i64) -> Self
Set the game time.
Sourcepub fn with_weather(self, weather: WeatherState) -> Self
pub fn with_weather(self, weather: WeatherState) -> Self
Set the weather state.
Sourcepub fn with_this_entity(self, entity: EntityRef<'a>) -> Self
pub fn with_this_entity(self, entity: EntityRef<'a>) -> Self
Set the entity being looted.
Sourcepub fn with_killer_entity(self, entity: EntityRef<'a>) -> Self
pub fn with_killer_entity(self, entity: EntityRef<'a>) -> Self
Set the killer entity.
Sourcepub fn with_direct_killer_entity(self, entity: EntityRef<'a>) -> Self
pub fn with_direct_killer_entity(self, entity: EntityRef<'a>) -> Self
Set the direct killer entity (e.g., projectile).
Sourcepub fn with_last_damage_player(self, entity: EntityRef<'a>) -> Self
pub fn with_last_damage_player(self, entity: EntityRef<'a>) -> Self
Set the player who dealt the final damage.
Sourcepub fn with_damage_source(self, damage_source: DamageSourceInfo<'a>) -> Self
pub fn with_damage_source(self, damage_source: DamageSourceInfo<'a>) -> Self
Set the damage source information.
Sourcepub fn with_block_entity(self, block_entity: BlockEntityRef<'a>) -> Self
pub fn with_block_entity(self, block_entity: BlockEntityRef<'a>) -> Self
Set the block entity reference.
Sourcepub fn with_interacting_entity(self, entity: EntityRef<'a>) -> Self
pub 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 fn get_entity(&self, target: LootContextEntity) -> Option<EntityRef<'a>>
pub fn get_entity(&self, target: LootContextEntity) -> Option<EntityRef<'a>>
Get an entity reference by target.