Skip to main content

LootFunction

Enum LootFunction 

Source
pub enum LootFunction {
Show 41 variants SetCount { count: NumberProvider, add: bool, }, ExplosionDecay, ApplyBonus { enchantment: Identifier, formula: BonusFormula, }, EnchantedCountIncrease { enchantment: Identifier, count: NumberProvider, limit: i32, }, LimitCount { min: Option<i32>, max: Option<i32>, }, SetDamage { damage: NumberProvider, add: bool, }, EnchantRandomly { options: EnchantmentOptions, }, EnchantWithLevels { levels: NumberProvider, options: EnchantmentOptions, }, CopyComponents { source: CopySource, include: &'static [Identifier], }, CopyState { block: Identifier, properties: &'static [&'static str], }, SetComponents { components: &'static str, }, SetCustomData { tag: &'static str, }, FurnaceSmelt, ExplorationMap { destination: Identifier, decoration: Identifier, zoom: i32, skip_existing_chunks: bool, }, SetName { name: &'static str, target: NameTarget, }, SetOminousBottleAmplifier { amplifier: NumberProvider, }, SetPotion { id: Identifier, }, SetStewEffect { effects: &'static [StewEffect], }, SetInstrument { options: Identifier, }, SetEnchantments { enchantments: &'static [(Identifier, NumberProvider)], add: bool, }, SetItem { item: Identifier, }, CopyName { source: CopySource, }, SetLore { lore: &'static [&'static str], mode: ListOperation, }, SetContents { entries: &'static [LootEntry], component_type: Identifier, }, ModifyContents { modifier: &'static [ConditionalLootFunction], component_type: Identifier, }, SetLootTable { loot_table: Identifier, seed: Option<i64>, }, SetAttributes { modifiers: &'static [AttributeModifier], replace: bool, }, FillPlayerHead { entity: LootContextEntity, }, CopyCustomData { source: CopySource, operations: &'static [CopyDataOperation], }, SetBannerPattern { patterns: &'static [BannerPattern], append: bool, }, SetFireworks { explosions: Option<&'static [FireworkExplosion]>, flight_duration: Option<i32>, }, SetFireworkExplosion { explosion: FireworkExplosion, }, SetBookCover { title: Option<&'static str>, author: Option<&'static str>, generation: Option<i32>, }, SetWrittenBookPages { pages: &'static [&'static str], mode: ListOperation, }, SetWritableBookPages { pages: &'static [&'static str], mode: ListOperation, }, ToggleTooltips { toggles: &'static [(Identifier, bool)], }, SetCustomModelData { value: NumberProvider, }, Discard, Reference(Identifier), Sequence { functions: &'static [ConditionalLootFunction], }, Filtered { item_filter: ToolPredicate, modifier: &'static ConditionalLootFunction, },
}
Expand description

A function that modifies loot items.

Variants§

§

SetCount

Set the count of the item.

Fields

§add: bool
§

ExplosionDecay

Apply explosion decay - each item has 1/radius chance to survive.

§

ApplyBonus

Apply bonus count based on enchantment level.

Fields

§enchantment: Identifier
§

EnchantedCountIncrease

Increase count based on enchantment (like looting).

Fields

§enchantment: Identifier
§limit: i32
§

LimitCount

Limit the count to a range.

Fields

§

SetDamage

Set the damage of the item (0.0 = broken, 1.0 = full durability).

Fields

§add: bool
§

EnchantRandomly

Enchant the item randomly with enchantments from options.

Fields

§

EnchantWithLevels

Enchant the item as if using an enchanting table at the specified level.

§

CopyComponents

Copy components from the block entity to the item.

Fields

§source: CopySource
§include: &'static [Identifier]
§

CopyState

Copy block state properties to the item.

Fields

§properties: &'static [&'static str]
§

SetComponents

Set components on the item.

Fields

§components: &'static str
§

SetCustomData

Set custom NBT data on the item (merges with existing custom_data).

Fields

§tag: &'static str
§

FurnaceSmelt

Smelt the item (convert raw to cooked, ore to ingot, etc.).

§

ExplorationMap

Create an exploration map pointing to a structure.

Fields

§destination: Identifier
§decoration: Identifier
§zoom: i32
§skip_existing_chunks: bool
§

SetName

Set the custom name of the item.

Fields

§name: &'static str
§target: NameTarget
§

SetOminousBottleAmplifier

Set the ominous bottle amplifier.

Fields

§amplifier: NumberProvider
§

SetPotion

Set the potion type.

Fields

§

SetStewEffect

Set the suspicious stew effects.

Fields

§effects: &'static [StewEffect]
§

SetInstrument

Set the instrument for goat horns.

Fields

§options: Identifier
§

SetEnchantments

Set enchantments on the item.

Fields

§enchantments: &'static [(Identifier, NumberProvider)]
§add: bool
§

SetItem

Change the item type entirely.

Fields

§

CopyName

Copy name from source entity/block to item.

Fields

§source: CopySource
§

SetLore

Add lore lines to the item.

Fields

§lore: &'static [&'static str]
§

SetContents

Set container inventory contents.

Fields

§entries: &'static [LootEntry]
§component_type: Identifier
§

ModifyContents

Modify existing container contents.

Fields

§modifier: &'static [ConditionalLootFunction]
§component_type: Identifier
§

SetLootTable

Set container’s loot table reference.

Fields

§loot_table: Identifier
§seed: Option<i64>
§

SetAttributes

Set attribute modifiers on the item.

Fields

§modifiers: &'static [AttributeModifier]
§replace: bool
§

FillPlayerHead

Fill player head with texture from entity.

Fields

§

CopyCustomData

Copy NBT/custom data from source.

Fields

§source: CopySource
§operations: &'static [CopyDataOperation]
§

SetBannerPattern

Set banner pattern layers.

Fields

§patterns: &'static [BannerPattern]
§append: bool
§

SetFireworks

Set firework rocket properties.

Fields

§explosions: Option<&'static [FireworkExplosion]>
§flight_duration: Option<i32>
§

SetFireworkExplosion

Set firework star explosion properties.

Fields

§

SetBookCover

Set book cover (title/author for written books).

Fields

§title: Option<&'static str>
§author: Option<&'static str>
§generation: Option<i32>
§

SetWrittenBookPages

Set written book page contents.

Fields

§pages: &'static [&'static str]
§

SetWritableBookPages

Set writable book page contents.

Fields

§pages: &'static [&'static str]
§

ToggleTooltips

Toggle tooltip visibility.

Fields

§toggles: &'static [(Identifier, bool)]
§

SetCustomModelData

Set custom model data.

Fields

§

Discard

Discard/delete the item entirely.

§

Reference(Identifier)

Reference to a named function in the registry.

§

Sequence

Apply multiple functions in sequence.

Fields

§functions: &'static [ConditionalLootFunction]
§

Filtered

Conditionally apply function to specific item predicate matches.

Fields

§item_filter: ToolPredicate
§modifier: &'static ConditionalLootFunction

Implementations§

Source§

impl LootFunction

Source

pub fn apply<R: Rng>(&self, item: &mut ItemStack, ctx: &mut LootContext<'_, R>)

Apply this function to modify the item stack.

This modifies the item in place. Functions can change:

  • Count (SetCount, ExplosionDecay, ApplyBonus, etc.)
  • Damage/durability (SetDamage)
  • Enchantments (EnchantRandomly, EnchantWithLevels, SetEnchantments)
  • Components/NBT (CopyComponents, SetComponents, CopyState)
  • Item type (FurnaceSmelt)
  • And more…

Trait Implementations§

Source§

impl Clone for LootFunction

Source§

fn clone(&self) -> LootFunction

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 LootFunction

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