I want to build a set of command blocks that will automatically place a torch at the foot of a player (or entity) when the light level falls below a certain threshold. So basically I need to be able to determine the light level at a player using command blocks.
I've looked the some of the wiki pages on NBT data to see if the light level is stored with the block, so I could do something like /execute @p ~ ~ ~ testforblock ~ ~ ~ minecraft:air 0 {dataTagForLight:3b}
, but there doesn't seem to be any such data tag.
I've considered spawning a daylight detector, but I have a feeling it won't do what I want it to do while in caves, since as far as I can tell, in the primary mode, it's only affected by sunlight. Plus there's other issue with the plan, and it just feels like a kludge.
So, is there a way to determine the light level of a given block? If so, how?
Best Answer
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:
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:
You can also create custom mob spawners will spawn a mob every tick by changing its
MinSpawnDelay
andMaxSpawnDelay
.Using either of these methods (or both), what you'd need to do is something like:
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.