#how can i check to see a villagers xp level in a data pack

1 messages · Page 1 of 1 (latest)

sterile musk
#

how can i check to see a villagers xp level in a data pack

lost impBOT
#

<@&1201956957406109788>

Someone will come and help soon!

💬 While you wait, take this time to provide more context and details.

🙇 If nobody has answered you by <t:1744745282:t>, feel free to use the Summon Helpers button to ping our helper team.

✅ Once your question has been resolved (or you no longer need it), please click Resolve Question or run /resolve

#
⚠️ You already have a question open!

Don't forget to close or resolve your old questions once you're done with them. It makes our lives much easier! :D

Open question: #1361683556362879097

sterile musk
#

this is what i have so far

#

execute at @a run execute as @e[type=villager,tag=!scanned,distance=..20] run data remove entity @s Offers.Recipes[{sell:{id:"minecraft:emerald"}}]
execute as @s tag add scanned
schedule function n:remove_emerald_offers 5s

#

but im looking to remove the scanned tag if a villager has leveled up

knotty gorge
#

you can get the villager's experience level by using the data command

#

try using data get entity @n[type=villager] and see that the villager has an xp tag somwere in it's data

sterile musk
#

im guessing its the one under level ?

sterile musk
knotty gorge
#

look into that data of the villager

#

where the data is located an thats the path

sterile musk
trim cradle
#

What would you like us to do with this?

knotty gorge
#

it's called level inside the villager data

sterile musk
#

i ran it but it resulted in Found no elements matching level

trim cradle
#

Because level is not the full path

#

Look at the data

#

Look at where level is. What objects it's inside of

sterile musk
#

/data get entity @n[type=minecraft:villager] {VillagerData:{level:1}}

trim cradle
#

Very close. It'll actually be formatted as VillagerData.level:1 here

#

Iirc, that's from memory

sterile musk
#

for me that doesnt work but im probably being stupid again

sterile musk
#

execute at @a run execute as @e[type=minecraft:villager,tag=scanned,distance=..20] run data get entity @n[type=minecraft:villager] {VillagerData:{level:1}}

sleek stirrup
#

You need to add the tag to the villager

#

I recommend you execute a function as all unscanned villagers - in that function you can reference the villager with @s and then add the tag once you're done

sterile musk
sleek stirrup
#

That would work as long as you make sure that before you run that command you run the command to actually do whatever it is you need to do

#

So basically put that at the end and you're good

sterile musk
#

ah ok thankls

sterile musk
#

i need it to remove a tag if it says it level 1,2,4,5,6 or however many levels there are

sleek stirrup
#

data get generally won't do what you want/expect it to do in a datapack. Instead you probably want to use execute if entity and check the NBT in a target selector

#

Or if you just want to check whether the level is not 0, use execute unless entity

#

Then you can use a target selector to check the NBT

potent smeltBOT
sterile musk
#

hmm ok il take a look quick

sleek stirrup
sterile musk
#

oh like this /execute unless entity @e[type=minecraft:villager,level=..1]

sleek stirrup
#

level= is only for player XP. You still need to use nbt= to check it for villagers

sterile musk
#

/execute unless entity @e[type=minecraft:villager,nbt={VillagerData:{level:1}}]

sleek stirrup
#

Pretty much. Exceeeeept you want to execute as all unchecked villagers, and use if entity @s[nbt=...]. Otherwise, you're just checking if that villager exists at all

sterile musk
#

execute at @a run execute as @e[type=minecraft:villager,nbt={VillagerData:{level:1}},distance=..20,tag=scanned]

sleek stirrup
#

I don't see you use if entity there

sterile musk
#

thats a invalid command

#

so is this one

#

/execute at @a run execute as if entity @e[type=minecraft:villager,nbt={VillagerData:{level:1.}},distance=..20,tag=scanned] run tag @s remove scanned

sleek stirrup
#

You want to do execute at @a as <any villager without the scanned tag within 20 blocks> if entity @s[<nbt check for the specific level>] run <whatever command to run>

#

I can't type out the target selectors by hand because I'm on mobile and it would take a long time

#

But you need to have some understanding of the execute command

potent smeltBOT
sterile musk
sleek stirrup
#

Yep that works

#

You don't need the type= on the second selector because you've already selected the villager in the first one

sterile musk
sterile musk
#

execute at @a run execute as @e[type=minecraft:villager,distance=..20,tag=!scan1] if entity @s[nbt={VillagerData:{level:1}}] run data remove entity @s Offers.Recipes[{sell:{id:"minecraft:emerald"}}]
execute at @a run execute as @e[type=minecraft:villager,distance=..20,tag=!scan2] if entity @s[nbt={VillagerData:{level:2}}] run data remove entity @s Offers.Recipes[{sell:{id:"minecraft:emerald"}}]
execute at @a run execute as @e[type=minecraft:villager,distance=..20,tag=!scan3] if entity @s[nbt={VillagerData:{level:3}}] run data remove entity @s Offers.Recipes[{sell:{id:"minecraft:emerald"}}]
execute at @a run execute as @e[type=minecraft:villager,distance=..20,tag=!scan4] if entity @s[nbt={VillagerData:{level:4}}] run data remove entity @s Offers.Recipes[{sell:{id:"minecraft:emerald"}}]
execute at @a run execute as @e[type=minecraft:villager,distance=..20,tag=!scan5] if entity @s[nbt={VillagerData:{level:5}}] run data remove entity @s Offers.Recipes[{sell:{id:"minecraft:emerald"}}]

execute at @a run execute as @e[type=minecraft:villager,distance=..20,tag=!scan1] if entity @s[nbt={VillagerData:{level:1}}] run tag @s add scan1
execute at @a run execute as @e[type=minecraft:villager,distance=..20,tag=!scan2] if entity @s[nbt={VillagerData:{level:2}}] run tag @s add scan2
execute at @a run execute as @e[type=minecraft:villager,distance=..20,tag=!scan3] if entity @s[nbt={VillagerData:{level:3}}] run tag @s add scan3
execute at @a run execute as @e[type=minecraft:villager,distance=..20,tag=!scan4] if entity @s[nbt={VillagerData:{level:4}}] run tag @s add scan4
execute at @a run execute as @e[type=minecraft:villager,distance=..20,tag=!scan5] if entity @s[nbt={VillagerData:{level:5}}] run tag @s add scan5

schedule function n:remove_emerald_offers 5s

sleek stirrup
#

That looks like it would work

sterile musk
#

oh thats good XD

sterile musk
sleek stirrup
#

Wdym

sterile musk
# sleek stirrup Wdym

like it shouldnt try and correct level 2 every 5 seaconds because that level is done

sleek stirrup
#

Don't think so

sterile musk
#

ok nice

#

thank you for the help

sterile musk
#

execute at @a run execute as @e[type=minecraft:villager,distance=..20,tag=!scan1] if entity @s[nbt={VillagerData:{level:1}}] run data remove entity @s Offers.Recipes[{sell:{id:"minecraft:emerald"}}]