muon-rw / Apothic-Combat

0 stars 2 forks source link

Proper fix for attack range #1

Open SiverDX opened 6 months ago

SiverDX commented 6 months ago

Do you plan sth. in that regard?

See

https://github.com/ZsoltMolnarrr/BetterCombat/blob/1.20.1/common/src/main/java/net/bettercombat/api/client/AttackRangeExtensions.java


On 1.19.2 I'm doing

@Mixin(value = AttributesLibClient.class, remap = false)
public class AttributesLibClientMixin {
    /** Use Better Combat attack range for tooltip */
    @ModifyVariable(method = "applyTextFor", at = @At("STORE"), ordinal = 0)
    private static double modifyAttackRange(double original, @Local(argsOnly = true) final ItemStack stack, @Local final Attribute attribute) {
        if (TrialAndError.isModLoaded(Compat.BETTER_COMBAT) && attribute == ForgeMod.ATTACK_RANGE.get()) {
            WeaponAttributes attributes = WeaponRegistry.getAttributes(stack);

            if (attributes != null) {
                return attributes.attackRange();
            }
        }

        return original;
    }
}
@Mixin(value = TargetFinder.class, remap = false)
public class TargetFinderMixin {
    @ModifyVariable(method = "findAttackTargetResult", at = @At("HEAD"), argsOnly = true)
    private static double updateAttackRange(double attackRange, final Player player) {
        ItemStack stack = null;

        if (player instanceof EntityPlayer_BetterCombat access) {
            AttackHand currentAttack = access.getCurrentAttack();

            if (currentAttack != null) {
                stack = currentAttack.itemStack();
            }
        }

        if (stack == null) {
            stack = player.getMainHandItem();
        }

        return AttributeHandler.getAttackRange(attackRange, stack);
    }
}
public class AttributeHandler {
    public static double getAttackRange(double attackRange, final ItemStack stack) {
        Collection<AttributeModifier> modifiers = stack.getAttributeModifiers(EquipmentSlot.MAINHAND).get(ForgeMod.ATTACK_RANGE.get());

        if (!modifiers.isEmpty()) {
            AttributeInstance instance = new AttributeInstance(ForgeMod.ATTACK_RANGE.get(), ignored -> { /* Nothing to do */ });
            instance.setBaseValue(attackRange);
            modifiers.forEach(instance::addTransientModifier);
            attackRange = instance.getValue();
        }

        return attackRange;
    }
}
muon-rw commented 6 months ago

I wasn’t initially planning this, but it’s an interesting idea. The current implementation was made to adhere to Better Combat’s balance philosophy as I’m not personally interested in non-weapon-sourced attack range extensions for my pack.

That said I really like that this implementation would support mods which are currently using Entity Reach for their weapon without a pack dev having to manually add Weapon Attributes, so I’ll look into it at some point.

HatelessHeart commented 1 month ago

I am dealing with the weapon-attack-reach problem. I Don't know where to find the data packs that will help me to add reach to my custom weapons in my mod pack. I'm a mod pack creator developing "escape from the skylands" on curse forge and my custom weapons mod is very important. Are there any resources you can point me to?

muon-rw commented 1 month ago

I am dealing with the weapon-attack-reach problem. I Don't know where to find the data packs that will help me to add reach to my custom weapons in my mod pack. I'm a mod pack creator developing "escape from the skylands" on curse forge and my custom weapons mod is very important. Are there any resources you can point me to?

You can add Weapon Attributes manually with a datapack - there are also compatibility datapacks for most mods (which you could edit/use as a reference) on the Better Combat discord.

HatelessHeart commented 1 month ago

Thank you

Branden Dickerson

On Tue, Jul 16, 2024 at 9:11 PM muon-rw @.***> wrote:

I am dealing with the weapon-attack-reach problem. I Don't know where to find the data packs that will help me to add reach to my custom weapons in my mod pack. I'm a mod pack creator developing "escape from the skylands" on curse forge and my custom weapons mod is very important. Are there any resources you can point me to?

You can add Weapon Attributes manually with a datapack - there are also compatibility datapacks for most mods (which you could edit/use as a reference) on the Better Combat discord.

— Reply to this email directly, view it on GitHub https://github.com/muon-rw/Apothic-Combat/issues/1#issuecomment-2232210791, or unsubscribe https://github.com/notifications/unsubscribe-auth/BDX3BJ4LGNVBCXYQWMTXCK3ZMXHDNAVCNFSM6AAAAABEYNAO6WVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEMZSGIYTANZZGE . You are receiving this because you commented.Message ID: @.***>