#Right-Click, Consume Item

85 messages · Page 1 of 1 (latest)

uncut island
#

I run a server with, among many other thins, enhanced celestials. I made a token that I want to use to start blue moons. I already wrote a function that sets the time to the beginning of night, then starts a blue moon. I also have it so that the item executes the function via right-click. I was wondering what the easiest way would be to get the item to disappear after being used, and also to only be usable in the overworld.

lofty houndBOT
#

Once your ticket has been resolved, please close it with </ticket close:1054771505520717835> command!

uncut island
#

ItemEvents.rightClicked("kubejs:celestial_token",event=> event.server.runCommandSilent("function nivs:bluemoon") )

#

I have tried a few things to get it to get rid of the item, but I haven't gotten any to work, and I guess I don't know where to start to get it to only work in the overworld

paper eagle
#
event.item.count--```
uncut island
#

would that delete the whole stack? Or do I set the count to something like -1?

manic basin
#

-1

uncut island
#

ayyy, im starting to get it 😄 thanks

#

any ideas for making it only work in the overworld?

paper eagle
#
if (event.level.dimension == "minecraft:overworld")```
uncut island
#

huh, thats somehow both simpler than I anticipated, yet about as simple as I should have expected it to be

#

code is funny that way, im still rather fresh into this, thanks a bunch

#

ItemEvents.rightClicked("kubejs:celestial_token",event=> event.server.runCommandSilent("function nivs:bluemoon"), event.item.count(-1) )

#

does it matter where I put the 'if', phrase?

paper eagle
#

whered you get .count(number) from?

manic basin
#

not count(-1)^^
just like this:

ItemEvents.rightClicked("kubejs:celestial_token", event => {
    if (!event.level.dimension == "minecraft:overworld") return
    event.server.runCommandSilent("function nivs:bluemoon")
    event.item.count--
})
paper eagle
#

its count--

#

actually it'd be like js if (event.level.dimension != "minecraft:overworld") return

manic basin
#

it should works booth way^^

paper eagle
#

what no

#

doing !event.level.dimension would default to (event.level.dimension == undefined)

#

then you'd be detecting if undefined equals "minecraft:overworld"

uncut island
#

okay, that makes sense to me, thanks a bunch, I tried to figure this out for like 2 hours last night, and while I'm proud of how far I got by myself, it would have taken me A WHILE to get this far alone.

#

learning is a process lmao

#

thanks again

lofty houndBOT
#

Ticket re-opened!

uncut island
#

sorry to be a bother, but I have tried like 20 different ways and clearly something is going over my head

#

if I also wanted this to play a sound, would this be correct?

#

ItemEvents.rightClicked("kubejs:celestial_token", event => { if (!event.level.dimension == "minecraft:overworld") return event.server.runCommandSilent("function nivs:bluemoon") event.item.count-- player.playSound("block.amethyst_block.step", 1.0, 1.0) })

paper eagle
#

like i said before his implementation is wrong

uncut island
#

oh, that part was working fine, but I can update it regardless in case it is causuing issues down the line

hasty tangleBOT
paper eagle
#

does nothing

#

it should be not consuming the diamond if you're in the nether for example @uncut island

uncut island
#

oh, you know what, dont htink i remembered to even check other dimensions when I said it was working the other way, I was just excited they were consuming properly in the overworld and didnt fully test

#

ItemEvents.rightClicked("kubejs:celestial_token", event => { if (event.level.dimension != "minecraft:overworld") return event.server.runCommandSilent("function nivs:bluemoon") event.item.count-- player.level.playSound(null, entity.x, entity.y, entity.z, 'minecraft:block.amethyst_block.step', 'block', 1, 0.5);

#

does the "null" need to be replaced with something specific?

paper eagle
#

thats the player, it should be null so it plays wherever the set coordinates are

#

its weird logic i know heh

uncut island
#

I mean, thats the "cool" thing about this stuff, its weird, but there is a method to the madness

#

I will know the method eventually >.<

hasty tangleBOT
#

Paste version of item_events.js from @uncut island

uncut island
#

well thats the whole file, is that pooking proper? because I still don't hear anything

paper eagle
#

hmm

#

entity isnt defined

#

should be event.entity

#

you can also define it at the start of the event with js let entity = event.entity

uncut island
hasty tangleBOT
#

Paste version of item_events.js from @uncut island

uncut island
#

still silent 😦

paper eagle
paper eagle
#

if it doesnt connect to event keyword somehow its probably undefined

uncut island
#

I see, what is the best way to define it?

paper eagle
#

event.player

uncut island
#

huh, that would make sense wouldnt it

#

XD

hasty tangleBOT
#

Paste version of item_events.js from @uncut island

uncut island
#

bah, still silent lmao

#

I expected this to be the easy part DX, was just gonna be icing on the cake after getting the rest going

#

thanks for bearing with me though

paper eagle
#

??kjslogs

hasty tangleBOT
# paper eagle ??kjslogs

You can find your KubeJS server log in /minecraft/logs/kubejs/server.log.
If you are on 1.18 or 1.16 it will be called server.txt.
Please send it if asked, as it contains helpful information.

paper eagle
#

send me that

uncut island
hasty tangleBOT
#

Paste version of server.log from @uncut island

uncut island
#

I could clean that up, im in a test instance and some of that is clutter from other things I had tested

paper eagle
#

ah its blocks not block

#
    event.player.level.playSound(null, event.entity.x, event.entity.y, event.entity.z, "minecraft:block.amethyst_block.step", "blocks", 1, 0.5);
#

you were close

uncut island
#

this is not the first time I have gotten incredibly close, then messed up the easy part lmao. I fixed it, am gonna test now

#

YES

#

Well, sorry about wasting that last bit of time from a simple typo, but if its any consolation, I think I learned a bit from the resulting discussion

paper eagle
#

nah you're good, glad its working now 🙂

#

we all start somewhere

uncut island
#

thanks a million, the server I host is pretty small, but I'm sure everyone will be very excited at the new stuff

#

❤️