#how to edit player nbt

28 messages · Page 1 of 1 (latest)

silver garnet
#

Trying to figure out how to edit players nbt data like seting foodlevel or any of the thw other nbt info

celest yewBOT
#

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

lone citrus
#

You can use an entity tick event

#

Get the entity from the event

#

Check if it's a player

#

Return if not

#

Get nbt

#

With .nbt

#

Then modify it

silver garnet
#

How do you modify it

lone citrus
#

Look at what it returns

#

By logging it

#

The use that as reference of how to modify it

upbeat badge
#
 ServerEvents.tick(e => {
    const { server } = e

    if(server.tickCount % 20) return

    server.entities.filterSelector('@e[type=minecraft:player]').forEach(player => { 
        console.log(player.foodData.saturation)
    })
}) ```
#

I confunded myself twice

steel dove
upbeat badge
#
PlayerEvents.tick(e => {
    const { player, level, server } = e

    if(server.tickCount % 20) return
    console.log(player.foodData.saturation)
   
})```
#

you can use the set methods to change the values, like setSaturation for example

silver garnet
#

so how does player.foodData.saturation connect to the level

upbeat badge
silver garnet
#

this does show player.foodlevel

#

its marked as an interger

#

next goal is to just detect the change

silver garnet
#

now i can freely edit it

#

it works thank you!