How to change block drops into an itemstack

Discussion in 'Plugin Development' started by fireboyev, Jul 3, 2016.

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

    fireboyev

    How would you be able to change block drops into an itemstack like:
    Code:
    ItemStack item = new ItemStack(block.getDrops());
    Thanks.
     
  2. Offline

    Caedus

    You'd want to:

    Listen for BlockBreakEvent
    Set the event as cancelled.
    Turn the block that was broken into air.
    Get the block that was broken.
    Get the type of the block.
    Create a new ItemStack based on the block.getType()

    This is assuming you want to stop the drop of the block you broke and instead want to convert it to an item stack.
     
  3. Offline

    fireboyev

    but setting the block as air would also bypass grief prevention plugins wouldn't it?

    and plus i want to go the drop way in case people are using fortune pickaxes or breaking grass blocks to get seeds
     
  4. Offline

    Caedus

    Yes, I reckon the method I suggested might interfere with grief prevention plugins.

    I don't quite understand what you're trying to achieve. If you want the block to drop, why do you want to make it into an itemstack?
     
  5. Offline

    fireboyev

    I do not want the block to drop but I want to first achieve getting the block drop into an itemstack.

    My plugin would be something that takes whatever you mine and puts it into your inventory so other players can't steal it
     
  6. Offline

    I Al Istannen

    @fireboyev
    Loop through block.getDrops. It returns a list of ItemStacks.
    And then maybe clear the drops? Don't know if it works.

    For grief prevention, all the protection plugins should cancel the event on a low priority, so it should already be cancelled by the time your listener runs. Just set @EventHandler(ignoreCancelled = true), to not receive such events.
     
  7. Offline

    fireboyev

    how would you loop it? sorry I'm not familiar with every part of java lol
     
  8. Offline

    Zombie_Striker

    @fireboyev
    for looping is one of the basics of Java. Have you ever seen something like this?
    Code:
    for(Object object : CollectionOfObjects){
    
    //OR
    
    for(int i = 0; i < the max number: i++){
     
Thread Status:
Not open for further replies.

Share This Page