Skip to main content

LootCondition

Enum LootCondition 

Source
pub enum LootCondition {
Show 19 variants SurvivesExplosion, BlockStateProperty { block: Identifier, properties: &'static [PropertyCheck], }, RandomChance(f32), RandomChanceWithEnchantedBonus { enchantment: Identifier, unenchanted_chance: f32, enchanted_chance: EnchantedChance, }, MatchTool(ToolPredicate), TableBonus { enchantment: Identifier, chances: &'static [f32], }, Inverted(&'static LootCondition), AnyOf(&'static [LootCondition]), AllOf(&'static [LootCondition]), KilledByPlayer, EntityProperties { entity: LootContextEntity, predicate: EntityPredicate, }, DamageSourceProperties { predicate: DamageSourcePredicate, }, LocationCheck { offset_x: i32, offset_y: i32, offset_z: i32, predicate: LocationPredicate, }, WeatherCheck { raining: Option<bool>, thundering: Option<bool>, }, TimeCheck { value: NumberProviderRange, period: Option<i64>, }, ValueCheck { value: NumberProvider, range: NumberProviderRange, }, EnchantmentActiveCheck { enchantment: Identifier, active: bool, }, EntityScores { entity: LootContextEntity, scores: &'static [(&'static str, NumberProviderRange)], }, Reference(Identifier),
}
Expand description

A condition that must be met for a loot entry or pool to apply.

Variants§

§

SurvivesExplosion

The loot survives explosion damage (random chance based on explosion radius). Vanilla: 1/radius chance to pass. If no explosion, always passes.

§

BlockStateProperty

Check block state properties match expected values.

Fields

§properties: &'static [PropertyCheck]
§

RandomChance(f32)

Simple random chance (0.0 to 1.0).

§

RandomChanceWithEnchantedBonus

Random chance affected by an enchantment (e.g., looting). Vanilla 1.21+: uses enchanted_chance which can be constant or linear.

Fields

§enchantment: Identifier
§unenchanted_chance: f32
§enchanted_chance: EnchantedChance

For linear formula: chance = base + per_level * (level - 1)

§

MatchTool(ToolPredicate)

Match tool predicate - checks if the tool matches certain criteria.

§

TableBonus

Table bonus condition - chance based on enchantment level from a table. The chances array is indexed by enchantment level (0 = no enchant, 1 = level 1, etc.)

Fields

§enchantment: Identifier
§chances: &'static [f32]
§

Inverted(&'static LootCondition)

Inverted condition - passes if the inner condition fails.

§

AnyOf(&'static [LootCondition])

Any of the conditions pass (OR logic).

§

AllOf(&'static [LootCondition])

All of the conditions pass (AND logic).

§

KilledByPlayer

Killed by player condition.

§

EntityProperties

Entity properties condition - checks entity predicates.

Fields

§

DamageSourceProperties

Damage source properties condition - checks how the entity was damaged.

Fields

§

LocationCheck

Location check condition - checks the location predicate.

Fields

§offset_x: i32
§offset_y: i32
§offset_z: i32
§

WeatherCheck

Weather check condition - checks current weather.

Fields

§raining: Option<bool>
§thundering: Option<bool>
§

TimeCheck

Time check condition - checks game time.

Fields

§period: Option<i64>
§

ValueCheck

Value check condition - compares a number provider value against a range.

§

EnchantmentActiveCheck

Check if a specific enchantment is active.

Fields

§enchantment: Identifier
§active: bool
§

EntityScores

Check entity scoreboard scores.

Fields

§scores: &'static [(&'static str, NumberProviderRange)]
§

Reference(Identifier)

Reference to a named condition in the registry.

Implementations§

Source§

impl LootCondition

Source

pub fn test<R: Rng>(&self, ctx: &mut LootContext<'_, R>) -> bool

Test if this condition passes given the loot context.

Trait Implementations§

Source§

impl Clone for LootCondition

Source§

fn clone(&self) -> LootCondition

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for LootCondition

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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