From bc88e7d41b78471fb748f302aa65eb442bc0dfda Mon Sep 17 00:00:00 2001 From: Partonetrain Date: Sat, 4 May 2024 13:01:00 -0500 Subject: [PATCH 1/3] Actually fix crits. for real --- .../shadowsoffire/attributeslib/impl/AttributeEvents.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) 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; From 9780311599c153ad0ec052f29e10123c96c9bf65 Mon Sep 17 00:00:00 2001 From: Partonetrain Date: Wed, 15 May 2024 15:18:54 -0500 Subject: [PATCH 2/3] sort of fix armor issue? --- .../dev/shadowsoffire/attributeslib/api/ALCombatRules.java | 4 ++++ .../attributeslib/mixin/CombatRulesMixin.java | 7 +++++-- .../attributeslib/mixin/LivingEntityMixin.java | 2 ++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/main/java/dev/shadowsoffire/attributeslib/api/ALCombatRules.java b/src/main/java/dev/shadowsoffire/attributeslib/api/ALCombatRules.java index 0f33aba..f9db22f 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/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)); } From 3f4728524409d4408b9747c33f70d663ee127657 Mon Sep 17 00:00:00 2001 From: Partonetrain Date: Thu, 23 May 2024 15:07:03 -0500 Subject: [PATCH 3/3] fix #27 but really --- .../attributeslib/api/ALCombatRules.java | 2 +- .../attributeslib/api/IFormattableAttribute.java | 11 ++++++++++- .../attributeslib/client/AttributesGui.java | 7 +++++-- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/main/java/dev/shadowsoffire/attributeslib/api/ALCombatRules.java b/src/main/java/dev/shadowsoffire/attributeslib/api/ALCombatRules.java index f9db22f..c5077e2 100644 --- a/src/main/java/dev/shadowsoffire/attributeslib/api/ALCombatRules.java +++ b/src/main/java/dev/shadowsoffire/attributeslib/api/ALCombatRules.java @@ -76,7 +76,7 @@ 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); + //AttributesLib.LOGGER.info("getDamageAfterArmor was passed " + amount); if (src.getEntity() instanceof LivingEntity attacker) { float shred = (float) attacker.getAttributeValue(Attributes.ARMOR_SHRED); 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;