Skip to content

Commit

Permalink
Actually fix the RecklessEnchantment
Browse files Browse the repository at this point in the history
  • Loading branch information
Thelnfamous1 committed Feb 14, 2024
1 parent 58a40a8 commit 535ce90
Showing 1 changed file with 18 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,32 @@ public static void onLivingUpdate(LivingEquipmentChangeEvent event) {
int levelFrom = event.getFrom().getEnchantmentLevel(EnchantmentInit.RECKLESS.get());
int levelTo = event.getTo().getEnchantmentLevel(EnchantmentInit.RECKLESS.get());
if (levelFrom == levelTo) return;
if (levelFrom == 0) {
// equipping armor with reckless
if (levelTo > 0) {
// remove any existing modifiers
livingEntity.getAttribute(Attributes.MAX_HEALTH).removeModifier(RECKLESS);
livingEntity.getAttribute(Attributes.ATTACK_DAMAGE).removeModifier(RECKLESS);

// add the modifiers and update health
livingEntity.getAttribute(Attributes.MAX_HEALTH).addTransientModifier(new AttributeModifier(RECKLESS, "reckless multiplier", DungeonsGearConfig.RECKLESS_MAX_HEALTH_MULTIPLIER.get(), AttributeModifier.Operation.MULTIPLY_BASE));
if(livingEntity.getHealth() > livingEntity.getMaxHealth()){
livingEntity.setHealth(livingEntity.getMaxHealth());
}
livingEntity.getAttribute(Attributes.ATTACK_DAMAGE).addTransientModifier(new AttributeModifier(RECKLESS, "reckless multiplier", DungeonsGearConfig.RECKLESS_ATTACK_DAMAGE_BASE_MULTIPLIER.get() + (DungeonsGearConfig.RECKLESS_ATTACK_DAMAGE_MULTIPLIER_PER_LEVEL.get() * levelTo), AttributeModifier.Operation.MULTIPLY_BASE));
}
// removing reckless armor
else{
// remove the modifiers and regain health lost from reckless
AttributeModifier existingRecklessHealthMod = livingEntity.getAttribute(Attributes.MAX_HEALTH).getModifier(RECKLESS);
if(existingRecklessHealthMod != null){
livingEntity.getAttribute(Attributes.MAX_HEALTH).removeModifier(existingRecklessHealthMod);
if(livingEntity.getHealth() < livingEntity.getMaxHealth()){
float regainedHealth = Math.abs(livingEntity.getMaxHealth() * DungeonsGearConfig.RECKLESS_MAX_HEALTH_MULTIPLIER.get().floatValue());
float regainedHealth = Math.abs(livingEntity.getMaxHealth() * (float)existingRecklessHealthMod.getAmount());
livingEntity.setHealth(livingEntity.getHealth() + regainedHealth);
}
}
livingEntity.getAttribute(Attributes.ATTACK_DAMAGE).removeModifier(RECKLESS);
}
if (levelTo > 0) {
livingEntity.getAttribute(Attributes.MAX_HEALTH).addTransientModifier(new AttributeModifier(RECKLESS, "reckless multiplier", DungeonsGearConfig.RECKLESS_MAX_HEALTH_MULTIPLIER.get(), AttributeModifier.Operation.MULTIPLY_BASE));
if(livingEntity.getHealth() > livingEntity.getMaxHealth()){
livingEntity.setHealth(livingEntity.getMaxHealth());
}
livingEntity.getAttribute(Attributes.ATTACK_DAMAGE).addTransientModifier(new AttributeModifier(RECKLESS, "reckless multiplier", DungeonsGearConfig.RECKLESS_ATTACK_DAMAGE_BASE_MULTIPLIER.get() + (DungeonsGearConfig.RECKLESS_ATTACK_DAMAGE_MULTIPLIER_PER_LEVEL.get() * levelTo), AttributeModifier.Operation.MULTIPLY_BASE));

}
}

Expand Down

0 comments on commit 535ce90

Please sign in to comment.