**getDrops() method help!**

Discussion in 'Plugin Development' started by DefaultSyntax, Jun 12, 2014.

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


    Hi, I've been trying to make a plugin that gets the drops of a block when it's mined. It's for a prison server, so of course there will be fortune.

    My questions is "Is there a way to get the amount of ingots dropped from a block when it's mine and when the pickaxe has fortune on it? Thanks!
  2. Offline


    Check the 'getItemInHand()' method from player in the bukkit docs.
  3. Offline


    That wouldn't work because what I'm trying to do is I want to get that amount and put it in the player's inventory while deleting the block that was mined.
  4. Offline


    My friend did this let me see if I can find the code.
  5. Offline


    There is no easy way. You can apply the same check the enchant applies and generate the results that way, but there is no method that does it.
  6. Offline


    Oh ok I get what you're saying. Thanks for saving me hours trying to look for an answer! :D
  7. Offline


    DefaultSyntax Garris0n yes there is. On a BlockBreakEvent, do event.getBlock.getDrops(); it returns a collection of itemstacks so u can see them all there :D

    EDIT// after testing, you cant get the amount with this way :S unless i find a way later. sorry :S
  8. Offline


    There is a method Block.getDrops(ItemStack). This gets the items a block would drop when broken with a specific tool, so you would probably do
    However, I don't know if this would give the right results with a fortune enchant due to the RNG involved.

    In short, yes, this feature does appear to be missing from Bukkit. This would be solved by my suggestion over here:
  9. Offline


    getDrops only gets default drops of the block. On the plus side, there is an nms method that is the equivalent to getDrops with a specified item and will return based on the enchantments. Bukkit however, hasn't supported this method.

    You can dive into the CB and nms code yourself to find it. If you can't find it or don't know how to use it then you probably should learn a bit more before doing so.
  10. Offline


    adam753 i was testing this just before u posted, and it doesnt work with fortune, (didnt test other enchants but i guess it wont work with them either)
  11. Offline


    You can do it it by checking to see if the player has fortune, and if they do do a random number to add.

    if the item is an ore
    if the player's item has an fortune enchant
    ItemStack drop = new ItemStack(Material.ORE, Math.max(rand.nextInt(4) - 2, 0));
    cancel the block drop

    This is what I use
  12. Offline


    Thanks man! I'm pretty new at coding and I'm happy that I was able to understand what code you have put there. The only party however I don't get is (rand.nextInt(4) -2, 0));
    What does the nextInt method do and what does the (4)-2 mean?
  13. Offline



    It is getting a random number each time it is called, you would need to use javas random feature.

    Random rand = new Random(); //I hope this is right, haven't used it in awhile
    int randomnumber = rand.nextInt(10); //This includes numbers 0-9 for a total of 10 digits.
  14. Offline



    The method you gave me, when a player mines a block, will it apply to any type of block?
    And what does the "(4) - 2, 0" part mean?
    ItemStack drop = new ItemStack(Material.ORE, Math.max(rand.nextInt(4) - 2, 0));
Thread Status:
Not open for further replies.

Share This Page