本文整理汇总了Java中org.bukkit.entity.Entity.setVelocity方法的典型用法代码示例。如果您正苦于以下问题:Java Entity.setVelocity方法的具体用法?Java Entity.setVelocity怎么用?Java Entity.setVelocity使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bukkit.entity.Entity
的用法示例。
在下文中一共展示了Entity.setVelocity方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: boost
import org.bukkit.entity.Entity; //导入方法依赖的package包/类
private boolean boost(Entity source, Entity receiver) {
if (!(source instanceof Player) || !(receiver instanceof Player) || !isPlaying((Player) source) || !isPlaying((Player) receiver))
return false;
receiver.sendMessage(ChatColor.GREEN + "Whoosh!");
Vector toSender = source.getVelocity().subtract(receiver.getVelocity());
toSender.setY(0);
double distance = toSender.length();
if(distance > 0) {
toSender.multiply(1D / distance);
} else {
float yaw = source.getLocation().getYaw();
toSender.setX(-1 * Math.sin(toRad(yaw)));
toSender.setZ(Math.cos(toRad(yaw)));
}
toSender.multiply(2.5D);
toSender.setY(2);
receiver.setVelocity(toSender);
return true;
}
示例4: cast
import org.bukkit.entity.Entity; //导入方法依赖的package包/类
@Override
public boolean cast(final Player p, PlayerDataRPG pd, int level) {
double force = 0;
switch (level) {
case 1:
force = 1.5;
break;
case 2:
force = 3;
break;
case 3:
force = 5;
break;
}
for (Entity e : RMath.getNearbyEntitiesCylinder(p.getLocation(), 7, 9)) {
boolean pull = false;
if (e instanceof Player && e != p) {
Player p2 = (Player) e;
PlayerDataRPG pd2 = Spell.plugin.getPD(p2);
if (pd2 == null)
continue;
if (pd.party != null && pd2.party != null && pd.party == pd2.party)
continue;
if (pd2 != null && pd2.isPVP())
pull = true;
} else if (MobManager.spawnedMobs_onlyMain.containsKey(e.getUniqueId())) {
pull = true;
}
if (pull) {
Vector pushVector = e.getLocation().toVector().subtract(p.getLocation().toVector()).normalize();
pushVector.multiply(force);
if (pushVector.getY() > 0.5)
pushVector.setY(0.5);
e.setVelocity(pushVector);
}
}
RParticles.show(ParticleEffect.EXPLOSION_LARGE, p.getLocation(), 5);
Spell.notify(p, "You push away nearby enemies.");
return true;
}
示例5: moveToward
import org.bukkit.entity.Entity; //导入方法依赖的package包/类
private void moveToward(Entity entity, Location to, double speed) {
Location loc = entity.getLocation();
double x = loc.getX() - to.getX();
double y = loc.getY() - to.getY();
double z = loc.getZ() - to.getZ();
Vector velocity = new Vector(x, y, z).normalize().multiply(-speed);
entity.setVelocity(velocity);
}
示例6: afraidWaterEffect
import org.bukkit.entity.Entity; //导入方法依赖的package包/类
public static int afraidWaterEffect(PetBlock petBlock, int counter) {
final Entity entity = (Entity) petBlock.getEngineEntity();
if (ConfigPet.getInstance().isAfraidOfwater()) {
if (entity.getLocation().getBlock().isLiquid() && counter <= 0) {
final Vector vec = new Vector(random.nextInt(3) * isNegative(random), random.nextInt(3) * isNegative(random), random.nextInt(3) * isNegative(random));
entity.setVelocity(vec);
if (ConfigPet.getInstance().isAfraidwaterParticles()) {
petBlock.getEffectPipeline().playParticleEffect(entity.getLocation(), angryParticle);
}
counter = 20;
}
counter--;
}
return counter;
}
示例7: 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);
}
}
示例8: cast
import org.bukkit.entity.Entity; //导入方法依赖的package包/类
@Override
public boolean cast(final Player p, PlayerDataRPG pd, int level) {
double radius = 0;
int damage = pd.getDamage(true);
switch (level) {
case 1:
radius = 8;
damage *= 2.5;
break;
case 2:
radius = 8;
damage *= 2.7;
break;
case 3:
radius = 9;
damage *= 2.9;
break;
case 4:
radius = 9;
damage *= 3.1;
break;
case 5:
radius = 10;
damage *= 3.3;
break;
case 6:
radius = 10;
damage *= 3.5;
break;
case 7:
radius = 11;
damage *= 3.7;
break;
case 8:
radius = 11;
damage *= 3.9;
break;
case 9:
radius = 12;
damage *= 4.1;
break;
case 10:
radius = 12;
damage *= 4.3;
break;
}
for (Entity e : RMath.getNearbyEntitiesCylinder(p.getLocation(), radius, 9)) {
boolean pull = false;
if (e instanceof Player && e != p) {
Player p2 = (Player) e;
PlayerDataRPG pd2 = Spell.plugin.getPD(p2);
if (pd2 == null)
continue;
if (pd.party != null && pd2.party != null && pd.party == pd2.party)
continue;
if (pd2 != null && pd2.isPVP())
pull = true;
} else if (MobManager.spawnedMobs_onlyMain.containsKey(e.getUniqueId())) {
pull = true;
}
if (pull) {
Vector pullVector = e.getLocation().toVector().subtract(p.getLocation().toVector()).normalize().multiply(-1.5);
pullVector.setY(pullVector.getY() + 0.2);
e.setVelocity(pullVector);
}
}
final int fDamage = damage;
RScheduler.schedule(Spell.plugin, new Runnable() {
public void run() {
RParticles.show(ParticleEffect.EXPLOSION_LARGE, p.getLocation(), 5);
Spell.damageNearby(fDamage, p, p.getLocation(), 3, new ArrayList<Entity>());
}
}, RTicks.seconds(0.5));
Spell.notify(p, "You pull in nearby enemies.");
return true;
}
示例9: changeBowProjectile
import org.bukkit.entity.Entity; //导入方法依赖的package包/类
@EventHandler(ignoreCancelled = true)
public void changeBowProjectile(EntityShootBowEvent event) {
Plugin plugin = this.getMatch().getPlugin();
Entity newProjectile;
if(this.projectile == Arrow.class && event.getProjectile() instanceof Arrow) {
// Don't change the projectile if it's an Arrow and the custom entity type is also Arrow
newProjectile = event.getProjectile();
} else {
// Replace the projectile
World world = event.getEntity().getWorld();
Projectile oldEntity = (Projectile) event.getProjectile();
if(Projectile.class.isAssignableFrom(projectile)) {
// Ender Pearls need to be soawned this way, otherwise they will hit the shooter sometimes
newProjectile = event.getEntity().launchProjectile(projectile.asSubclass(Projectile.class), oldEntity.getVelocity());
} else {
newProjectile = world.spawn(oldEntity.getLocation(), projectile);
newProjectile.setVelocity(oldEntity.getVelocity());
}
event.setProjectile(newProjectile);
// Copy some things from the old projectile
newProjectile.setFallDistance(oldEntity.getFallDistance());
newProjectile.setFireTicks(oldEntity.getFireTicks());
if(newProjectile instanceof Projectile) {
((Projectile) newProjectile).setShooter(oldEntity.getShooter());
((Projectile) newProjectile).setBounce(oldEntity.doesBounce());
}
// Save some special properties of Arrows
if(oldEntity instanceof Arrow) {
Arrow arrow = (Arrow) oldEntity;
newProjectile.setMetadata("critical", new FixedMetadataValue(plugin, arrow.isCritical()));
newProjectile.setMetadata("knockback", new FixedMetadataValue(plugin, arrow.getKnockbackStrength()));
newProjectile.setMetadata("damage", new FixedMetadataValue(plugin, arrow.getDamage()));
}
}
// Tag the projectile as custom
newProjectile.setMetadata("customProjectile", new FixedMetadataValue(plugin, true));
getMatch().callEvent(new EntityLaunchEvent(newProjectile, event.getEntity()));
}
示例10: onShoot
import org.bukkit.entity.Entity; //导入方法依赖的package包/类
@EventHandler
public void onShoot(EntityShootBowEvent event)
{
if(event.getEntity() instanceof Player)
{
Player player = (Player)event.getEntity();
ItemStack mainItem = event.getBow();
if(mainItem.getItemMeta().getLore() != null)
{
Random rand = new Random();
if(event.getForce() >= 1.0F)
{
final Entity arrow = event.getProjectile();
final Vector velocity = player.getLocation().getDirection().add(new Vector(0, 0.025, 0)).multiply(4);
arrow.setVelocity(velocity);
player.getWorld().playSound(player.getLocation(), Sound.BLOCK_LEVER_CLICK, 1.0F, rand.nextFloat() * 0.4F + 0.8F);
player.getWorld().playSound(player.getLocation(), Sound.ENTITY_SHULKER_BULLET_HURT, 0.5F, rand.nextFloat() * 0.4F + 0.8F);
final Runnable task = new Runnable()
{
int times = 4;
public void run()
{
if(!arrow.isOnGround())
{
arrow.setVelocity(velocity);
if(times-- > 0)
Bukkit.getScheduler().scheduleSyncDelayedTask(Survival.instance, this, 5);
}
}
};
Bukkit.getScheduler().scheduleSyncDelayedTask(Survival.instance, task, -1);
}
else
{
event.setCancelled(true);
player.getWorld().playSound(player.getLocation(), Sound.BLOCK_LEVER_CLICK, 0.5F, rand.nextFloat() * 0.4F + 0.8F);
}
}
}
}
示例11: applyVelocity
import org.bukkit.entity.Entity; //导入方法依赖的package包/类
@Override
public void applyVelocity(Entity entity) {
entity.setVelocity(this.toVector());
}