How to get testfor to go on and off as I please
How I understand it you just put a fast clock go into a command block (or 1.9's repeating command block) with the command testfor @p[r=5]
(replace 5 with anything) then a comparator coming out of that command block and into a command block with say hello
or however you wish to output text.
The following worked for me in Minecraft 1.9.2:
- Place a repeating command block, and enter the command "
testfor @p[r=n]
" where n is the maximum distance in blocks that a player must be from the command block for the villager to "say" hello. In the options for the repeating command block, click the button to the right that says "Needs Redstone
," and it will change to "Always Active
." So in order the three options say: Repeat, Unconditional, Always Active. Your chat might be spammed with "[@: Found <username>]
" when anyone gets within the maximum range. To fix this, type "/gamerule commandBlockOutput false
" and command blocks will not report command outputs anymore. - Place a redstone comparator with the A end of it (the side with the two torches) against the command block. You'll notice it lights up whenever the a player enters the maximum range.
- Redstone dust coming off of the C end of the comparator (directly across from the A end) is optional, but I added one. Place a sticky piston touching the redstone or the C end of the comparator, facing any of three directions but not with the moving end towards the comparator.
- Put a redstone block onto the sticky end of the piston.
- Place a normal command block in a place such that when the piston pushes the redstone block one space, it will then be touching the command block. The command inside this block will fire only once until the redstone block is pulled away and pushed back again. Inside this command block I put "say Hello." See the image below if you are confused.