org.bukkit.entity.Entity.setVelocity()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(8.6k)|赞(0)|评价(0)|浏览(232)

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

Entity.setVelocity介绍

[英]Sets this entity's velocity
[中]设置此实体的速度

代码示例

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

entity.setVelocity(currentVelocity);

代码示例来源:origin: bergerkiller/BKCommonLib

@Override
public void setVelocity(Vector arg0) {
  base.setVelocity(arg0);
}

代码示例来源:origin: bergerkiller/BKCommonLib

public void setVelocity(Vector arg0) {
  entity.setVelocity(arg0);
}

代码示例来源:origin: stackoverflow.com

@EventHandler
public void onEntityDamageByEntity(EntityDamageByEntityEvent event) {
  if (event.getDamager() instanceof Egg) { // If damager is an egg
    final Entity hurt = event.getEntity(); // Declare entity final so that we can use it in future scheduling
    Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() { // Schedule a delayed task to run in one tick, plugin is main class
      public void run() { 
        hurt.setVelocity(new Vector(0, 0, 0)); // Set velocity to zero vector, cancelling all motion
      }
    });
  }
}

代码示例来源:origin: EngineHub/CommandHelper

@Override
public void setVelocity(Vector3D velocity) {
  Vector v = new Vector(velocity.X(), velocity.Y(), velocity.Z());
  e.setVelocity(v);
}

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

public static void setVelocity(Entity entity, Vector velocity) {
    if (!MathUtils.isFinite(velocity.getX()) || !MathUtils.isFinite(velocity.getY()) || !MathUtils.isFinite(velocity.getZ())) {
      return;
    }
    if (Math.abs(velocity.getX()) > MAX_VELOCITY) velocity.setX(MAX_VELOCITY * Math.signum(velocity.getX()));
    if (Math.abs(velocity.getY()) > MAX_VELOCITY) velocity.setY(MAX_VELOCITY * Math.signum(velocity.getY()));
    if (Math.abs(velocity.getZ()) > MAX_VELOCITY) velocity.setZ(MAX_VELOCITY * Math.signum(velocity.getZ()));
    entity.setVelocity(velocity);
  }
}

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

@Override
public void onRun() {
  Entity entity = getEntity();
  if (entity == null) {
    cancel();
    return;
  }
  Vector v = entity.getVelocity();
  v.setY(v.getY() + power);
  entity.setVelocity(v);
}

代码示例来源:origin: CitizensDev/CitizensAPI

@Override
  public void run() {
    if (npc.getEntity().getLocation(dummy).getBlock().getType() == Material.LADDER
        && current.next().getY() > current.previous().getY()) {
      npc.getEntity().setVelocity(npc.getEntity().getVelocity().setY(0.3));
    }
  }
};

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

private void moveEarth(final Vector apply, final Vector direction) {
  for (final Entity entity : GeneralMethods.getEntitiesAroundPoint(this.origin, 2)) {
    if (entity.getEntityId() != this.player.getEntityId()) {
      entity.setVelocity(apply);
    }
  }
  this.moveEarth(this.origin.clone().subtract(direction), direction, 3, false);
}

代码示例来源:origin: CitizensDev/CitizensAPI

@Override
public void run() {
  Collection<NPC> nearby = flock.getNearby(npc);
  if (nearby.isEmpty())
    return;
  Vector base = new Vector(0, 0, 0);
  for (FlockBehavior behavior : behaviors) {
    base.add(behavior.getVector(npc, nearby));
  }
  base = clip(maxForce, base);
  npc.getEntity().setVelocity(npc.getEntity().getVelocity().add(base));
}

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

private void affect(final Entity entity) {
  final Vector direction = GeneralMethods.getDirection(this.origin, entity.getLocation());
  direction.setY(0);
  direction.normalize();
  entity.setVelocity(entity.getVelocity().clone().add(direction.multiply(this.knockback)));
}

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

private void launch() {
  final Location location = this.player.getLocation();
  for (final Entity entity : TARGETED_ENTITIES.keySet()) {
    final Location target = entity.getLocation().clone();
    Vector vector = new Vector(0, 0, 0);
    if (location.getWorld().equals(target.getWorld())) {
      vector = GeneralMethods.getDirection(location, GeneralMethods.getTargetedLocation(this.player, location.distance(target)));
    }
    vector.normalize();
    entity.setVelocity(vector.multiply(this.throwFactor));
    new HorizontalVelocityTracker(entity, this.player, 200, this);
  }
  this.remove();
  this.bPlayer.addCooldown(this);
}

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

private void affect(final Entity entity) {
  if (entity instanceof LivingEntity) {
    DamageHandler.damageEntity(entity, this.damage, this);
  }
  final Vector vector = this.direction.clone();
  vector.setY(.5);
  final double knock = this.bPlayer.isAvatarState() ? AvatarState.getValue(this.knockback) : this.knockback;
  entity.setVelocity(vector.clone().normalize().multiply(knock));
  AirAbility.breakBreathbendingHold(entity);
}

代码示例来源:origin: TheBusyBiscuit/Slimefun4

@Override
public void tick(Block b, SlimefunItem item, Config data) {
  if (b.getType() != Material.HOPPER) {
    // we're no longer a hopper, we were probably destroyed. skipping this tick.
    return;
  }
  ArmorStand hologram = InfusedHopper.getArmorStand(b, true);
  boolean sound = false;
  for (Entity n: hologram.getNearbyEntities(3.5D, 3.5D, 3.5D)) {
    if (n instanceof Item && !n.hasMetadata("no_pickup") && n.getLocation().distance(hologram.getLocation()) > 0.4D) {
      n.setVelocity(new Vector(0, 0.1, 0));
      n.teleport(hologram);
      sound = true;
    }
  }
  if (sound) b.getWorld().playSound(b.getLocation(), Sound.ENTITY_ENDERMAN_TELEPORT, 5F, 2F);
}

代码示例来源:origin: Dytanic/CloudNet

@Override
  public void run()
  {
    if (location.getBlock().getType().equals(Material.SIGN_POST) || location.getBlock().getType().equals(Material.WALL_SIGN))
      try
      {
        Location entityLocation = entity.getLocation();
        entity.setVelocity(new Vector(
            entityLocation.getX() - location.getX(),
            entityLocation.getY() - location.getY(),
            entityLocation.getZ() - location.getZ())
            .normalize().multiply(signLayoutConfig.getStrength()).setY(0.2D));
      } catch (Exception ex)
      {
        ex.printStackTrace();
      }
  }
});

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

private void affect(final Location location) {
  for (final Entity entity : GeneralMethods.getEntitiesAroundPoint(location, this.attackRange)) {
    if (entity.getEntityId() == this.player.getEntityId()) {
      continue;
    } else if (GeneralMethods.isRegionProtectedFromBuild(this, entity.getLocation())) {
      continue;
    } else if (GeneralMethods.isObstructed(location, entity.getLocation())) {
      continue;
    }
    final double knock = this.bPlayer.isAvatarState() ? AvatarState.getValue(this.knockback) : this.knockback;
    entity.setVelocity(GeneralMethods.getDirection(this.player.getLocation(), location).normalize().multiply(knock));
    if (entity instanceof LivingEntity) {
      DamageHandler.damageEntity(entity, this.damage, this);
    }
    AirAbility.breakBreathbendingHold(entity);
  }
}

代码示例来源:origin: mcmonkeyprojects/Sentinel

/**
 * Fires a snowball from the NPC at a target.
 */
public void fireSnowball(Location target) {
  sentinel.swingWeapon();
  sentinel.stats_snowballsThrown++;
  sentinel.faceLocation(target);
  Vector forward = getLivingEntity().getEyeLocation().getDirection();
  Location spawnAt = getLivingEntity().getEyeLocation().clone().add(forward.clone().multiply(sentinel.firingMinimumRange()));
  Entity ent = spawnAt.getWorld().spawnEntity(spawnAt, EntityType.SNOWBALL);
  ((Projectile) ent).setShooter(getLivingEntity());
  ent.setVelocity(sentinel.fixForAcc(target.clone().subtract(spawnAt).toVector().normalize().multiply(2.0))); // TODO: Fiddle with '2.0'.
}

代码示例来源:origin: mcmonkeyprojects/Sentinel

/**
 * Fires an egg from the NPC at a target.
 */
public void fireEgg(Location target) {
  sentinel.swingWeapon();
  sentinel.stats_eggsThrown++;
  sentinel.faceLocation(target);
  Vector forward = getLivingEntity().getEyeLocation().getDirection();
  Location spawnAt = getLivingEntity().getEyeLocation().clone().add(forward.clone().multiply(sentinel.firingMinimumRange()));
  Entity ent = spawnAt.getWorld().spawnEntity(spawnAt, EntityType.EGG);
  ((Projectile) ent).setShooter(getLivingEntity());
  ent.setVelocity(sentinel.fixForAcc(target.clone().subtract(spawnAt).toVector().normalize().multiply(2.0))); // TODO: Fiddle with '2.0'.
}

代码示例来源:origin: mcmonkeyprojects/Sentinel

/**
 * Fires a fireballs from the NPC at a target.
 */
public void fireFireball(Location target) {
  sentinel.swingWeapon();
  sentinel.stats_fireballsFired++;
  sentinel.faceLocation(target);
  Vector forward = getLivingEntity().getEyeLocation().getDirection();
  Location spawnAt = getLivingEntity().getEyeLocation().clone().add(forward.clone().multiply(sentinel.firingMinimumRange()));
  Entity ent = spawnAt.getWorld().spawnEntity(spawnAt, EntityType.SMALL_FIREBALL);
  ((Projectile) ent).setShooter(getLivingEntity());
  ent.setVelocity(sentinel.fixForAcc(target.clone().subtract(spawnAt).toVector().normalize().multiply(4))); // TODO: Fiddle with '4'.
}

代码示例来源:origin: mcmonkeyprojects/Sentinel

/**
 * Fires a skull from the NPC at a target.
 */
public void fireSkull(Location target) {
  sentinel.swingWeapon();
  sentinel.stats_skullsThrown++;
  sentinel.faceLocation(target);
  Vector forward = getLivingEntity().getEyeLocation().getDirection();
  Location spawnAt = getLivingEntity().getEyeLocation().clone().add(forward.clone().multiply(sentinel.firingMinimumRange()));
  Entity ent = spawnAt.getWorld().spawnEntity(spawnAt, EntityType.WITHER_SKULL);
  ((Projectile) ent).setShooter(getLivingEntity());
  ent.setVelocity(sentinel.fixForAcc(target.clone().subtract(spawnAt).toVector().normalize().multiply(4))); // TODO: Fiddle with '4'.
}

相关文章

微信公众号

最新文章

更多