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

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

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

Entity.getVelocity介绍

[英]Gets this entity's current velocity
[中]获取此实体的当前速度

代码示例

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

rayLength.multiply(exposure);
Vector currentVelocity = entity.getVelocity();
currentVelocity.add(rayLength);
entity.setVelocity(currentVelocity);

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

@Override
public Vector getVelocity() {
  return base.getVelocity();
}

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

public Vector getVelocity() {
  return entity.getVelocity();
}

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

Entity arrow = event.getEntity();
Vector velocity = arrow.getVelocity();
Item item = arrow.getWorld().dropItem(arrow.getLocation(), ItemStack);
item.setVelocity(velocity);

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

@Override
  public Vector getVector(NPC npc, Collection<NPC> nearby) {
    Vector velocities = new Vector(0, 0, 0);
    for (NPC neighbor : nearby) {
      if (!neighbor.isSpawned())
        continue;
      velocities = velocities.add(neighbor.getEntity().getVelocity());
    }
    Vector desired = velocities.multiply((double) 1 / nearby.size());
    return desired.subtract(npc.getEntity().getVelocity()).multiply(weight);
  }
}

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

static boolean collisionDown(Entity e)
{
  Rectangle player = new Rectangle(e.getX(), e.getY() + e.getVelocity(), e.getWidth(), e.getHeight());
  for(Block i : Game.blocks)
  {
    Rectangle block = new Rectangle(i.getX(), i.getY(), size, size );
    if (player.intersects(block))
    {
      //e.goUp(1);
      return true;
    }
  }
  return false;
}

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

/**
 * Returns the launch Direction.
 *
 * @param entity entity
 * @return launchDirection
 */
private Vector getDirection(Entity entity) {
  final Vector vector = new Vector();
  final double rotX = entity.getLocation().getYaw();
  final double rotY = entity.getLocation().getPitch();
  vector.setY(-Math.sin(Math.toRadians(rotY)));
  final double h = Math.cos(Math.toRadians(rotY));
  vector.setX(-h * Math.sin(Math.toRadians(rotX)));
  vector.setZ(h * Math.cos(Math.toRadians(rotX)));
  vector.setY(0.5);
  vector.add(entity.getVelocity());
  return vector.multiply(3);
}

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

@Override
public Vector3D getVelocity() {
  Vector v = e.getVelocity();
  return new Vector3D(v.getX(), v.getY(), v.getZ());
}

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

/**
 * Returns the launch Direction.
 *
 * @param entity entity
 * @return launchDirection
 */
private Vector getDirection(Entity entity) {
  final Vector vector = new Vector();
  final double rotX = entity.getLocation().getYaw();
  final double rotY = entity.getLocation().getPitch();
  vector.setY(-Math.sin(Math.toRadians(rotY)));
  final double h = Math.cos(Math.toRadians(rotY));
  vector.setX(-h * Math.sin(Math.toRadians(rotX)));
  vector.setZ(h * Math.cos(Math.toRadians(rotX)));
  vector.setY(0.5);
  vector.add(entity.getVelocity());
  return vector.multiply(3);
}

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

/**
 * Returns the launch Direction.
 *
 * @param entity entity
 * @return launchDirection
 */
private Vector getDirection(Entity entity) {
  final Vector vector = new Vector();
  final double rotX = entity.getLocation().getYaw();
  final double rotY = entity.getLocation().getPitch();
  vector.setY(-Math.sin(Math.toRadians(rotY)));
  final double h = Math.cos(Math.toRadians(rotY));
  vector.setX(-h * Math.sin(Math.toRadians(rotX)));
  vector.setZ(h * Math.cos(Math.toRadians(rotX)));
  vector.setY(0.5);
  vector.add(entity.getVelocity());
  return vector.multiply(3);
}

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

/**
 * Returns the launch Direction.
 *
 * @param entity entity
 * @return launchDirection
 */
private Vector getDirection(Entity entity) {
  final Vector vector = new Vector();
  final double rotX = entity.getLocation().getYaw();
  final double rotY = entity.getLocation().getPitch();
  vector.setY(-Math.sin(Math.toRadians(rotY)));
  final double h = Math.cos(Math.toRadians(rotY));
  vector.setX(-h * Math.sin(Math.toRadians(rotX)));
  vector.setZ(h * Math.cos(Math.toRadians(rotX)));
  vector.setY(0.5);
  vector.add(entity.getVelocity());
  return vector.multiply(3);
}

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

/**
 * Returns the launch Direction.
 *
 * @param entity entity
 * @return launchDirection
 */
private Vector getDirection(Entity entity) {
  final Vector vector = new Vector();
  final double rotX = entity.getLocation().getYaw();
  final double rotY = entity.getLocation().getPitch();
  vector.setY(-Math.sin(Math.toRadians(rotY)));
  final double h = Math.cos(Math.toRadians(rotY));
  vector.setX(-h * Math.sin(Math.toRadians(rotX)));
  vector.setZ(h * Math.cos(Math.toRadians(rotX)));
  vector.setY(0.5);
  vector.add(entity.getVelocity());
  return vector.multiply(3);
}

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

/**
 * Returns the launch Direction.
 *
 * @param entity entity
 * @return launchDirection
 */
private Vector getDirection(Entity entity) {
  final Vector vector = new Vector();
  final double rotX = entity.getLocation().getYaw();
  final double rotY = entity.getLocation().getPitch();
  vector.setY(-Math.sin(Math.toRadians(rotY)));
  final double h = Math.cos(Math.toRadians(rotY));
  vector.setX(-h * Math.sin(Math.toRadians(rotX)));
  vector.setZ(h * Math.cos(Math.toRadians(rotX)));
  vector.setY(0.5);
  vector.add(entity.getVelocity());
  return vector.multiply(3);
}

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

/**
 * Returns the launch Direction.
 *
 * @param entity entity
 * @return launchDirection
 */
private Vector getDirection(Entity entity) {
  final Vector vector = new Vector();
  final double rotX = entity.getLocation().getYaw();
  final double rotY = entity.getLocation().getPitch();
  vector.setY(-Math.sin(Math.toRadians(rotY)));
  final double h = Math.cos(Math.toRadians(rotY));
  vector.setX(-h * Math.sin(Math.toRadians(rotX)));
  vector.setZ(h * Math.cos(Math.toRadians(rotX)));
  vector.setY(0.5);
  vector.add(entity.getVelocity());
  return vector.multiply(3);
}

代码示例来源: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

public HorizontalVelocityTracker(final Entity e, final Player instigator, final long delay, final Ability ability) {
  if (!ProjectKorra.plugin.getConfig().getBoolean("Properties.HorizontalCollisionPhysics.Enabled")) {
    return;
  }
  remove(e);
  this.entity = e;
  this.instigator = instigator;
  this.fireTime = System.currentTimeMillis();
  this.delay = delay;
  this.thisVelocity = e.getVelocity().clone();
  this.launchLocation = e.getLocation().clone();
  this.impactLocation = this.launchLocation.clone();
  this.delay = delay;
  this.abil = ability;
  this.update();
  instances.put(this.entity, this);
}

代码示例来源: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: CitizensDev/CitizensAPI

@Override
  public Vector getVector(NPC npc, Collection<NPC> nearby) {
    Vector steering = new Vector(0, 0, 0);
    Vector pos = npc.getEntity().getLocation().toVector();
    int c = 0;
    for (NPC neighbor : nearby) {
      if (!neighbor.isSpawned())
        continue;
      double dist = neighbor.getEntity().getLocation().toVector().distance(pos);
      Vector repulse = pos.subtract(neighbor.getEntity().getLocation().toVector()).normalize()
          .divide(new Vector(dist, dist, dist));
      steering = repulse.add(steering);
      c++;
    }
    steering = steering.divide(new Vector(c, c, c));
    return steering.subtract(npc.getEntity().getVelocity()).multiply(weight);
  }
}

相关文章

微信公众号

最新文章

更多