-
-
Notifications
You must be signed in to change notification settings - Fork 0
feat/Enchantment/NimbusEnchantment? #315
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
ddb044b
9fefb6d
6b16f7e
08f79c5
0b48b16
6a5104a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,59 @@ | ||||||||||||||||||||||||||||||||||||||
| package org.xodium.vanillaplus.enchantments | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| import io.papermc.paper.event.entity.EntityEquipmentChangedEvent | ||||||||||||||||||||||||||||||||||||||
| import io.papermc.paper.registry.data.EnchantmentRegistryEntry | ||||||||||||||||||||||||||||||||||||||
| import org.bukkit.attribute.Attribute | ||||||||||||||||||||||||||||||||||||||
| import org.bukkit.entity.HappyGhast | ||||||||||||||||||||||||||||||||||||||
| import org.bukkit.inventory.EquipmentSlot | ||||||||||||||||||||||||||||||||||||||
| import org.bukkit.inventory.EquipmentSlotGroup | ||||||||||||||||||||||||||||||||||||||
| import org.xodium.vanillaplus.interfaces.EnchantmentInterface | ||||||||||||||||||||||||||||||||||||||
| import org.xodium.vanillaplus.utils.ExtUtils.mm | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| /** Represents an object handling nimbus enchantment implementation within the system. */ | ||||||||||||||||||||||||||||||||||||||
| @Suppress("UnstableApiUsage") | ||||||||||||||||||||||||||||||||||||||
| internal object NimbusEnchantment : EnchantmentInterface { | ||||||||||||||||||||||||||||||||||||||
| const val DEFAULT_FLY_SPEED = 0.05 | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| override fun invoke(builder: EnchantmentRegistryEntry.Builder): EnchantmentRegistryEntry.Builder = | ||||||||||||||||||||||||||||||||||||||
| builder | ||||||||||||||||||||||||||||||||||||||
| .description(key.value().replaceFirstChar { it.uppercase() }.mm()) | ||||||||||||||||||||||||||||||||||||||
| .anvilCost(2) | ||||||||||||||||||||||||||||||||||||||
| .maxLevel(5) | ||||||||||||||||||||||||||||||||||||||
| .weight(2) | ||||||||||||||||||||||||||||||||||||||
| .minimumCost(EnchantmentRegistryEntry.EnchantmentCost.of(25, 5)) | ||||||||||||||||||||||||||||||||||||||
| .maximumCost(EnchantmentRegistryEntry.EnchantmentCost.of(75, 10)) | ||||||||||||||||||||||||||||||||||||||
| .activeSlots(EquipmentSlotGroup.SADDLE) | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||||||||||
| * Handles the event when an entity's equipment changes, specifically for Happy Ghasts with the nimbus enchantment. | ||||||||||||||||||||||||||||||||||||||
| * @param event The event representing the change in entity equipment. | ||||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||
| fun nimbus(event: EntityEquipmentChangedEvent) { | ||||||||||||||||||||||||||||||||||||||
| val entity = event.entity as? HappyGhast ?: return | ||||||||||||||||||||||||||||||||||||||
| val harness = entity.equipment.getItem(EquipmentSlot.BODY) | ||||||||||||||||||||||||||||||||||||||
| val attribute = entity.getAttribute(Attribute.FLYING_SPEED) | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| if (harness.hasItemMeta() && harness.itemMeta.hasEnchant(get())) { | ||||||||||||||||||||||||||||||||||||||
| val level = harness.itemMeta.getEnchantLevel(get()) | ||||||||||||||||||||||||||||||||||||||
| val speedMultiplier = getSpeedMultiplier(level) | ||||||||||||||||||||||||||||||||||||||
| attribute?.baseValue = DEFAULT_FLY_SPEED * speedMultiplier | ||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||
| attribute?.baseValue = DEFAULT_FLY_SPEED | ||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+35
to
+41
|
||||||||||||||||||||||||||||||||||||||
| if (harness.hasItemMeta() && harness.itemMeta.hasEnchant(get())) { | |
| val level = harness.itemMeta.getEnchantLevel(get()) | |
| val speedMultiplier = getSpeedMultiplier(level) | |
| attribute?.baseValue = DEFAULT_FLY_SPEED * speedMultiplier | |
| } else { | |
| attribute?.baseValue = DEFAULT_FLY_SPEED | |
| if (attribute == null) { | |
| org.bukkit.Bukkit.getLogger().warning("HappyGhast entity missing FLYING_SPEED attribute in NimbusEnchantment.") | |
| return | |
| } | |
| if (harness.hasItemMeta() && harness.itemMeta.hasEnchant(get())) { | |
| val level = harness.itemMeta.getEnchantLevel(get()) | |
| val speedMultiplier = getSpeedMultiplier(level) | |
| attribute.baseValue = DEFAULT_FLY_SPEED * speedMultiplier | |
| } else { | |
| attribute.baseValue = DEFAULT_FLY_SPEED |
Copilot
AI
Nov 17, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code resets the flying speed to DEFAULT_FLY_SPEED whenever equipment changes, regardless of whether the harness was actually removed or changed. This could overwrite custom speed values set by other plugins or game mechanics. The reset should only occur when the harness is removed or the enchantment is specifically removed, not on every equipment change event. Consider checking if event.slot == EquipmentSlot.BODY before modifying the speed, similar to how NightVisionEnchantment checks the specific slot.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code doesn't verify that the changed equipment slot is actually the BODY slot. This means the function performs unnecessary work on every equipment change (helmet, boots, etc.). Consider adding a check like
if (event.slot != EquipmentSlot.BODY) returnearly in the function to avoid processing irrelevant equipment changes, consistent with how other enchantments in the codebase filter their events.