#Location changed
1 messages · Page 1 of 1 (latest)
you want it to trigger if the player moves?
Yes, but not necessarily through movement keys
Just when the player changes coordinates by an integer value
I'd rather not use /data because of its performance
no idea how you would do that tbh
summon marker every tick and check if marker has distance greater than 0 to player
but that's not an advancement
is there a predicate
?
i can only find location check
something like this
{
"condition": "minecraft:entity_properties",
"entity": "this",
"predicate": {
"minecraft:movement": {
"speed": {
"min": 0.1
}
}
}
}
You can use that in an advancement
{
"criteria": {
"move": {
"trigger": "minecraft:location",
"conditions": {
"player": {
"minecraft:movement": {
"speed": {
"min": 0.00001
}
}
}
}
}
},
"rewards": {
"function": "foo:bar"
}
}
but the location trigger only checks every second, so you might end up with gaps
Two options:
- Use the
minecraft.custom:minecraft.<travel_type>_one_cm
Minecraft has a few scoreboard objectives that detect whether you have moved 1 cm. You can create a scoreboard with these objectives by doing/scoreboard objective add <name> minecraft.custom:minecraft.<travel_type>_one_cm. Keep in mind you'll have to do this for each type of movement and it may not even give you all of the types. Some include:
- Walk on Water 1cm (
walk_on_water_one_cm) - Walk 1cm (
walk_one_cm) - Walk Underwater 1cm (
walk_under_water_one_cm) - Happy Gas Travel 1cm (
happy_ghast_one_cm) - Pig 1cm (
pig_one_cm) - and a few more
-
Make a scoreboard for each of these different types.
-
In your tick file or any file that will be ticking/checking, check if any of these values are bigger than zero.
-
If it's bigger than zero, the player has moved using this method.
-
Run your code and then set it back to zero, ready for the next check.
-
Use the players' coordinates in six scoreboards and check if the new coordinates are equal to the old coordinates.
You could create 6 scoreboards:
XYZX.oldY.oldZ.old
set the values forX,YandZto each players cords (found in their data)
check ifX = X.old, ifY = Y.oldandZ = Z.old. if any of those is true, the player has moved. to which you can add your code to do something, afterwards, setX.old -> X,Y.old -> YandZ.old -> Z, this makes sure that it only triggers once.
Make sure though that when the datapack loads, you instantly set X.old -> X, Y.old -> Y and Z.old -> Z otherwite it will trigger instantly even if you havent moved.
While the second one requires a lot more operations and therefore isn't entirely optimised, it should work well depending on the size of your project and how much you're utilising it. The first option does not cover all types of movement. This could include teleportation, I'm unsure myself.
Although I have heard that scoreboards are quite well optimised, it shouldn't be too much of an issue
Through using predicates or advancements I'm unsure if it's possible. If so I imagine it would use some kind of technique related to some of the ones I've said above
-# (Ping in reply @ripe valve)
i'm pretty sure this also works @ripe valve
because player movement is fairly accurate
ohh
hmm
because if they teleport this will work
would this work if they don't move though?
As in if they are knocked back by an explosion
Yeah it should
But like I said, the location trigger only checks every second. You could probably switch it to the tick advancement trigger, but at that point just do it all with functions with
[35mexecute [34mas [36m@a[33m[[37mpredicate[34m=[33mfoo:moving] [34mrun [0m<whatever you want>
The speed predicate is just any speed, not just through movement keys