Is it possible to make a block harder to break?

Discussion in 'Plugin Development' started by Zidkon, Sep 6, 2012.

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

    Zidkon

    Thats the question, basically is by example making a stone that the user will take longer to destroy than any other stone at the world.

    Also I would like if its possible to make that the "breaking effect" of the stone (u know those images that comes up when u are breaking something letting u know that is getting broken more and more) takes as long as the block to break, here I'm not sure if the server sends to the client the level of brokeness of the stone so the client puts the correct image for it, but anyway that would be cool.

    I know there is something when you create an item that is durability (I think thats the name), but that doesn't do a block harder to destroy?

    THank you very much ;)
     
  2. The durability (or data, or damage) is a value that changes the item or block type... like wool color, wood style, lever state, sign direction, etc.
    For tools, that exact same value is used to set how much they're damaged.
    So no, that value has nothing to do with block strength.

    However, you could fiddle with minecraft code, that will change it for all blocks tough... if it even works, I am not sure.

    You'll need to import CraftBukkit instead of Bukkit, then access net.minecraft.server's Block then the block you want... then... I have no clue which variable it is, you'll have to use Minecraft Coder Pack or something to figure that out I guess... blame it on obsfucation :)
     
  3. Offline

    Zidkon

    So do it with Bukkit API is impossible after all?
     
  4. Offline

    Courier

    Not nicely. The breaking animation is client side (or at least the breaking animation that they player who does the breaking sees). Even if you make the block take longer / shorter to break, the client will show it breaking at the time the client expects it to break. The nicest looking thing you can do is make them break it twice, but that still looks bad.

    You might be able get something to work if you experiment with changing the player's tool while they are mining. I think that might reset the breaking animation in the client if you change to a tool that mines more slowly, or takes less damage.
     
  5. Offline

    whitehooder

    No. (As I know...) It is possible with NMS however, as Courier said it would not look as good as you were probably expecting
     
  6. Maybe you could work with potion effects?^^

    The player gets the slow digging potion if he hits your defined block.
    I think you should also be able to define the strength of the potion effect for the "harder" blocks

    Code:
        @EventHandler
        public void addSlowDigging(PlayerInteractEvent event) {
            Player spieler = event.getPlayer();
       
                if (event.getClickedBlock().getType() == Material.DIAMOND.ORE) {
                spieler.addPotionEffect(new PotionEffect(PotionEffectType.SLOW_DIGGING, 300, 1));
            }
        }
    And as soon as the block gets mined the potion effect will be removed from the player.

    Code:
     
        @EventHandler
        public void onBlockBreak(BlockBreakEvent event) {
            Player player = event.getPlayer();
            if (event.getBlock().getType() == Material.DIAMOND_ORE) {
                if (player.hasPotionEffect(PotionEffectType.SLOW_DIGGING)) {
                    player.removePotionEffect(PotionEffectType.SLOW_DIGGING);
     
                }
            }
        }
    
    Tested and it's working well! :)
     
    Zidkon likes this.
  7. Offline

    Zidkon

    I know that the animation is client side, but I through that to avoid any "fast breaking block clients" the server was sending the client the expectation of when to pass from image of breaking to image of broken, like is the server who says when the block is broken, not the client xD. So I don't know then :p

    Sir you just got a good point there! Thanks, is not exactly what I meant but it can work. The thing is that I don't know if it will cause any lag to the server if is a block that the people will usually destroy xD
     
  8. Offline

    Courier

    The server does validate... and it will correct the client. There is a latency though, so the client still sees the block disappear. It is like when you break a block that is protected by WorldGuard (or anything)... you see it break for a tick before it reappears.
    Heh... I forgot about those effects for some reason. Yeah, PotionEffects are the only clean-looking way to modify the client's behavior like this. It shouldn't be too laggy, but you'll have to test.
     
  9. Offline

    Zidkon

    Ty for answers, this method will definitelly works :)
     
  10. 'Likes' are appreciated :p
    Zidkon
    Well i don't think that it will cause lag^^
    Because if you think about other plugins like mcMMO/Logblock/etc. which are logging every block with the date of destroying, the location, the player... these plugins are causing lag :)
     
    Zidkon likes this.
  11. Offline

    Zidkon

    Ok got it, I'm trying to identify what kind of codes inside the events causes lags, seems that access to database and big loops does :p thanks man.
     
    Ahmet094 likes this.
Thread Status:
Not open for further replies.

Share This Page