#Its possible to create item with custom nbt?
289 messages · Page 1 of 1 (latest)
Once your ticket has been resolved, please close it with </ticket close:1054771505520717835> command!
No
NBT is not on the item, its on the itemstack
you can only create items
"default nbt" is only a concept where you give an item an nbt when the player obtains it
So how do I stop it when I get the item and it already comes with NBT?
you mean you want to remove the nbt?
or when player get item
i want add nbt
you use the event you need for when the player obtains it
are you just trying to set the default item model?
like loot tables, crafting, pickup etc
wat
this is the 3rd ticket I've followed up on they made
but yeah like lex said you can just give it nbt when the player obtains it tbh
how
you make it sound like theres an alternative
event to detect player get item?
me?
ye :d
i was just asking if they want to set the default model texture because it's going off nbt data
ye but i mean what i said is the only way to give an item "default" nbt
nevermind xD

ItemEvents.pickedUp is this event to detect when player get item?
you can create item with NBT using subtypes I guess
think about how the player will get the item, is it through crafting? looting? sign from god?
just like potions
crafting
for recipe is easy
I wanted the item to come with NBT even without me picking it up or getting a recipe
but if there is no way to do it then let it be
StartupEvents.registry('item', event => {
event.create('kubejs:circuit_integrated')
.maxStackSize(64)
.displayName('Programmed Circuit (0)')
.subtypes(originalStack => {
let myItemList = Utils.newList()
let myNewItem = originalStack.copy()
myNewItem.nbt = {"Something": "here"}
myItemList.add(myNewItem)
return myItemList
})
.modelJson({
parent: 'kubejs:item/circuit_integrated',
textures: {
layer0: 'kubejs:item/others/circuit_integrated/1'
}})
})
this is how to use subtype
and now
in tooltip when i create item how i do break line
with \n appear that symbol
use subtypes
with subtypes you can make all 20 items showup in JEI
do you want?
no i just want 1
is not working 😂
.subtypes(originalStack => {
let myItemList = Utils.newList()
let myNewItem = originalStack.copy()
myNewItem.nbt = { "CustomModelData": "0.0d", "Num" : "7.0d" }
myItemList.add(myNewItem)
return myItemList
})
uh
myNewItem.nbt = { CustomModelData: 0, Num : 7 }```wouldn't it be like this?
though i think uncandangos workin on it still
not sure tho
was worth a shot
without this
How do I break the line in the tooltip?
[Quote ➤](#1183236648104902716 message) and now
in tooltip when i create item how i do break line
with \n appear that symbol
you want to remove "right click to increase number" ?
ohh you want it to be one line lower?
??code
🗒️**Send the code!**🗒️
You may have an issue with a KubeJS script and you explain it to the best of your ability yet without the actual code in question we have very little to go off of in trying to assist you.
yeah that
.tooltip(['', Text.of('Right Click to increase number').gray()])
\n this put a random symbol
send the full tooltip code
ItemEvents.tooltip(event => {
let circuitItem = 'kubejs:circuit_integrated'
event.addAdvanced(circuitItem, (item, advanced, text) => {
text.add(3, [
Text.of('Right Click to increase number').gray()
])
if (!Item.exists(item?.id)) return
// Check if the item has NBT data and 'Num' property
if (item?.nbt?.Num != null) {
text.add(1, [
Text.of('Configured Value: ').green(),
Text.of(item.nbt.Num.toString()).white()
])
} else if (item?.nbt?.Num == null) {
text.add(1, [
Text.of('Configured Value: ').green(),
Text.of('0').white()
])
}
})
})
ty
try that ```js
ItemEvents.tooltip(event => {
let circuitItem = 'kubejs:circuit_integrated'
event.addAdvanced(circuitItem, (item, advanced, text) => {
text.add(3, [
Text.of(' ').gray()
])
text.add(4, [
Text.of('Right Click to increase number').gray()
])
if (!Item.exists(item?.id)) return
// Check if the item has NBT data and 'Num' property
if (item?.nbt?.Num != null) {
text.add(1, [
Text.of('Configured Value: ').green(),
Text.of(item.nbt.Num.toString()).white()
])
} else if (item?.nbt?.Num == null) {
text.add(1, [
Text.of('Configured Value: ').green(),
Text.of('0').white()
])
}
})
})```
it is lol, check Creative Tab lol
I need to findout why it is not on JEI 
oh ok
also I'm testing the .use() callback, so you don't need the item rightclicked event
nice
I'm losing my powers, not first try 😢
@rain thunder do you have create in your pack?
at startup
StartupEvents.registry('item', event => {
event.create('kubejs:circuit_integrated')
.maxStackSize(64)
.displayName("Programmed Circuit (0)")
.subtypes(originalStack => {
let myItemList = Utils.newList()
let myNewItem = originalStack.copy()
myNewItem.setNbt({CustomModelData: NBT.i(0), Num: NBT.i(0)})
myItemList.add(myNewItem)
return myItemList
})
.modelJson({
parent: 'kubejs:item/circuit_integrated',
textures: {
layer0: 'kubejs:item/others/circuit_integrated/1'
}
}).use((level, player, interactionHand) => {
let maxNumber = 20
let item = player.getItemInHand(interactionHand)
item.setNbt(item.hasNBT() ? {CustomModelData: NBT.i((item.nbt.getInt("CustomModelData") + 1) % (maxNumber + 1)), Num: NBT.i((item.nbt.getInt("Num") + 1) % (maxNumber + 1))} : {CustomModelData: NBT.i(1), Num: NBT.i(1)})
level.clientSide && player.playNotifySound("create:confirm","ambient",1,1)
item.setHoverName(Text.translate("item.kubejs.circuit_integrated_with_digits", [item.nbt.getInt("Num").toFixed(0)]).italic(false))
return true
})
})
at client + your tooltip event
ClientEvents.lang("en_us", event => {
event.add("item.kubejs.circuit_integrated_with_digits", "Programmed Circuit (%s)")
})
JEIEvents.hideItems(event => {
event.hide(Item.of("kubejs:circuit_integrated").strongNBT())
})
JEIEvents.subtypes(event => {
event.useNBT("kubejs:circuit_integrated")
})
nothing at server
also you need to fix your 18 and 20 model.json, I think numbers are swaped
no i dont
ok, change the notification sound to something else
How do I make a recipe with NBT?
I'm using an example here like this
I set it to be number 1 for the craft but the other numbers also work
ServerEvents.recipes(event => {
event.shapeless('kubejs:phenolic_circuit_board', [Item.of('kubejs:circuit_integrated', "{CustomModelData:1,Num:1}"), 'kubejs:phenolic_board'])
})
if as ingredient, add .weakNBT() at the end
still no working
in recipe not show 3 tags and just only 1
or i need to put full nbt?
i delete the displayname nbt
now it work with full nbt
event.shapeless('kubejs:phenolic_circuit_board', [
Item.of('kubejs:circuit_integrated', "{CustomModelData:10.0d,Num:10.0d,display:{Name:'[{\"text\":\"Programmed Circuit (\",\"color\":\"white\",\"italic\":\"false\"},{\"text\":\"10\",\"color\":\"white\",\"italic\":\"false\"},{\"text\":\")\",\"color\":\"white\",\"italic\":\"false\"}]'}}").weakNBT(),
'kubejs:phenolic_board'
])
but its possible to remove display from nbt?
if you are using my script, it is not double anymore, they are integer
can you try the original recipe with a new circuit?
i will try
ok thank u its work without display
now I wanted to add a feature that was
If you press shift + right click the circuit resets and stays at 0
in right clicked event
i use
if (player.isShiftKeyDown()) {
item.nbt = { Num: 0, CustomModelData: 0 }
// item.nbt.merge(`{display:{Name:'[{"text":"Programmed Circuit (0)","color":"white","italic":"false"}]'}}`)
}
inside .use() right
oh ok
yes
The only problem with your code is that I always need to close and open Minecraft, right? 😂

you can use a global function in this right?js .use((level, player, interactionHand) => { let maxNumber = 20 let item = player.getItemInHand(interactionHand) item.setNbt(item.hasNBT() ? {CustomModelData: NBT.i((item.nbt.getInt("CustomModelData") + 1) % (maxNumber + 1)), Num: NBT.i((item.nbt.getInt("Num") + 1) % (maxNumber + 1))} : {CustomModelData: NBT.i(1), Num: NBT.i(1)}) level.clientSide && player.playNotifySound("create:confirm","ambient",1,1) item.setHoverName(Text.translate("item.kubejs.circuit_integrated_with_digits", [item.nbt.getInt("Num").toFixed(0)]).italic(false)) return true })
prob can
is that what they're refreshing?
cause anything else and youd have to restart lol only in callbacks you can
I use global while I test, when it is done I just remove, hence why code don't have it

.use((level, player, interactionHand) => {
let maxNumber = 32
let item = player.getItemInHand(interactionHand)
if (player.isShiftKeyDown()) item.setNbt({ CustomModelData: NBT.i(0), Num: NBT.i(0) })
item.setNbt(item.hasNBT() ? { CustomModelData: NBT.i((item.nbt.getInt("CustomModelData") + 1) % (maxNumber + 1)), Num: NBT.i((item.nbt.getInt("Num") + 1) % (maxNumber + 1)) } : { CustomModelData: NBT.i(1), Num: NBT.i(1) })
level.clientSide && player.playNotifySound("minecraft:block.amethyst_block.place", "master", 1, 1)
item.setHoverName(Text.translate("item.kubejs.circuit_integrated_with_digits", [item.nbt.getInt("Num").toFixed(0)]).italic(false))
return true
})
when i shift click reset to number 1 and not 0
let maxNumber = 32
let item = player.getItemInHand(interactionHand)
if (player.isShiftKeyDown()) {
item.setNbt({ CustomModelData: NBT.i(0), Num: NBT.i(0) })
} else {
item.setNbt(item.hasNBT() ? { CustomModelData: NBT.i((item.nbt.getInt("CustomModelData") + 1) % (maxNumber + 1)), Num: NBT.i((item.nbt.getInt("Num") + 1) % (maxNumber + 1)) } : { CustomModelData: NBT.i(1), Num: NBT.i(1) })
level.clientSide && player.playNotifySound("minecraft:block.amethyst_block.place", "master", 1, 1)
item.setHoverName(Text.translate("item.kubejs.circuit_integrated_with_digits", [item.nbt.getInt("Num").toFixed(0)]).italic(false))
return true
}
like this?
probably, I'm on mobile can't read properly the braces
oh ok i will try
here replace your code with this ```js
/**
*
- @param {Internal.Player} player
- @returns
*/
global.programclick = player => {
//can refresh/edit this by doing /kubejs reload startup_scripts
let maxNumber = 32
let item = player.getItemInHand(interactionHand)
if (player.isShiftKeyDown()) {
item.setNbt({ CustomModelData: NBT.i(0), Num: NBT.i(0) })
} else {
item.setNbt(item.hasNBT() ? { CustomModelData: NBT.i((item.nbt.getInt("CustomModelData") + 1) % (maxNumber + 1)), Num: NBT.i((item.nbt.getInt("Num") + 1) % (maxNumber + 1)) } : { CustomModelData: NBT.i(1), Num: NBT.i(1) })
player.level.clientSide && player.playNotifySound("minecraft:block.amethyst_block.place", "master", 1, 1)
item.setHoverName(Text.translate("item.kubejs.circuit_integrated_with_digits", [item.nbt.getInt("Num").toFixed(0)]).italic(false))
return true
}
}
StartupEvents.registry('item', event => {
event.create('kubejs:circuit_integrated')
.maxStackSize(64)
.displayName("Programmed Circuit (0)")
.subtypes(originalStack => {
let myItemList = Utils.newList()
let myNewItem = originalStack.copy()
myNewItem.setNbt({ CustomModelData: NBT.i(0), Num: NBT.i(0) })
myItemList.add(myNewItem)
return myItemList
})
.modelJson({
parent: 'kubejs:item/circuit_integrated',
textures: {
layer0: 'kubejs:item/others/circuit_integrated/1'
}
}).use((level, player, interactionHand) => {
//putting the global function in here
global.programclick(player)
})
})```
then restart your game once
after that you can edit anything in that global function up top and run /kubejs reload startup_scripts to instantly reload it without having to restart the entire game
oh ok
here you can get the level off the player by putting let level = player.level at the top of the global function like this js global.programclick = player => { //can refresh this by doing /kubejs reload startup_scripts let maxNumber = 32 let item = player.getItemInHand(interactionHand) let level = player.level if (player.isShiftKeyDown()) { item.setNbt({ CustomModelData: NBT.i(0), Num: NBT.i(0) }) } else { item.setNbt(item.hasNBT() ? { CustomModelData: NBT.i((item.nbt.getInt("CustomModelData") + 1) % (maxNumber + 1)), Num: NBT.i((item.nbt.getInt("Num") + 1) % (maxNumber + 1)) } : { CustomModelData: NBT.i(1), Num: NBT.i(1) }) level.clientSide && player.playNotifySound("minecraft:block.amethyst_block.place", "master", 1, 1) item.setHoverName(Text.translate("item.kubejs.circuit_integrated_with_digits", [item.nbt.getInt("Num").toFixed(0)]).italic(false)) return true } }
player level is light level on player feet?
no
thats the level of your server basically
level is where you can get stuff like dimension, event.entity.level.dimension for example
you need interaction hand
its basically world
hmm
sec
/**
*
* @param {Internal.Player} player
* @param {Internal.Level} level
* @param {Internal.InteractionHand} interactionHand
* @returns
*/
global.programclick = (level, player, interactionHand) => {
//can refresh this by doing /kubejs reload startup_scripts
let maxNumber = 32
let item = player.getItemInHand(interactionHand)
if (player.isShiftKeyDown()) {
item.setNbt({ CustomModelData: NBT.i(0), Num: NBT.i(0) })
} else {
item.setNbt(item.hasNBT() ? { CustomModelData: NBT.i((item.nbt.getInt("CustomModelData") + 1) % (maxNumber + 1)), Num: NBT.i((item.nbt.getInt("Num") + 1) % (maxNumber + 1)) } : { CustomModelData: NBT.i(1), Num: NBT.i(1) })
level.clientSide && player.playNotifySound("minecraft:block.amethyst_block.place", "master", 1, 1)
item.setHoverName(Text.translate("item.kubejs.circuit_integrated_with_digits", [item.nbt.getInt("Num").toFixed(0)]).italic(false))
return true
}
}
StartupEvents.registry('item', event => {
event.create('kubejs:circuit_integrated')
.maxStackSize(64)
.displayName("Programmed Circuit (0)")
.subtypes(originalStack => {
let myItemList = Utils.newList()
let myNewItem = originalStack.copy()
myNewItem.setNbt({ CustomModelData: NBT.i(0), Num: NBT.i(0) })
myItemList.add(myNewItem)
return myItemList
})
.modelJson({
parent: 'kubejs:item/circuit_integrated',
textures: {
layer0: 'kubejs:item/others/circuit_integrated/1'
}
}).use((level, player, interactionHand) => {
//putting the global function in here
return global.programclick(level, player, interactionHand)
})
})``` like that?
and level from a player is level() ?
https://bytebin.lucko.me/Af5VBG0iJB
give that error when i press right click
yeah use the above script i just updated
i forgot to grab the interaction hand
see if it works
will have to do one more full game restart though
error when i press right click
Paste version of crash-2023-12-10_13.15.57-client.txt from @rain thunder
this?
ah ok
there edited
i also edited it to just use the level and give probejs suggestions for interaction hand as well
so why this is for?
everything look good now?
thats for probejs if you have it
i have
when e press ctrl + space they suggestion that?
wym
looking good to me
it crashing when shift right click
Paste version of crash-2023-12-10_13.24.02-client.txt from @rain thunder
dev.latvian.mods.rhino.EvaluatorException: Cannot convert dev.latvian.mods.rhino.Undefined@0 to boolean
you restart your game?
yeah
if you edited anything outside that global function like adding the return you gotta restart
on if (player.isShiftKeyDown()) i need some other check?
I don't know where the error of not converting undefined to boolean is coming from
the scope is wrong, player.level above should be outside that check block
ops
below
ah true
get that 3 lines out
i am lost
no
lemme look at this script more closely to understand the logistics cause i have yet to understand it at this point
you are 1 line far to solve
lmao

i think is put return true before last line block no ... or before close }
return true after item.setHoverNamr
??tryitandsee
based on lio's code, do this
Raiden is missing the else stuff
no you need to do action
how i check if is it undefined value?
the sethovername?
setNbt
ah ok
so we set it with non shift click then shift click resets it
im starting to understand this i think
there is nothing undefined here, the problem was the return was in the wrong place not being caught
also are you running /kubejs reload startup_scripts to reload the global event?
just making sure
i am close mine and reopen 😂
this is final code?
return true should outside of if condition?
ONLY item.setNbt inside the if block
amen
😂
finally
/**
*
* @param {Internal.Player} player
* @param {Internal.Level} level
* @param {Internal.InteractionHand} interactionHand
* @returns
*/
global.programClick = (level, player, interactionHand) => {
//can refresh/edit this by doing /kubejs reload startup_scripts
let maxNumber = 32
let item = player.getItemInHand(interactionHand)
if (player.isShiftKeyDown()) {
item.setNbt({ CustomModelData: NBT.i(0), Num: NBT.i(0) })
} else {
item.setNbt(item.hasNBT() ? { CustomModelData: NBT.i((item.nbt.getInt("CustomModelData") + 1) % (maxNumber + 1)), Num: NBT.i((item.nbt.getInt("Num") + 1) % (maxNumber + 1)) } : { CustomModelData: NBT.i(1), Num: NBT.i(1) })
}
level.clientSide && player.playNotifySound("minecraft:block.amethyst_block.place", "master", 1, 1)
item.setHoverName(Text.translate("item.kubejs.circuit_integrated_with_digits", [item.nbt.getInt("Num").toFixed(0)]).italic(false))
return true
}
StartupEvents.registry('item', event => {
event.create('kubejs:circuit_integrated')
.maxStackSize(64)
.displayName("Programmed Circuit (0)")
.subtypes(originalStack => {
let myItemList = Utils.newList()
let myNewItem = originalStack.copy()
myNewItem.setNbt({ CustomModelData: NBT.i(0), Num: NBT.i(0) })
myItemList.add(myNewItem)
return myItemList
})
.modelJson({
parent: 'kubejs:item/circuit_integrated',
textures: {
layer0: 'kubejs:item/others/circuit_integrated/1'
}
}).use((level, player, interactionHand) => {
return global.programClick(level, player, interactionHand)
})
})
u are god
final code
when it works is the time I remove global 
you need Num
ah ok nvm then lol
also just 0 turns into Double
i woulda been wrong anyways
cuz Rhino
this is hard for me
i think youre doing great tbh
So you're used to making "things" easy, changing recipes and so this blew my mind
can explain me what this do or what is this
it is your oldest code u send it
it detects if theres a Num property in the nbt of the item
on lexxie
i just can do item.nbt.Num?
thats a null check as well
because youre checking if theres a Num property from nbt but if theres no nbt to check from then you get a rhino error
its like to do (item.nbt && item.nbt.Num) or not
item?.nbt?.Num == null so how can i write this for noobs like me and more easy to understand
item.nbt.Num == null is checking what the Num returns
if(item != null && item.nbt !=null && item.nbt.Num == null)
oh ok
my mind is blowing
item ? (item.nbt ? (item.nbt.Num == null ? (true):(false)) : (false)) : (false) 
Thank you so much to everyone who helped me with this 💜
??closeticket
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.