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 params, RandomSource random, HolderGetter.Provider lootDataResolver) private
LootContext
(LootParams params, RandomSource random, HolderGetter.Provider lootDataResolver, ResourceLocation queriedLootTableId) -
Method Summary
Modifier and TypeMethodDescriptionvoid
addDynamicDrops
(ResourceLocation name, Consumer<ItemStack> consumer) Add the dynamic drops for the given dynamic drops name to the given consumer.createVisitedEntry
(LootItemFunction modifier) static LootContext.VisitedEntry
<LootTable> createVisitedEntry
(LootTable lootTable) createVisitedEntry
(LootItemCondition predicate) getLevel()
float
getLuck()
<T> T
getParam
(LootContextParam<T> param) Get the value of the given parameter.<T> T
getParamOrNull
(LootContextParam<T> parameter) Get the value of the given parameter if it is present in this context, null otherwise.boolean
hasParam
(LootContextParam<?> parameter) Check whether the given parameter is present in this context.boolean
hasVisitedElement
(LootContext.VisitedEntry<?> element) void
popVisitedElement
(LootContext.VisitedEntry<?> element) boolean
pushVisitedElement
(LootContext.VisitedEntry<?> element) void
setQueriedLootTableId
(@Nullable ResourceLocation queriedLootTableId)
-
Field Details
-
params
-
random
-
lootDataResolver
-
visitedElements
-
queriedLootTableId
-
-
Constructor Details
-
LootContext
LootContext(LootParams params, RandomSource random, HolderGetter.Provider lootDataResolver) -
LootContext
private LootContext(LootParams params, RandomSource random, HolderGetter.Provider lootDataResolver, 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 predicate) -
createVisitedEntry
public static LootContext.VisitedEntry<LootItemFunction> createVisitedEntry(LootItemFunction modifier) -
setQueriedLootTableId
-
getQueriedLootTableId
-