How do I make it so a item loses durability over time

Started by Mr Beard Man Dude on

Topic category: Help with modding (Java Edition)

Last seen on 19:50, 25. Aug 2024
Joined Aug 2024
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
How do I make it so a item loses durability over time
Sun, 08/25/2024 - 06:00 (edited)

I'm making a mod and I want an item to lose durability (1 every second) anytime it is in hand
Can anybody help?

I tried doing
(every wait 20 server ticks then deal 1 damage to item stack)
and it kinda works but whenever you hover over it the durability goes down drastically (removing durability every tick and not every second). sure I could keep this but I feel like it would be annoying to check how much durability is left (with advanced tooltips)

Edited by Mr Beard Man Dude on Sun, 08/25/2024 - 06:00
Last seen on 13:38, 27. Aug 2024
Joined Jan 2024
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
try to use  wait - ticks…
Sun, 08/25/2024 - 20:01

try to use 

wait - ticks then on server side 

do: every wait 20 server ticks then deal 1 damage to item stack

(u can find wait - ticks then on server side  block in flow control tab on very down of it)

Hope i helped =)

Last seen on 20:25, 12. Sep 2024
Joined Apr 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I just want to point out…
Sun, 08/25/2024 - 21:48

I just want to point out that the 'wait - ticks then on server side' does not make timers, it pauses the current procedure, but does not stop it from running again.

This isn't very obvious in the interface at first, but I will try to explain it.

If you have a procedure that runs once, such as when it item is used, and you wait 20 ticks, the procedure will happen once after a second.

However, for a procedure that runs every tick, such as on item in hand tick, it will run the procedure 20 times per second, and if you wait for 20 ticks, it will start repeating 20 times per second, it will just be delayed in when it starts.

To put it differently, a procedure will run regardless of whether or not there is already a procedure running with a wait block, every tick will still run every tick, it will just have a delay for when it starts and stops running, but it will run constantly between the start and stop.

If you want to reduce the frequency, you can use an NBT tag-based timer, a variable-based timer, or simply use the 'do with 70% chance' procedure template but change 0.7 to be 0.05 for an average of once per second. For the timers, you should be able to find something that works fairly easily if you search for them.