Skip to main content

LootContext

Struct LootContext 

Source
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 R

Random number generator.

§luck: f32

Luck 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: bool

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

Source

pub fn new(rng: &'a mut R) -> Self

Create a new loot context with just an RNG.

Source

pub fn with_luck(self, luck: f32) -> Self

Set the luck value.

Source

pub fn with_block_state(self, state: BlockStateId) -> Self

Set the block state.

Source

pub fn with_tool(self, tool: &'a ItemStack) -> Self

Set the tool used.

Source

pub fn with_explosion(self, radius: f32) -> Self

Set the explosion radius.

Source

pub fn with_killed_by_player(self, killed: bool) -> Self

Set whether killed by player.

Source

pub fn with_origin(self, x: f64, y: f64, z: f64) -> Self

Set the world origin position.

Source

pub fn with_game_time(self, time: i64) -> Self

Set the game time.

Source

pub fn with_weather(self, weather: WeatherState) -> Self

Set the weather state.

Source

pub fn with_this_entity(self, entity: EntityRef<'a>) -> Self

Set the entity being looted.

Source

pub fn with_killer_entity(self, entity: EntityRef<'a>) -> Self

Set the killer entity.

Source

pub fn with_direct_killer_entity(self, entity: EntityRef<'a>) -> Self

Set the direct killer entity (e.g., projectile).

Source

pub fn with_last_damage_player(self, entity: EntityRef<'a>) -> Self

Set the player who dealt the final damage.

Source

pub fn with_damage_source(self, damage_source: DamageSourceInfo<'a>) -> Self

Set the damage source information.

Source

pub fn with_block_entity(self, block_entity: BlockEntityRef<'a>) -> Self

Set the block entity reference.

Source

pub fn with_interacting_entity(self, entity: EntityRef<'a>) -> Self

Set the interacting entity (e.g., player opening a chest).

Source

pub fn get_enchantment_level_by_id(&self, enchantment: &Identifier) -> i32

Get the level of an enchantment on the tool by identifier.

Source

pub fn get_entity(&self, target: LootContextEntity) -> Option<EntityRef<'a>>

Get an entity reference by target.

Auto Trait Implementations§

§

impl<'a, R> !UnwindSafe for LootContext<'a, R>

§

impl<'a, R> Freeze for LootContext<'a, R>

§

impl<'a, R> RefUnwindSafe for LootContext<'a, R>
where R: RefUnwindSafe,

§

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

§

impl<T> Instrument for T

§

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

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

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

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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