Solved Item Pickup Priority?

Discussion in 'Plugin Development' started by DoctorDark, Apr 7, 2014.

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

    DoctorDark

    Let's say my inventory is full and there are a bunch of dropped items on the floor.

    If I was to pickup an ItemStack from the ground, it is usually random (or however Minecraft controls this), therefore looting the items you don't work (e.g: mushroom soup), instead of picking up the good items (e.g armour/weapons).

    When I have a full inventory I would like to be able to pickup items from a specified item list before it picks up the items from the specified item blacklist.

    What would be the suggested method of doing this, as I have noticed the PlayerPickupItemEvent doesn't have a Item list from all the items about to be picked up.

    Thanks.
     
  2. Offline

    Timbo_KZ

    Whenever PlayerPickupItemEvent is called you can check for dropped item entities around the player, and if there are other items that player can pickup, iterate through the list of them and determine the order.
     
  3. Offline

    DoctorDark

    Timbo_KZ
    Thanks for your response, I ended up fixing this a day or two ago and forgot to check the thread as solved;

    only performing the following if the inventory was full and it was returning true to the boolean confirming it was an important item and the integer of a custom method that counts the important items within a radius of 1, 3, 1 to the players location was more than 1.

    {

    1. Setting the pickup event to cancelled;

    2. Saving the item to a HashMap<String, Item>;
    - Key - The items uniqueID
    - Value - event.getItem()

    3. Remove the item, as it can now be called using the HashMap.

    4. Running the delayed sync task to 10 ticks later to drop the item in the hashmap naturally and then removing the item from the HashMap to prevent the item duplicating.

    }
     
Thread Status:
Not open for further replies.

Share This Page