Solved Get Block Drops Accounting For Fortune

Discussion in 'Spigot Plugin Development' started by Cornchip, Jun 28, 2018.

  1. I've been digging around the NMS library and various other resources and have failed to find an efficient way of retrieving the items that will be dropped from a block that was mined with an item with enchantments such as fortune. I want to have the items that would have been dropped without actually breaking the block, and (if possible) without calculating the randomness myself (as this always yields different results than actually breaking it in my experience).
    Thanks :)
  2. I dont think so but im not sure
  3. I do believe Block#getDrops(ItemStack) check the tools enchantments. Not at a PC to double check, but I'm almost certain it does.
  4. Nope, that seems to just return one item with fortune every time, whereas breaking it w/ fortune returns about 5 items :(
  5. Oh! You want to know the amounts. Yeah, that method only tells possible block types, not amounts. Look in the classes of each Item to find the method you want. I've used it in Forge, but idk the NMS name of the method. Each item has its own math/chance stuff for that.

    Edit: Wrong information. See my next post for correct information.
    #5 BillyGalbreath, Jun 28, 2018
    Last edited: Jun 28, 2018
  6. Ah, alright thanks :)
    That would also explain why the method for rng I was using yielded different results as I was using it as a blanket statement for all items.
    • Like Like x 1
  7. FrostedSnowman

    Resource Staff

    For future users seeking the solution, since op marked as solved and didn't bother posting the solution, like always:

    Code (Java):
    Block block = Bukkit.getWorld("example").getBlockAt(location);
    CraftMagicNumbers.getBlock(block).getDropCount(fortuneLevel, random);
    Like mentioned, the random should be grabbed from the world
    • Like Like x 2
    • Useful Useful x 1
  8. I know that I'm reviving a very old thread, but this is the thread that shows up on Google when you search for this topic.

    Anyway, in 1.15.2 you need to use "net.minecraft.server.v1_15_R1.Block.getDrops" to get the blocks drops.

    Here's an example (Kotlin):
    Code (Text):

    fun getDrops(block: Block, entity: Entity?, itemStack: ItemStack): List<ItemStack> {
       val nmsWorld = ( as CraftWorld).handle
       val nmsBlock = CraftMagicNumbers.getBlock(block.type)

       return net.minecraft.server.v1_15_R1.Block.getDrops(nmsBlock.blockData, nmsWorld, BlockPosition(block.x, block.y, block.z), null, (entity as? CraftEntity)?.handle, CraftItemStack.asNMSCopy(itemStack))
          .map {

    Don't be dumb like me, Bukkit now has a "Block.getDrops(itemStack)" method and I've only noticed that after I made this post, whoops.
    #9 MrPowerGamerBR, May 14, 2020
    Last edited: May 23, 2020
    • Useful Useful x 1