本文整理汇总了Java中org.bukkit.entity.Projectile.setVelocity方法的典型用法代码示例。如果您正苦于以下问题:Java Projectile.setVelocity方法的具体用法?Java Projectile.setVelocity怎么用?Java Projectile.setVelocity使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.bukkit.entity.Projectile
的用法示例。
在下文中一共展示了Projectile.setVelocity方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: shoot
import org.bukkit.entity.Projectile; //导入方法依赖的package包/类
/**
* A basic shoot method, it _can_ be overridden but take care.
* Handles passing the bullet to its BulletType for configuration, sets shooter, velocity, etc.
*
* @param begin The location to shoot from
* @param bulletType the Bullet type of this bullet
* @param shooter the entity shooting
* @param velocity the velocity to use as base for this shooting, if any
* @param overrideVelocity if true, use the passed velocity and override anything set up by the bullet type.
* @return the new Projectile that has been unleashed.
*/
public Projectile shoot(Location begin, Bullet bulletType, ProjectileSource shooter, Vector velocity, boolean overrideVelocity) {
World world = begin.getWorld();
begin = begin.clone();
begin.setDirection(velocity);
Projectile newBullet = world.spawn(begin, bulletType.getProjectileType() );
newBullet.setCustomName(this.bulletTag);
newBullet.setBounce(false);
newBullet.setGravity(true);
newBullet.setShooter(shooter);
bulletType.configureBullet(newBullet, world, shooter, velocity);
if (overrideVelocity) {
newBullet.setVelocity(velocity);
}
return newBullet;
}
示例2: notify
import org.bukkit.entity.Projectile; //导入方法依赖的package包/类
@Override
public void notify(Player player, Object extra) {
Location eye = player.getEyeLocation();
Vector direction = eye.getDirection().multiply(2);
Block source = (Block) extra;
Projectile projectile = player.getWorld().spawn(source.getRelative(BlockFace.UP).getLocation().setDirection(direction), LargeFireball.class);
projectile.setShooter(player);
projectile.setVelocity(direction);
Inventory inv = player.getInventory();
if (inv.contains(Material.TNT)) {
int slot = inv.first(Material.TNT);
ItemStack ammo = inv.getItem(slot);
int amount = ammo.getAmount();
if (amount > 1) {
ammo.setAmount(amount - 1);
inv.setItem(slot, ammo);
} else {
inv.setItem(slot, null);
}
projectile.setCustomName("recreator.structure.turret.tnt");
}
AzureAPI.playSound(player, Sound.ITEM_FIRECHARGE_USE, true);
}
示例3: shoot
import org.bukkit.entity.Projectile; //导入方法依赖的package包/类
public void shoot(final Player p) {
// First create a vector
Vector v = new Vector(getVelocity(), getVelocity(), getVelocity());
Vector pVec = p.getLocation().getDirection();
Vector finalVec = new Vector(v.getX() * pVec.getX(), v.getY() * pVec.getY(), v.getZ() * pVec.getZ());
Location eye = p.getEyeLocation();
Location oneUp = eye.add(0.0D, 1.0D, 0.0D);
Location loc = oneUp.toVector().add(p.getLocation().getDirection().multiply(2))
.toLocation(p.getWorld(), p.getLocation().getYaw(), p.getLocation().getPitch());
// then launch the projectile
Projectile proj = (Projectile) p.getWorld().spawnEntity(loc, EntityType.FIREBALL);
// launchProjectile(this.projectileClass, finalVec);
// finally, set the shooter
proj.setVelocity(finalVec);
/*if (!(proj instanceof Egg) || !(proj instanceof Snowball)) {
proj.setShooter((ProjectileSource) p);
}*/
proj.setShooter(p);
// play sounds
p.getWorld().playSound(p.getLocation(), Sound.ENTITY_ARROW_SHOOT, 2.0F, 1.0F);
}
示例4: fireOnTarget
import org.bukkit.entity.Projectile; //导入方法依赖的package包/类
public void fireOnTarget(){
lastFired = System.currentTimeMillis();
Vector target = toTarget();
Vector target2 = target.clone().multiply(5);
//System.out.println("addition: " + target2);
//System.out.println("SOUND");
//myGhast.getWorld().playSound(myGhast.getLocation(), Sound.GHAST_DEATH, 2.0f, (float) (Math.random() * 3.0f));
Location fireLoc = myGhast.getLocation().clone().add(target2);
//System.out.println("fireloc: " + fireLoc);
//Fireball f = (Fireball) myGhast.getWorld().spawnEntity(fireLoc, EntityType.FIREBALL);
//f.setDirection(target);
Projectile proj = myGhast.getWorld().spawn(fireLoc, Fireball.class);
// launchProjectile(this.projectileClass, finalVec);
// finally, set the shooter
proj.setVelocity(target);
Fireball f = (Fireball) proj;
if(myGhast.getWorld().getName().startsWith("Trinitos_")){
f.setIsIncendiary(false);
f.setYield(2.0F);
} else {
f.setIsIncendiary(true);
f.setYield(1.5F);
}
}
示例5: onDamageGet
import org.bukkit.entity.Projectile; //导入方法依赖的package包/类
@EventHandler(priority=EventPriority.MONITOR)
public void onDamageGet(EntityDamageEvent e) {
if (!e.isCancelled()) {
if (e instanceof EntityDamageByEntityEvent) {
if (((EntityDamageByEntityEvent) e).getDamager() instanceof Player && SlimefunStartup.chance(100, 45)) {
if (SlimefunManager.isItemSimiliar(((Player) ((EntityDamageByEntityEvent) e).getDamager()).getInventory().getItemInMainHand(), SlimefunItem.getItem("BLADE_OF_VAMPIRES"), true)) {
((Player) ((EntityDamageByEntityEvent) e).getDamager()).playSound(((EntityDamageByEntityEvent) e).getDamager().getLocation(), Sound.ENTITY_ARROW_HIT_PLAYER, 0.7F, 0.7F);
((Player) ((EntityDamageByEntityEvent) e).getDamager()).addPotionEffect(new PotionEffect(PotionEffectType.HEAL, 1, 1));
}
}
}
if (e.getEntity() instanceof Player) {
if (!e.isCancelled()) {
if (e.getCause() == DamageCause.LAVA) Talisman.checkFor(e, SlimefunItem.getByID("LAVA_TALISMAN"));
if (e.getCause() == DamageCause.DROWNING) Talisman.checkFor(e, SlimefunItem.getByID("WATER_TALISMAN"));
if (e.getCause() == DamageCause.FALL) Talisman.checkFor(e, SlimefunItem.getByID("ANGEL_TALISMAN"));
if (e.getCause() == DamageCause.FIRE) Talisman.checkFor(e, SlimefunItem.getByID("FIRE_TALISMAN"));
if (e.getCause() == DamageCause.ENTITY_ATTACK) Talisman.checkFor(e, SlimefunItem.getByID("WARRIOR_TALISMAN"));
if (e.getCause() == DamageCause.ENTITY_ATTACK) Talisman.checkFor(e, SlimefunItem.getByID("KNIGHT_TALISMAN"));
if (e.getCause() == DamageCause.PROJECTILE) {
if (Talisman.checkFor(e, SlimefunItem.getByID("WHIRLWIND_TALISMAN"))) {
if (((EntityDamageByEntityEvent) e).getDamager() instanceof Projectile) {
Vector direction = ((Player) e.getEntity()).getEyeLocation().getDirection().multiply(2.0);
Projectile projectile = (Projectile) e.getEntity().getWorld().spawnEntity(((LivingEntity) e.getEntity()).getEyeLocation().add(direction.getX(), direction.getY(), direction.getZ()), ((EntityDamageByEntityEvent) e).getDamager().getType());
projectile.setVelocity(direction);
((EntityDamageByEntityEvent) e).getDamager().remove();
}
}
}
}
}
}
}
示例6: configureBullet
import org.bukkit.entity.Projectile; //导入方法依赖的package包/类
/**
* Based on the parameters in this bullet, configure some stuff.
*
* @param bullet the newly minted projectile
* @param world the world it inhabits
* @param shooter who shot it
* @param velocity The gun's intrinsic velocity. Might be ignored.
*/
public void configureBullet(Projectile bullet, World world, ProjectileSource shooter, Vector velocity) {
bullet.setVelocity(velocity);
bullet.setFireTicks(this.fireTicks);
if (bullet instanceof Fireball) {
((Fireball) bullet).setIsIncendiary(Math.random() < this.fireChance);
}
}
示例7: onProjectileLaunch
import org.bukkit.entity.Projectile; //导入方法依赖的package包/类
@EventHandler
public void onProjectileLaunch(final ProjectileLaunchEvent event) {
if (event.getEntityType() == EntityType.SPLASH_POTION) {
final Projectile projectile = event.getEntity();
if (projectile.getShooter() instanceof Player && ((Player) projectile.getShooter()).isSprinting()) {
final Vector velocity = projectile.getVelocity();
velocity.setY(velocity.getY() - 0.8);
projectile.setVelocity(velocity);
}
}
}
示例8: run
import org.bukkit.entity.Projectile; //导入方法依赖的package包/类
@Override
public void run(PlayerInteractEvent evt) {
Player player = evt.getPlayer();
Inventory inv = player.getInventory();
if (!inv.contains(Material.FIREWORK_CHARGE)) {
AzureAPI.log(player, "你没有弹药! 需要 " + ChatColor.RED + "迷你核弹" + ChatColor.GOLD + " 作为弹药");
AzureAPI.playSound(player, Sound.ENTITY_ITEM_BREAK);
return;
}
int slot = inv.first(Material.FIREWORK_CHARGE);
ItemStack ammo = inv.getItem(slot);
if (ammo.hasItemMeta()) {
if (!ammo.getItemMeta().hasLore()) return;
if (!ammo.getItemMeta().getLore().contains("弹药")) return;
} else {
return;
}
int amount = ammo.getAmount();
if (amount > 1) {
ammo.setAmount(amount - 1);
inv.setItem(slot, ammo);
} else {
inv.setItem(slot, null);
}
Location eye = player.getEyeLocation();
Vector direction = eye.getDirection().multiply(2);
Projectile projectile = player.getWorld().spawn(eye.add(direction), DragonFireball.class);
projectile.setBounce(true);
projectile.setGravity(true);
projectile.setShooter(player);
projectile.setVelocity(direction);
projectile.setCustomName("recreator.item.fatman");
AzureAPI.playSound(player, Sound.ITEM_FIRECHARGE_USE, true);
}
示例9: run
import org.bukkit.entity.Projectile; //导入方法依赖的package包/类
@Override
public void run(PlayerInteractEvent evt) {
Player player = evt.getPlayer();
if (CooldownTicker.can(this, player) || evt.getItem().getItemMeta().getLore().contains("§6高速射击")) {
Inventory inv = player.getInventory();
if (!inv.contains(Material.SULPHUR)) {
AzureAPI.log(player, "你没有弹药! 需要 " + ChatColor.RED + "火药" + ChatColor.GOLD + " 作为弹药");
AzureAPI.playSound(player, Sound.ENTITY_ITEM_BREAK);
return;
}
int slot = inv.first(Material.SULPHUR);
ItemStack ammo = inv.getItem(slot);
int amount = ammo.getAmount();
if (amount > 1) {
ammo.setAmount(amount - 1);
inv.setItem(slot, ammo);
} else {
inv.setItem(slot, null);
}
Location eye = player.getEyeLocation();
Vector direction = eye.getDirection().multiply(2);
Projectile projectile = player.getWorld().spawn(eye.add(direction), Fireball.class);
projectile.setShooter(player);
projectile.setVelocity(direction);
AzureAPI.playSound(player, Sound.ITEM_FIRECHARGE_USE, true);
CooldownTicker.cooldown(this, player, TimeUnit.SECONDS, 3);
} else {
AzureAPI.playSound(player, Sound.UI_BUTTON_CLICK);
AzureAPI.log(player, "冷却时间还没有结束呢!");
}
}
示例10: onProjectileLaunch
import org.bukkit.entity.Projectile; //导入方法依赖的package包/类
@EventHandler
public void onProjectileLaunch(ProjectileLaunchEvent e){
Projectile projectile = e.getEntity(); //Getting the projectile
ProjectileSource shooter = projectile.getShooter(); //Getting the shooter
if(shooter instanceof Player){ //If the shooter was a player
Player player = (Player) shooter;
if(!isEnabled(player.getWorld())) return; //If this module is enabled in this world
debug("Making projectile go straight", player);
//Here we get a unit vector of the direction the player is looking in and multiply it by the projectile's vector's magnitude
//We then assign this to the projectile as its new velocity
projectile.setVelocity(player.getLocation().getDirection().normalize().multiply(projectile.getVelocity().length()));
}
}
示例11: onGraczInteract
import org.bukkit.entity.Projectile; //导入方法依赖的package包/类
@EventHandler
public void onGraczInteract(PlayerInteractEvent pie) {
Player gracz = (Player) pie.getPlayer();
String mb = pie.getPlayer().getItemInHand().getItemMeta().getDisplayName();
if(mb.equals(plugin.nameM9) || mb.equals(plugin.nameSG) || mb.equals(plugin.nameM14) || mb.equals(plugin.nameM16) || mb.equals(plugin.nameAK47)) {
if (pie.getAction() == Action.LEFT_CLICK_BLOCK
|| pie.getAction() == Action.LEFT_CLICK_AIR) {
World world = gracz.getWorld();
org.bukkit.Location loc = pie.getPlayer().getEyeLocation();
Projectile zmienna = (Projectile) world.spawnEntity(loc,
EntityType.SNOWBALL);
Vector loce = gracz.getLocation().getDirection().multiply(4);
zmienna.setShooter(gracz);
zmienna.setVelocity(loce);
Map<Projectile, Amunicja> projMap = plugin.nabojeMap.get(gracz.getName());
if (projMap == null)
{
projMap = new HashMap<>();
plugin.nabojeMap.put(gracz.getName(), projMap);
}
if(mb.equals(plugin.nameAK47)) {
projMap.put(zmienna, Amunicja.amoAK47);
} else if(mb.equals(plugin.nameM16)) {
projMap.put(zmienna, Amunicja.amoM16);
} else if(mb.equals(plugin.nameM14)) {
projMap.put(zmienna, Amunicja.amoM14);
} else if(mb.equals(plugin.nameSG)) {
projMap.put(zmienna, Amunicja.amoSG);
} else if(mb.equals(plugin.nameM9)) {
projMap.put(zmienna, Amunicja.amoM9);
}
}
}
}