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.