Bugs found on PlayerMobEntity.java
AylanJ123 opened this issue ยท 1 comments
I was reading your code because the mod was behaving weirdly. I found a total of 3 different bugs and got a fix for all of them.
Bugs:
- The chances of having an offhand item has a reversed comparator
- PlayerMob gets increased health even if it doesn't have a shield in the offhand
- PlayerMob health remains at 20HP despite having max health attribute increased
Spotted at:
- PlayerMobEntity.java:162
pRandom.nextDouble() > Configs.COMMON.offhandSpawnChance.get()
- PlayerMobEntity.java:170-173 (There isn't a check to increase attribute)
- PlayerMobEntity.java:170-173 (Attribute increased but current health remains)
Solutions:
- Just turn around the operator so it's < (Less than)
- Make a check if the created stack's item is
instanceof ShieldItem
before increasing attribute. This should work even for modded shields if they inherit from that class. - Heal the PlayerMob enough to max their health, or directly modify the current health field. Take into account that other mods can increase the PlayerMob health, for example, InControl. In this case, it would be wise to set the max health to be the same value as the current health so it doesn't matter the exact amount.
Edit: Also, just a suggestion. It would be a good idea to rise the health AND defense if they have a shield. Maybe make it proportional to the durability of the shield so modded shields can have different effects. This would make the PlayerMobs more challenging and fun.