elBukkit / MagicPlugin

A Bukkit plugin for spells, wands and other magic
http://mine.elmakers.com
MIT License
242 stars 149 forks source link

Armor Attribute being read wrong #1162

Open NightScythe1 opened 1 year ago

NightScythe1 commented 1 year ago

For some reason, the Armor attribute in magic seems to be registering incorrectly when used in classes/spells. I have a class that has a 'protection' depending on a player's armour amount:

  protection:
    necromancy_damage: armor/200

The intended function would be a player in full Diamond (20 armor points) gets a 0.2 reduction. But the 'armor' value here only seems to register from the last time the armor value changed. Aka, it reads it when a player equips/unequips armour, but does not catch the new value caused by the value that triggered it. E.G:

a player with 0 armour who puts on boots, will still register as 0 armor, but if they then put on leggings, it now triggers and registers that the player has boots on, and updates the value to 3 armor but misses the leggings. if a player then equipped a chestplate, it would trigger and register the boots AND the leggings, updating it to 9 armor, but missing the chestplate.

the same issue occurs when un-equipping armor. Taking off any armour will update it again to the last known armor value, but doesn't catch the unequip. meaning if a player equipped, then unequipped a chestplate, they would still be read as 8 armor by magic, until they equip/unequip something else.

The strange part is that using "/mage attribute armor" still shows the correct, expected value. The issue is only apparent when using this 'armor' attribute in a spell/class protection as i showed above.

Here's a class and spell if you'd like to try reproducing it. Just enable the class for yourself, equip various armor levels, and cast the spell on yourself. (I changed the custom damage type to just Magic here, for easier time reproducing it.)

attribute_bug_spell:
  actions:
    cast:
    - class: Damage
  parameters:
    target: self
    damage: 10
    damage_type: magic
attribute_bug_class:
  passive: true
  protection:
    magic: armor/200
NightScythe1 commented 1 year ago

Another issue I've found- the enchantment 'attributes' don't stack with multiple armour pieces. E.G. if all 4 armour pieces have 'Protection IV' your 'Protection' attribute is '4', the same is true with just one armour piece with 'Protection IV'

I0nTech commented 1 year ago

You need to add stackable: true to the armor piece config for enchantment attributes to stack I believe, the armor attribute problem I know of and can't fix with config alone.

NightScythe1 commented 1 year ago

You need to add stackable: true to the armor piece config for enchantment attributes to stack I believe, the armor attribute problem I know of and can't fix with config alone.

Which armour piece config are you referring to? The armour i'm using is just standard, vanilla armour with enchantments.

I0nTech commented 1 year ago

Ah, never mind - I thought you were working on custom armor. In that case I'd recommend using PAPI instead to read for armor values/enchantments.

NightScythe1 commented 1 year ago

Ah, never mind - I thought you were working on custom armor. In that case I'd recommend using PAPI instead to read for armor values/enchantments.

I'm not too sure how to do this, do you have a recommendation? I tried making an attribute with the default value set to a PAPI placeholder-

helmet_armor:
  default: "%armor_amount_helmet%"

but magic doesn't recognise it, and defaults it to 0

NightScythe1 commented 1 year ago

Update: this happens with the 'attack_damage' attribute as well. Unfortunately due to the attributes being read when a wand is Deactivated rather than Activated, it's breaking the lore of items that use these attributes in their description :( Example here, a custom weapon which is meant to reflect the attribute 'attack_damage' in the lore, but shows the wrong value entirely when held.