I wanted to eliminate the single NBT check from my Minecraft data pack, Detect AFK Players. It uses the player's head rotation, and currently, there isn't a command like /rotate query to get that information without using NBT.
NBT is the save format, and requires the game to convert all the player data to that format from the in-memory data structures, serialize it, parse the lookup, and finally return the data. That's pretty slow! Naturally, the community's motto is to stay away from NBT unless you absolutely have to. I tried a few different things to detect activity, including:
- Spawn a marker entity where the player is looking
- Ties rotation to position, which is not good
- Spawn an entity where the player is looking, "positioned at" a particular point
- Requires either force loading chunks or using known loaded chunks
- Use a predicate to detect input directly
- Runs into edge cases such as player-operated farms where you use the mouse but not any keyboard inputs, and being a boat/camel passeng