Solved BlockBreak to ItemStack (1.19.3)

Discussion in 'Plugin Development' started by ItZ_JameZ_, Mar 12, 2023.

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

    ItZ_JameZ_

    Hello yall I'm trying to make a method where when a Player breaks a block via BlockBreakEvent it takes the item that's gonna naturally drop and make it into a ItemStack

    Currently I'm using
    Code:
        @EventHandler
        public void blockBreak(BlockBreakEvent event)
        {   
            event.getPlayer().getInventory().addItem(new ItemStack(event.getBlock().getType()));
            event.setDropItems(false);
       }
    But if a player breaks coal ore it gives them Coal Ore instead of the coal.

    If anyone has any suggestions I would greatly appreciate any help
     
  2. Offline

    timtower Administrator Administrator Moderator

    Try event.getDrops() and add those to the inventory
     
  3. Offline

    ItZ_JameZ_

    I don’t see that method under BlockBreakEvent only a Boolean to toggled if they drop #isDropItems()
     
  4. Offline

    timtower Administrator Administrator Moderator

  5. Offline

    ItZ_JameZ_

    I see your using the Block class I’ll try that method when I redo it

    Edit: that worked thank you
     
    Last edited: Mar 13, 2023
Thread Status:
Not open for further replies.

Share This Page