#custom item use

31 messages · Page 1 of 1 (latest)

agile crystalBOT
#

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

coral pier
#

event.item.count-- if event.item exists

coral pier
#
StartupEvents.registry('item', e => {
    e.create('ominous_potion')
        .texture('kubejs:item/ominous_potion')
        .rarity('uncommon')
        .displayName('Ominous Bottle')
        .tooltip('§9Bad Omen +1 \(∞\)')
        .maxStackSize(16)
        .useAnimation("drink")
        .useDuration(item => 32)
        .use(hand => true)
        .finishUsing((itemstack, level, entity) => {
            itemstack.count--
            return itemstack
        })
})
coral pier
#
level.runCommandSilent(`playsound soundhere block ${entity.displayName.string} ${Math.round(entity.x)} ${Math.round(entity.y)} ${Math.round(entity.z)} volumehere pitchhere`)
  })
}
#

yeah

#

one of many ways to create a function

function myFunction(){
  //code
}

to call this function:

myFunction()
#

then it's just global.funcOminousPotionEffects()

dreamy quest
#

whats that

#

and

cobalt mapleBOT
#

You can write your code in a codeblock by typing it between the codeblock delimiters:
Note that these are backticks, not apostrophes

```js :arrow_left:

ServerEvents.recipes(event => {
event.smelting('minecraft:glass', '#forge:sand').xp(.1)
})

``` :arrow_left:

This example will look like this:

ServerEvents.recipes(event => {
  event.smelting('minecraft:glass', '#forge:sand').xp(.1)
})
dreamy quest
#

and how do you get the level from nothing

#
player.level //get level from player
level //can't get level from nothing
#

and if you want to test the code, you can add some

Utils.server.tell('hi')

into the code, so you can know where it stops

#
global.funcOminousPotionEffects = ctx => {
    const player = ctx.player;
    Utils.server.tell('1')
    player.level.runCommandSilent(`playsound block.glass.break player @a ${Math.round(entity.x)} ${Math.round(entity.y)} ${Math.round(entity.z)}`)

    if(!player.hasEffect('minecraft:bad_omen')) {
            Utils.server.tell('2.1')
        player.potionEffects.add('minecraft:bad_omen', -1, 0);
        return;
    }

    const amp = player.getEffect('minecraft:bad_omen').amplifier
    if(amp >= 4) {
            Utils.server.tell('2.2')
player.potionEffects.add('minecraft:bad_omen', -1, 3)
        return;
    }
    player.potionEffects.add('minecraft:bad_omen', -1, amp + 1)
}
cobalt mapleBOT
#

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.

dreamy quest
#

if something's not working, there will be error message

#

most of the time

cobalt mapleBOT
#

Paste version of startup.log, server.log from @sacred ledge

dreamy quest
#

then probably it didn't pass the if statement

#

send your code with that test message in(Utils.server.tell(...))

#

it should work, send the code of item registery

#

maybe the problem goes there

#

a screenshot is also acceptable

#

oh, you returned it early

#
        .finishUsing((itemstack, level, entity) => {
            itemstack.count--
           global.funcOminousPotionEffects(ctx)
            return itemstack
        })
#

return stops the script from its line

#

if(!entity.isCreative()) itemstack.count--

#

if entity isn't in creative mode, decrease the count

dreamy quest
#
StartupEvents.registry('item', e => {
    e.create('ominous_potion')
        .texture('kubejs:item/ominous_potion')
        .rarity('uncommon')
        .displayName('Ominous Bottle')
        .tooltip('§9Bad Omen +1 \(∞\)')
        .maxStackSize(16)
        .useAnimation("drink")
        .useDuration(item => 32)
        .use(hand => true)
        .finishUsing((itemstack, level, entity) => {
            itemstack.count--
            global.funcOminousPotionEffects(entity) //pass the entity to function
            return itemstack

        })
})
#
global.funcOminousPotionEffects = entity => {
    const player = entity;
    Utils.server.tell('1')
    player.level.runCommandSilent(`playsound block.glass.break player @a ${Math.round(entity.x)} ${Math.round(entity.y)} ${Math.round(entity.z)}`)

    if(!player.hasEffect('minecraft:bad_omen')) {
            Utils.server.tell('2.1')
        player.potionEffects.add('minecraft:bad_omen', -1, 0);
        return;
    }

    const amp = player.getEffect('minecraft:bad_omen').amplifier
    if(amp >= 4) {
            Utils.server.tell('2.2')
player.potionEffects.add('minecraft:bad_omen', -1, 3)
        return;
    }
    player.potionEffects.add('minecraft:bad_omen', -1, amp + 1)
}
#

ctx is for other places