Skip to content

API reference Obsidian.API.Loot

LootContext class

The state shared while generating loot from a table, like vanilla's LootContext: the random source every draw comes from, the luck and the optional context parameters.

public sealed class LootContext

In Obsidian.API.

Remarks

A context is used for a single generation; it isn't thread-safe. Use LootTable.CreateRandom to seed LootContext.Random the way vanilla does for a stored loot table seed.

Constructors

public LootContext();

Properties

AdditionalCostComponentAllowed

public bool AdditionalCostComponentAllowed { get; init; }

Whether enchanting modifiers may add an additional trade cost to the item (vanilla's additional_cost_component_allowed parameter), as merchants' trade drawing allows.

AttackerWeapon

public ItemStack AttackerWeapon { get; init; }

Fallback weapon for callers without a living attacker's equipment resolver. The server resolves enchantments from the attacker's current applicable equipment, including for projectile kills.

AttackingEntity

public IEntity AttackingEntity { get; init; }

The entity responsible for killing the entity whose loot this is (vanilla's attacking_entity), like the player who shot it.

BlockEntityComponents

public IReadOnlyList<DataComponent> BlockEntityComponents { get; init; }

Components exposed by the broken block entity for copy_components.

BlockProperties

public IReadOnlyDictionary<string, string> BlockProperties { get; init; }

The state's named values, supplied by the level.

BlockState

public IBlock BlockState { get; init; }

The block before removal, for block predicates and state copying.

DirectAttackingEntity

public IEntity DirectAttackingEntity { get; init; }

The projectile or entity that dealt the final hit, for direct_attacker predicates.

DynamicDrops

public Action<string, Action<ItemStack>> DynamicDrops { get; init; }

Dynamic drops supplied by a block entity, such as a decorated pot's contents.

EnchantmentLevel

public int? EnchantmentLevel { get; init; }

The enchantment-level context parameter, when evaluating an enchantment's data.

ExplorationMaps

public IExplorationMapFactory ExplorationMaps { get; init; }

Creates the explorer maps of minecraft:exploration_map functions, or null where the level can't (the map is then left as is).

ExplosionRadius

public float? ExplosionRadius { get; init; }

Radius when explosion drop decay is enabled; null makes all items survive.

LastDamagePlayer

public IPlayer LastDamagePlayer { get; init; }

The player who hurt the entity whose loot this is lately (vanilla's last_damage_player), which killed_by_player conditions require.

Luck

public float Luck { get; init; }

Raises the weight of entries with a quality and adds bonus rolls. For containers this is the opening player's luck attribute, 0 without luck effects.

Numbers

public NumberContext Numbers { get; }

The shared provider context, using the same random stream and predicates as this loot evaluation.

Origin

public VectorD? Origin { get; init; }

Where the loot is generated (vanilla's origin parameter); for containers, the center of the block.

public required IRandomSource Random { get; init; }

ResolveTable

public Func<string, LootTable> ResolveTable { get; init; }

Resolves the tables referenced by minecraft:loot_table entries. Defaults to the vanilla tables in LootTables.All; unknown ids generate nothing.

SmeltItem

public Func<ItemStack, ItemStack> SmeltItem { get; init; }

Resolves a furnace recipe. Return its result stack, or null when the input cannot be smelted.

TargetEntity

public IEntity TargetEntity { get; init; }

The entity an action targets (vanilla's target_entity), like the one /compute entity selects.

TestLocation

public Func<JsonElement, bool> TestLocation { get; init; }

Tests a location predicate, including its offsets, against the containing level.

ThisEntity

public IEntity ThisEntity { get; init; }

The entity the loot is generated for (vanilla's this_entity parameter), e.g. the player opening a container.

Tool

public ItemStack Tool { get; init; }

The stack used to break a block, or null for an empty hand or explosion.

On this page