#Trying to apply custom tag on server tick check for certain tag

21 messages · Page 1 of 1 (latest)

fast crane
#

Basically what i'm trying to do is to check for food items to see if they have the following tag "spoiled:SpoilTimer", and if it checks as true then it'll add another tag to it, that adds a custom model data to that item. Like so:

ServerEvents.tick('minecraft:bread', event => {
    event.modify('minecraft:bread', item => {
        // Check if the item is food and has the "SpoilTime" tag
        if (item.isFood() && item.hasTag('spoiled:SpoilTimer')) {
            // Add CustomModelData tag to the item
            item.customModelData = 12345;
        }
    });
});
quick veldtBOT
#

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

old mirage
#

you mean nbt tag? in that case the following:

if(!item.nbt) return
if(item.nbt["spoiled:SpoilTimer"] > 100) return
#

though I'm pretty sure there isn't an event.modify on server tick

fast crane
#

and the nbt pathing is not nbt.spoiled.SpoilTimer

#

For some reason the nbt tag of that mod has the mod name in it

fast crane
old mirage
#

item.nbt.mytag = "hello" should work

fast crane
#

will try it and get back to you if i'm stuck at this still

fast crane
#

any idea how i can do that then?

#

i have this

#
ServerEvents.tick( event => {
    event.modify( item => {
        // Check if the item is food and has the "SpoilTime" tag
        if (item.hasTag('forge:foods') && item.hasTag('spoiled:SpoilTimer')) {
            // Add CustomModelData tag to the item
            item.nbt.customModelData = 12345;
        }
    });
});
fast crane
#

anyone can help me on this?

woeful python
#

there isn't an item modify method for server events iirc

#

you cant do it like this

fast crane
#

Ok fixed it

#
PlayerEvents.inventoryChanged(event => {
    // Loop through all items in the player's inventory
    event.player.inventory.items.forEach(item => {

        // Check if the item is food (using forge:foods tag) and has the "SpoilTime" tag
        if (item.hasTag('spoiled:foods') && item.nbt["spoiled:SpoilTimer"] >= 10) {
            
            item.nbt.CustomModelData = NBT.i(12345)

        }
    });
});