Class SetNameFunction
java.lang.Object
net.minecraft.world.level.storage.loot.functions.LootItemConditionalFunction
net.minecraft.world.level.storage.loot.functions.SetNameFunction
- All Implemented Interfaces:
BiFunction<ItemStack, LootContext, ItemStack>, LootItemFunction, LootContextUser, Validatable
LootItemFunction that sets a stack's name.
The Component for the name is optionally resolved relative to a given
LootContext.EntityTarget for entity-sensitive component data such as scoreboard scores.-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from class LootItemConditionalFunction
LootItemConditionalFunction.Builder<T> -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final org.slf4j.Loggerstatic final com.mojang.serialization.MapCodec<SetNameFunction> private final Optional<LootContext.EntityTarget> private final SetNameFunction.TargetFields inherited from class LootItemConditionalFunction
predicates -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateSetNameFunction(List<LootItemCondition> predicates, Optional<Component> name, Optional<LootContext.EntityTarget> resolutionContext, SetNameFunction.Target target) -
Method Summary
Modifier and TypeMethodDescriptioncom.mojang.serialization.MapCodec<SetNameFunction> codec()static UnaryOperator<Component> createResolver(LootContext context, @Nullable LootContext.EntityTarget entityTarget) Create a UnaryOperator that resolves Components based on the given LootContext and EntityTarget.Set<ContextKey<?>> run(ItemStack itemStack, LootContext context) Called to perform the actual action of this function, after conditions have been checked.static LootItemConditionalFunction.Builder<?> setName(Component value, SetNameFunction.Target target) static LootItemConditionalFunction.Builder<?> setName(Component value, SetNameFunction.Target target, LootContext.EntityTarget resolutionContext) Methods inherited from class LootItemConditionalFunction
apply, commonFields, simpleBuilder, validateMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface BiFunction
andThen
-
Field Details
-
LOGGER
private static final org.slf4j.Logger LOGGER -
MAP_CODEC
-
name
-
resolutionContext
-
target
-
-
Constructor Details
-
SetNameFunction
private SetNameFunction(List<LootItemCondition> predicates, Optional<Component> name, Optional<LootContext.EntityTarget> resolutionContext, SetNameFunction.Target target)
-
-
Method Details
-
codec
- Specified by:
codecin interfaceLootItemFunction- Specified by:
codecin classLootItemConditionalFunction
-
getReferencedContextParams
-
createResolver
public static UnaryOperator<Component> createResolver(LootContext context, @Nullable LootContext.EntityTarget entityTarget) Create a UnaryOperator that resolves Components based on the given LootContext and EntityTarget. This will replace for example score components. -
run
Description copied from class:LootItemConditionalFunctionCalled to perform the actual action of this function, after conditions have been checked.- Specified by:
runin classLootItemConditionalFunction
-
setName
public static LootItemConditionalFunction.Builder<?> setName(Component value, SetNameFunction.Target target) -
setName
public static LootItemConditionalFunction.Builder<?> setName(Component value, SetNameFunction.Target target, LootContext.EntityTarget resolutionContext)
-