#Item interaction event

39 messages · Page 1 of 1 (latest)

lusty hill
#

Hi, I'm very new to modding, and only have a little bit of experience coding in general, so maybe a stupid question:

when creating an interaction event for a custom item, do you create the event in the startup script for the item creation, or do you create the interaction in a server script and reference it in item creation?

I'm trying to set up an event where player uses item, it causes player instant damage, and is replaced with a new item. I have this in the startup script. The item loads, and the use animation works, but at the end of the use duration, the game crashes, so I must have it wrong somewhere.

viral pathBOT
#

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

lusty hill
#

For reference, here is the startup script:

#

event.create('dark_fragment').displayName('Dark Fragment')
.useAnimation('bow')
.useDuration(itemStack => 64)
.use((level, player, hand) => true)
.finishUsing((itemstack, level, entity) => {
entity.mobEffects("minecraft:instant_damage", 4)
itemstack.itemStack.shrink(1)
if (entity.player) {
entity.minecraftPlayer.addItem(Item.of('kubejs:item/imbued_fragment').itemStack)
}
return itemstack
})

dusk tulip
#
entity.give('kubejs:item/imbued_fragment')
lusty hill
#

definitely simplifies that line, but crash still happens after use duration 😅

blazing karmaBOT
#

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

dusk tulip
#
entity.potionEffects.add("minecraft:instant_damage", tick, amplifier, true, false)
lusty hill
#

is there somewhere I can see the list of these effects so I know what I want the tick, amplifier, and those last two booleans to be?

dusk tulip
lusty hill
#

okay, so now new error: Cannot call method "shrink" of undefined (startup_scripts:items.js#26)

#

(thank you for the help btw)

#

oh maybe it's because I only have the one item in the stack and it can't shrink to a null stack?

dusk tulip
#

item.count--

lusty hill
#

would it be itemstack.item.count-- ?

dusk tulip
#

oh, yup

#

itemstack.count--

lusty hill
#

okay, so now everything works except the give

#

maybe it needs a count

#

count does not seem to be the answer:

Error: dev.latvian.mods.rhino.EvaluatorException: Can't find method dev.latvian.mods.kubejs.core.PlayerKJS.kjs$give(string,number). (startup_scripts:items.js#28)

dusk tulip
#

no, it only accepts a string

#

.give('4x kubejs:item/imbued_fragment)

lusty hill
#

okay so I have it as

.finishUsing((itemstack, level, entity) => {
entity.potionEffects.add("minecraft:instant_damage", 1, 1, false, false)
itemstack.count--
entity.give('1x kubejs:item/imbued_fragment')

})
#

and give still isn't giving

dusk tulip
#

error?

lusty hill
#

no crash, just no item

dusk tulip
#

no, i mean something in log

blazing karmaBOT
lusty hill
#

[12:14:40] [INFO] Loaded script startup_scripts:example.js in 0.001 s
[12:14:40] [INFO] Loaded script startup_scripts:items.js in 0.004 s
[12:14:40] [INFO] Loaded 3/3 KubeJS startup scripts in 0.658 s with 0 errors and 0 warnings

#

no error

dusk tulip
#

where's the kubejs:item/imbued_fragment?

#

please send the full code

lusty hill
#

StartupEvents.registry('item', event => {
event.create('profane_dust').displayName('Profane Dust')

event.create('imbued_fragment').displayName('Imbued Fragement')
.texture('kubejs:item/dark_fragment')
.glow(true)

event.create('dark_fragment').displayName('Dark Fragment')
.useAnimation('bow')
.useDuration(itemStack => 64)
.use((level, player, hand) => true)
.finishUsing((itemstack, level, entity) => {
    entity.potionEffects.add("minecraft:instant_damage", 1, 1, false, false)
    itemstack.count--
    entity.give('1x kubejs:item/imbued_fragment')
    
})

})

dusk tulip
#

then it's called kubejs:imbued_fragment

#

not kubejs:item/...

lusty hill
#

ahh okay that works

#

thank you so much

dusk tulip