#Can I not overwrite the WHOLE METHOD? [SOLVED]

8 messages · Page 1 of 1 (latest)

sour pine
#

So i added this method:

public class CombatHandler {
    public static void register() {
        AttackEntityCallback.EVENT.register(((player, world, hand, entity, entityHitResult) -> {
            if (world.isClient() || hand != Hand.MAIN_HAND) {
                return ActionResult.PASS;
            }

            PlayerStats stats = ModComponents.STATS.get(player).getStats();
            Stat fuerza = stats.getStat(PlayerStats.StatEnum.FUERZA);

            // Añadir experiencia
            float cooldownProgress = player.getAttackCooldownProgress(1.0f);
            if (cooldownProgress >= 0.99f) {
                float exp_amount = 1f;

                stats.addExperiencia(exp_amount);
                fuerza.addExperiencia(exp_amount);
            }

            // Hacer daño
            float baseDamage = (float) player.getAttributeValue(net.minecraft.entity.attribute.EntityAttributes.GENERIC_ATTACK_DAMAGE);
            boolean emptyHand = player.getMainHandStack().isEmpty();
            float handMultiplier = emptyHand ? 1f : 0.5f;

            float scaledDamage = baseDamage + (fuerza.getValor() * 0.2f * handMultiplier);
            entity.damage(world.getDamageSources().playerAttack(player), scaledDamage);

            // Sincronizar server y cliente
            ModComponents.STATS.sync(player);
            return ActionResult.SUCCESS;
        }
        ));
    }
}

that overwrittes what the game does when hitting, but i found out testing it that, of course it overwrittes the whole thing, if i dont re-code things like armour use, weapon use, enchantments, cooldown, the game doesn't apply them.
So my question is, could I only overwrite the case when the attack is bare handed? If not, what could I do? Like for not rewritting minecraft from scratch basically.

#

Maybe adding like ADDING a method AFTER hitting, so i can handle all my logic but not overwrite minecraft's

neat gull
#

Returning actionresult.pass will make all other logic go still

#

It also won't make the hand swing iirc

sour pine
#
public class CombatHandler {
    public static void register() {
        AttackEntityCallback.EVENT.register(((player, world, hand, entity, entityHitResult) -> {
            if (world.isClient() || hand != Hand.MAIN_HAND) {
                return ActionResult.PASS;
            }

            PlayerStats stats = ModComponents.STATS.get(player).getStats();
            Stat fuerza = stats.getStat(PlayerStats.StatEnum.FUERZA);

            // Añadir experiencia
            float cooldownProgress = player.getAttackCooldownProgress(1.0f);
            if (cooldownProgress >= 0.99f) {
                float exp_amount = 1f;

                stats.addExperiencia(exp_amount);
                fuerza.addExperiencia(exp_amount);
                ModComponents.STATS.sync(player);
            }

            // Hacer daño
            float baseDamage = (float) player.getAttributeValue(net.minecraft.entity.attribute.EntityAttributes.GENERIC_ATTACK_DAMAGE);
            boolean emptyHand = player.getMainHandStack().isEmpty();

            if (!emptyHand) {
                return ActionResult.PASS;
            }

            float handMultiplier = emptyHand ? 1f : 0.5f;

            float scaledDamage = baseDamage + (fuerza.getValor() * 0.2f * handMultiplier);
            entity.damage(world.getDamageSources().playerAttack(player), scaledDamage);

            String debug = "Daño: " + scaledDamage;
            DragonBallRebirth.LOGGER.info(debug);

            return ActionResult.PASS;
        }));
    }
}
#

Yeah, i tried that, and it kinda? works, but when the function reaches entity.damage() all from a sudden it overwrites everything, so now i have normal combat and overwriten bare hand combat, its kinda fine like that but i would like to still apply that half damage aumentation when fighting with swords or axes without overwritting the other code

#

also letting cooldown and critical hits happen with hands would be cool, but the biggest perk is that im pretty sure it also doesnt wear down armour and such

sour pine
#

Can I not overwrite the WHOLE METHOD? [SOLVED]