Class LootContext
java.lang.Object
net.minecraft.world.level.storage.loot.LootContext
LootContext stores various context information for loot generation.
This includes the Level as well as any known
LootContextParam
s.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
static enum
Represents a type of entity that can be looked up in aLootContext
using aLootContextParam
.static final record
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final HolderGetter.Provider
private final LootParams
private @Nullable ResourceLocation
private final RandomSource
private final Set
<LootContext.VisitedEntry<?>> -
Constructor Summary
ConstructorsModifierConstructorDescription(package private)
LootContext
(LootParams pParams, RandomSource pRandom, HolderGetter.Provider pLootDataResolver) private
LootContext
(LootParams pParams, RandomSource pRandom, HolderGetter.Provider pLootDataResolver, ResourceLocation queriedLootTableId) -
Method Summary
Modifier and TypeMethodDescriptionvoid
addDynamicDrops
(ResourceLocation pName, Consumer<ItemStack> pConsumer) Add the dynamic drops for the given dynamic drops name to the given consumer.createVisitedEntry
(LootItemFunction pModifier) static LootContext.VisitedEntry
<LootTable> createVisitedEntry
(LootTable pLootTable) createVisitedEntry
(LootItemCondition pPredicate) getLevel()
float
getLuck()
<T> T
getParam
(LootContextParam<T> pParam) Get the value of the given parameter.<T> T
getParamOrNull
(LootContextParam<T> pParameter) Get the value of the given parameter if it is present in this context, null otherwise.boolean
hasParam
(LootContextParam<?> pParameter) Check whether the given parameter is present in this context.boolean
hasVisitedElement
(LootContext.VisitedEntry<?> pElement) void
popVisitedElement
(LootContext.VisitedEntry<?> pElement) boolean
pushVisitedElement
(LootContext.VisitedEntry<?> pElement) void
setQueriedLootTableId
(@Nullable ResourceLocation queriedLootTableId)
-
Field Details
-
params
-
random
-
lootDataResolver
-
visitedElements
-
queriedLootTableId
-
-
Constructor Details
-
LootContext
LootContext(LootParams pParams, RandomSource pRandom, HolderGetter.Provider pLootDataResolver) -
LootContext
private LootContext(LootParams pParams, RandomSource pRandom, HolderGetter.Provider pLootDataResolver, ResourceLocation queriedLootTableId)
-
-
Method Details
-
hasParam
Check whether the given parameter is present in this context. -
getParam
Get the value of the given parameter. -
addDynamicDrops
Add the dynamic drops for the given dynamic drops name to the given consumer. If no dynamic drops provider for the given name has been registered to this LootContext, nothing is generated.- See Also:
-
getParamOrNull
Get the value of the given parameter if it is present in this context, null otherwise. -
hasVisitedElement
-
pushVisitedElement
-
popVisitedElement
-
getResolver
-
getRandom
-
getLuck
public float getLuck() -
getLevel
-
createVisitedEntry
-
createVisitedEntry
public static LootContext.VisitedEntry<LootItemCondition> createVisitedEntry(LootItemCondition pPredicate) -
createVisitedEntry
public static LootContext.VisitedEntry<LootItemFunction> createVisitedEntry(LootItemFunction pModifier) -
setQueriedLootTableId
-
getQueriedLootTableId
-