战利品函数
战利品函数用于修改战利品条目的结果,或战利品池、战利品表产生的多个结果。这些情况下都会定义一个按顺序执行的函数列表。数据生成时,调用 LootPoolSingletonContainer.Builder<?>、LootPool.Builder 或 LootTable.Builder 的 #apply 即可应用函数。本文介绍可用的战利品函数。创建自己的函数请参阅自定义战利品函数。
提示 战利品函数不能应用于组合战利品条目(
CompositeEntryBase的子类及其对应构建器类),必须手动添加到每个单项条目。
除 minecraft:sequence 外,所有原版战利品函数都可以在 conditions 块中指定战利品条件。任一条件失败时,函数便不会应用。在代码中,此行为由 LootItemConditionalFunction 控制;除 SequenceFunction 外,所有战利品函数都继承它。
minecraft:set_item
将结果物品堆叠中的物品替换为另一种物品。
{
"function": "minecraft:set_item",
// The item to use.
"item": "minecraft:dirt"
}
目前无法通过数据生成创建此函数。
minecraft:set_count
设置结果物品堆叠的物品数量。使用数字提供器。
{
"function": "minecraft:set_count",
// The count to use.
"count": {
"type": "minecraft:uniform",
"min": 1,
"max": 3
},
// Whether to add to the existing value instead of setting it. Optional, defaults to false.
"add": true
}
数据生成时,向 SetItemCountFunction#setCount 传入所需数字提供器和可选的 add 布尔值,创建此函数的构建器。
minecraft:explosion_decay
应用爆炸衰减。每个物品有 1 除以 explosion_radius 的概率“存活”。根据物品数量会执行多次。需要 minecraft:explosion_radius 战利品参数,缺少时不作修改。
{
"function": "minecraft:explosion_decay"
}
数据生成时,调用 ApplyExplosionDecay#explosionDecay 创建此函数的构建器。
minecraft:limit_count
将物品堆叠数量限制在给定的 IntRange 内。
{
"function": "minecraft:limit_count",
// The limit to use. Can have a min, a max, or both.
"limit": {
"max": 32
}
}
数据生成时,向 LimitCount#limitCount 传入所需 IntRange,创建此函数的构建器。
minecraft:set_custom_data
为物品堆叠设置自定义 NBT 数据。
{
"function": "minecraft:set_custom_data",
"tag": {
"exampleproperty": 0
}
}
数据生成时,向 SetCustomDataFunction#setCustomData 传入所需 CompoundTag,创建此函数的构建器。
警告 通常应将此函数视为已弃用,改用
minecraft:set_components。
minecraft:copy_custom_data
将方块实体或实体来源的自定义 NBT 数据复制到物品堆叠。不建议对方块实体使用此函数,应改用 minecraft:copy_components 或 minecraft:set_contents。用于实体时,需要设置实体目标。需要对应指定来源(实体目标或方块实体)的战利品参数,缺少时不作修改。
{
"function": "minecraft:copy_custom_data",
// The source to use. Valid values are either an entity target, "block_entity" to use the loot context's
// block entity parameter, or be "storage" for command storage. If this is "storage", it can instead be a
// JSON object that additionally specify the command storage path to be used.
"source": "this",
// Example for using "storage".
"source": {
"type": "storage",
"source": "examplepath"
},
// The copy operation(s).
"ops": [
{
// The source and target paths. In this example, we copy from "src" in the source to "dest" in the target.
"source": "src",
"target": "dest",
// A merging strategy. Valid values are "replace", "append", and "merge".
"op": "merge"
}
]
}
数据生成时,向 CopyCustomDataFunction#copy 传入所需来源值、目标值及合并策略(可选,默认 replace),创建此函数的构建器。
minecraft:set_components
设置物品堆叠的数据组件值。多数原版用途都有专用函数,下文会介绍。
{
"function": "minecraft:set_components",
// Any component can be used. In this example, we set the dyed color of the item to red.
"components": {
"dyed_color": {
"rgb": 16711680
}
}
}
数据生成时,向 SetComponentsFunction#setComponent 传入所需数据组件及其值,创建此函数的构建器。
minecraft:copy_components
将方块实体的数据组件值复制到物品堆叠。需要 minecraft:block_entity 战利品参数,缺少时不作修改。
{
"function": "minecraft:copy_components",
// The system is designed to allow multiple sources, however for now, there are only block entities available.
"source": "block_entity",
// By default, all components are copied. The "exclude" list allows excluding certain components, and the
// "include" list allows explicitly re-including components. Both fields are optional.
"exclude": [],
"include": []
}
数据生成时,向 CopyComponentsFunction#copyComponents 传入所需数据来源(通常为 CopyComponentsFunction.Source.BLOCK_ENTITY),创建此函数的构建器。
minecraft:copy_state
将方块状态属性复制到物品堆叠的 block_state 数据组件中,在尝试放置方块时使用。必须明确指定需要复制的属性。需要 minecraft:block_state 战利品参数,缺少时不作修改。
{
"function": "minecraft:copy_state",
// The expected block. If this does not match the block that is actually broken, the function does not run.
"block": "minecraft:oak_slab",
// The block state properties to save.
"properties": {
"type": "top"
}
}
数据生成时,向 CopyBlockState#copyState 传入方块创建构建器,再通过 #copy 指定所需方块状态属性值。
minecraft:set_contents
设置物品堆叠中的内容物。
{
"function": "minecraft:set_contents",
// The contents component to use. Valid values are "container", "bundle_contents" and "charged_projectiles".
"component": "container",
// A list of loot entries to add to the contents.
"entries": [
{
"type": "minecraft:empty",
"weight": 3
},
{
"type": "minecraft:item",
"item": "minecraft:arrow"
}
]
}
数据生成时,向 SetContainerContents#setContents 传入所需内容物组件创建构建器,再调用构建器的 #withEntry 添加条目。
minecraft:modify_contents
对物品堆叠的内容物应用一个函数。
{
"function": "minecraft:modify_contents",
// The contents component to use. Valid values are "container", "bundle_contents" and "charged_projectiles".
"component": "container",
// The function to use.
"modifier": "apply_explosion_decay"
}
目前无法通过数据生成创建此函数。
minecraft:set_loot_table
为结果物品堆叠设置容器战利品表。用于箱子等容器,它们在放置后会保留这一属性。
{
"function": "minecraft:set_loot_table",
// The id of the loot table to use.
"name": "minecraft:entities/enderman",
// The id of the block entity type of the target block entity.
"type": "minecraft:chest",
// The random seed for generating loot tables. Optional, defaults to 0.
"seed": 42
}
数据生成时,向 SetContainerLootTable#withLootTable 传入所需方块实体类型、战利品表资源键和可选种子,创建此函数的构建器。
minecraft:set_name
设置结果物品堆叠的名称。名称可以是 Component,不必是字面字符串;也可以通过实体目标解析。适用时需要对应实体战利品参数,缺少时不作修改。
{
"function": "minecraft:set_name",
"name": "Funny Item",
// The entity target to use.
"entity": "this",
// Whether to set the custom name ("custom_name") or the item name ("item_name") itself.
// Custom name are displayed in italics and can be changed in an anvil, while item names cannot.
"target": "custom_name"
}
数据生成时,向 SetNameFunction#setName 传入所需名称组件、名称目标和可选实体目标,创建此函数的构建器。
minecraft:copy_name
将实体目标或方块实体的名称复制到结果物品堆叠。需要对应指定来源(实体目标或方块实体)的战利品参数,缺少时不作修改。
{
"function": "minecraft:copy_name",
// The entity target, or "block_entity" if a block entity's name should be copied.
"source": "this"
}
数据生成时,向 CopyNameFunction#copyName 传入所需实体来源,创建此函数的构建器。
minecraft:set_lore
设置结果物品堆叠的描述文本(提示信息行)。每行可以是 Component,不必是字面字符串;也可以通过实体目标解析。适用时需要对应实体战利品参数,缺少时不作修改。
{
"function": "minecraft:set_lore",
"lore": [
"Funny Lore",
"Funny Lore 2"
],
// The merging mode used. Valid values are:
// - "append": Appends the entries to any existing lore entries.
// - "insert": Inserts the entries at a certain position. The position is denoted as an additional field
// named "offset". "offset" is optional and defaults to 0.
// - "replace_all": Removes all previous entries and then appends the entries.
// - "replace_section": Removes a section of entries and then adds the entries at that position.
// The section removed is denoted through the "offset" and optional "size" fields.
// If "size" is omitted, the amount of lines in "lore" is used.
"mode": {
"type": "insert",
"offset": 0
},
// The entity target to use.
"entity": "this"
}
数据生成时,调用 SetLoreFunction#setLore 创建构建器,再按需调用 #addLine、#setMode 和 #setResolutionContext。
minecraft:toggle_tooltips
启用或禁用某些组件的提示信息。
{
"function": "minecraft:toggle_tooltips",
"toggles": {
// All values are optional. If omitted, these values will use pre-existing values on the stack.
// The pre-existing values are generally true, unless they have already been modified by another function.
"minecraft:attribute_modifiers": false,
"minecraft:can_break": false,
"minecraft:can_place_on": false,
"minecraft:dyed_color": false,
"minecraft:enchantments": false,
"minecraft:jukebox_playable": false,
"minecraft:stored_enchantments": false,
"minecraft:trim": false,
"minecraft:unbreakable": false
}
}
目前无法通过数据生成创建此函数。
minecraft:enchant_with_levels
使用给定的等级数量对物品堆叠进行随机附魔。使用数字提供器。
{
"function": "minecraft:enchant_with_levels",
// The amount of levels to use.
"levels": {
"type": "minecraft:uniform",
"min": 10,
"max": 30
},
// A list of possible enchantments. Optional, defaults to all applicable enchantments for the item.
"options": [
"minecraft:sharpness",
"minecraft:fire_aspect"
]
}
数据生成时,向 EnchantWithLevelsFunction#enchantWithLevels 传入所需数字提供器创建构建器,再按需通过 #fromOptions 设置附魔列表。
minecraft:enchant_randomly
为物品添加一个随机附魔。
{
"function": "minecraft:enchant_randomly",
// A list of possible enchantments. Optional, defaults to all enchantments.
"options": [
"minecraft:sharpness",
"minecraft:fire_aspect"
]
// Whether to only allow compatible enchantments, or any enchantments. Optional, defaults to true.
"only_compatible": true
}
数据生成时,调用 EnchantRandomlyFunction#randomEnchantment 或 EnchantRandomlyFunction#randomApplicableEnchantment 创建构建器,再按需调用 #withEnchantment 或 #withOneOf。
minecraft:set_enchantments
设置结果物品堆叠的附魔。
{
"function": "minecraft:set_enchantments",
// A map of enchantments to number providers.
"enchantments": {
"minecraft:fire_aspect": 2,
"minecraft:sharpness": {
"type": "minecraft:uniform",
"min": 3,
"max": 5,
}
},
// Whether to add enchantment levels to existing levels instead of overwriting them. Optional, defaults to false.
"add": true
}
数据生成时,调用 new SetEnchantmentsFunction.Builder 创建构建器,可选传入 add 布尔值;然后调用 #withEnchantment 添加要设置的附魔。
minecraft:enchanted_count_increase
根据附魔值增加物品堆叠数量。使用数字提供器。需要 minecraft:attacking_entity 战利品参数,缺少时不作修改。
{
"function": "minecraft:enchanted_count_increase",
// The enchantment to use.
"enchantment": "minecraft:fortune",
// The increase count per level. The number provider is rolled once per function, not once per level.
"count": {
"type": "minecraft:uniform",
"min": 1,
"max": 3
},
// The stack size limit, which will not be exceeded no matter the enchantment level. Optional.
"limit": 5
}
数据生成时,向 EnchantedCountIncreaseFunction#lootingMultiplier 传入所需数字提供器创建构建器,之后可选调用 #setLimit。
minecraft:apply_bonus
根据附魔值和不同公式增加物品堆叠数量。需要 minecraft:tool 战利品参数,缺少时不作修改。
{
"function": "minecraft:apply_bonus",
// The enchantment value to query.
"enchantment": "minecraft:fortune",
// The formula to use. Valid values are:
// - "minecraft:binomial_with_bonus_count": Applies a bonus based on a binomial distribution with
// n = enchantment level + extra and p = probability.
// - "minecraft:ore_drops": Applies a bonus based on a special formula for ore drops, including randomness.
// - "minecraft:uniform_bonus_count": Adds a bonus based on the enchantment level scaled by a constant multiplier.
"formula": "ore_drops",
// The parameter values, depending on the formula.
// If the formula is "minecraft:binomial_with_bonus_count", requires "extra" and "probability".
// If the formula is "minecraft:ore_drops", requires no parameters.
// If the formula is "minecraft:uniform_bonus_count", requires "bonusMultiplier".
"parameters": {}
}
数据生成时,向 ApplyBonusCount#addBonusBinomialDistributionCount、ApplyBonusCount#addOreBonusCount 或 ApplyBonusCount#addUniformBonusCount 传入附魔和相应公式所需的其他参数,创建此函数的构建器。
minecraft:furnace_smelt
尝试像熔炉一样熔炼物品;无法熔炼时返回未修改的物品堆叠。
{
"function": "minecraft:furnace_smelt"
}
数据生成时,调用 SmeltItemFunction#smelted 创建此函数的构建器。
minecraft:set_damage
设置结果物品堆叠的耐久损耗值。使用数字提供器。
{
"function": "minecraft:set_damage",
// The damage to set.
"damage": {
"type": "minecraft:uniform",
"min": 10,
"max": 300
},
// Whether to add to the existing damage instead of setting it. Optional, defaults to false.
"add": true
}
数据生成时,向 SetItemDamageFunction#setDamage 传入所需数字提供器和可选 add 布尔值,创建此函数的构建器。
minecraft:set_attributes
向结果物品堆叠添加属性修改器列表。
{
"function": "minecraft:set_attributes",
// A list of attribute modifiers.
"modifiers": [
{
// The resource location id of the modifier. Should be prefixed by your mod id.
"id": "examplemod:example_modifier",
// The id of the attribute the modifier is for.
"attribute": "minecraft:generic.attack_damage",
// The attribute modifier operation.
// Valid values are "add_value", "add_multiplied_base" and "add_multiplied_total".
"operation": "add_value",
// The amount of the modifier. This can also be a number provider.
"amount": 5,
// The slot(s) the modifier applies for. Valid values are "any" (any inventory slot),
// "mainhand", "offhand", "hand", (mainhand/offhand/both hands),
// "feet", "legs", "chest", "head", "armor" (boots/leggings/chestplates/helmets/any armor slots)
// and "body" (horse armor and similar slots).
"slot": "armor"
}
],
// Whether to replace the existing values instead of adding to them. Optional, defaults to true.
"replace": false
}
数据生成时,调用 SetAttributesFunction#setAttributes 创建构建器,再通过 #withModifier 添加修改器。使用 SetAttributesFunction#modifier 获取修改器。
minecraft:set_potion
设置结果物品堆叠的药水。
{
"function": "minecraft:set_potion",
// The id of the potion.
"id": "minecraft:strength"
}
数据生成时,向 SetPotionFunction#setPotion 传入所需药水,创建此函数的构建器。
minecraft:set_stew_effect
设置结果物品堆叠的炖菜效果列表。
{
"function": "minecraft:set_stew_effect",
// The effects to set.
"effects": [
{
// The effect id.
"type": "minecraft:fire_resistance",
// The effect duration, in ticks. This can also be a number provider.
"duration": 100
}
]
}
数据生成时,调用 SetStewEffectFunction#stewEffect 创建构建器,再调用 #withModifier。
minecraft:set_ominous_bottle_amplifier
设置结果物品堆叠的不祥之瓶效果增幅。使用数字提供器。
{
"function": "minecraft:set_ominous_bottle_amplifier",
// The amplifier to use.
"amplifier": {
"type": "minecraft:uniform",
"min": 1,
"max": 3
}
}
数据生成时,向 SetOminousBottleAmplifierFunction#amplifier 传入所需数字提供器,创建此函数的构建器。
minecraft:exploration_map
当且仅当结果物品堆叠为地图时,将它变为探险家地图。需要 minecraft:origin 战利品参数,缺少时不作修改。
{
"function": "minecraft:exploration_map",
// A structure tag, containing the structures an exploration map can lead to.
// Optional, defaults to "minecraft:on_treasure_maps", which only contains buried treasures by default.
"destination": "minecraft:eye_of_ender_located",
// The map decoration type to use. See the MapDecorationTypes class for available values.
// Optional, defaults to "minecraft:mansion".
"decoration": "minecraft:target_x",
// The zoom level to use. Optional, defaults to 2.
"zoom": 4,
// The search radius to use. Optional, defaults to 50.
"search_radius": 25,
// Whether existing chunks are skipped when searching for structures. Optional, defaults to true.
"skip_existing_chunks": true
}
数据生成时,调用 ExplorationMapFunction#makeExplorationMap 创建构建器,再按需调用其各个 setter。
minecraft:fill_player_head
根据给定的实体目标设置结果物品堆叠的玩家头颅所有者。需要对应战利品参数,缺少时不作修改。
{
"function": "minecraft:fill_player_head",
// The entity target to use. If this doesn't resolve to a player, the stack is not modified.
"entity": "this_entity"
}
数据生成时,向 FillPlayerHead#fillPlayerHead 传入所需实体目标,创建此函数的构建器。
minecraft:set_banner_pattern
设置结果物品堆叠的旗帜图案。此函数用于旗帜本身,而非旗帜图案物品。
{
"function": "minecraft:set_banner_patterns",
// A list of banner pattern layers.
"patterns": [
{
// The id of the banner pattern to use.
"pattern": "minecraft:globe",
// The dye color of the layer.
"color": "light_blue"
}
],
// Whether to append to the existing layers instead of replacing them.
"append": true
}
数据生成时,向 SetBannerPatternFunction#setBannerPattern 传入 append 布尔值创建构建器,再调用 #addPattern 添加图案。
minecraft:set_instrument
设置结果物品堆叠的乐器标签。
{
"function": "minecraft:set_instrument",
// The instrument tag to use.
"options": "minecraft:goat_horns"
}
数据生成时,向 SetInstrumentFunction#setInstrumentOptions 传入所需乐器标签,创建此函数的构建器。
minecraft:set_fireworks
{
"function": "minecraft:set_fireworks",
// The explosions to use. Optional, uses the existing data component value if absent.
"explosions": [
{
// The firework explosion shape to use. Valid vanilla values are "small_ball", "large_ball",
// "star", "creeper" and "burst". Optional, defaults to "small_ball".
"shape": "star",
// The colors to use. Optional, defaults to an empty list.
"colors": [
16711680,
65280
],
// The fade colors to use. Optional, defaults to an empty list.
"fade_colors": [
65280,
255
],
// Whether the explosion has a trail. Optional, defaults to false.
"has_trail": true,
// Whether the explosion has a twinkle. Optional, defaults to false.
"has_twinkle": true
}
],
// The flight duration of the fireworks. Optional, uses the existing data component value if absent.
"flight_duration": 5
}
目前无法通过数据生成创建此函数。
minecraft:set_firework_explosion
设置结果物品堆叠的烟花爆炸效果。
{
"function": "minecraft:set_firework_explosion",
// The firework explosion shape to use. Valid vanilla values are "small_ball", "large_ball",
// "star", "creeper" and "burst". Optional, defaults to "small_ball".
"shape": "star",
// The colors to use. Optional, defaults to an empty list.
"colors": [
16711680,
65280
],
// The fade colors to use. Optional, defaults to an empty list.
"fade_colors": [
65280,
255
],
// Whether the explosion has a trail. Optional, defaults to false.
"has_trail": true,
// Whether the explosion has a twinkle. Optional, defaults to false.
"has_twinkle": true
}
数据生成时,向 SetItemCountFunction#setCount 传入所需数字提供器和可选 add 布尔值,创建此函数的构建器。
minecraft:set_book_cover
设置成书中不属于特定书页的内容。
{
"function": "minecraft:set_book_cover",
// The book title. Optional, if absent, the book title remains unchanged.
"title": "Hello World!",
// The book author. Optional, if absent, the book author remains unchanged.
"author": "Steve",
// The book generation, i.e. how often it has been copied. Clamped between 0 and 3.
// Optional, if absent, the book generation remains unchanged.
"generation": 2
}
数据生成时,向 new SetBookCoverFunction 传入所需参数,创建此函数的构建器。
minecraft:set_written_book_pages
设置成书的书页。
{
"function": "minecraft:set_written_book_pages",
// The pages to set, as a list of strings.
"pages": [
"Hello World!",
"Hello World on page 2!",
"Never Gonna Give You Up!"
],
// The merging mode used. Valid values are:
// - "append": Appends the entries to any existing lore entries.
// - "insert": Inserts the entries at a certain position. The position is denoted as an additional field
// named "offset". "offset" is optional and defaults to 0.
// - "replace_all": Removes all previous entries and then appends the entries.
// - "replace_section": Removes a section of entries and then adds the entries at that position.
// The section removed is denoted through the "offset" and optional "size" fields.
// If "size" is omitted, the amount of lines in "lore" is used.
"mode": {
"type": "insert",
"offset": 0
}
}
目前无法通过数据生成创建此函数。
minecraft:set_writable_book_pages
设置可书写书籍(书与笔)的书页。
{
"function": "minecraft:set_writable_book_pages",
// The pages to set, as a list of strings.
"pages": [
"Hello World!",
"Hello World on page 2!",
"Never Gonna Give You Up!"
],
// The merging mode used. Valid values are:
// - "append": Appends the entries to any existing lore entries.
// - "insert": Inserts the entries at a certain position. The position is denoted as an additional field
// named "offset". "offset" is optional and defaults to 0.
// - "replace_all": Removes all previous entries and then appends the entries.
// - "replace_section": Removes a section of entries and then adds the entries at that position.
// The section removed is denoted through the "offset" and optional "size" fields.
// If "size" is omitted, the amount of lines in "lore" is used.
"mode": {
"type": "insert",
"offset": 0
}
}
目前无法通过数据生成创建此函数。
minecraft:set_custom_model_data
设置结果物品堆叠的自定义模型数据。
{
"function": "minecraft:set_custom_model_data",
// The custom model data value to use. This can also be a number provider.
"value": 4
}
目前无法通过数据生成创建此函数。
minecraft:filtered
接收 ItemPredicate,并用它检查 tool 战利品参数;通过时执行另一个函数。ItemPredicate 可以指定有效物品 ID 列表(items)、物品数量的最小/最大范围(count)、DataComponentPredicate(components)和 ItemSubPredicate(predicates);所有字段均可选。需要 minecraft:tool 参数,缺少时始终失败。
{
"function": "minecraft:filtered",
// The custom model data value to use. This can also be a number provider.
"item_filter": {
"items": [
"minecraft:diamond_shovel"
]
},
// The other loot function to run, as either a loot modifier file or an in-line list of functions.
"modifier": "examplemod:example_modifier"
}
目前无法通过数据生成创建此函数。
警告 通常应将此函数视为已弃用,改为给传入函数添加
minecraft:match_tool条件。
minecraft:reference
引用一个物品修改器,并将其应用到结果物品堆叠。更多信息见物品修改器。
{
"function": "minecraft:reference",
// Refers to the item modifier file at data/examplemod/item_modifier/example_modifier.json.
"name": "examplemod:example_modifier"
}
数据生成时,向 FunctionReference#functionReference 传入所引用谓词文件的 ID,创建此函数的构建器。
minecraft:sequence
依次执行其他战利品函数。
{
"function": "minecraft:sequence",
// A list of functions to run.
"functions": [
{
"function": "minecraft:set_count",
// ...
},
{
"function": "minecraft:explosion_decay"
}
],
}
数据生成时,向 SequenceFunction#of 传入其他函数,创建构建器。
另请参阅
来源: NeoForged/Documentation(1.21.1)。中文翻译依据提交
4a680cdd4d15。