How can I make a weapon that doesn't break when its durability is depleted?

Started by Ion99 on

Topic category: Help with modding (Java Edition)

Last seen on 17:54, 17. Sep 2023
Joined Aug 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
How can I make a weapon that doesn't break when its durability is depleted?

First of all, before anyone comments "just set the durability to zero," no, that's not what I want. I want a melee weapon with very limited durability that still stays in your inventory when it breaks, and you just can't use it until the durability is replenished or "reloaded" with a certain item by hitting a key (I kinda know how keybinds work) with the weapon in your hand, which depletes the count of said specific item by one, and in turn heals the durability of the weapon by one.

I really hope I can get some help in order to achieve something at least remotely similar to this idea. Anything's appreciated, thanks.

Last seen on 20:43, 20. Aug 2024
Joined May 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Make a procedure for the…
Mon, 10/02/2023 - 10:50

Make a procedure for the object that, when its durability is at 1, (or some other low value), the item is swapped out with a 'damaged' variant of that item. (Making sure to retain the name, enchantments, NBT data, etc.) Then when the keybind is pressed, just swap it out again. I use this system for reloadable weapons, and it works pretty well. (Though retaining custom data between items can be somewhat tricky, and you need to check that the item is named before transferring names; otherwise it'll italicize the item's name the first time it's reloaded, which isn't the end of the world, but is slightly annoying. You can check if the display name equals the registry name of the item to get around this.)