Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ private static DamageSource src(ResourceKey<DamageType> 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);
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Float> 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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
}

Expand Down