This method is also a fairly bad kludge and a bit impractical, but it should be able to detect block light as well as sunlight.
There are a few of processes that only occur at certain light levels, sunlight or not:
Event || Light Level
================================
Snow/ice melt || >=12
Mushrooms uproot || >=13
Flowers uproot || <=7
Plants grow || <=9
With a very high /gamerule randomTickSpeed
, these processes can happen almost immediately. Obvious disadvantage here is that the gamerule will also effect the processes throughout the entire world.
Different mobs also have different spawning light levels:
Mob || Light Level
================================
Bats || <=3
Most hostiles || <=7
Blaze/silverfish || <=11
Most passives || >=9
You can also create custom mob spawners will spawn a mob every tick by changing its MinSpawnDelay
and MaxSpawnDelay
.
Using either of these methods (or both), what you'd need to do is something like:
- Clone blocks around the block/player to a specific area
- Set the block/spawner in the middle of the newly cloned area
- Wait a few ticks
- Test if a mob has spawned, or a process occurred
You could also have the mob spawner (minecart) or test block at the actual player's location, rather than cloning it first, which would reduce lag a lot but cause the player to see flickering mobs/blocks.
I think I can see two ways to do this. One is more simple but does not give you exactly what you want, whereas the other is more complex but I think it does do what you want.
The simple way is to give every player a unique id on login, and have that id displayed next to each players' name in tablist (using scoreboard setdisplay sidebar
). Then, you teleport to a player using trigger objective set [ID of person you want to TP to]
and then the command logic should be pretty straightforward from there.
The second method is to assign these IDs on the fly. When a player runs the command to open the menu, you assign the nearest 10 players a unique TPA-ID-score
between 1-10. Then, you have a mcfunction with 10 of your trigger commands hardcorded 1-10, where you do trigger objective set 1
, trigger objective set 2
and so on. (you would also change the selector to make sure the numbers line up). If you want an additional "page" of results, give all players with TPA-ID-score
1-10 some sort of tpa-excluded
tag, and assign the next 10 players a unique TPA-ID-score
1-10. Then print out your 10 tellraw messages again.
This will allow you to scroll through every player on the server, and when someone chooses to click on someone to teleport to, reset by removing everyone's tpa-exclude
tag and set all TPA-ID-score
s back to zero.
The downside of this second method is that multiple players would not be able to use it at the same time (you'd have to prevent players from opening the tp menu while another player is using it), whereas with the first method is fully functional in multiplayer.
Best Answer
I tried a few things and I'm pretty sure the only way is setting the player's individual spawn point to something invalid (like 0 0 0), setting
gamerule spawnRadius
to 0, killing them, waiting until they respawn (like this) and then checking their coordinates.