Setting Block Resistance Values

Discussion in 'Plugin Development' started by Zachster, Jan 23, 2012.

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

    Zachster

    I like to build these Monster Arenas with a bunch of spawners that spawn monsters. Included in these monsters are creepers. I want to make a plugin for my server that gives glowstone the explosion resistance of obsidian or bedrock (bedrock preferably) but maintain its hardness and "mineability", if you will. I know this is probably a noob question but I'm just getting started with plugin development.
     
  2. Offline

    gyroninja

    Try getting the Block_break event check if its in the "arena", check if its glowstone. Check if a player broke it... PROFIT
     
  3. Offline

    Zachster

    Is there just a way to make it explosion resistant that's all I'm asking.
     
  4. Offline

    gyroninja

    Don't think theres a way to directly do it. D:
     
  5. Offline

    desht

    Hook the onEntityExplode event (EntityExplodeEvent). In your handler, get the list of affected blocks with event.blockList(), and remove any glowstone blocks from that list.

    That should make glowstone immune to explosions - adding resistance is a little more work. Two possible ways:
    1. Track the damage taken to each block and remove the block if the damage exceeds a certain level. Could lead to a lot of storage requirements, and persistence would need to be considered.
    2. (Easier) Add a random possibility that the block will be removed if it's hit by an explosion, perhaps proportional to the distance of the block from the explosion's centre (event.getLocation())
    Hmm, that could be generalised into a configurable explosion-resistance plugin where damage resistance could be defined on a per-block basis :)
     
    RROD likes this.
  6. If you want to set the resistance for ALL glowstone (meaning: not a specific block somewhere, but the block type glowstone in general), that's actually pretty straight-forward. There is a method to set explosion resistance for a block type (independently from its strength, which affects how long it takes to mine). It's only used in the static initializer of the NMS block class to give all the blocks their values.

    I'm not 100% sure if it's that method I mean, but I think in CraftBukkit it is called b(float f). Even though the block types are public, that method is protected, so it would still require hacking into it with reflection.
    And since the method is a simple setter, you can then just directly modify the "durability" attribute - it is less likely to change name as well.

    Code:
    Field f = Block.class.getDeclaredField("durability");
    f.setAccessible(true);
    f.set(Block.GLOWSTONE, <your durability>F); // make sure it's a float
    Written from the top of my head, but I think it would work.
    (Obviously, "Block" isn't the bukkit API thingy, but net.minecraft.server.Block, so you need to compile against craftbukkit)
     
  7. Offline

    Zachster

    Ok That makes sense but modifying the durability, won't that modify the strength too?
     
  8. No. What is named "durability" in bukkit is called "blockResistance" when deobfuscating the client/server with MCP (and the respective method: setResistance(float)). There is another property called "blockHardness" (in bukkit: "strength", setter method in MCP: setHardness(float)), which is responsible for how long the block takes to mine.

    "setHardness" also sets the resistance, by the way (to 5 * blockHardness). Many blocks override that default value to provide a different ratio, though, and you can do that as well (as previously described).
     
  9. Offline

    Zachster

    Ty. I've worked with mcp before as you can see by my avatar. Now what is the durability of obsidian?
     
  10. It's in NMS Block.java:

    Code:
        public static final Block OBSIDIAN = (new BlockObsidian(49, 37)).c(50.0F).b(2000.0F).a(h).a("obsidian");
    So the resistance/durability is 2000.
     
Thread Status:
Not open for further replies.

Share This Page