#Location changed

1 messages · Page 1 of 1 (latest)

ripe valve
#

How do I make a location changed advancement?

{
  "criteria": {
    "requirements": {
      "trigger": "minecraft:location"
    }
  },
  "rewards": {
    "function": "quantum:sayhi"
  }
}```
I used this, yet even if I stand still it triggers
ripe valve
#

I've done it with enchantments

#

Just not advancements

sharp socket
#

you want it to trigger if the player moves?

ripe valve
#

Just when the player changes coordinates by an integer value

#

I'd rather not use /data because of its performance

sharp socket
#

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

haughty remnant
#

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
      }
    }
  }
}
mint shuttle
#

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

cloud rune
#

Two options:

  1. 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
  1. Make a scoreboard for each of these different types.

  2. In your tick file or any file that will be ticking/checking, check if any of these values are bigger than zero.

  3. If it's bigger than zero, the player has moved using this method.

  4. Run your code and then set it back to zero, ready for the next check.

  5. Use the players' coordinates in six scoreboards and check if the new coordinates are equal to the old coordinates.
    You could create 6 scoreboards:
    X Y Z X.old Y.old Z.old
    set the values for X, Y and Z to each players cords (found in their data)
    check if X = X.old, if Y = Y.old and Z = Z.old. if any of those is true, the player has moved. to which you can add your code to do something, afterwards, set X.old -> X, Y.old -> Y and Z.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)

haughty remnant
#

because player movement is fairly accurate

haughty remnant
#

hmm

#

because if they teleport this will work

ripe valve
#

As in if they are knocked back by an explosion

mint shuttle
#

Yeah it should

fluid canyonBOT
#

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

execute as @a[predicate=foo:moving] run <whatever you want>
mint shuttle
#

The speed predicate is just any speed, not just through movement keys