#how do I differentiate between enchanting books

39 messages · Page 1 of 1 (latest)

nocturne void
#

Every enchantment has the same itemid so how do I differentiate between them ?

dense solarBOT
#

Paste version of enchantLore.js from @nocturne void

wraith ibex
#

enchantment books are nbt data I believe

vivid carbon
#

Yep they are NBT. So a give command would be:
minecraft:enchanted_book{StoredEnchantments: "minecraft:sharpness", lvl: 10}

The lvl can be a short number I think

nocturne void
#

well i would work with the /give cmd but it dosent work in kubejs

vivid carbon
#

So it does kind of. The command is just the root of what you would use in KJS

Instead you would use a method:

Item.of('minecraft:enchanted_book').enchant('minecraft:sharpness', 5)
nocturne void
#

i already found out about that bc of the /kubejs hand cmd but it didnt work either but i will test it again real quick

#

all it did was giving every enchanted book the tooltip the same as the above ...

vivid carbon
#

Wait, what's the end goal?

nocturne void
#

i want to give every enchant a different tooltip

proper moss
#

you need to use .addAdvanced() for nbt sensitivity at all

#
    event.addAdvanced(Item.of('minecraft:enchanted_book'), (stack, adv, text) => {
        stack.nbt.StoredEnchantments.forEach((enchant) => {
            if(enchant.id == 'minecraft:mending'){
                text.add(Text.of('Quark\'s Mending Nerf is enabled! Items will not repair by absorbing XP!').color('#E66232'))
            }
        })
    })```
here's an example of what i did to add a tooltip to mending
however, this can be done in a *MUCH* more efficient and universal way, by concating strings and using localization
#
event.addAdvanced(Item.of('minecraft:enchanted_book'), (stack, adv, text) => {
  stack.nbt.StoredEnchantments.forEach((enchant) => {
    let key = `modpack.enchantment.${enchant}.info`;
    if(Text.translate(key) != key) text.add(Text.translate(key));
  })
})```
if i'm not being stupid, this should allow you to add new language keys to add tooltips, and it should simply not display them if the language key has no localized version
nocturne void
#

well previously I used the tooltip event.. should I switch to a client.init , logged or tick event ?

#

its fine found exactly what i needed in old example scripts

#

thank u for ur help

nocturne void
#

but I do wonder... Where can I get Information abaut the methods like addAdvanced() or stack.nbt.StoredEn... ?

#

Im new to kubejs well js in general so I hope u can help me

proper moss
#

kjs wiki(s), reading the source code, or using probejs

dense solarBOT
#

You can make custom items with KubeJS, and the wiki has a page on them!

#

ProbeJS is an addon mod for KubeJS that generates typings files for VSCode, allowing VSCode to offer autocompletions for a ton of things!

Mod by @unreal oriole

proper moss
nocturne void
#

i tried using probe but i cant do the /probejs dump cmd

proud mistBOT
#

@nocturne void Unresolved thread still hasn't been closed! If your question was answered, please close this post with </ticket close:1054771505520717835> command!

proud mistBOT
#

@nocturne void Unresolved thread still hasn't been closed! If your question was answered, please close this post with </ticket close:1054771505520717835> command!

proud mistBOT
#

Ticket closed!

loud arrow
#

Why is this post not closing AAAAAAAAAAAAAAAA

loud arrow
#

@fossil isle example of a post not closing, no matter how i try it

#

manually closing just revives the bot to ping the person instead

fossil isle
#

ooh I see why

#

because its super old

#

and doesnt have tags

#

it can't have 0 tags

#

smh @ op who didnt add mc version/loader

loud arrow
#

lets try now