While you cannot use testfor to do this, you CAN use execute detect. This is most likely how it would look: /execute @a ~ ~ ~ detect ~1 ~ ~ grass 0 <command>
the execute command will detect a grass block to the left (in the X cord) of all players in the world. the command is how you would track that player if it detects the block successfully.
an example tracking command would be /execute @a ~ ~ ~ detect ~1 ~ ~ grass 0 scoreboard players set @p Sample_Obj 1
comment if you have any other questions.
Source: http://minecraft.gamepedia.com/Commands#execute
(I assume you are on 1.8+) Since you cannot test for a player that isn't in game, Try using an armorstand.
First, Summon an armorstand with the nbt tags NoGravity, Marker, and CustomName. (Ex. /summon ArmorStand ~ ~ ~ {NoGravity:1b,Marker:1b,CustomName:MobHunger}
To set it a scoreboard, you can use an entity selector in place of the player. This would work: scoreboard players set @e[type=ArmorStand,name=MobHunger] stats 1
You can also use an entity selector in the testfor command, it's just a bit different syntax. /testfor @e[type=ArmorStand,name=MobHunger,score_stats_min=1]
Also, just a tip: try transitioning over to the execute command rather than testfor, as with testfor you need an comparator and a different command that needs to target the entity (unless you need that comparator for lag or other purposes). With execute, you can do a command in the same command if it finds the armorstand with a score of 1 in stats. Ex. execute @e[type=ArmorStand,name=MobHunger,score_stats_min=1] ~ ~ ~ setblock ~ ~ ~ stone
is much more efficient than using a comparator.
Best Answer
The
name
argument shoudn't be capitalized, and also unless you are testing for the mob in a specific area,r
argument isn't required, nor the~
sTry this: