Possible problems with two enchantments
obernulpe opened this issue ยท 2 comments
I think I found two problems with the Committed Enchantment and the Critical Hit Enchantment (unless I messed something up while testing the enchantments):
Critical Hit Enchantment:
So while testing this enchantment I noticed that some attacks would deal much more damage than I expected.
The chat log below shows the health of my target before each hit. I attacked with a Critical III diamond sword standing still and waiting a few seconds before the next hit.
command: /data get entity @e[type=iron_golem,distance=..10,limit=1] Health
[20:52:13] [main/INFO]: [CHAT] Iron Golem has the following entity data: 100.0f
[20:52:16] [main/INFO]: [CHAT] Iron Golem has the following entity data: 82.5f // damage: 17.5f
[20:52:19] [main/INFO]: [CHAT] Iron Golem has the following entity data: 68.5f // damage: 14.0f
[20:52:21] [main/INFO]: [CHAT] Iron Golem has the following entity data: 54.5f // damage: 14.0f
[20:52:24] [main/INFO]: [CHAT] Iron Golem has the following entity data: 23.0f // damage: 31.5f
[20:52:27] [main/INFO]: [CHAT] Iron Golem has the following entity data: 12.5f // damage: 10.5f
[20:52:29] [main/INFO]: [CHAT] Iron Golem has the following entity data: 5.5f // damage: 7.0f
The last two damage numbers seem to be like intended: 7.0f damage for a normal hit and 10.5f with the enchantment being applied.
I think I found a "loop" responsible for hits with >10.5f damage.
*player hits* --> LivingEntity.damage() ---> LivingEntity.applyDamage()
^ V
target.damage() <--- applyCriticalHitEnchantmentDamage()
The loop breaks when if(criticalHitRand <= criticalHitChance) is false.
Committed Enchantment:
This enchantment seems to not apply the extra damage because of the following lines in LivingEntity.damage():
// ...
if ((float)this.timeUntilRegen > 10.0F) {
if (amount <= this.lastDamageTaken) {
return false;
}
this.applyDamage(source, amount - this.lastDamageTaken);
// ...
} else {
this.lastDamageTaken = amount;
this.timeUntilRegen = 20;
this.applyDamage(source, amount);
// ...
}
// ...
When hitting an entity it first executes the else block. It sets lastDamageTaken to 7.0f (used a diamond sword again) then calls applyDamage / applyCommittedEnchantmentDamage. It calculates the extra damage and goes back to LivingEntity.damage() where the if block is executed this time. It will return false then because the extra damage will never exceed 7.0f so (amount <= this.lastDamageTaken) is true.
I hope you can reproduce that otherwise I might have a problem on my end :D
Just wanted to add a quick comment here. I'm completely unaffiliated with MC Dungeon Weapons, so I can't help you out with this trouble ticket - but as a Minecraft Mod developer myself, I just want to say how much I appreciate seeing the time and effort you've obviously put into creating this issue. If every issue could look more like this and less like "durr it don't work good", I'm convinced the world would be a much better place.