Java Code Examples for org.bukkit.util.Vector#isZero()

The following examples show how to use org.bukkit.util.Vector#isZero() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: KnockbackPlayerFacet.java    From ProjectAres with GNU Affero General Public License v3.0 6 votes vote down vote up
private void applyImpulses(LivingEntity attacker) {
    final KnockbackSettings knockback = this.knockback.get();

    final Vector normal = victim.getLocation().subtract(attacker.getLocation()).toVector();
    if(normal.isZero()) return;
    normal.normalize();

    final Vector victimNormal = knockback.pitchedNormal(normal);
    final Vector attackerNormal = normal.times(-1);

    if(victimNormal.isZero() || attackerNormal.isZero()) return;

    final boolean ground = attacker.isOnGround();
    final double attackSpeed = Math.max(0, attacker.getPredictedVelocity().dot(normal));
    final boolean sprint = ground && attackSpeed > knockback.sprintThreshold;

    victim.applyImpulse(victimNormal.multiply(knockback.power(sprint)), true);
    attacker.applyImpulse(attackerNormal.multiply(knockback.recoil(ground) * attackSpeed), true);

    final MatchPlayer matchAttacker = match.getPlayer(attacker);
    if(matchAttacker != null) {
        matchAttacker.facet(DamageDisplayPlayerFacet.class).showKnockback(victim, sprint);
    }
}
 
Example 2
Source File: KnockbackSettings.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
public Vector pitchedNormal(Vector delta) {
    delta = delta.clone();
    delta.setY(0);
    if(delta.isZero()) return Vectors.ZERO;
    delta.normalize();
    final double theta = Math.toRadians(pitch);
    final double cos = Math.cos(theta);
    delta.set(cos * delta.getX(),
               Math.sin(theta),
               cos * delta.getZ());
    return delta;
}
 
Example 3
Source File: NMSHacks.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void spawn(Player viewer, Location location, Vector velocity) {
    spawn(viewer, uuid, location);
    if(!velocity.isZero()) {
        sendPacket(viewer, new PacketPlayOutEntityVelocity(entityId(), velocity.getX(), velocity.getY(), velocity.getZ()));
    }
}