How can I drop an item at the destroyed block after a player broke it?

Discussion in 'Plugin Development' started by Tauryuu, Jan 1, 2012.

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

    Tauryuu

    I tried to do something like this.

    PHP:
    Block b e.getBlock();
    if (
    b.getType() == Material.STONE) {
         
    b.getWorld().dropItemNaturally(b.getLocation(), new ItemStack(Material.COAL));
         
    e.getPlayer().sendMessage("You mined into Coal!");
    }
    But nothing dropped, and there was no message. What am I doing wrong?

    Thanks in advance.
     
  2. Offline

    billofbong

    Is this in a playerlistener?
     
  3. Offline

    theguynextdoor

    Maybe try
    Code:
     b.getWorld().dropItemNaturally(b.getLocation(), new ItemStack(Material.COAL, 1));
    Setting the amount of coal to drop, just a guess. If not then check you have declared your player listener and registered the event correctly
     
    hammale likes this.
  4. Offline

    spywhere

    And don't forget about block data. If you break a log of birch tree, it must drop birch tree's log not normal log.
     
  5. Offline

    Don Redhorse

    well your if statement is wrong..

    this one works... event.getBlock().getType() == Material.TNT)
    where Event is a BlockPlaceEvent event
     
  6. Offline

    Perdog

    How is his if statement wrong? e is the variable that he assigned to the event, it doesn't have to be "event".

    My thoughts are you didn't register the event in onEnable()?
     
  7. For some reason when you create a new ItemStack without an amount, the amount will be 0, thus nothing is dropped. If you did that somewhere in the past, it would have dropped an invalid ItemStack, crashing nearby clients and making the world corrupt ;)

    Do what @theguynextdoor said.
    Also, I wouldn't use dropItemNaturally, but rather just dropItem - the "naturally" part gives the item a random velocity, like when you die and everything you had is scattered around the actual place - that's naturally, and I don't think you want that.
     
  8. Offline

    Don Redhorse

    hmm... and why doesn't he have a message? that points to the if statement not working.. but perhaps as perdog said the event is not registered..
     
  9. Offline

    elraro

    Sry for the /bump, but im having this problem
    how can i drop log of X tree, not normal log? :/
     
  10. Offline

    Garris0n

    At this point you should have just made a new thread...that said, set the log's data value to whatever value of the tree you're dropping..
     
  11. Offline

    elraro

    Garris0n yes, but how? :/
     
Thread Status:
Not open for further replies.

Share This Page