Java Code Examples for org.bukkit.entity.Item#setVelocity()
The following examples show how to use
org.bukkit.entity.Item#setVelocity() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RealDisplayItem.java From QuickShop-Reremake with GNU General Public License v3.0 | 6 votes |
@Override public void safeGuard(@NotNull Entity entity) { if (!(entity instanceof Item)) { Util.debugLog("Failed to safeGuard " + entity.getLocation() + ", cause target not a Item"); return; } Item item = (Item) entity; // Set item protect in the armorstand's hand if (plugin.getConfig().getBoolean("shop.display-item-use-name")) { item.setCustomName(Util.getItemStackName(this.originalItemStack)); item.setCustomNameVisible(true); } else { item.setCustomNameVisible(false); } item.setPickupDelay(Integer.MAX_VALUE); item.setSilent(true); item.setPortalCooldown(Integer.MAX_VALUE); item.setVelocity(new Vector(0, 0.1, 0)); }
Example 2
Source File: Vectors.java From TabooLib with MIT License | 6 votes |
public static Item itemDrop(Player player, ItemStack itemStack, double bulletSpread, double radius) { Location location = player.getLocation().add(0.0D, 1.5D, 0.0D); Item item = player.getWorld().dropItem(location, itemStack); double yaw = Math.toRadians((double)(-player.getLocation().getYaw() - 90.0F)); double pitch = Math.toRadians((double)(-player.getLocation().getPitch())); double x; double y; double z; if (bulletSpread > 0.0D) { double[] spread = new double[]{1.0D, 1.0D, 1.0D}; IntStream.range(0, 3).forEach((t) -> { spread[t] = (Numbers.getRandom().nextDouble() - Numbers.getRandom().nextDouble()) * bulletSpread * 0.1D; }); x = Math.cos(pitch) * Math.cos(yaw) + spread[0]; y = Math.sin(pitch) + spread[1]; z = -Math.sin(yaw) * Math.cos(pitch) + spread[2]; } else { x = Math.cos(pitch) * Math.cos(yaw); y = Math.sin(pitch); z = -Math.sin(yaw) * Math.cos(pitch); } Vector dirVel = new Vector(x, y, z); item.setVelocity(dirVel.normalize().multiply(radius)); return item; }
Example 3
Source File: Scorpio.java From AnnihilationPro with MIT License | 6 votes |
@EventHandler(priority = EventPriority.HIGHEST) public void specialItemActionCheck(final PlayerInteractEvent event) { if(event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK) { Player player = event.getPlayer(); AnniPlayer pl = AnniPlayer.getPlayer(player.getUniqueId()); if(pl != null && pl.getKit().equals(this)) { if(this.isHookItem(player.getItemInHand())) { if(!Delays.getInstance().hasActiveDelay(player, this.getInternalName())) { Delays.getInstance().addDelay(player, System.currentTimeMillis()+5000, this.getInternalName());//kits.addDelay(player.getName(), DelayType.SCORPIO, 10, TimeUnit.SECONDS); Item item = player.getWorld().dropItem(player.getEyeLocation(), new ItemStack(Material.NETHER_STAR,1)); item.setPickupDelay(Integer.MAX_VALUE); item.setVelocity(player.getEyeLocation().getDirection().multiply(2)); Bukkit.getScheduler().scheduleSyncDelayedTask(AnnihilationMain.getInstance(), new HookTracer(item,pl,90,this.getName()), 1); } } } } }
Example 4
Source File: VisualItemProcessor.java From EliteMobs with GNU General Public License v3.0 | 6 votes |
private void rotateItem(Object itemObject, Vector vector, EliteMobEntity eliteMobEntity) { Item item = (Item) itemObject; if (!item.isValid()) return; Location currentLocation = item.getLocation().clone(); Location newLocation = eliteMobEntity.getLivingEntity().getLocation().clone().add(new Vector(0, 1, 0)).add(vector); // if (currentLocation.distanceSquared(newLocation) > Math.pow(3, 2)) { // item.teleport(newLocation); // item.setVelocity(new Vector(0.01, 0.01, 0.01)); // return; // } Vector movementVector = (newLocation.subtract(currentLocation)).toVector(); movementVector = movementVector.multiply(0.3); // if (Math.abs(movementVector.getX()) > 3 || Math.abs(movementVector.getY()) > 3 || Math.abs(movementVector.getZ()) > 3) { // item.teleport(newLocation); // } else { item.setVelocity(movementVector); // } }
Example 5
Source File: AncientAltarListener.java From Slimefun4 with GNU General Public License v3.0 | 6 votes |
private void insertItem(Player p, Block b) { ItemStack hand = p.getInventory().getItemInMainHand(); ItemStack stack = new CustomItem(hand, 1); if (p.getGameMode() != GameMode.CREATIVE) { ItemUtils.consumeItem(hand, false); } String nametag = ItemUtils.getItemName(stack); Item entity = b.getWorld().dropItem(b.getLocation().add(0.5, 1.2, 0.5), new CustomItem(stack, "&5&dALTAR &3Probe - &e" + System.nanoTime())); entity.setVelocity(new Vector(0, 0.1, 0)); SlimefunUtils.markAsNoPickup(entity, "altar_item"); entity.setCustomNameVisible(true); entity.setCustomName(nametag); p.playSound(b.getLocation(), Sound.ENTITY_ITEM_PICKUP, 0.3F, 0.3F); }
Example 6
Source File: Grenade.java From QualityArmory with GNU General Public License v3.0 | 5 votes |
@SuppressWarnings("deprecation") @Override public boolean onRMB(Player thrower, ItemStack usedItem) { if (throwItems.containsKey(thrower)) { ThrowableHolder holder = throwItems.get(thrower); ItemStack grenadeStack = thrower.getItemInHand(); ItemStack temp = grenadeStack.clone(); temp.setAmount(1); if (thrower.getGameMode() != GameMode.CREATIVE) { if (grenadeStack.getAmount() > 1) { grenadeStack.setAmount(grenadeStack.getAmount() - 1); } else { grenadeStack = null; } thrower.setItemInHand(grenadeStack); } Item grenade = holder.getHolder().getWorld().dropItem(holder.getHolder().getLocation().add(0, 1.5, 0), temp); grenade.setPickupDelay(Integer.MAX_VALUE); grenade.setVelocity(thrower.getLocation().getDirection().normalize().multiply(1.2)); holder.setHolder(grenade); thrower.getWorld().playSound(thrower.getLocation(), Sound.ENTITY_ARROW_SHOOT, 1, 1.5f); throwItems.put(grenade, holder); throwItems.remove(thrower); QAMain.DEBUG("Throw grenade"); } else { thrower.sendMessage(QAMain.prefix + QAMain.S_GRENADE_PULLPIN); } return true; }
Example 7
Source File: ResourceSpawner.java From BedwarsRel with GNU General Public License v3.0 | 5 votes |
public void dropItem(Location dropLocation, ItemStack itemStack) { Item item = this.game.getRegion().getWorld().dropItemNaturally(dropLocation, itemStack); item.setPickupDelay(0); if (this.spread != 1.0) { item.setVelocity(item.getVelocity().multiply(this.spread)); } }
Example 8
Source File: ItemTransferListener.java From PGM with GNU Affero General Public License v3.0 | 4 votes |
private void dropFromPlayer(Player player, ItemStack stack) { Item entity = player.getWorld().dropItem(player.getEyeLocation(), stack); entity.setVelocity(player.getLocation().getDirection().multiply(0.3)); }
Example 9
Source File: ItemTransferListener.java From ProjectAres with GNU Affero General Public License v3.0 | 4 votes |
private void dropFromPlayer(Player player, ItemStack stack) { Item entity = player.getWorld().dropItem(player.getEyeLocation(), stack); entity.setVelocity(player.getLocation().getDirection().multiply(0.3)); }
Example 10
Source File: QuadCrate.java From Crazy-Crates with MIT License | 4 votes |
@EventHandler public void onChestClick(PlayerInteractEvent e) { Player player = e.getPlayer(); if (QuadCrateSession.inSession(player)) { QuadCrateSession session = QuadCrateSession.getSession(player); if (e.getAction() == Action.RIGHT_CLICK_BLOCK || e.getAction() == Action.LEFT_CLICK_BLOCK) { Block block = e.getClickedBlock(); if (session.getChestLocations().contains(block.getLocation())) { e.setCancelled(true); if (!session.hasChestBeenOpened(block.getLocation())) { nms.openChest(block, true); Crate crate = session.getCrate(); Prize prize = crate.pickPrize(player, block.getLocation().add(.5, 1.3, .5)); cc.givePrize(player, prize); ItemBuilder itemBuilder = ItemBuilder.convertItemStack(prize.getDisplayItem()); itemBuilder.addLore(new Random().nextInt(Integer.MAX_VALUE) + "");//Makes sure items don't merge ItemStack item = itemBuilder.build(); NBTItem nbtItem = new NBTItem(item); nbtItem.setBoolean("crazycrates-item", true); item = nbtItem.getItem(); Item reward = player.getWorld().dropItem(block.getLocation().add(.5, 1, .5), item); reward.setMetadata("betterdrops_ignore", new FixedMetadataValue(cc.getPlugin(), true)); reward.setVelocity(new Vector(0, .2, 0)); reward.setCustomName(prize.getDisplayItem().getItemMeta().getDisplayName()); reward.setCustomNameVisible(true); reward.setPickupDelay(Integer.MAX_VALUE); session.getDisplayedRewards().add(reward); session.setChestOpened(block.getLocation(), true); if (session.allChestsOpened()) {//All 4 crates have been opened new BukkitRunnable() { @Override public void run() { session.endCrate(); player.playSound(player.getLocation(), cc.getSound("BLOCK_STONE_STEP", "STEP_STONE"), 1, 1); } }.runTaskLater(cc.getPlugin(), 60); } } } } } }
Example 11
Source File: GenericBomb.java From NBTEditor with GNU General Public License v3.0 | 4 votes |
private Item createItem(Location loc, Vector vel) { Item item = loc.getWorld().dropItem(loc, getItem()); item.setVelocity(vel); item.setPickupDelay(Integer.MAX_VALUE); return item; }
Example 12
Source File: ChickenHandler.java From EliteMobs with GNU General Public License v3.0 | 2 votes |
public void dropEggs() { ItemStack eggStack = new ItemStack(Material.EGG, 1); ItemMeta eggMeta = eggStack.getItemMeta(); eggMeta.setLore(lore); eggStack.setItemMeta(eggMeta); Iterator<LivingEntity> superChickenIterator = EntityTracker.getSuperMobs().iterator(); while (superChickenIterator.hasNext()) { LivingEntity chicken = superChickenIterator.next(); if (!(chicken instanceof Chicken)) continue; if (chicken == null || !chicken.isValid()) { superChickenIterator.remove(); } else { Item droppedItem = chicken.getWorld().dropItem(chicken.getLocation(), eggStack); droppedItem.setVelocity(ItemDropVelocity.ItemDropVelocity()); new BukkitRunnable() { @Override public void run() { if (droppedItem.isValid()) { droppedItem.remove(); } } }.runTaskLater(MetadataHandler.PLUGIN, 20 * 60); } } }