耐力属性
此 API 添加了一个由实体属性控制的耐力系统。
默认实现
生物实体最多拥有 staminaattributes:max_stamina 点耐力。耐力每 staminaattributes:stamina_tick_threshold 刻恢复 staminaattributes:stamina_regeneration 点。
当耐力降低时,恢复将在 staminaattributes:stamina_regeneration_delay_threshold 刻内停止。
当耐力 <= 0 时,恢复将在 staminaattributes:depleted_stamina_regeneration_delay_threshold 刻内停止。
staminaattributes:reserved_stamina 描述了当前不可用的最大耐力百分比。
staminaattributes:item_use_stamina_cost 是使用具有耐力消耗的物品时减少的耐力量。
有两种方式为物品赋予耐力消耗:
- 位于 "staminaattributes:using_costs_stamina" 物品标签中的物品在使用一次时会减少 staminaattributes:item_use_stamina_cost 点耐力。
当耐力 < 0 时,使用动作不会执行。在这种情况下,物品会获得一个冷却时间,
该冷却时间在服务器配置中配置。
- 位于 "staminaattributes:continuous_using_costs_stamina" 物品标签中的物品在持续使用时,每刻减少 staminaattributes:item_use_stamina_cost 点耐力。当耐力 < 0 时,使用会被取消。在
这种情况下,物品会获得一个冷却时间,该冷却时间在服务器配置中配置。
不同的 staminaattributes:*_tick_stamina_cost 属性描述了相应活动的耐力消耗。此消耗
每刻(每秒 20 次)应用一次。这包括以下活动:
- 疾跑 (sprinting)
- 潜行 (sneaking)
- 行走 (walking)
- 游泳 (swimming)
- 水下行走 (walking underwater)
- 水中行走 (walking in water)
- 攀爬 (climbing)
不同的 staminaattributes:*_action_stamina_cost 属性描述了相应动作的耐力消耗。此消耗
每次执行动作时应用一次。这包括以下动作:
- 跳跃 (jumping)
- 疾跑跳跃 (sprint jumping)
- 攻击格挡 (attack blocking)
- 攻击 (attacking)
- 破坏方块 (block breaking)
多种活动和动作可以配置为需要耐力。如果耐力为 0 或更低,则无法执行这些操作。
这包括:
- 跳跃 (jumping)
- 疾跑 (sprinting)
- 游泳 (swimming)
- 攻击 (attacking)
- 破坏方块 (block breaking)
- 攻击 (attacking)
- 攻击格挡 (attack blocking)
可以通过手瞬间破坏的方块("destroyTime" 为 0 的方块)可以排除在耐力要求之外。
疲劳 (Exhaustion)
如果玩家耐力为 0 或更少,他们将处于疲劳状态,这意味着会施加一种状态效果。此状态效果
在服务器配置中定义。
此功能可以在服务器配置中启用,但默认情况下是禁用的。
默认属性值
- staminaattributes:max_stamina: 10 (玩家为 10)
- staminaattributes:stamina_regeneration: 0 (玩家为 1)
- staminaattributes:stamina_tick_threshold: 20
- staminaattributes:stamina_regeneration_delay_threshold: 20
- staminaattributes:depleted_stamina_regeneration_delay_threshold: 60
- staminaattributes:reserved_stamina: 0
- staminaattributes:item_use_stamina_cost: 0 (玩家为 0.05)
- staminaattributes:sprinting_tick_stamina_cost: 0 (玩家为 0.05)
- staminaattributes:sneaking_tick_stamina_cost: 0 (玩家为 0.05)
- staminaattributes:walking_tick_stamina_cost: 0
- staminaattributes:swimming_tick_stamina_cost: 0 (玩家为 0.05)
- staminaattributes:walking_underwater_tick_stamina_cost: 0 (玩家为 0.05)
- staminaattributes:walking_in_water_tick_stamina_cost: 0 (玩家为 0.05)
- staminaattributes:climbing_tick_stamina_cost: 0 (玩家为 0.05)
- staminaattributes:jumping_action_stamina_cost: 0 (玩家为 1)
- staminaattributes:sprint_jumping_action_stamina_cost: 0 (玩家为 1)
- staminaattributes:attack_blocking_action_stamina_cost: 0 (玩家为 1)
- staminaattributes:attacking_action_stamina_cost: 0 (玩家为 1)
- staminaattributes:block_breaking_action_stamina_cost: 0 (玩家为 1)
所有玩家的默认值都可以在服务器配置中设置。
默认物品标签
"staminaattributes:using_costs_stamina":
{
"values": [
"minecraft:snowball"
]
}
"staminaattributes:continuous_using_costs_stamina":
{
"values": [
"minecraft:bow",
"minecraft:crossbow",
"minecraft:shield"
]
}
自定义
客户端配置允许自定义 HUD 元素。
使用耐力系统
Java
将 "LivingEntity" 强制转换为 "StaminaUsingEntity" 接口即可访问所有相关方法。
数据包
Stamina Attributes 实现了多种数据驱动的方法,以与实体的当前耐力值进行交互。
- "staminaattributes:add_stamina" 附魔效果允许向当前耐力增加指定数量
- "staminaattributes:stamina_using_entity" 实体子谓词在实体的当前耐力匹配
定义的范围内时通过
示例
此附魔会使攻击者的耐力减少 2,只要攻击者至少有 5 点耐力:
{
"anvil_cost": 1,
"description": {
"translate": "enchantment.staminaattributes.test"
},
"effects": {
"minecraft:post_attack": [
{
"affected": "attacker",
"effect": {
"type": "staminaattributes:add_stamina",
"amount": {
"type": "minecraft:linear",
"base": -2.0,
"per_level_above_first": -2.0
}
},
"enchanted": "attacker",
"requirements": {
"condition": "minecraft:entity_properties",
"entity": "direct_attacker",
"predicate": {
"type_specific": {
"type": "staminaattributes:stamina_using_entity",
"stamina_amount": {
"min": 5.0
}
}
}
}
}
]
},
"max_cost": {
"base": 25,
"per_level_above_first": 8
},
"max_level": 1,
"min_cost": {
"base": 5,
"per_level_above_first": 8
},
"slots": [
"hand"
],
"supported_items": "#minecraft:swords",
"weight": 5
}
Stamina Attributes
This API adds a stamina system controlled by entity attributes.
Default implementation
LivingEntities can have up to staminaattributes:max_stamina amounts of stamina. Stamina is regenerated by staminaattributes:stamina_regeneration every staminaattributes:stamina_tick_threshold ticks.
When stamina is reduced, regeneration is stopped for staminaattributes:stamina_regeneration_delay_threshold ticks.
When stamina is <= 0, regeneration is stopped for staminaattributes:depleted_stamina_regeneration_delay_threshold ticks.
staminaattributes:reserved_stamina describes the percentage amount of maximum stamina that is currently not available.
staminaattributes:item_use_stamina_cost is the amount of stamina that is reduced when using an item with a stamina cost.
There are two ways to give an item a stamina cost:
- Items in the "staminaattributes:using_costs_stamina" item tag reduce stamina by staminaattributes:item_use_stamina_cost
when they are used once. When stamina is < 0 the use action is not performed. In that case the item gets a cooldown,
configured in the server config.
- Items in the "staminaattributes:continuous_using_costs_stamina" item tag reduce stamina by staminaattributes:item_use_stamina_cost every tick while they are used. When stamina is < 0, the usage is cancelled. In
that case the item gets a cooldown, configured in the server config.
The different staminaattributes:*_tick_stamina_cost attributes describe the stamina cost for the corresponding activity. This cost is
applied every tick (20x per second). This includes the following activities:
- sprinting
- sneaking
- walking
- swimming
- walking underwater
- walking in water
- climbing
The different staminaattributes:*_action_stamina_cost attributes describe the stamina cost for the corresponding actions. This cost is
applied once every time the action is performed. This includes the following actions:
- jumping
- sprint jumping
- attack blocking
- attacking
- block breaking
Several activities and actions can be configured to require stamina. If stamina is 0 or lower, they can't be performed.
This includes:
- jumping
- sprinting
- swimming
- attacking
- block breaking
- attacking
- attack blocking
Blocks that can be broken instantly by hand (blocks with a "destroyTime" of 0) can be excluded from the stamina
requirement.
Exhaustion
If a player has 0 or less stamina, they are exhausted, which means that a status effect is applied. This status effect
is defined in the server config.
This feature can be enabled in the server config, but it's disabled by default.
Default attribute values
- staminaattributes:max_stamina: 10 (10 for players)
- staminaattributes:stamina_regeneration: 0 (1 for players)
- staminaattributes:stamina_tick_threshold: 20
- staminaattributes:stamina_regeneration_delay_threshold: 20
- staminaattributes:depleted_stamina_regeneration_delay_threshold: 60
- staminaattributes:reserved_stamina: 0
- staminaattributes:item_use_stamina_cost: 0 (0.05 for players)
- staminaattributes:sprinting_tick_stamina_cost: 0 (0.05 for players)
- staminaattributes:sneaking_tick_stamina_cost: 0 (0.05 for players)
- staminaattributes:walking_tick_stamina_cost: 0
- staminaattributes:swimming_tick_stamina_cost: 0 (0.05 for players)
- staminaattributes:walking_underwater_tick_stamina_cost: 0 (0.05 for players)
- staminaattributes:walking_in_water_tick_stamina_cost: 0 (0.05 for players)
- staminaattributes:climbing_tick_stamina_cost: 0 (0.05 for players)
- staminaattributes:jumping_action_stamina_cost: 0 (1 for players)
- staminaattributes:sprint_jumping_action_stamina_cost: 0 (1 for players)
- staminaattributes:attack_blocking_action_stamina_cost: 0 (1 for players)
- staminaattributes:attacking_action_stamina_cost: 0 (1 for players)
- staminaattributes:block_breaking_action_stamina_cost: 0 (1 for players)
All default values for players can be set in the server config.
Default item tags
"staminaattributes:using_costs_stamina":
{
"values": [
"minecraft:snowball"
]
}
"staminaattributes:continuous_using_costs_stamina":
{
"values": [
"minecraft:bow",
"minecraft:crossbow",
"minecraft:shield"
]
}
Customization
The client config allows customizing the HUD element.
Using the stamina system
Java
Casting a "LivingEntity" to the "StaminaUsingEntity" interface gives access to all relevant methods.
Data packs
Stamina Attributes implements several data driven methods to interact with the current stamina value of an entity.
- the "staminaattributes:add_stamina" enchantment effect allows adding a defined amount to the current stamina
- the "staminaattributes:stamina_using_entity" entity sub predicate passes when the current stamina of an entity matches
the defined range
Example
This enchantment reduces stamina of the attacker by 2, as long as the attacker has at least 5 stamina:
{
"anvil_cost": 1,
"description": {
"translate": "enchantment.staminaattributes.test"
},
"effects": {
"minecraft:post_attack": [
{
"affected": "attacker",
"effect": {
"type": "staminaattributes:add_stamina",
"amount": {
"type": "minecraft:linear",
"base": -2.0,
"per_level_above_first": -2.0
}
},
"enchanted": "attacker",
"requirements": {
"condition": "minecraft:entity_properties",
"entity": "direct_attacker",
"predicate": {
"type_specific": {
"type": "staminaattributes:stamina_using_entity",
"stamina_amount": {
"min": 5.0
}
}
}
}
}
]
},
"max_cost": {
"base": 25,
"per_level_above_first": 8
},
"max_level": 1,
"min_cost": {
"base": 5,
"per_level_above_first": 8
},
"slots": [
"hand"
],
"supported_items": "#minecraft:swords",
"weight": 5
}
评论 0
登录后参与评分
还没有评论,来抢沙发吧