Pickup ItemStacks with size over 64

Discussion in 'Plugin Development' started by netolokao, May 17, 2017.

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

    netolokao

    Hello,

    I've developed a simple plugin to group the drops of stacked mobs.
    Here's the basic concept of the plugin:

    Code:
        List<ItemStack> drops = event.getDrops();
                for (Iterator<ItemStack> dropIterator = drops.iterator(); dropIterator.hasNext();) {
                    ItemStack is = dropIterator.next();
                    if (is.getType() == Material.NETHER_STAR) {
                        qtdDrop += is.getAmount();
                        Bukkit.broadcastMessage(String.valueOf(qtdDrop));
                        dropIterator.remove();
                    }
                }
                drops.add(new ItemStack(Material.NETHER_STAR, qtdDrop));
    
    The problem is, let's say your inventory is almost full, with only 1 slot reamining, and there's 340 nether stars dropped on the ground (On a single ItemStack), sometimes the player will grab 64 Nether Stars, and leave the rest on the ground, so the player will be able to pick them up when he has enough inventory space. BUT SOMETIMES, the player will grab 64 Nether Stars to his inventory, and the remaining will vanish, along with the 64 that he managed to got.

    Gif showing what happens:
    https://media.giphy.com/media/3oKIPhMGt6Qvo95SsU/giphy.gif
     
  2. Online

    timtower Administrator Administrator Moderator

    @netolokao Decrease the amount of dropIterator instead of removing it.
    Limit qtdDrop to the amount that the user can pickup.
     
  3. Offline

    netolokao

    Hello Tim,

    Would the part about the dropIterator matter? Because i'm removing it and creating a new drop. Also, how can I decrease it? Seeing as it's an Iterator, and there's no method to decrease.

    About the limiting part, you mean, limit to their inventory size?

    What I'm trying to accomplish with this plugin is to reduce lag, mainly caused due to players killing up to 50000 iron golems at the same time, which leaves us with a lot of dropped iron ingots on the ground. I want it to be a single drop, with all the items, so they can pickup, clear their inventory, and pick the rest of the ingots. Limiting the amount of drops wouldn't really help on this case, because they would be losing way too much drops.
     
  4. Offline

    Horsey

    How about listening for an item pickup event and then manually adding the item into the inventory?
     
Thread Status:
Not open for further replies.

Share This Page