0
\$\begingroup\$

Like the title says, how do I get the player from the LivingEntity so I can make this knockback effect on the amethyst sword? i want the amethyst sword to give knockback 10 to any entity i hit and in the direction im looking at

@SubscribeEvent
public static void onPlayerAttack(LivingAttackEvent event){
    Entity entity = event.getEntity();
    LivingEntity living = event.getEntityLiving();
    Item item = ItemInit.AMETHYST_SWORD.get();
    if (event.getEntity() instanceof LivingEntity){
        living.applyKnockback(10, 20, 20);
        System.out.println("i print");
    }
}
\$\endgroup\$
1
  • 1
    \$\begingroup\$ It's not clear with what part of the question/code you're having trouble. Could you tell us what part of it is supposed to be working? Or what you've been able to do so far? \$\endgroup\$
    – Vaillancourt
    Jul 22, 2021 at 20:14

1 Answer 1

0
\$\begingroup\$

Use the AttackEntityEvent instead. Here's an example:

@SubscribeEvent
public void onPlayerAttack(AttackEntityEvent event) {
    PlayerEntity attacker = event.getPlayer();
    Entity target = event.getTarget();
}

Hope this helps!

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .