#Help With Item Tags/NBT

24 messages · Page 1 of 1 (latest)

loud canyon
#

Im rather confused on how item tags work, i am trying to add two tags to automatically spoil food if it sits in the inventory too long. I have the following

    event.modify('/.*:.*/', item => {
      let blacklist = []
      if (item.isEdible()) {
        if (item.foodProperties != null) {
        if (blacklist.includes(item.name) == false) {
          item.setNbt({'age':0, 'spoiled':false})
          console.log(item.nbt)
          }
        }}
        })
        
      })```

It then crashes saying that certain food items do not have NBT data, is there a different function I should be using?
cerulean prismBOT
#

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

tame pagoda
#

nbt is set when the item generates an instance of itself so it cant be set on startup, if it must be an nbt tag then you'll have to set the nbt in every way that you can get the item such as being crafted/looted from chests.

loud canyon
#

ok, is there another way to associate an integer with an instance of an item?

tame pagoda
#
ItemEvents.crafted(event => {
    const { item } = event
    let blacklist = []
    if (item.isEdible()) {
        if (item.item.foodProperties != null) {
            if (!blacklist.includes(item.name)) {
                item.nbt.merge(`{age:0,spoiled:false}`)
                console.log(item.nbt)
            }
        }
    }
})```
tame pagoda
loud canyon
#

ok. Thank you. Do you think it will cause alot of lag?

tame pagoda
#

changing the nbt over time?

loud canyon
#

yes

tame pagoda
#

not really if you're smart the way you do it, are you familiar with returning once a second in a tick event?

loud canyon
#

yeah, i think i have that set up, just havent tested it because i couldnt get this part to work

tame pagoda
#
PlayerEvents.tick(event => {
    const {entity} = event
    if (entity.age % 20 != 0) return
    //code ran once a second/20 ticks
})```
loud canyon
#

ok thank you, is there a difference between that and ```LevelEvents.tick( event => {

})```

tame pagoda
#

running something once a second is the standard for most mods doing things in tick events

#

hmm sec

#

like this js LevelEvents.tick(event => { const { level } = event level.entities.forEach(entity => { if (!entity.player) return if (entity.age % 20 != 0) return //code ran once a second/20 ticks }) })

#

though at that point you'd just wanna use the player tick event if you only want it to fire for players

loud canyon
#

ok, what if i want to work for items in chests as well?

tame pagoda
#

having those also tick inside chests is probably both impossible without mixins and not a good idea performance-wise

loud canyon
#

ok

#

thank you, i might keep this open for now in case i run into any more issues if that is ok

loud canyon
#

ok, this is kindve relevant, im trying to do something similar with a telescope block, where every day at the time of 0 it changes to a random value. When you right click it logs the value, Is there a tag i can use to preserve the chosen value until the next day. Unless there is another way to transfer the stage between the levelevent and blockevent

#
function decide_astral_stage() {
    const stages = ['Aries', 'Taurus', 'Gemini', 'Cancer', 'Leo', 'Virgo', 'Libra', 'Scorpio', 'Sagittarius', 'Capricorn', 'Aquarius', 'Pisces']
    let stage = random_select(stages)
    return stage
    
}
LevelEvents.tick( event => {
    let level = event.level;
    if (level.dayTime == 0) {
        stage = decide_astral_stage()
        return stage
}

})

BlockEvents.rightClicked(event => {
    if (event.block == 'it_all_started_with_a_bean:arcane_telescope') {
        
        message = 'Current Constellation: '.concat(stage)
        console.log(message)
    }
})```
loud canyon
#

im just going too make this a new thread as its becoming irrelevant