Skip to content

LootContext 5.46.0 ​

final class · pocketmine\loot\LootContext · source

Everything a loot table may look at while rolling (vanilla's LootContext and LootParams): the random source, the luck, and the optional parameters (origin, entities, tool, explosion...). Conditions that need a parameter that is not set fail, like in vanilla.

Checks that depend on things the loot engine does not model (entity predicates, damage sources, locations, block states, dynamic drops) are delegated to the optional resolver closures; without a resolver they fail.

Properties ​

$attackingEntity ​

php
public ?\pocketmine\entity\Entity $attackingEntity

ATTACKING_ENTITY: the entity whose attack killed $thisEntity (the shooter for projectiles)

$biomeAt ​

php
public ?\Closure $biomeAt

Java biome id at a position, for location checks: fn(int $x, int $y, int $z) : ?string

$blockId ​

php
public ?string $blockId

$blockProperties ​

php
public ?array $blockProperties

Java block id and string properties of the BLOCK_STATE parameter (blocks broken), or null.

$damageSourcePredicate ​

php
public ?\Closure $damageSourcePredicate

minecraft:damage_source_properties: fn(array $predicate) : bool

$directAttackingEntity ​

php
public ?\pocketmine\entity\Entity $directAttackingEntity

DIRECT_ATTACKING_ENTITY: the entity that dealt the damage (the projectile for projectiles)

$dynamicDrops ​

php
public ?\Closure $dynamicDrops

minecraft:dynamic entries ("contents", "sherds"): fn(string $name, \Closure(LootStack) : void $output) : void

$entityEnchantmentLevel ​

php
public ?\Closure $entityEnchantmentLevel

Enchantment level of a living entity's equipment (EnchantmentHelper.getEnchantmentLevel), used by looting-like functions: fn(Entity $entity, string $javaEnchantmentId) : int. Defaults to the held item of humans.

$entityPredicate ​

php
public ?\Closure $entityPredicate

minecraft:entity_properties: fn(string $target, array $predicate) : bool, $target being "this", "attacker", "direct_attacker" or "attacking_player".

$explosionRadius ​

php
public ?float $explosionRadius

EXPLOSION_RADIUS: set when the loot comes from a block destroyed by an explosion

$lastDamagePlayer ​

php
public ?\pocketmine\player\Player $lastDamagePlayer

LAST_DAMAGE_PLAYER: set when a player took part in the kill (killed_by_player)

$locationPredicate ​

php
public ?\Closure $locationPredicate

minecraft:location_check: fn(array $predicate, int $offsetX, int $offsetY, int $offsetZ) : bool. Without a resolver only "biomes" predicates are checked, with $biomeAt.

$luck ​

php
public float $luck

$origin ​

php
public ?\pocketmine\math\Vector3 $origin

$random ​

php
public readonly \pocketmine\world\generator\vanilla\random\LegacyRandom $random

$thisEntity ​

php
public ?\pocketmine\entity\Entity $thisEntity

THIS_ENTITY: the entity that died, the player opening a container, the player brushing...

$tool ​

php
public ?\pocketmine\loot\LootStack $tool

TOOL: the item used to break a block, brush, shear...

$visited ​

php
public array $visited

Loot tables and predicates being evaluated (recursion guard, like vanilla's visited elements).

$world ​

php
public ?\pocketmine\world\World $world

Methods ​

__construct() ​

php
public function __construct(\pocketmine\world\generator\vanilla\random\LegacyRandom $random)

create() ​

php
public static function create() : self

A context with a random seed.

getEntityEnchantmentLevel() ​

php
public function getEntityEnchantmentLevel(?\pocketmine\entity\Entity $entity, string $enchantment) : int

Enchantment level of an entity's equipment.

randomSeed() ​

php
public static function randomSeed() : int

seeded() ​

php
public static function seeded(int $seed) : self

A context whose random is seeded like vanilla's LootContext.Builder.withOptionalRandomSeed(): a seed of 0 means "no seed" (a random one is used).

VanillaMine is a fork of PocketMine-MP, maintained by Luxury Nodes. Not affiliated with the PMMP team or Mojang.