Mana Attributes

Mana Attributes

一个由实体属性控制的小型法力系统API。

游戏机制

魔力属性

该 API 添加了一套由实体属性控制的魔力系统。

默认实现

LivingEntity(生物实体)最多可拥有 manaattributes:max_mana 点魔力。魔力会每隔 manaattributes:mana_tick_threshold tick 恢复 manaattributes:mana_regeneration 点。

当魔力减少时,恢复会暂停 manaattributes:mana_regeneration_delay_threshold tick。

当魔力小于等于 0 时,恢复会暂停 manaattributes:depleted_mana_regeneration_delay_threshold tick。

manaattributes:reserved_mana 表示当前不可用的最大魔力百分比。

默认属性值

  • manaattributes:max_mana:0
  • manaattributes:mana_regeneration:0
  • manaattributes:mana_tick_threshold:20
  • manaattributes:mana_regeneration_delay_threshold:20
  • manaattributes:depleted_mana_regeneration_delay_threshold:60
  • manaattributes:reserved_mana:0

玩家的所有默认值都可以在服务器配置中设置。

自定义

客户端配置允许自定义 HUD 元素。

使用魔力系统

Java

将“LivingEntity”转换为“ManaUsingEntity”接口即可访问所有相关方法。

数据包

魔力属性实现了多种数据驱动的方法来与实体的当前魔力值进行交互。

  • “manaattributes:add_mana”附魔效果允许向当前魔力添加指定数量
  • “manaattributes:mana_using_entity”实体子谓词在当前实体的魔力符合定义范围时通过

示例

以下附魔在攻击者拥有至少 5 点魔力时,将其魔力减少 2 点:

{
	"anvil_cost": 1,
	"description": {
		"translate": "enchantment.manaattributes.test"
	},
	"effects": {
		"minecraft:post_attack": [
			{
				"affected": "attacker",
				"effect": {
					"type": "manaattributes:add_mana",
					"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": "manaattributes:mana_using_entity",
							"mana_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
}