Solved Change break speed

Discussion in 'Spigot Plugin Development' started by SickSkillz, May 16, 2016.

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

    Supporter

    how can I change the break time of skulls(in Java of course)?
     
  2. I'm not 100% sure, but once i've changed one value in the nmsBlock class so mining a block takes longer.
    I don't have the code anymore, but it could be that it was the integer field "durability" (could be different by now) in the nms class.
    I recommend decompiling the class or at least get a list of all declared fieldsand if "durability" is not present, maybe try another value.
    By already talkung about nms and fields, you must use reflection to change the value.
     
    • Agree Agree x 1
  3. Just kinda took a quick peek, and the two variables that seem to affect this is
    protected float strength;
    protected float durability;

    This is in 1.9.4
     
  4. SickSkillz

    Supporter

  5. I just met myself.
     
    • Like Like x 3
  6. SickSkillz

    Supporter

    ????
     
  7. I've no idea if this will work but you can try it if you want. *for 1.9.4
    Code (Text):

        try {
           java.lang.reflect.Field field = net.minecraft.server.v1_9_R2.Block.class.getDeclaredField("strength");
           field.setAccessible(true);
           field.setFloat(net.minecraft.server.v1_9_R2.Blocks.BED, 50.0F);
         } catch (Exception ex) {
           ex.printStackTrace();
         }
     
    EDIT: Removed "#getClass()" from BED. No idea why I added it to begin with.
     
    #7 NinjaStix, May 16, 2016
    Last edited: May 16, 2016
  8. same (very alike) skin / profile pic.
     
  9. It's possible to do, but only with NMS code (meaning it's not a bukkit API, but in the vanilla minecraft code). If you want to change it, simply do this:
    Code (Text):
    Field field=net.minecraft.server.Block.class.getDeclaredField("strength");
    field.setAccessible(true);
    field.setFloat(net.minecraft.server.Block.BED, 50.0F);
    This would mean that it would take as long time to break a Bed as it takes to break an obsidian.
     
  10. SickSkillz

    Supporter

    But if I change BED to SKULL I get an error(same with all blocks)
     
  11. You shouldn't be, what is the error? Show code.
     
  12. SickSkillz

    Supporter

    I didn't saw this reply but this one works for me. Thanks :)
     
    • Like Like x 1
  13. SickSkillz

    Supporter

    I marked this is resolved a bit too fast but if I place a skull(yes I did it with skulls) it's breaking at it's normal time. Do I need to put this in onEnable or in an Event or anything?
     
  14. I would put it in onEnable()
     
  15. SickSkillz

    Supporter

    If I do that skulls doesn't break faster
     
  16. Yeah I am testing this too and it doesn't seem to affect the break speed. They only thing that happens is if I set it too high it doesn't break anymore and it's instead replaced with a skeleton skull.
     
  17. Okay so this seems to make the skull break instantly, even by hand.
    Code (Text):

        try {
           java.lang.reflect.Field field = net.minecraft.server.v1_9_R2.Block.class.getDeclaredField("strength");
           field.setAccessible(true);
           field.setFloat(net.minecraft.server.v1_9_R2.Blocks.SKULL, Material.SKULL.getMaxDurability() / 4);
         } catch (Exception ex) {
           ex.printStackTrace();
         }
     
    NOTE: The original value of strength for the skull block is 1.0F
     
  18. Okay so Material.SKULL.getMaxDurability() actually returns 0 :p so 0 / 4 = 0 .... I am thinking you want to set the strength to a very low value.

    EDIT: Sorry for the multiple posts... :oops:
     
    • Agree Agree x 1
  19. SickSkillz

    Supporter

    Yup you're right. going to test now
     
  20. It seems there is a threshold between normal break speed and instant break, with nothing in between. o_O I'll try to take a closer look at the code and see if I can try to understand what is going on, and possibly find a real solution. If you have not yet that is.
     
Thread Status:
Not open for further replies.