org.bukkit.util.Vector.normalize()方法的使用及代码示例

x33g5p2x  于2022-01-31 转载在 其他  
字(7.7k)|赞(0)|评价(0)|浏览(154)

本文整理了Java中org.bukkit.util.Vector.normalize()方法的一些代码示例,展示了Vector.normalize()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Vector.normalize()方法的具体详情如下:
包路径:org.bukkit.util.Vector
类名称:Vector
方法名:normalize

Vector.normalize介绍

[英]Converts this vector to a unit vector (a vector with length of 1).
[中]将此向量转换为单位向量(长度为1的向量)。

代码示例

代码示例来源:origin: GlowstoneMC/Glowstone

@Override
public Vector getDirection() {
  return velocity.normalize();
}

代码示例来源:origin: GlowstoneMC/Glowstone

@Override
public void setDirection(Vector vector) {
  setVelocity(vector.normalize().multiply(velocity.length()));
}

代码示例来源:origin: GlowstoneMC/Glowstone

@Override
public Arrow spawnArrow(Location location, Vector velocity, float speed, float spread) {
  // Transformative magic
  Vector randVec = new Vector(ThreadLocalRandom.current().nextGaussian(), ThreadLocalRandom
      .current().nextGaussian(), ThreadLocalRandom.current().nextGaussian());
  randVec.multiply(0.0075 * spread);
  velocity.normalize();
  velocity.add(randVec);
  velocity.multiply(speed);
  // yaw = Math.atan2(x, z) * 180.0D / 3.1415927410125732D;
  // pitch = Math.atan2(y, Math.sqrt(x * x + z * z)) * 180.0D / 3.1415927410125732D
  Arrow arrow = spawn(location, Arrow.class);
  arrow.setVelocity(velocity);
  return arrow;
}

代码示例来源:origin: GlowstoneMC/Glowstone

/**
 * Maps {0, 0, 0} to {0, 1, 0} and all other vectors to their normalized form.
 *
 * @param ray the ray to transform
 * @return a ray of length 1
 */
public static Vector getVelocityRay(Vector ray) {
  Vector velocityRay = ray.clone();
  if (velocityRay.lengthSquared() == 0) {
    velocityRay.setX(0);
    velocityRay.setY(1);
    velocityRay.setZ(0);
  } else {
    velocityRay.normalize();
  }
  return velocityRay;
}

代码示例来源:origin: GlowstoneMC/Glowstone

direction.normalize();

代码示例来源:origin: GlowstoneMC/Glowstone

.getRayBetween(getLocation(), ((LivingEntity) source).getEyeLocation());
Vector rayLength = RayUtil.getVelocityRay(distance).normalize();

代码示例来源:origin: Slikey/EffectLib

public static Vector getRandomVector() {
  double x, y, z;
  x = random.nextDouble() * 2 - 1;
  y = random.nextDouble() * 2 - 1;
  z = random.nextDouble() * 2 - 1;
  return new Vector(x, y, z).normalize();
}

代码示例来源:origin: elBukkit/MagicPlugin

protected Vector getDirection() {
  Location origin = this.getOrigin();
  Location target = this.getTarget();
  if (origin == null) return new Vector(0, 1, 0);
  Vector direction = target == null ? origin.getDirection() : target.toVector().subtract(origin.toVector());
  return direction.normalize();
}

代码示例来源:origin: ProjectKorra/ProjectKorra

public int getEarthbendableBlocksLength(final Block block, Vector direction, final int maxlength) {
  final Location location = block.getLocation();
  direction = direction.normalize();
  for (int i = 0; i <= maxlength; i++) {
    final double j = i;
    if (!this.isEarthbendable(location.clone().add(direction.clone().multiply(j)).getBlock())) {
      return i;
    }
  }
  return maxlength;
}

代码示例来源:origin: ProjectKorra/ProjectKorra

/**
 * Returns the location of the tip of the left arm assuming it is fully
 * extended. Use the displayLeftArm() check to see if it is fully extended.
 *
 * @return location of the tip of the left arm
 */
public Location getLeftArmEnd() {
  final Location l1 = GeneralMethods.getLeftSide(this.player.getLocation(), 2).add(0, 1.5, 0);
  return l1.clone().add(this.player.getLocation().getDirection().normalize().multiply(this.initLength));
}

代码示例来源:origin: garbagemule/MobArena

@Override
  public void execute(Arena arena, MABoss boss) {
    Location bLoc = boss.getEntity().getLocation();
    
    for (Player p : AbilityUtils.getNearbyPlayers(arena, boss.getEntity(), RADIUS)) {
      Location loc = p.getLocation();
      Vector v     = new Vector(loc.getX() - bLoc.getX(), 0, loc.getZ() - bLoc.getZ());
      p.setVelocity(v.normalize().setY(0.8));
    }
  }
}

代码示例来源:origin: garbagemule/MobArena

@Override
  public void execute(Arena arena, MABoss boss) {
    LivingEntity target = AbilityUtils.getTarget(arena, boss.getEntity(), RANDOM);
    if (target == null) return;

    Location bLoc = boss.getEntity().getLocation();
    Location loc  = target.getLocation();
    Vector v      = new Vector(loc.getX() - bLoc.getX(), 0, loc.getZ() - bLoc.getZ());
    
    target.setVelocity(v.normalize().setY(0.8));
  }
}

代码示例来源:origin: com.github.shynixn.ball/ball-bukkit-core

void setVelocity(Vector velocity) {
  try {
    this.times = (int) (50 * this.ball.getMeta().getModifiers().getRollingDistanceModifier());
    this.getSpigotEntity().setVelocity(velocity);
    final Vector normalized = velocity.clone().normalize();
    this.originVector = velocity.clone();
    this.reduceVector = new Vector(normalized.getX() / this.times
        , 0.0784 * this.ball.getMeta().getModifiers().getGravityModifier()
        , normalized.getZ() / this.times);
  } catch (IllegalArgumentException ignored) {
  }
}

代码示例来源:origin: com.github.shynixn.ball/ball-bukkit-core

void setVelocity(Vector velocity) {
  try {
    this.times = (int) (50 * this.ball.getMeta().getModifiers().getRollingDistanceModifier());
    this.getSpigotEntity().setVelocity(velocity);
    final Vector normalized = velocity.clone().normalize();
    this.originVector = velocity.clone();
    this.reduceVector = new Vector(normalized.getX() / this.times
        , 0.0784 * this.ball.getMeta().getModifiers().getGravityModifier()
        , normalized.getZ() / this.times);
  } catch (IllegalArgumentException ignored) {
  }
}

代码示例来源:origin: com.github.shynixn.ball/ball-bukkit-core

void setVelocity(Vector velocity) {
  try {
    this.times = (int) (50 * this.ball.getMeta().getModifiers().getRollingDistanceModifier());
    this.getSpigotEntity().setVelocity(velocity);
    final Vector normalized = velocity.clone().normalize();
    this.originVector = velocity.clone();
    this.reduceVector = new Vector(normalized.getX() / this.times
        , 0.0784 * this.ball.getMeta().getModifiers().getGravityModifier()
        , normalized.getZ() / this.times);
  } catch (IllegalArgumentException ignored) {
  }
}

代码示例来源:origin: com.github.shynixn.ball/ball-bukkit-core

void setVelocity(Vector velocity) {
  try {
    this.times = (int) (50 * this.ball.getMeta().getModifiers().getRollingDistanceModifier());
    this.getSpigotEntity().setVelocity(velocity);
    final Vector normalized = velocity.clone().normalize();
    this.originVector = velocity.clone();
    this.reduceVector = new Vector(normalized.getX() / this.times
        , 0.0784 * this.ball.getMeta().getModifiers().getGravityModifier()
        , normalized.getZ() / this.times);
  } catch (IllegalArgumentException ignored) {
  }
}

代码示例来源:origin: com.github.shynixn.ball/ball-bukkit-core

void setVelocity(Vector velocity) {
  try {
    this.times = (int) (50 * this.ball.getMeta().getModifiers().getRollingDistanceModifier());
    this.getSpigotEntity().setVelocity(velocity);
    final Vector normalized = velocity.clone().normalize();
    this.originVector = velocity.clone();
    this.reduceVector = new Vector(normalized.getX() / this.times
        , 0.0784 * this.ball.getMeta().getModifiers().getGravityModifier()
        , normalized.getZ() / this.times);
  } catch (IllegalArgumentException ignored) {
  }
}

代码示例来源:origin: com.github.shynixn.ball/ball-bukkit-core

void setVelocity(Vector velocity) {
  try {
    this.times = (int) (50 * this.ball.getMeta().getModifiers().getRollingDistanceModifier());
    this.getSpigotEntity().setVelocity(velocity);
    final Vector normalized = velocity.clone().normalize();
    this.originVector = velocity.clone();
    this.reduceVector = new Vector(normalized.getX() / this.times
        , 0.0784 * this.ball.getMeta().getModifiers().getGravityModifier()
        , normalized.getZ() / this.times);
  } catch (IllegalArgumentException ignored) {
  }
}

代码示例来源:origin: com.github.shynixn.ball/ball-bukkit-core

void setVelocity(Vector velocity) {
  try {
    this.times = (int) (50 * this.ball.getMeta().getModifiers().getRollingDistanceModifier());
    this.getSpigotEntity().setVelocity(velocity);
    final Vector normalized = velocity.clone().normalize();
    this.originVector = velocity.clone();
    this.reduceVector = new Vector(normalized.getX() / this.times
        , 0.0784 * this.ball.getMeta().getModifiers().getGravityModifier()
        , normalized.getZ() / this.times);
  } catch (IllegalArgumentException ignored) {
  }
}

代码示例来源:origin: com.github.shynixn.ball/ball-bukkit-core

void setVelocity(Vector velocity) {
  try {
    this.times = (int) (50 * this.ball.getMeta().getModifiers().getRollingDistanceModifier());
    this.getSpigotEntity().setVelocity(velocity);
    final Vector normalized = velocity.clone().normalize();
    this.originVector = velocity.clone();
    this.reduceVector = new Vector(normalized.getX() / this.times
        , 0.0784 * this.ball.getMeta().getModifiers().getGravityModifier()
        , normalized.getZ() / this.times);
  } catch (IllegalArgumentException ignored) {
  }
}

相关文章