Reduce block break time?

Discussion in 'Plugin Development' started by fritz, Jul 13, 2011.

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


    I've tried searching the forums and javadocs for information on this, but so far no luck. I'm hoping it's just a matter of me using the wrong terms and that this is possible.

    What I am looking to do is to reduce the amount of time it takes to break a block. Not insta-break, just faster break. For example, set obsidian blocks to break in 10 seconds instead of 20 with a diamond pick.

    I've found the block damage event, I was hoping there may be a way to see how much damage it has taken in the current punching session or something along those lines.

    Does anybody have any suggestions?
  2. Offline


    Try something like:

    public void onBlockDamage(BlockDamageEvent event)
    if(event.getDamage() >= threshold && event.getBlock().getTypeID() == 49)​
    event.getWorld().dropItemNaturally(event.getBlock.getLocation(), new ItemStack(49, 1));​

    Threshold would be how much damage has been received after 10 seconds. I just wrote that off the top of my head, so it may be flawed. Also, I'm not sure that the block damage event is fired during the breaking process of a block, though I've never tried it myself.
  3. Offline


    That looks like what I need, but can I ask where you found event.getDamage? It's probably just that I'm new to javadocs (never used them before bukkit), but I only see the getDamage() method documented in relation to entities and not blocks.

    If I can learn where you found the info, hopefully I can answer my own questions better in the future.

  4. Offline


    I'm not sure if it's there, though I would imagine it would be because it's an event related to damage. As I said, all that code was off of the top of my head.
  5. Offline


    import org.bukkit.event.block.BlockDamageEvent;
    import org.bukkit.event.block.BlockListener;
    public class MehBlockListener extends BlockListener {
        public void onBlockDamage(BlockDamageEvent event) {
  6. Offline


    Unless I'm missing something, this doesn't help with the question. I know how to identify a BlockDamageEvent, but this event is thrown only when the block is damaged and isn't a constant event. My question is how to determine how long the block has been being damaged for.
  7. Offline


    thats why i posted this.. and well i think you have to save the block + System.currentTimeMillis() to a HashMap and then check if the block is already stored and if the current time differs x secons then do event.setInstaBreak(true)...
    but there is still the problem on how to kick a block out of the list again if a user stops damaging it... sort of a shit solution ... theres for sure a better way...
  8. Offline


    isn't the problem here onBlockDamage() is only called once and not continuously while the block is being damaged?
  9. Offline


    I'm not entirely sure this would work, but you could use the scheduler method scheduleSyncRepeatingTask() to make a method that clears a List every tick, and then when the BlockDamageEvent is triggered, add the player back in. That way you could do what @s1mpl3x said, and detect if they stopped damaging it by checking if they are in the list.

    EDIT: or PlayerInteractEvent if what Kitteh says is true
  10. Offline


    hm well never used onBlockDamage... so idk but yes PlayerInteract is fired on every hit...
  11. Offline


    Well, it sounds like the main conclusion is that I didn't miss anything in the docs, there just isn't a clean way of doing this. I don't think the benefits of the time reduction would be worth the overhead of any of the work around.

    Thanks anyway :D
  12. Offline


    Check out Levelcraft - I think I saw something that said they got faster block breaking working.
Thread Status:
Not open for further replies.

Share This Page