这是一个库模组,旨在让我的模组和其他模组能够对伤害和一些战斗机制进行精细控制。
默认情况下,此模组会执行以下操作:
- 修改造成暴击时的伤害类型,使模组能够轻松追踪攻击是否为暴击。伤害类型为 "pml:player_critical"。
- 修改造成横扫攻击时的伤害类型。伤害类型为 "pml:sweeping_damage"。
面向模组开发者
它提供了一种新的方式来注册和添加伤害加成与减免,并与 First Aid Mod(急救模组)协同工作,从而实现对受损身体部位的控制。
DamageControl 类是核心组件。它以结构化的方式提供在伤害应用于游戏之前修改、控制和计算伤害值的途径。
该系统允许使用多种修饰符,包括固定加成、基于百分比的加成,以及来自护甲、附魔和特殊机制的减免。
? 工作原理:
系统从原始基础伤害开始。
应用武器特定的缩放比例(在进行进一步计算之前减少伤害)。
首先应用基础加成(固定值和基于百分比的值)。
接着应用额外加成(固定值和基于百分比的值)。
系统计算减免值(护甲、附魔、特殊减免)。
最终伤害被存储,并可以在 LivingDamageEvent 中获取或修改。
? 变量详解:
?️ 增加伤害的修饰符
| 变量 |
描述 |
baseFlatBonus |
在百分比乘数之前添加的固定加成(例如 +10 伤害)。 |
basePercentBonus |
在其他计算之前应用的基于百分比的增加量(例如 1.2 倍乘数)。 |
flatBonus |
在基础加成之后添加的固定加成(例如 +5 伤害)。 |
percentBonus |
在基础计算之后应用的基于百分比的增加量。 |
?️ 减少伤害的修饰符
| 变量 |
描述 |
weapondamagecontrol |
在所有计算之前控制基于武器的缩放比例。 |
armorReduction |
由于护甲而减少的伤害(单独处理)。 |
enchReduction |
由于附魔而减少的伤害(单独处理)。 |
specialReduction |
直接减少最终伤害,因此必须谨慎使用。 |
? 参考原始值
| 变量 |
描述 |
originalDamage |
存储所有计算完成后的最终伤害,准备用于 LivingDamageEvent。 |
originalAbsorption |
存储修改前的吸收值。 |
?️ 关键方法
✔️ 添加加成
?️ getArmorReduction()
✅ 返回: 由于护甲造成的伤害减免量。
? 用法: 该值由 setArmorReduction(float value) 设置,代表通过基于护甲的机制(例如原版护甲计算或其他模组的自定义护甲效果)阻挡的伤害量。
? getEnchantmentReduction()
✅ 返回: 由附魔造成的伤害减免量。
? 用法: 这跟踪防御性附魔(如保护或自定义附魔)减少了多少最终伤害。模组可以使用此功能来平衡附魔效果或在工具提示中显示它们。
⚠️ getSpecialReduction()
✅ 返回: 通过特殊机制应用的直接伤害减免量。
? 用法: 这是最强大的伤害减免形式,因为它是在伤害计算的最后阶段减去的。模组应谨慎使用此功能,因为如果数值过高,它可能会完全抵消伤害。
? First Aid Mod 兼容系统
此系统与 First Aid Mod(急救模组)集成,该模组通过引入特定于身体部位的损伤来改变伤害处理方式。以下代码有助于在使用 First Aid Mod 时追踪哪个身体部位受到了伤害,并确保与 DamageControl 系统的兼容性。
[代码块省略]
?️ 关键方法
? getDamagedBodyPart(Player player)
✅ 目的: 检索受到损伤的身体部位。返回一个对应于受损身体部位的 EquipmentSlot 变量。
? 用法:
- 此方法仅应在
LivingDamageEvent 期间且存在 First Aid 模组时使用。
- 如果玩家未映射,则返回 null。
一个使用示例位于 Just a lot more Enchantments 模组内部。
This is a library mod aimed to allow my mods and other mods have great control over damage and some combat mechanics
By default this mod does this
Modifies damage type done when landing a critical strike, allowing mods to easily track down if an attack is a critical hit. Damage type is "pml:player_critical"
Modifies damage type done when dealing a sweeping attack. Damage type is "pml:sweeping_damage".
For Mod developers
It adds a new way to register and add damage bonuses and reductions alongside making this work with First Aid Mod to allow control over damaged bodyparts
The DamageControl class is a core component. It provides a structured way to modify, control, and calculate damage values before they are applied in the game.
This system allows for multiple modifiers, including flat bonuses, percentage-based bonuses, and reductions from armor, enchantments, and special mechanics.
? How It Works:
The system starts with raw base damage.
It applies weapon-specific scaling (reducing damage before further calculations).
Base bonuses are applied first (flat and percentage-based).
Additional bonuses are applied next (flat and percentage-based).
The system calculates reductions (armor, enchantments, special reductions).
The final damage is stored and can be retrieved or modified in LivingDamageEvent.
? Breakdown of Variables:
?️ Modifiers for Increasing Damage
Variable Description
baseFlatBonus Flat bonus added before percentage multipliers (e.g., +10 damage).
basePercentBonus Percentage-based increase applied before other calculations (e.g., 1.2 multiplier).
flatBonus Flat bonus added after base bonuses (e.g., +5 damage).
percentBonus Percentage-based increase applied after base calculations.
?️ Modifiers for Reducing Damage
Variable Description
weapondamagecontrol Controls weapon-based scaling before all calculations.
armorReduction Damage reduced due to armor (handled separately).
enchReduction Damage reduced due to enchantments (handled separately).
specialReduction Directly reduces final damage, so it must be used carefully.
? Original Values for Reference
Variable Description
originalDamage Stores the final damage after all calculations, ready for LivingDamageEvent.
originalAbsorption Stores the absorption value before modifications.
?️ Key Methods
✔️ Adding Bonuses
?️ getArmorReduction()
✅ Returns: The amount of damage reduction due to armor.
? Usage: This value is set by setArmorReduction(float value) and represents the amount of damage blocked by armor-based mechanics(e.g., vanilla armor calculations or custom armor effects from other mods).
? getEnchantmentReduction()
✅ Returns: The amount of damage reduction caused by enchantments.
? Usage: This tracks how much defensive enchantments (such as Protection or custom enchantments) reduce the final damage. Mods can use this to balance enchantment effects or display them in tooltips.
⚠️ getSpecialReduction()
✅ Returns: The amount of direct damage reduction applied through special mechanics.
? Usage: This is the most powerful form of damage reduction, as it is subtracted at the very end of the damage calculation. Mods should use this carefully because it can completely negate damage if too high.
? First Aid Mod Compatibility System
This system integrates with the First Aid mod, which modifies how damage is handled by introducing body-part-specific injuries. The following code helps track which body part was damaged when using the First Aid mod and ensures compatibility with the DamageControl system.
?️ Key Methods
? getDamagedBodyPart(Player player)
✅ Purpose: Retrieves the body part that was damaged. Returns a EquipmentSlot var corresponding to the bodypart damaged.
? Usage:
This method should only be used during LivingDamageEvent and when First Aid is present.
If the player isn't mapped, it returns null.
One example of use is inside the mod Just a lot more Enchantments.
评论 0
登录后参与评分
还没有评论,来抢沙发吧