Interface Enchantments
public interface Enchantments
The behaviour of the enchantments, and the helpers applying them to stacks.
The enchantments themselves are held by the RegistryKey.ENCHANTMENT registry: a
definition built by define(TypedKey) is registered through
GameRegistries.writable(RegistryKey).
- Since:
- 0.1.0
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionbooleanareCompatible(TypedKey<EnchantmentDefinition> first, TypedKey<EnchantmentDefinition> second) Returns whether the two enchantments can be applied to the same stack.voidattach(TypedKey<EnchantmentDefinition> key, EnchantmentBehaviour behaviour, Plugin owner) Adds a behaviour to an enchantment, on top of its existing ones.booleancanEnchant(ItemStack stack, TypedKey<EnchantmentDefinition> enchantment) Returns whetherenchantmentcan be applied tostack, as/enchantchecks it: the item is supported and the enchantment is compatible with those already on the stack.Returns a new builder for the enchantment identified bykey.booleandetach(TypedKey<EnchantmentDefinition> key, Plugin owner) Removes the behaviours a plugin added to an enchantment.disenchant(ItemStack stack, TypedKey<EnchantmentDefinition> enchantment) Removes an enchantment from a stack.displayName(TypedKey<EnchantmentDefinition> enchantment, int level) Returns the name of an enchantment followed by its level, as displayed in item tooltips.enchant(ItemStack stack, TypedKey<EnchantmentDefinition> enchantment, int level) Applies an enchantment to a stack, or changes its level.enchantedBook(TypedKey<EnchantmentDefinition> enchantment, int level) Returns an enchanted book storingenchantment.booleanisSupportedItem(TypedKey<EnchantmentDefinition> enchantment, TypedKey<Item> item) Returns whetherenchantmentcan be applied toitem.intlevel(LivingEntity entity, TypedKey<EnchantmentDefinition> enchantment) Returns the highest level ofenchantmentamong the stacksentitywears or holds in the slots of the enchantment, or0if absent.intlevel(ItemStack stack, TypedKey<EnchantmentDefinition> enchantment) Returns the level ofenchantmentonstack, or0if absent.Returns the effect components run by the server.
-
Method Details
-
define
Returns a new builder for the enchantment identified bykey.- Parameters:
key- the key of the enchantment- Returns:
- a new builder for the enchantment identified by
key - Since:
- 0.1.0
-
attach
Adds a behaviour to an enchantment, on top of its existing ones.- Parameters:
key- the key of the enchantment, vanilla or notbehaviour- the behaviour to addowner- the plugin adding it- Throws:
IllegalArgumentException- if no enchantment is registered underkey- Since:
- 0.1.0
-
detach
Removes the behaviours a plugin added to an enchantment.- Parameters:
key- the key of the enchantmentowner- the plugin that added them- Returns:
trueif at least one behaviour was removed- Since:
- 0.1.0
-
supportedEffectComponents
-
isSupportedItem
Returns whetherenchantmentcan be applied toitem.An item registered by a plugin is also tested as the vanilla item it is rendered as.
- Parameters:
enchantment- the key of the enchantmentitem- the item, such asminecraft:diamond_sword- Returns:
- whether
enchantmentcan be applied toitem - Since:
- 0.1.0
-
areCompatible
boolean areCompatible(TypedKey<EnchantmentDefinition> first, TypedKey<EnchantmentDefinition> second) Returns whether the two enchantments can be applied to the same stack.Two enchantments are compatible when they differ and neither belongs to the exclusive set of the other.
- Parameters:
first- the key of an enchantmentsecond- the key of another enchantment- Returns:
- whether the two enchantments can be applied to the same stack
- Since:
- 0.1.0
-
canEnchant
Returns whetherenchantmentcan be applied tostack, as/enchantchecks it: the item is supported and the enchantment is compatible with those already on the stack.- Parameters:
stack- the stackenchantment- the key of the enchantment- Returns:
- whether
enchantmentcan be applied tostack, as/enchantchecks it: the item is supported and the enchantment is compatible with those already on the stack - Since:
- 0.1.0
-
level
Returns the level ofenchantmentonstack, or0if absent.- Parameters:
stack- the stackenchantment- the key of the enchantment- Returns:
- the level of
enchantmentonstack, or0if absent - Since:
- 0.1.0
-
level
Returns the highest level ofenchantmentamong the stacksentitywears or holds in the slots of the enchantment, or0if absent.- Parameters:
entity- the entityenchantment- the key of the enchantment- Returns:
- the highest level of
enchantmentamong the stacksentitywears or holds in the slots of the enchantment, or0if absent - Since:
- 0.1.0
-
enchant
Applies an enchantment to a stack, or changes its level. Enchanted books receive it as a stored enchantment.No compatibility check is performed; see
canEnchant(ItemStack, TypedKey).- Parameters:
stack- the stackenchantment- the key of the enchantmentlevel- the level, between1and 255- Returns:
- the enchanted stack
- Throws:
IllegalArgumentException- if the enchantment is not registered or the level is out of range- Since:
- 0.1.0
-
disenchant
Removes an enchantment from a stack.- Parameters:
stack- the stackenchantment- the key of the enchantment- Returns:
- the stack without the enchantment, or
stackif it was absent - Since:
- 0.1.0
-
enchantedBook
Returns an enchanted book storingenchantment.- Parameters:
enchantment- the key of the enchantmentlevel- the level, between1and 255- Returns:
- an enchanted book storing
enchantment - Throws:
IllegalArgumentException- if the enchantment is not registered or the level is out of range- Since:
- 0.1.0
-
displayName
Returns the name of an enchantment followed by its level, as displayed in item tooltips.The name is gray, or red for a curse (
#minecraft:curse). The level is omitted when both the level and the maximum level are1.- Parameters:
enchantment- the key of the enchantmentlevel- the level- Returns:
- the name of an enchantment followed by its level, as displayed in item tooltips
- Since:
- 0.1.0
-