Random Item Tick in inventory

Started by baileywithaw on

Topic category: Help with modding (Java Edition)

Last seen on 02:46, 15. Jul 2024
Joined Nov 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Random Item Tick in inventory

So I'm trying to make a phone item that randomly rings when in the players inventory, but having a "wait random tick then play sound" procedure will indefinitely play sounds after some time. How do I make it play once and restart the wait random ticks?

Last seen on 17:49, 7. Sep 2024
Joined Apr 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
One possibility is to use an…
Tue, 07/09/2024 - 15:43

One possibility is to use an if block that is something like:

[if[[random 0,1]<[0.001]]]

     do [your procedure]

 

Instead of using the wait block, which does not pause the procedure from working.

The option I offered is a simple method that does a random delay, by simply randomizing when it happens.

If you want a more complex system with more control, you could do something with the item's NBT data, checking if NBT number value "timer" is greater than 0, setting "timer" to "timer" - 1 if it is. Else do your procedure to play the sound, then set timer to a random number within the range you want for the wait block.

The first option is purely random, the second is a little more complicated but has more control, neither of them use the built-in wait block as it acts as a delay for the current procedure, but does not stop the procedure from running again in the next tick, and the next.

I hope this helps.

Last seen on 02:46, 15. Jul 2024
Joined Nov 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
YES! that works perfectly!!…
Tue, 07/09/2024 - 23:26

YES! that works perfectly!! thank you!