Solved Change block resistance

Discussion in 'Plugin Development' started by dumbasPL, Aug 1, 2017.

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

    dumbasPL

    I want to change the global resistance of obsidian to low enough value that it can be broken by tnt or creeper.
    Is there a way to do it without decompiling and compiling back entire server jar?
     
  2. @dumbasPL
    It is possible to do it using NMS (see here). But using API methods is a bit more tricky. You could listen to explosion events and manually delete the blocks, but I could see this getting complex quite quickly.
     
  3. Offline

    dumbasPL

    @AlvinB
    I have seen it, but it changed in 1.8 and field utils link no longer works.
    some example code pls
     
  4. @dumbasPL
    We need to change the "durability" field of the Block class corresponding to obsidian to a lower value, using reflection since it is protected. We get the (NMS) Block instance like this:
    Code:java
    1. Block block = Block.getByName("obsidian");
    And the we change the value using reflection:
    Code:java
    1.  
    2. try {
    3. Field field = Block.class.getDeclaredField("durability");
    4. field.setAccessible(true);
    5. field.set(block, 30f);
    6. e.printStackTrace();
    7. }
    In this case I used 30, which is the default value for cobblestone, but you can of course change it to whatever you like.

    Do note that if you don't implement further reflection, this will not work between versions.
     
    dumbasPL likes this.
  5. Offline

    dumbasPL

    thx bro it works
    ps. how to mark code as java??
     
  6. @dumbasPL
    I use [syntax=java][/syntax] tags. But be aware that these sometimes glitch out with edits (I still think they're a better alternative than the broken [code][/code] tags though).
     
Thread Status:
Not open for further replies.

Share This Page