Skip to content

Enchantments

Provi edited this page Feb 19, 2024 · 1 revision

Enchantments can implement the CPCEnchantment interface or extend one of the four available enchantment classes: AspectEnchantment, WeaponUtilityEnchantment, AdditionalDamageEnchantent, OffhandEnchantment.

Using any of the above grants access to a number of callback and utility methods, these are used by the Combat+ Enchantment Helper.


Interface

The CPCEnchantment interface provides enchantments with access to important hooks, allowing enchantments to trigger their own on-hit and on-kill effects.

The source code can be seen here.

Usage

The Combat+ Enchantment Helper is used to trigger callbacks for CPCEnchantment classes. The four provided Enchantment subclasses also implement this interface.

Methods

getAttackDamage

This should be used instead of the vanilla version. This method returns the damage bonus the enchantment should grant. It does not have to be on the mainhand weapon. This method is called for enchantments on every equipment slot, this should be filtered by using the slot parameter.

postChargedHit

Used for callbacks involving fully charged hits. This method does not have a slot parameter and is triggered on a single item slot.

postCriticalHit

Used for callbacks involving critical hits. This method does not have a slot parameter and is triggereed on a single item slot.


Enchantment Subclasses

There are four types of enchantment that are provided by Combat+ Core. This allows different mods to add a diversity of enchantments whilst maintain compatibility with each other. All subclasses have equal access to CPCEnchantment methods, the difference exists primarily for compatibility.
With the exception of offhand enchantments, you can only put one of each enchantment on a single item.

Each group additionally has an associated datapack tag. Enchantments in these tags will be considered for compatibility.

Name Default Target Description Source
Additional Damage Ench Table accepts WEAPON; anvil accepts MELEE_WEAPON Used as a more advanced alternative to vanilla damaging enchantments. Here
Aspect WEAPON Enchantments that apply ticking effects on-hit to either the user or the target. Here
Offhand DUAL_WEAPON A miscellaneous category used for offhand weaponry. Has an internal grouping mechanism for compatibility. Here
Weapon Utility MELEE_WEAPON Utility enchantments that either grant new effects to weapons, or enhance their existing abilities. Here

Datapack Tags

Enchantments from non-Combat+ mods may fulfill similar niches to those defined here. The following tags allow other developers, modpack makers, etc, to define enchantments as being considered part of a Combat+ group.
This is useful as it affects which enchantments are compatible or incompatible with each other. For consistency, Combat+ enchantments should also be added to these tags.

  • combat-plus:additional_damage
  • combat-plus:aspect
  • combat-plus:offhand
  • combat-plus:weapon_utility

Enchantment Helper

As a parallel to the vanilla Enchantment Helper, Combat+ Core comes with its own CPCEnchantmentHelper. This is used to trigger callbacks involving the new enchantments.

Mods using Combat+ Core can create their own triggers and call methods from the enchantment helper in new contexts. For example, Dual Swords triggers the on-hit effects of enchantments as part of parrying and lunging.

The source code can be seen here.

Usage

The helper is used in mixins to trigger the enchantment callbacks. Additionally the onkill event is registered to trigger for mainhand items.

Methods

getAttackDamage

Gets the total attack damage for the user. This encompasses damage bonuses from all equipped items and also calls the vanilla equivalent. This should always be used instead of the vanilla version.

postChargedHit

Can be called with an item stack or an equipment slot. This activates all callbacks for charged hits found on the relevant item.

postCriticalHit

Can be called with an item stack or an equipment slot. This activates all callbacks for critical hits found on the relevant item.

postKill

Can be called with an item stack or an equipment slot. This activates all callbacks for klls found on the relevant item.

forEachEnchantment

Can be called with an item stack or an equipment slot. This allows you to call a function on each enchantment found on an item.

isDamage

Checks if an enchantment is considered as a damage enchantment. This is done by checking if it inherits the vanilla DamageEnchantment class or if it is in the associated convention tag.

isAdditionalDamage

Checks if an enchantment is considered as an additional damage enchantment. This is done by checking if it inherits from the class or is in the associated tag.

isAspect

Checks if an enchantment is considered as an aspect enchantment. This is done by checking if it inherits from the class or is in the associated tag.

isOffhand

Checks if an enchantment is considered as an offhand enchantment. This is done by checking if it inherits from the class or is in the associated tag.

isWeaponUtility

Checks if an enchantment is considered as a weapon utility enchantment. This is done by checking if it inherits from the class or is in the associated tag.