Changing Block Explosion Resistance

Discussion in 'Plugin Development' started by KeybordPiano459, Sep 4, 2012.

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

    KeybordPiano459

    Is there a way to change the blast resistance of a block? For example instead of 18000 I could change bedrock blast resistance to 2 or something like that.

    Bump

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 28, 2016
  2. Offline

    Comphenix

    There are many ways of doing it. The simplest would be to just alter the durability field of the net.minecraft.server.Block class in question.

    I've made a simple prototype for doing this safely and efficiently. First, add the following BlockOverride class to a package:
    https://gist.github.com/3642791

    Then add this modified FieldUtils from Apache Commons to the same package. You'll now be able to modify the durability field like so:
    Code:
    import net.minecraft.server.Block;
     
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class ResistanceMod extends JavaPlugin  {
     
        // Modify obsidian!
        private BlockOverride obsidian = new BlockOverride(Block.OBSIDIAN);
     
        @Override
        public void onLoad() {
            // Even less than wood
            obsidian.set("durability", 2.0f * 3);
        }
     
        @Override
        public void onDisable() {
            obsidian.revertAll();
        }
    }
    
    It's important to reset the values if the user disables the plugin. You shouldn't go about modifying internal Minecraft classes without cleaning up after yourself.

    The end result is something like this:
    http://imgur.com/a/LIXXT

    If you need to customize the explosion algorithm in even more detail, you'd have to do something like FatTNT and replace the default algorithm altogether. But that shouldn't be necessary for simple things like setting the blast resistance.
     
    Xp10d3 likes this.
Thread Status:
Not open for further replies.

Share This Page