#how can i check to see a villagers xp level in a data pack
1 messages · Page 1 of 1 (latest)
<@&1201956957406109788>
💬 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
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
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
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
im guessing its the one under level ?
how can i get the path of the level
What would you like us to do with this?
it's called level inside the villager data
i ran it but it resulted in Found no elements matching level
Because level is not the full path
Look at the data
Look at where level is. What objects it's inside of
i think i figured it out
/data get entity @n[type=minecraft:villager] {VillagerData:{level:1}}
Very close. It'll actually be formatted as VillagerData.level:1 here
Iirc, that's from memory
for me that doesnt work but im probably being stupid again
is this what i need ?
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}}
Also your last line (execute as @s tag ...) is invalid syntax and wouldn't work anyway
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
would this work im not good at this stuff : execute at @a run execute as @e[type=villager,distance=..20] run tag @s add scanned
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
ah ok thankls
and this one checks to see if the villager is level 1 ? 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}}
i need it to remove a tag if it says it level 1,2,4,5,6 or however many levels there are
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
View this wiki page on datapack.wiki: https://datapack.wiki/wiki/concepts/target-selectors/
hmm ok il take a look quick
oh like this /execute unless entity @e[type=minecraft:villager,level=..1]
level= is only for player XP. You still need to use nbt= to check it for villagers
like this ?
/execute unless entity @e[type=minecraft:villager,nbt={VillagerData:{level:1}}]
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
so the full command would be this
execute at @a run execute as @e[type=minecraft:villager,nbt={VillagerData:{level:1}},distance=..20,tag=scanned]
I don't see you use if entity there
/execute at @a run execute as @e[type=minecraft:villager,nbt={VillagerData:{level:1.}},distance=..20,tag=scanned] run tag if entity @s remove scanned
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
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
View this wiki page on datapack.wiki: https://datapack.wiki/wiki/command/execute/
oh like this /execute at @a run execute as @e[type=minecraft:villager,distance=..20] if entity @s[type=minecraft:villager,nbt={VillagerData:{level:1}}] run
Yep that works
You don't need the type= on the second selector because you've already selected the villager in the first one
so this execute at @a run execute as @e[type=minecraft:villager,distance=..20] if entity @s[nbt={VillagerData:{level:5}}] run
als othis is what im doing
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
That looks like it would work
oh thats good XD
and it shouldn't back track on its self right ?
Wdym
like it shouldnt try and correct level 2 every 5 seaconds because that level is done
Don't think so
this command doesnt work
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"}}]