下面列出了org.bukkit.entity.Entity#getVelocity ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private void pullEntityToLocation(Entity e, Location loc)
{
Location entityLoc = e.getLocation();
entityLoc.setY(entityLoc.getY() + 0.5D);
e.teleport(entityLoc);
double g = -0.08D;
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);
//addNoFall(e, 100);
}
/**
* Gets the velocity for an entity. Uses a special tracker for players (since velocity doesn't network properly).
*/
public static Vector getVelocity(Entity entity) {
if (entity instanceof Player && !CitizensAPI.getNPCRegistry().isNPC(entity)) {
return VelocityTracker.getVelocityFor((Player) entity);
}
return entity.getVelocity();
}
/**
* Prevent FireWorks from loading chunks
* @param event
*/
@EventHandler(priority = EventPriority.LOWEST)
public void onChunkLoad(ChunkLoadEvent event) {
if (!Settings.IMP.TICK_LIMITER.FIREWORKS_LOAD_CHUNKS) {
Chunk chunk = event.getChunk();
Entity[] entities = chunk.getEntities();
World world = chunk.getWorld();
Exception e = new Exception();
int start = 14;
int end = 22;
int depth = Math.min(end, getDepth(e));
for (int frame = start; frame < depth; frame++) {
StackTraceElement elem = getElement(e, frame);
if (elem == null) return;
String className = elem.getClassName();
int len = className.length();
if (className != null) {
if (len > 15 && className.charAt(len - 15) == 'E' && className.endsWith("EntityFireworks")) {
for (Entity ent : world.getEntities()) {
if (ent.getType() == EntityType.FIREWORK) {
Vector velocity = ent.getVelocity();
double vertical = Math.abs(velocity.getY());
if (Math.abs(velocity.getX()) > vertical || Math.abs(velocity.getZ()) > vertical) {
Fawe.debug("[FAWE `tick-limiter`] Detected and cancelled rogue FireWork at " + ent.getLocation());
ent.remove();
}
}
}
}
}
}
}
}
@Override
public void onRun() {
Entity entity = getEntity();
if (entity == null) {
cancel();
return;
}
Vector v = entity.getVelocity();
v.setY(v.getY() + power);
entity.setVelocity(v);
}
@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 += match.getRandom().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);
}
// If the projectile is not an arrow, play an impact sound.
if (event.getEntity() instanceof Player
&& (projectile instanceof Projectile && !(projectile instanceof Arrow))) {
Projectile customProjectile = (Projectile) projectile;
if (customProjectile.getShooter() instanceof Player) {
Player bukkitShooter = (Player) customProjectile.getShooter();
MatchPlayer shooter = match.getPlayer(bukkitShooter);
if (shooter != null && event.getEntity() != null) {
shooter.playSound(PROJECTILE_SOUND);
}
}
}
}
// Apply any potion effects attached to the projectile
if (event.getEntity() instanceof LivingEntity) {
for (PotionEffect potionEffect : this.potionEffects) {
((LivingEntity) event.getEntity()).addPotionEffect(potionEffect);
}
}
}
}
@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);
}
}
}
}
@Override
@Nullable
public Vector convert(Entity e) {
return e.getVelocity();
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void EntityDamageEvent(EntityDamageEvent e) {
Entity damaged = e.getEntity();
if (damaged instanceof Player) {
CEventHandler.handleEvent((Player) damaged, e, damageNature);
if (damaged.hasMetadata("ce.springs")) {
e.setCancelled(true);
Vector vel = damaged.getVelocity();
vel.setY((vel.getY() * -0.75) > 1 ? vel.getY() * -0.75 : 0);
damaged.setVelocity(vel);
}
}
}