Changing item durability in Minecraft's database

Discussion in 'Plugin Development' started by Allov, Feb 22, 2012.

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

    Allov

    Hi,

    Perhaps there's a mod for this already, but I've got no luck with my searches so far. Is there any way to change items durability overall, permanently in the Minecraft's database? What I mean by this is, I don't want to track every event and existing items in chests and player's inventory to call item.setDurability(), I just want to change it directly for ALL of the items.

    So, if there's a mod for this, what's the technic they're using? Or, what would be the best way to approach this problem.

    Thanks!
     
  2. Offline

    Shamebot

    Try this:
    Code:java
    1. void setDurability(Material mat, int newDurability)
    2. {
    3. if(!mat.isBlock())
    4. {
    5. net.minecraft.server.Item nmsItem = net.minecraft.server.Item.byId[mat.getId()];
    6. Field field = net.minecraft.server.Item.class.getDeclaredField("durability");
    7. field.setAccessible(true);
    8. field.setInt(nmsItem, newDurability);
    9. }
    10. }

    you'll need to import craftbukkit.
     
    Allov likes this.
  3. Offline

    Allov

    Hi, thanks! It seems to work, but it doesn't seem to update on the client side. Do you think it's using the local database for item durability on client side?

    Thanks again
     
  4. Offline

    Shamebot

    Probably. Try a player.updateInventory() every minute or so.
     
Thread Status:
Not open for further replies.

Share This Page