Solved Get Knockback?

Discussion in 'Plugin Development' started by Nashor, Dec 27, 2012.

Thread Status:
Not open for further replies.
  1. Offline


    Hello. Today I ask if there is any way to get the knockback that a player receives when he is hit in the form of a vector. I have already tried to do e.getEntity().getVelocity() from the EntityDamageByEntity event but this does not provide the knockback vector. I have also tried to research an answer but nothing good has come up. Thanks if you can help.

    UPDATE: The problem has been solved thanks to fireblast709. Here is the code I use:

        public void augmentedKnockback(EntityDamageByEntityEvent e ) {
            final Entity damager = e.getDamager();
            final Entity defender = e.getEntity();
            //Only affects a player hit by a non projectile attack
            if (defender instanceof Player && !(damager instanceof Projectile)) {
                this.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
                    public void run() {
                        //Multiplying by a number lower than 1 will reduce knockback
                        //Multiplying by a number greater than 1 will increase knockback
                        Vector knockback = defender.getVelocity().multiply(0.5f);
                }, 1L);
  2. Offline


    there is no method for it. You could try getting the attacked entity's velocity 1 tick later
    Nashor likes this.
  3. Offline


    I was thinking of doing this but I was hoping I did not have to. Thank you anyways. (BTW, its nice to see you replying to all these threads in this forum. You are doing a great service for the community.)

    UPDATE: It worked like a charm. I will post the code for anyone else who may be interested.
Thread Status:
Not open for further replies.

Share This Page