dropItem (Naturally) drops untakable ItemStacks

Discussion in 'Plugin Development' started by JoshuaBehrens, Jul 4, 2011.

Thread Status:
Not open for further replies.
  1. Offline

    JoshuaBehrens

    Hey guys,

    in a new plugin I can't take dropped ItemStacks neither by the World.dropItem-Method nor by the World.dropItemNaturally-Method. They're lying on the ground, can get destroyed by fire/lava/cacti and disappears after several minutes, but I can't take them. After some of those drops (>300 untakable ItemStacks) the server (running on a netbook) throws a warning (system time change?) every 5 to 10 seconds.

    I noticed this behaviour in an earlier devbukkit (I'm using the devbukkit for the latest craftbukkit), but this got fixed. Any ideas ?

    Thanks in advance, Joshua
     
  2. Offline

    ChrizC

  3. Offline

    JoshuaBehrens

    Pastie isn't worth for this bit ;)
    Show Code
    Code:
    package joshuabehrens.plugins.monsterhatchery;
    
    import org.bukkit.Material;
    import org.bukkit.event.block.BlockBreakEvent;
    import org.bukkit.event.block.BlockListener;
    import org.bukkit.inventory.ItemStack;
    
    public class MHBlockListener extends BlockListener
    {
        @Override
        public void onBlockBreak(BlockBreakEvent e)
        {
            if (e.getBlock().getType() == Material.MOB_SPAWNER)
                e.getBlock().getWorld().dropItem(e.getBlock().getLocation(), new ItemStack(Material.MOB_SPAWNER));
        }
    }
    
    I can't pickup the dropped spawner.
     
  4. Offline

    Vynlar


    Just an idea as whenever I try and drop something, I make the item in a new item stack then use the variable in the dropItem() and I use the item id instead of Material.

    Code:java
    1. package joshuabehrens.plugins.monsterhatchery;
    2.  
    3. import org.bukkit.Material;
    4. import org.bukkit.event.block.BlockBreakEvent;
    5. import org.bukkit.event.block.BlockListener;
    6. import org.bukkit.inventory.ItemStack;
    7.  
    8. public class MHBlockListener extends BlockListener
    9. {
    10. @Override
    11. public void onBlockBreak(BlockBreakEvent e)
    12. {
    13.  
    14. if (e.getBlock().getType() == Material.MOB_SPAWNER)
    15. ItemStack item = new ItemStack(<ITEM ID>);
    16. e.getBlock().getWorld().dropItem(e.getBlock().getLocation(), item));
    17. }
    18. }
    19. [\SYNTAX]
    20.  
    21. PS, I did this out of ide (iPad) so if I'm totally off somewhere, that's why. Hope this helps
     
  5. Offline

    nisovin

    You need to specify a quantity.
     
  6. Offline

    ChrizC

    Yeah, as above, ItemStack needs a quantity, really.
    new ItemStack(Material.MOB_SPAWNER, 1);
     
  7. Offline

    JoshuaBehrens

    Thanks to nivison. Now it's working. But why it was working this way in earlier versions.
     
  8. Offline

    Acrobot

    Because in earlier version, CraftBukkit didn't block stacks with quantity lower than 1.
     
  9. Offline

    JoshuaBehrens

    I thought the stacksize is always 1 when it's not given. Now I know it better.
     
Thread Status:
Not open for further replies.

Share This Page