/** * Instantiates a new item projectile. * * @param name projectile name * @param loc location of projectile (sets position of projectile and shoots in pitch and yaw * direction) * @param itemstack item stack to shoot * @param shooter projectile shooter * @param power projectile power */ @SuppressWarnings("deprecation") public ItemProjectile( String name, Location loc, org.bukkit.inventory.ItemStack itemstack, LivingEntity shooter, float power) { super(((CraftWorld) loc.getWorld()).getHandle(), loc.getX(), loc.getY(), loc.getZ(), null); if (CraftItemStack.asNMSCopy(itemstack) != null) setItemStack(CraftItemStack.asNMSCopy(itemstack)); else setItemStack( new net.minecraft.server.v1_8_R1.ItemStack( Item.getById(itemstack.getTypeId()), itemstack.getAmount(), itemstack.getData().getData())); if (itemstack.getTypeId() == 0) System.out.println("You cannot shoot air!"); this.name = name; this.pickupDelay = Integer.MAX_VALUE; this.shooter = ((CraftLivingEntity) shooter).getHandle(); this.a(0.25F, 0.25F); setPositionRotation(loc.getX(), loc.getY(), loc.getZ(), loc.getYaw(), loc.getPitch()); locX -= (MathHelper.cos(yaw / 180.0F * 3.1415927F) * 0.16F); locY -= 0.10000000149011612D; locZ -= (MathHelper.sin(yaw / 180.0F * 3.1415927F) * 0.16F); setPosition(locX, locY, locZ); float f = 0.4F; motX = (-MathHelper.sin(yaw / 180.0F * 3.1415927F) * MathHelper.cos(pitch / 180.0F * 3.1415927F) * f); motZ = (MathHelper.cos(yaw / 180.0F * 3.1415927F) * MathHelper.cos(pitch / 180.0F * 3.1415927F) * f); motY = (-MathHelper.sin(pitch / 180.0F * 3.1415927F) * f); shoot(motX, motY, motZ, power * 1.5F, 1.0F); world.addEntity(this); try { this.f = Entity.class.getDeclaredField("invulnerable"); } catch (NoSuchFieldException e) { e.printStackTrace(); } }
/** * Instantiates a new item projectile. * * @param name projectile name * @param shooter projectile shooter (it uses entity's location to set x, y, z, pitch and yaw of * projectile) * @param item item stack to shoot * @param power projectile power */ public ItemProjectile( String name, LivingEntity shooter, org.bukkit.inventory.ItemStack item, float power) { super(((CraftLivingEntity) shooter).getHandle().world); this.name = name; this.pickupDelay = Integer.MAX_VALUE; setItemStack(CraftItemStack.asNMSCopy(item)); this.shooter = ((CraftLivingEntity) shooter).getHandle(); this.a(0.25F, 0.25F); setPositionRotation( shooter.getLocation().getX(), shooter.getLocation().getY() + shooter.getEyeHeight(), shooter.getLocation().getZ(), shooter.getLocation().getYaw(), shooter.getLocation().getPitch()); locX -= (MathHelper.cos(yaw / 180.0F * 3.1415927F) * 0.16F); locY -= 0.10000000149011612D; locZ -= (MathHelper.sin(yaw / 180.0F * 3.1415927F) * 0.16F); setPosition(locX, locY, locZ); float f = 0.4F; motX = (-MathHelper.sin(yaw / 180.0F * 3.1415927F) * MathHelper.cos(pitch / 180.0F * 3.1415927F) * f); motZ = (MathHelper.cos(yaw / 180.0F * 3.1415927F) * MathHelper.cos(pitch / 180.0F * 3.1415927F) * f); motY = (-MathHelper.sin(pitch / 180.0F * 3.1415927F) * f); shoot(motX, motY, motZ, power * 1.5F, 1.0F); world.addEntity(this); try { this.f = Entity.class.getDeclaredField("invulnerable"); } catch (NoSuchFieldException e) { e.printStackTrace(); } }