战利品条件
战利品条件用于检查当前上下文是否应使用某个战利品条目或战利品池。这两种情况下都定义一个条件列表,只有全部条件通过时才使用条目或池。数据生成时,调用 LootPoolEntryContainer.Builder<?> 或 LootPool.Builder 的 #when,传入所需条件的实例,即可添加条件。本文介绍可用的战利品条件。创建自己的条件请参阅自定义战利品条件。
minecraft:inverted
接收另一个条件,并将其结果取反。需要的战利品参数与被取反条件相同。
{
"condition": "minecraft:inverted",
"term": {
// Some other loot condition.
}
}
数据生成时,向 InvertedLootItemCondition#invert 传入需要取反的条件,创建此条件的构建器。
minecraft:all_of
接收任意数量的其他条件,所有子条件都返回 true 时才返回 true。列表为空时返回 false。需要的战利品参数由其他条件决定。
{
"condition": "minecraft:all_of",
"terms": [
{
// A loot condition.
},
{
// Another loot condition.
},
{
// Yet another loot condition.
}
]
}
数据生成时,向 AllOfCondition#allOf 传入所需条件,创建此条件的构建器。
minecraft:any_of
接收任意数量的其他条件,至少一个子条件返回 true 时就返回 true。列表为空时返回 false。需要的战利品参数由其他条件决定。
{
"condition": "minecraft:any_of",
"terms": [
{
// A loot condition.
},
{
// Another loot condition.
},
{
// Yet another loot condition.
}
]
}
数据生成时,向 AnyOfCondition#anyOf 传入所需条件,创建此条件的构建器。
minecraft:random_chance
接收表示 0 到 1 之间概率的数字提供器,并按该概率随机返回 true 或 false。数字提供器通常不应返回 [0, 1] 范围之外的值。
{
"condition": "minecraft:random_chance",
// A constant 50% chance for the condition to apply.
"chance": 0.5
}
数据生成时,向 LootItemRandomChanceCondition#randomChance 传入数字提供器或恒定浮点值,创建此条件的构建器。
minecraft:random_chance_with_enchanted_bonus
接收附魔 ID、LevelBasedValue 和恒定的后备浮点值。存在指定附魔时,向 LevelBasedValue 查询值;不存在该附魔,或无法从 LevelBasedValue 获取值时,使用后备常量。随后按此值表示的概率随机返回 true 或 false,其中该值是返回 true 的概率。需要 minecraft:attacking_entity 参数,缺少时使用等级 0。
{
"condition": "minecraft:random_chance_with_enchanted_bonus",
// Add a 20% chance per looting level to succeed.
"enchantment": "minecraft:looting",
"enchanted_chance": {
"type": "linear",
"base": 0.2,
"per_level_above_first": 0.2
},
// Always fail if the looting enchantment is not present.
"unenchanted_chance": 0.0
}
数据生成时,向 LootItemRandomChanceWithEnchantedBonusCondition#randomChanceAndLootingBoost 传入注册表查询对象(HolderLookup.Provider)、基础值和每级增量,创建构建器。也可调用 new LootItemRandomChanceWithEnchantedBonusCondition 进一步指定这些值。
minecraft:value_check
接收数字提供器和 IntRange,当提供器的结果处于范围内时返回 true。
{
"condition": "minecraft:value_check",
// May be any number provider.
"value": {
"type": "minecraft:uniform",
"min": 0.0,
"max": 10.0
},
// A range with min/max values.
"range": {
"min": 2.0,
"max": 5.0
}
}
数据生成时,向 ValueCheckCondition#hasValue 传入数字提供器和范围,创建此条件的构建器。
minecraft:time_check
检查给定的 WorldClock 是否处于 IntRange 内。可以提供可选的 period 参数,先让时间对它取模。例如设为 24000 可检查 minecraft:overworld 一天内的时间(一个游戏昼夜周期为 24000 刻)。
{
"condition": "minecraft:time_check",
// The clock instance to check the time of.
// Points to a registered clock at `data/<namespace>/world_clock/<path>.json`.
"clock": "minecraft:overworld",
// Optional, can be omitted. If omitted, no modulo operation will take place.
// We use 24000 here, which is the length of one in-game day/night cycle.
"period": 24000,
// A range with min/max values. This example checks if the time is between 0 and 12000.
// Combined with the modulo operand of 24000 specified above, this example checks if it is currently daytime.
"value": {
"min": 0,
"max": 12000
}
}
数据生成时,向 TimeCheck#time 传入时钟和所需范围创建构建器,再用构建器的 #setPeriod 设置 period。
minecraft:weather_check
检查当前天气是否下雨、打雷。
{
"condition": "minecraft:weather_check",
// Optional. If unspecified, the rain state will not be checked.
"raining": true,
// Optional. If unspecified, the thundering state will not be checked.
// Specifying "raining": true and "thundering": true is functionally equivalent to just specifying
// "thundering": true, since it is always raining when a thunderstorm occurs.
"thundering": false
}
数据生成时,调用 WeatherCheck#weather 创建构建器,再分别用 #setRaining 和 #setThundering 设置 raining 与 thundering。
minecraft:location_check
接收 LocationPredicate,以及每个坐标轴方向上的可选偏移值。LocationPredicate 可以检查位置本身、该位置的方块或流体状态、维度、生物群系或结构、亮度、是否能看到天空等条件。所有可用值见 LocationPredicate 类定义。需要 minecraft:origin 战利品参数,缺少时始终失败。
{
"condition": "minecraft:location_check",
"predicate": {
// Succeed if our target is anywhere in the nether.
"dimension": "the_nether"
},
// Optional position offset values. Only relevant if you are checking the position in some way.
// Must either be provided all at once, or not at all.
"offsetX": 10,
"offsetY": 10,
"offsetZ": 10
}
数据生成时,向 LocationCheck#checkLocation 传入 LocationPredicate 和可选的 BlockPos,创建此条件的构建器。
minecraft:block_state_property
检查被破坏方块状态中指定属性是否为指定值。需要 minecraft:block_state 战利品参数,缺少时始终失败。
{
"condition": "minecraft:block_state_property",
// The expected block. If this does not match the block that is actually broken, the condition fails.
"block": "minecraft:oak_slab",
// The block state properties to match. Unspecified properties can have either value.
// In this example, we want to only succeed if a top slab - waterlogged or not - is broken.
// If this specifies properties not present on the block, a log warning will be printed.
"properties": {
"type": "top"
}
}
数据生成时,向 LootItemBlockStatePropertyCondition#hasBlockStateProperties 传入方块创建构建器,再用 #setProperties 设置所需方块状态属性值。
minecraft:survives_explosion
随机销毁掉落物。掉落物存活概率为 1 除以 explosion_radius 战利品参数。除信标、龙蛋等极少数例外外,所有方块掉落都使用此条件。需要 minecraft:explosion_radius 参数,缺少时始终成功。
{
"condition": "minecraft:survives_explosion"
}
数据生成时,调用 ExplosionCondition#survivesExplosion 创建此条件的构建器。
minecraft:match_tool
接收 ItemPredicate,并用它检查 tool 战利品参数。ItemPredicate 可以指定有效物品 ID 列表(items)、物品数量的最小/最大范围(count)、DataComponentPredicate(components)和 ItemSubPredicate 映射(predicates);所有字段均可选。需要 minecraft:tool 参数,缺少时始终失败。
{
"condition": "minecraft:match_tool",
// Match a netherite pickaxe or axe.
"predicate": {
"items": [
"minecraft:netherite_pickaxe",
"minecraft:netherite_axe"
]
}
}
数据生成时,向 MatchTool#toolMatches 传入 ItemPredicate.Builder,创建此条件的构建器。
minecraft:enchantment_active
返回附魔是否处于激活状态。需要 minecraft:enchantment_active 战利品参数,缺少时始终失败。
{
"condition": "minecraft:enchantment_active",
// Whether the enchantment should be active (true) or not (false).
"active": true
}
数据生成时,调用 EnchantmentActiveCheck#enchantmentActiveCheck 或 #enchantmentInactiveCheck 创建此条件的构建器。
minecraft:table_bonus
类似 minecraft:random_chance_with_enchanted_bonus,但使用固定值而非随机值。需要 minecraft:tool 战利品参数,缺少时始终失败。
{
"condition": "minecraft:table_bonus",
// Apply the bonus if the fortune enchantment is present.
"enchantment": "minecraft:fortune",
// The chances to use per level. This example has a 20% chance of succeeding if unenchanted,
// 30% if enchanted at level 1, and 60% if enchanted at level 2 or above.
"chances": [0.2, 0.3, 0.6]
}
数据生成时,向 BonusLevelTableCondition#bonusLevelFlatChance 传入附魔 ID 和概率,创建此条件的构建器。
minecraft:entity_properties
使用给定的 EntityPredicate 检查实体目标。EntityPredicate 可以检查实体类型、状态效果、NBT 值、装备、位置等。
{
"condition": "minecraft:entity_properties",
// The entity target to use. Valid values are "this", "attacker", "direct_attacker" or "attacking_player".
// These correspond to the "this_entity", "attacking_entity", "direct_attacking_entity" and
// "last_damage_player" loot parameters, respectively.
"entity": "attacker",
// Only succeed if the target is a pig. The predicate may also be empty, this can be used
// to check whether the specified entity target is set at all.
"predicate": {
"type": "minecraft:pig"
}
}
数据生成时,向 LootItemEntityPropertyCondition#entityPresent 传入实体目标,或向 LootItemEntityPropertyCondition#hasProperties 传入实体目标和 EntityPredicate,创建此条件的构建器。
minecraft:damage_source_properties
使用给定的 DamageSourcePredicate 检查伤害来源战利品参数。需要 minecraft:origin 和 minecraft:damage_source 参数,缺少时始终失败。
{
"condition": "minecraft:damage_source_properties",
"predicate": {
// Check whether the source entity is a zombie.
"source_entity": {
"type": "zombie"
}
}
}
数据生成时,向 DamageSourceCondition#hasDamageSource 传入 DamageSourcePredicate.Builder,创建此条件的构建器。
minecraft:killed_by_player
确定是否由玩家击杀。一些实体掉落会使用它,例如烈焰人掉落烈焰棒。需要 minecraft:last_player_damage 战利品参数,缺少时始终失败。
{
"condition": "minecraft:killed_by_player"
}
数据生成时,调用 LootItemKilledByPlayerCondition#killedByPlayer 创建此条件的构建器。
minecraft:entity_scores
检查实体目标的计分板。需要对应实体目标的战利品参数,缺少时始终失败。
{
"condition": "minecraft:entity_scores"
// The entity target to use. Valid values are "this", "attacker", "direct_attacker" or "attacking_player".
// These correspond to the "this_entity", "attacking_entity", "direct_attacking_entity" and
// "last_damage_player" loot parameters, respectively.
"entity": "attacker",
// A list of scoreboard values that must be in the given ranges.
"scores": {
"score1": {
"min": 0,
"max": 100
},
"score2": {
"min": 10,
"max": 20
}
}
}
数据生成时,向 EntityHasScoreCondition#hasScores 传入实体目标创建构建器,再通过 #withScore 添加所需分数。
minecraft:reference
引用谓词文件并返回它的结果。更多信息见物品谓词。
{
"condition": "minecraft:reference",
// Refers to the predicate file at data/examplemod/predicate/example_predicate.json.
"name": "examplemod:example_predicate"
}
数据生成时,向 ConditionReference#conditionReference 传入所引用谓词文件的 ID,创建此条件的构建器。
minecraft:environment_attribute_check
检查上下文所在维度的环境属性是否与给定值匹配。如果环境属性与位置有关(可随玩家在世界中的位置变化),则需要 minecraft:origin 战利品参数,缺少时始终失败。如果维度中不存在该属性,则使用默认值进行检查。
{
"condition": "minecraft:environment_attribute_check",
// The environment attribute to check the value of.
"attribute": "minecraft:gameplay/water_evaporates",
// The value the environment attribute must be.
"value": false
}
数据生成时,向 EnvironmentAttributeCheck#environmentAttribute 传入已注册的 EnvironmentAttribute 及其值,创建此条件的构建器。
neoforge:loot_table_id
仅当所在战利品表的 ID 匹配时返回 true。通常用于全局战利品修改器。
{
"condition": "neoforge:loot_table_id",
// Will only apply when the loot table is for dirt
"loot_table_id": "minecraft:blocks/dirt"
}
数据生成时,向 LootTableIdCondition#builder 传入所需战利品表 ID,创建此条件的构建器。
neoforge:can_item_perform_ability
仅当 tool 战利品上下文参数(LootContextParams.TOOL)中的物品可以执行指定的 ItemAbility 时返回 true。该物品通常是用于破坏方块或击杀实体的物品。需要 minecraft:tool 参数,缺少时始终失败。
{
"condition": "neoforge:can_item_perform_ability",
// Will only apply if the tool can strip a log like an axe
"ability": "axe_strip"
}
数据生成时,向 CanItemPerformAbility#canItemPerformAbility 传入所需物品能力的 ID,创建此条件的构建器。
另请参阅
来源: NeoForged/Documentation(26.1)。中文翻译依据提交
4a680cdd4d15。