本文整理汇总了Java中org.bukkit.entity.Entity.getVelocity方法的典型用法代码示例。如果您正苦于以下问题:Java Entity.getVelocity方法的具体用法?Java Entity.getVelocity怎么用?Java Entity.getVelocity使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bukkit.entity.Entity
的用法示例。
在下文中一共展示了Entity.getVelocity方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: pullEntityToLocation
import org.bukkit.entity.Entity; //导入方法依赖的package包/类
public void pullEntityToLocation(Entity e, Location loc) {
Location entityLoc = e.getLocation();
entityLoc.setY(entityLoc.getY() + 0.5D);
e.teleport(entityLoc);
double g = -0.08D;
if (loc.getWorld() != entityLoc.getWorld())
return;
double d = loc.distance(entityLoc);
double t = d;
double v_x = (1.0D + 0.07000000000000001D * t) * (loc.getX() - entityLoc.getX()) / t;
double v_y = (1.0D + 0.03D * t) * (loc.getY() - entityLoc.getY()) / t - 0.5D * g * t;
double v_z = (1.0D + 0.07000000000000001D * t) * (loc.getZ() - entityLoc.getZ()) / t;
Vector v = e.getVelocity();
v.setX(v_x);
v.setY(v_y);
v.setZ(v_z);
e.setVelocity(v);
e.setFallDistance(0f);
}
示例2: execute
import org.bukkit.entity.Entity; //导入方法依赖的package包/类
@Override
protected void execute(Event e) {
Entity ent = entity.getSingle(e);
Location to = towards.getSingle(e);
if (ent == null || to == null) {
return;
}
Vector velocity = ent.getVelocity();
float fallDistance = ent.getFallDistance();
Location from = ent.getLocation();
Vector direction = isToward ? MathUtils.vectorFromLocations(from, to) : MathUtils.vectorFromLocations(to, from);
ent.teleport(new Location(
ent.getWorld(),
from.getX(),
from.getY(),
from.getZ(),
MathUtils.notchYaw(MathUtils.getYaw(direction)),
MathUtils.notchPitch(MathUtils.getPitch(direction))
));
ent.setVelocity(velocity);
ent.setFallDistance(fallDistance);
}
示例3: movePlayer
import org.bukkit.entity.Entity; //导入方法依赖的package包/类
public void movePlayer(Entity p, int dx, int dy, int dz) {
NavyCraft.instance.DebugMessage("Moving player", 4);
int mccraftspeed = craft.speed;
if (mccraftspeed > 2) {
mccraftspeed = 2;
}
Vector pVel = p.getVelocity();
if (dx > 0) {
dx = craft.speed;
} else {
dx = craft.speed * -1;
}
if (dy > 0) {
dy = craft.speed;
} else {
dy = craft.speed * -1;
}
if (dz > 0) {
dz = craft.speed;
} else {
dz = craft.speed * -1;
}
pVel = pVel.add(new Vector(dx, dy, dz));
if ((pVel.getX() > 10) || (pVel.getZ() > 10) || (pVel.getY() > 10)) {
System.out.println("Velocity is too high, have to teleport " + p.getEntityId());
Location pLoc = p.getLocation();
pLoc.setX(pLoc.getX() + pVel.getX());
pLoc.setY(pLoc.getY() + pVel.getY() + .05);
pLoc.setZ(pLoc.getZ() + pVel.getZ());
p.teleport(pLoc);
} else {
p.setVelocity(pVel);
}
}
示例4: fixEntityDamage
import org.bukkit.entity.Entity; //导入方法依赖的package包/类
@EventHandler(ignoreCancelled = true)
public void fixEntityDamage(EntityDamageByEntityEvent event) {
Entity projectile = event.getDamager();
if(projectile.hasMetadata("customProjectile")) {
// If the custom projectile replaced an arrow, recreate some effects specific to arrows
if(projectile.hasMetadata("damage")) {
boolean critical = projectile.getMetadata("critical").get(0).asBoolean();
int knockback = projectile.getMetadata("knockback").get(0).asInt();
double damage = projectile.getMetadata("damage").get(0).asDouble();
double speed = projectile.getVelocity().length();
// Reproduce the damage calculation from nms.EntityArrow with the addition of our modifier
int finalDamage = (int) Math.ceil(speed * damage * this.velocityMod);
if(critical) {
finalDamage += random.nextInt(finalDamage / 2 + 2);
}
event.setDamage(finalDamage);
// Flame arrows - target burns for 5 seconds always
if(projectile.getFireTicks() > 0) {
event.getEntity().setFireTicks(100);
}
// Reproduce the knockback calculation for punch bows
if(knockback > 0) {
Vector projectileVelocity = projectile.getVelocity();
double horizontalSpeed = Math.sqrt(projectileVelocity.getX() * projectileVelocity.getX() +
projectileVelocity.getZ() * projectileVelocity.getZ());
Vector velocity = event.getEntity().getVelocity();
velocity.setX(velocity.getX() + projectileVelocity.getX() * knockback * 0.6 / horizontalSpeed);
velocity.setY(velocity.getY() + 0.1);
velocity.setZ(velocity.getZ() + projectileVelocity.getZ() * knockback * 0.6 / horizontalSpeed);
event.getEntity().setVelocity(velocity);
}
}
// Apply any potion effects attached to the projectile
if(event.getEntity() instanceof LivingEntity) {
for(PotionEffect potionEffect : this.potionEffects) {
((LivingEntity) event.getEntity()).addPotionEffect(potionEffect);
}
}
}
}