Block Break Speed?

Discussion in 'Spigot Plugin Development' started by Kilovice, May 17, 2015.

  1. I'm going to get straight to the point. Is there a way to change the speed with which a block is broken? I suppose I should say is there a manual way to, as I would like to change how fast blocks break with certain items. I do realize I could give them haste or mining fatigue on interact, however I'd like to know if there is a way through Bukkit / Spigot to do this be it packet or other.
     
  2. What you're trying to do it's a bit difficult. First of all, you should change the durability of the blocks in the server side, and I don't think that Bukkit or Spigot have that function. Therefore, you have to find out a way to do it through NMS.

    But that isn't the problem. The durability of the blocks also depends on client. So, for example, if you wanna increase a block hardness and you don't change it on the Client (something that only can be changed modding it), the Client will show the block as broken, but in the Server isn't. So the block will make a strange "blink" effect on the client.
     
  3. This is the easiest way:p
    Code (Text):
    public static int duration = 999999999;
    public static int amplifier =  3;
    public void onJoin(PlayerJoinEvent e) {
    Player p = e.getPlayer();
    p.addPotionEffect(new PotionEffect(PotionEffectType.FAST_DIGGING, duration, amplifier));
    }
     
    • Informative Informative x 1
  4. I personally was thinking more of the interact event and giving them haste / mining fatigue depending on efficiency level and or item used
     
  5. Code (Text):

    public static int duration = 999999999;
    public static int amplifier =  3;
    Player player = e.getPlayer();
    if(player.getAction() == Action.RIGHT_CLICK_BLOCK) {
        if(player.getItemInHand().containsEnchantment(Enchantment.Efficiency, 1) {
    player.addPotionEffect(new PotionEffect(PotionEffectType.FAST_DIGGING, duration, amplifier));
        }
    }
     
    Another way to use @FloThePony 's example.
    Haven't tested it yet, only wrote it up on here as I don't have eclipse open
     
    • Informative Informative x 1
  6. Just wrote it up into Eclipse, I havent tested it onto a minecraft server but heres the code I got
    Code (Text):
    import org.bukkit.enchantments.Enchantment;
    import org.bukkit.entity.Player;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.potion.PotionEffect;
    import org.bukkit.potion.PotionEffectType;

    public class main extends JavaPlugin implements Listener {
       
        public static int duration = 999999999;
        public static int amplifier =  3;  
       
        public void onInteract(PlayerInteractEvent e) {
            Player p = e.getPlayer();
            if(e.getAction() == Action.RIGHT_CLICK_BLOCK) {
            if(p.getItemInHand().containsEnchantment(Enchantment.DIG_SPEED)) {
                p.addPotionEffect(new PotionEffect(PotionEffectType.FAST_DIGGING, duration, amplifier));
                }
            }
        }
       
    }
    Obviously add anything else you want to add.
     
  7. Integer.MAX_VALUE
     
    • Agree Agree x 2
    • Like Like x 1
  8. Okay. I didn't know about that :p
     
    • Agree Agree x 1
    • Funny Funny x 1
  9. Or.. If you don't give a effect. Create a BlockBreak event (I forgot what it's called in the API) and then remove the block from your world. Like get the coordinates of where the block is being broken, then change the block to air.

    Edit: Sorry for posting after a month, but I just figured in case people needed help with this problem in the future.
     
  10. Erm... What's the point in setting a broken block to air?:confused:
     
  11. Tux

    Tux

    You can use it to prevent blocks from dropping.
     
  12. This has nothing to do with the context of this thread. The @TO asks about block breaking speed, not about cancelling drops.
     
  13. I mean check if it's being the block is being hit, then change the block to air (null). And then set a drop of that item.
    Or set a delay such as wait 10 ticks until set the block to air. Making it happen faster.
     
    #13 ItsWill, Jun 9, 2015
    Last edited: Jun 9, 2015
  14. Effect digSpeed
     
  15. Not at all. Have you read anything that I posted?
     
  16. You could possibly use reflection to modify the hardness.