#how to add Tooltips to multiple items?

1 messages · Page 1 of 1 (latest)

chilly dagger
#

I want to add the same text to several different items, I know there is a way but I haven't figured out how yet, an example of this is removing recipes:

function removeItem(banana) {
  onEvent('recipes', event => {
      event.remove({output: banana})
  })
}
removeItem('avaritia:iron_singularity');
removeItem('avaritia:copper_singularity');
removeItem('avaritia:diamond_singularity');
removeItem('avaritia:emerald_singularity');
removeItem('avaritia:gold_singularity');
removeItem('avaritia:iridium_singularity');
removeItem('avaritia:lapis_singularity');
removeItem('avaritia:lead_singularity');
removeItem('avaritia:nickel_singularity');
removeItem('avaritia:platinum_singularity');
removeItem('avaritia:quartz_singularity');
removeItem('avaritia:redstone_singularity');
removeItem('avaritia:silver_singularity');
removeItem('avaritia:tin_singularity');
removeItem('avaritia:infinity_hoe');
removeItem('avaritia:infinity_pickaxe');
removeItem('avaritia:infinity_shovel');
removeItem('avaritia:infinity_axe');```
Could someone give me an example of how to do this but instead of removing recipe, add text?
unkempt flareBOT
#

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

twilit mirage
#

one way to do is to have an array and do forEach() on it

onEvent('item.tooltip', tooltip => { 
    const unobtainables = [
        'quark:potato_crate',
        'quark:carrot_crate',
        'quark:beetroot_crate',

        'sculpt:dripstone_stairs',
        'sculpt:dripstone_slab',
        'sculpt:dripstone_wall',

        'quark:bonded_leather',

        'create_dd:coal_piece',

        'create_connected:copycat_block',
        'create_dd:copycat_slab'
        
    ].forEach(item => { tooltip.add(item, Text.red('Unobtainable')) })
})
#

and if you can fill/get that array by filtering instead of manually that's even better, probably by using regexp looking at your list

twilit mirage
proper kernel
#

IIRC, you don't need to, it accepts an array directly

#

also @chilly dagger you are creating a ton of same events, that is not good

#

you should make your code better

chilly dagger
#
    // Add tooltip to all of these items
    tooltip.add([
        'avaritia:infinity_hoe', 
        'avaritia:infinity_pickaxe', 
        'avaritia:infinity_shovel', 
        'avaritia:infinity_axe'
    ], Text.red('BANIDO'))
})```
I got it, thank you! in the Client Scripts folder
chilly dagger
midnight lion
#

and then you could put the array in startup scripts with global, so that it could be accessed from all script types

#

??tips

cobalt flintBOT
# midnight lion ??tips

How to use global?
global is an object accessible in all types of scripts.
It's useful if you want to use a variable between all script types.
Here's a basic example:

global.myVariable = 5
console.log(global.myVariable + 8) //13

Note that you can't define them using let or const.

let global.myVariable = 5 //this will result an error
chilly dagger
#

Did I make any progress?

midnight lion
#

... not really

#
// startup
global.unobtainables = [
    'avaritia:infinity_hoe', 
    'avaritia:infinity_pickaxe', 
    'avaritia:infinity_shovel', 
    'avaritia:infinity_axe'
]
// server
onEvent('recipes', e => {
    global.unobtainables.forEach(i => e.remove({ output: i}))
})
// client
onEvent('item.tooltip', tooltip => {
    tooltip.add(global.unobtainables, Text.red('BANIDO'))
})
chilly dagger
#

I'm starting out with Kubejs, I still don't understand these server/client/startup folder divisions, I need to delve deeper to understand

cobalt flintBOT
#

Please close your ticket (with </ticket close:1054771505520717835> or the button atop this thread) once you resolved your issue! This also helps others that would like to help out, as they don't have to look into this thread to check if it has been resolved by now.

Do you have any other questions regarding your issue? Feel free to ask!
Note: You generally should create a new post for unrelated issues.