diff --git a/src/main/java/dev/shadowsoffire/attributeslib/api/ALCombatRules.java b/src/main/java/dev/shadowsoffire/attributeslib/api/ALCombatRules.java index 0f33aba..c5077e2 100644 --- a/src/main/java/dev/shadowsoffire/attributeslib/api/ALCombatRules.java +++ b/src/main/java/dev/shadowsoffire/attributeslib/api/ALCombatRules.java @@ -1,6 +1,7 @@ package dev.shadowsoffire.attributeslib.api; import dev.shadowsoffire.attributeslib.ALConfig; +import dev.shadowsoffire.attributeslib.AttributesLib; import dev.shadowsoffire.attributeslib.api.ALObjects.Attributes; import net.minecraft.world.damagesource.DamageSource; import net.minecraft.world.entity.LivingEntity; @@ -75,6 +76,8 @@ public static float getProtDamageReduction(float protPoints) { * @return The modified damage value, after applying armor, accounting for the attacker's bypass. */ public static float getDamageAfterArmor(LivingEntity target, DamageSource src, float amount, float armor, float toughness) { + //AttributesLib.LOGGER.info("getDamageAfterArmor was passed " + amount); + if (src.getEntity() instanceof LivingEntity attacker) { float shred = (float) attacker.getAttributeValue(Attributes.ARMOR_SHRED); float bypassResist = Math.min(toughness * 0.02F, 0.6F); @@ -123,6 +126,7 @@ public static float getAValue(float damage) { * @see #getDamageAfterArmor(LivingEntity, DamageSource, float, float, float) */ public static float getArmorDamageReduction(float damage, float armor) { +// AttributesLib.LOGGER.info("getArmorDamageReduction was passed " + damage); float a = getAValue(damage); if (ALConfig.getArmorExpr().isPresent()) { return ALConfig.getArmorExpr().get().setVariable("a", new BigDecimal(a)).setVariable("damage", new BigDecimal(damage)).setVariable("armor", new BigDecimal(armor)).eval().floatValue(); diff --git a/src/main/java/dev/shadowsoffire/attributeslib/api/IFormattableAttribute.java b/src/main/java/dev/shadowsoffire/attributeslib/api/IFormattableAttribute.java index 8249160..0add7c7 100644 --- a/src/main/java/dev/shadowsoffire/attributeslib/api/IFormattableAttribute.java +++ b/src/main/java/dev/shadowsoffire/attributeslib/api/IFormattableAttribute.java @@ -67,6 +67,9 @@ default MutableComponent toValueComponent(@Nullable Operation op, double value, */ default MutableComponent toComponent(AttributeModifier modif, TooltipFlag flag) { Attribute attr = this.ths(); + if(attr == null){ + return null; + } double value = modif.getAmount(); MutableComponent comp; @@ -193,7 +196,13 @@ default Attribute ths() { * Helper method to invoke {@link #toComponent(AttributeModifier, TooltipFlag)}. */ public static MutableComponent toComponent(Attribute attr, AttributeModifier modif, TooltipFlag flag) { - return ((IFormattableAttribute) attr).toComponent(modif, flag); + if(attr != null){ + return ((IFormattableAttribute) attr).toComponent(modif, flag); + } + else{ + return null; + } + } /** diff --git a/src/main/java/dev/shadowsoffire/attributeslib/client/AttributesGui.java b/src/main/java/dev/shadowsoffire/attributeslib/client/AttributesGui.java index 3364476..80e6afc 100644 --- a/src/main/java/dev/shadowsoffire/attributeslib/client/AttributesGui.java +++ b/src/main/java/dev/shadowsoffire/attributeslib/client/AttributesGui.java @@ -254,8 +254,11 @@ else if (inst.getValue() < inst.getBaseValue()) { for (AttributeModifier modif : modifiers) { if (modif.getAmount() != 0) { Component comp = fAttr.toComponent(modif, AttributesLib.getTooltipFlag()); - var src = modifiersToSources.get(modif.getId()); - finalTooltip.add(new AttributeModifierComponent(src, comp, this.font, this.leftPos - 16)); + if(comp != null){ + var src = modifiersToSources.get(modif.getId()); + finalTooltip.add(new AttributeModifierComponent(src, comp, this.font, this.leftPos - 16)); + } + } } color = ChatFormatting.GRAY; diff --git a/src/main/java/dev/shadowsoffire/attributeslib/impl/AttributeEvents.java b/src/main/java/dev/shadowsoffire/attributeslib/impl/AttributeEvents.java index a07098b..ddcb622 100644 --- a/src/main/java/dev/shadowsoffire/attributeslib/impl/AttributeEvents.java +++ b/src/main/java/dev/shadowsoffire/attributeslib/impl/AttributeEvents.java @@ -201,7 +201,7 @@ private static DamageSource src(ResourceKey type, LivingEntity entit public static void apothCriticalStrike() { LivingEntityEvents.HURT.register((source, damaged, amount) -> { - LivingEntity attacker = source.getEntity() instanceof LivingEntity le ? le : null; + LivingEntity attacker = source.getEntity() instanceof LivingEntity le && !le.level().isClientSide ? le : null; if (attacker == null) return amount; double critChance = attacker.getAttributeValue(ALObjects.Attributes.CRIT_CHANCE); @@ -212,10 +212,12 @@ public static void apothCriticalStrike() { // Roll for crits. Each overcrit reduces the effectiveness by 15% // We stop rolling when crit chance fails or the crit damage would reduce the total damage dealt. - while (rand.nextFloat() <= critChance && critDmg > 0.0F) { + //AttributesLib.LOGGER.info("Outer: critChance " + critChance + " critMult " + critMult + " critDmg " + critDmg); + while (rand.nextFloat() <= critChance && critDmg > 1.0F) { critChance--; critMult *= critDmg; critDmg *= 0.85F; + //AttributesLib.LOGGER.info("Loop: critChance " + critChance + " critMult " + critMult + " critDmg " + critDmg); } amount *= critMult; diff --git a/src/main/java/dev/shadowsoffire/attributeslib/mixin/CombatRulesMixin.java b/src/main/java/dev/shadowsoffire/attributeslib/mixin/CombatRulesMixin.java index 2a8433d..9a95c57 100644 --- a/src/main/java/dev/shadowsoffire/attributeslib/mixin/CombatRulesMixin.java +++ b/src/main/java/dev/shadowsoffire/attributeslib/mixin/CombatRulesMixin.java @@ -26,7 +26,10 @@ public class CombatRulesMixin { */ @Inject(method ="getDamageAfterAbsorb", at = @At("HEAD"), cancellable = true) private static void zenith_attributes$getDamageAfterAbsorb(float damage, float totalArmor, float toughnessAttribute, CallbackInfoReturnable cir) { - AttributesLib.LOGGER.trace("Invocation of CombatRules#getDamageAfterAbsorb is bypassing armor pen."); - cir.setReturnValue(damage * ALCombatRules.getArmorDamageReduction(damage, totalArmor)); +// AttributesLib.LOGGER.info("Invocation of CombatRules#getDamageAfterAbsorb is bypassing armor pen."); //incorrect? +// AttributesLib.LOGGER.info("getDamageAfterAbsorb was passed " + damage); + float ret = damage; //* ALCombatRules.getArmorDamageReduction(damage, totalArmor); +// AttributesLib.LOGGER.info("getDamageAfterAbsorb returned " + ret); + cir.setReturnValue(ret); } } diff --git a/src/main/java/dev/shadowsoffire/attributeslib/mixin/LivingEntityMixin.java b/src/main/java/dev/shadowsoffire/attributeslib/mixin/LivingEntityMixin.java index 5e42221..b329aca 100644 --- a/src/main/java/dev/shadowsoffire/attributeslib/mixin/LivingEntityMixin.java +++ b/src/main/java/dev/shadowsoffire/attributeslib/mixin/LivingEntityMixin.java @@ -2,6 +2,7 @@ import com.llamalad7.mixinextras.injector.ModifyExpressionValue; import de.dafuqs.additionalentityattributes.AdditionalEntityAttributes; +import dev.shadowsoffire.attributeslib.AttributesLib; import dev.shadowsoffire.attributeslib.api.ALCombatRules; import dev.shadowsoffire.attributeslib.api.ALObjects; import dev.shadowsoffire.attributeslib.api.HealEvent; @@ -81,6 +82,7 @@ public LivingEntityMixin(EntityType pEntityType, Level pLevel) { @ModifyExpressionValue(at = @At(value = "INVOKE", target = "Lnet/minecraft/world/damagesource/CombatRules;getDamageAfterAbsorb(FFF)F"), method = "getDamageAfterArmorAbsorb", require = 1) public float zenith_applyArmorPen(float amount, DamageSource src) { +// AttributesLib.LOGGER.info("LivingEntityMixin#zenith_applyArmorPen was passed " + amount); return ALCombatRules.getDamageAfterArmor((LivingEntity) (Object) this, src, amount,((LivingEntity)(Object) this).getArmorValue(), (float) ((LivingEntity)(Object) this).getAttributeValue(Attributes.ARMOR_TOUGHNESS)); }