Skip to content

Commit

Permalink
Fixes to attack event
Browse files Browse the repository at this point in the history
  • Loading branch information
aromaa committed Dec 13, 2024
1 parent 2b74710 commit 2166b41
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ public static DamageFunction provideCriticalAttackFunction(final Player player,
}

public static DamageFunction provideCooldownAttackStrengthFunction(final Player player, final float attackStrength) {
final var modifier = DamageEventUtil.buildAttackDamageModifier(DamageModifierTypes.ATTACK_STRENGTH, player);
final var modifier = DamageEventUtil.buildAttackDamageModifier(DamageModifierTypes.ATTACK_COOLDOWN, player);
final DoubleUnaryOperator function = (damage) -> damage * (0.2F + attackStrength * attackStrength * 0.8F);
return new DamageFunction(modifier, function);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,31 +25,28 @@
package org.spongepowered.vanilla.mixin.core.world.entity.player;

import net.minecraft.world.entity.player.Player;
import org.objectweb.asm.Opcodes;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.ModifyVariable;
import org.spongepowered.asm.mixin.injection.Constant;
import org.spongepowered.asm.mixin.injection.ModifyConstant;
import org.spongepowered.asm.mixin.injection.Slice;
import org.spongepowered.common.util.DamageEventUtil;

@Mixin(Player.class)
public class PlayerMixin_Vanilla_Attack_Impl {
public abstract class PlayerMixin_Vanilla_Attack_Impl {
private DamageEventUtil.Attack<Player> attackImpl$attack;

/**
* Captures the crit multiplier as a function
*/
@ModifyVariable(method = "attack", ordinal = 2,
@ModifyConstant(method = "attack", constant = @Constant(floatValue = 1.5F),
slice = @Slice(from = @At(value = "INVOKE", target = "Lnet/minecraft/world/entity/player/Player;isSprinting()Z", ordinal = 1),
to = @At(value = "FIELD", target = "Lnet/minecraft/world/entity/player/Player;walkDist:F")),
at = @At(value = "JUMP", opcode = Opcodes.IFEQ)
to = @At(value = "FIELD", target = "Lnet/minecraft/world/entity/player/Player;walkDist:F"))
)
public boolean attackImpl$critHook(final boolean isCritical) {
public float attackImpl$critHook(final float constant) {
// if (isCritical) damage *= 1.5F;
if (isCritical) {
final var bonusDamageFunc = DamageEventUtil.provideCriticalAttackFunction(this.attackImpl$attack.sourceEntity(), 1.5);
this.attackImpl$attack.functions().add(bonusDamageFunc);
}
return isCritical;
final var bonusDamageFunc = DamageEventUtil.provideCriticalAttackFunction(this.attackImpl$attack.sourceEntity(), constant);
this.attackImpl$attack.functions().add(bonusDamageFunc);
return constant;
}
}

0 comments on commit 2166b41

Please sign in to comment.