本文整理匯總了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);
}
}
}
}