Started by
SHORT
on
Topic category: Help with Minecraft modding (Java Edition)
The title explains almost everything:
-
The sound keeps repeating itself all the time.
-
The item is of my creation.
-
I tried to make one solution with a "do" repeating it once, but it didn't work.
I would suggest a Number NBT tag for the item, then have a IF statement that says
NBT Variable += NBT Variable + 1
IF NBT Variable >= # (convert the length of your sound to ticks and use that number.) {
Play Sound
Set NBT Variable = 0
}
That way the sound will play, then wait for your tick to be >= to your sound length (in ticks, if sound is 3 seconds then its 60 ticks, 1 second = 20ticks) Also this is dependant on your procedure being used with a Update TIck Trigger, So that your NBT Variable will increment.
I tried doing it, but it didn't work. So I thought if I created 2 variables being time and quantity (that had selected the item) it would work, but it's not working.
And my trigger is on item (Item In Hand Tick)
Okay, so Firstly switch out the "Provided Itemstack" blocks with "Item in main hand" blocks. Since your item is on a Update Tick trigger (Item in hand Tick), which is ran every tick while the item is in your hand, then the line Set quantity to = 0 will be ran constantly, therefore not allowing your other line that sets it to 1, to actually trigger. As for the set time to += time + number from text. Is there a particular reason your using number from text with formatter? If not then change out the "number from text" with just a normal number block and set it to 1, so that it increments by 1 every tick while the item is in your hand. I'll check back on this post in a bit and see if you've worked it out.
It should look like this
and for clarity NBT variables do not need to be initialized if they are meant to start at 0 , because they will start at 0 anyways.
This will create a loop and does need to await 14.44 ticks to execute…
Okay, remember 1 second converted into ticks is 20 ticks, your sound is less then 1 second so it will appear to be looping/overlapping, so add some ticks to it, to allow for a small wait, I just tested out the code I sent you and it works fine.
On a side note I just made a Discord server if your interested, No Mic required. It would be much easier to debug this
Here is a link: https://discord.gg/afT5NR7Rje
If anyone else needs/wants help and is interested feel free to join the channel.
For anyone else who would like to know how to play a sound when a player puts the item in their "Main Hand"
Here's how
ITEM TRIGGERS
ITEM IN HAND TICK
ITEM IN INVENTORY TICK