#Prevent entity.item.pickup sound when picking up custom item

24 messages · Page 1 of 1 (latest)

tight stream
#

Here is the working pickup sound script :

onEvent('item.pickup', event => { if (event.item != "kubejs:banana") return event.server.runCommandSilent(playsound kubejs:banana player @a ${event.player.x} ${event.player.y} ${event.player.z} 1) })

Is there any way to prevent the classic minecraft "plop" pickup sound so that the two sounds do not overlap?

long oracleBOT
#

Once your question has been answered, please close this post with </resolve:1050379261372006400> command!

wind canopy
#

you could try /stopsound

tight stream
#
onEvent('item.pickup', event => {
        if (event.item != "kubejs:banana") return
        event.server.runCommandSilent(`stopsound entity.item.pickup player @a ${event.player.x} ${event.player.y} ${event.player.z} 1`)
        event.server.runCommandSilent(`playsound kubejs:banana player @a ${event.player.x} ${event.player.y} ${event.player.z} 1`)
})

Does not seem to work sadly.

slow gobletBOT
#

You can write your code in a codeblock by typing it between the codeblock delimiters:
```js
onEvent('recipes', e => {
e.smelting('minecraft:glass', '#forge:sand').xp(.1)
})
```
As an example, this will look like such:

onEvent('recipes', e => {
  e.smelting('minecraft:glass', '#forge:sand').xp(.1)
})
wind canopy
#

if you put your code inside three backticks you can hane single backticks in the code body without issue btw

tight stream
#

Thank you for the tip :)!

wind canopy
#

you could try delay the sound cancellation by a tick

#
event.server.scheduleInTicks(1, c => {
  event.server.runCommand(`blah`)
})
tight stream
#

Like so?

onEvent('item.pickup', event => {
        if (event.item != "kubejs:banana_coin") return
        event.server.scheduleInTicks(1, c => {
             event.server.runCommand(`stopsound entity.item.pickup player @a ${event.player.x} ${event.player.y} ${event.player.z} 1`)
                })
        event.server.runCommandSilent(`playsound kubejs:banana_coin player @a ${event.player.x} ${event.player.y} ${event.player.z} 1`)
})

Did not work either.

kind pagoda
#

the scheduling callback no longer has access to event i believe

wind canopy
#

it does

kind pagoda
#

oh it does?

#

nvm

wind canopy
kind pagoda
#

wait that's really weird

kind pagoda
#

stopsound ${event.player} player kubejs:banana_coin

tight stream
#

Tried the correct stopsound command and it doesn't work either.

onEvent('item.pickup', event => {
        if (event.item != "kubejs:banana") return
        event.server.scheduleInTicks(1, c => {
            event.server.runCommand(`stopsound @a player minecraft:entity.item.pickup`)
                })
        event.server.runCommand(`playsound kubejs:banana player @a ${event.player.x} ${event.player.y} ${event.player.z} 1`)
})

Might no be possible

kind pagoda
#

you can also use * as the source and/or set the timeout to 2 or 3

tight stream
#

Just to confirm, tried multiple times and the solution ended up setting the timeout at anything under 1 (eg. 0.5).

For anyone looking at this in the future, this solution prevents the pickup sound from playing:

onEvent('item.pickup', event => {
        if (event.item != "kubejs:banana") return
        event.server.scheduleInTicks(0.5, c => {
            event.server.runCommand(`stopsound ${event.player} player minecraft:entity.item.pickup`)
                })
        event.server.runCommand(`playsound kubejs:banana player @a ${event.player.x} ${event.player.y} ${event.player.z} 1`)
})