Solved Spawning Item entity

Discussion in 'Spigot Plugin Development' started by WaffleMast3r, Jan 9, 2020.

Thread Status:
Not open for further replies.
  1. Hello, I want to spawn an ItemStack at a specific location, I have tried with World#spawn(Location, EntityType.DROPPED_ITEM), World#dropItem(Location, ItemStack), World#dropItemNaturally(Location, ItemStack) and all of them spawns the item stack with an offset, or they fly away :))

    Any ideas how can I make them spawn at a fixed location?
     
  2. To spawn the ItemStack at a specific location you would use:
    Code (Java):
    world#dropItem(Location, ItemStack);
    You say "fly away"? This may be the cause of you trying to spawn an item, on a block break event? Here the block hasn't been removed yet, and therefore this effect happens. (add a delay)

    This would spawn the ItemStack with a natural offset, like when you mine/break a block.
    Code (Java):
    World#dropItemNaturally(Location, ItemStack);
     
  3. Code (Text):

    Bukkit.getScheduler().scheduleSyncDelayedTask(WaffleAPI.getPlugin(), new Runnable() {
        @Override
        public void run() {
            w.dropItem(location.clone().add(0.5, 1.2, 0.5), item.getStack());
        }
    }, 10);
     
    still flies up and then goes down. And this causes a small offset, sometimes fall off the block
     
  4. This should work. :)
    Code (Java):
    Item dropitem = w.dropItem(location.clone().add(0.5, 1.2, 0.5), item.getStack());
    dropitem.setVelocity(dropitem.getVelocity().zero());
     
    • Agree Agree x 2
  5. Code (Text):
    setVelocity(new Vector());
    :p
    no need to get the vector
     
    • Agree Agree x 1
  6. Great it works! Thanks
     
Thread Status:
Not open for further replies.