As with most counting problems in Minecraft, the answer is eggs.
Take a look at my sample setup.
Redstone explanation
To the right, we have a monostable circuit to shorten the input (the button) down to 1 tick. I use Sethbling's favored design, the repeater is set to 3.
The Centerpiece is a Hopper-Dropper-Counter (a hopper and dropper pointing into each other), containing, in this case, 9 Eggs (or anything that stacks to 16) and 10 Cobblestone (or anything that stacks to 64), for a total of 19 items. You realize this is 1 short, but that's actually fine.
The comparator turns to 3 when all items are in the hopper. In this case, the torch at the bottom of the picture turns off.
The last component is a Repeater-Lock. On each button press, the hopper will update to whatever redstone signal is on the bottom torch before the button was pressed. So if it's at three bars after 19 clicks, it will unlock the hopper on the 20th click, causing all items to go back into the dropper.
To make something happen every 20th click, you should get the signal from the block next to the hopper (i.e. the state of the locked repeater), it is only ever off 1/20 of the time. You could put redstone dust underneath, or put a torch on top, for example (but watch out for signal inversion).
Design notice: I used a variation of this for a three state enchanting room (lvl 1, lvl 18, lvl 30 enchants), using 2 wooden swords, and repeaters checking for a signal >0 and >3, respectively.
The coordinates can be added as target selector arguments, i.e. inside the @e[...]
, using the x
, y
, and z
arguments, combined with r
to set a maximum radius. Note that Tilde notation is not allowed for this, you need the absolute coordinates.
Placing an enchanted item in an Item Frame has to be done all at once, since the entitydata is running on the Item Frame, not on the item that is in it. This is done by setting the Item
tag of the item frame to a valid compound NBT structure for an item, such as
{id:"minecraft:stone_sword",tag:{ench:[{id:16,lvl:1}]}}
for a Sharpness I Stone Sword.
Overall, the command you want to be running might look like:
entitydata @e[type=ItemFrame,x=1,y=2,z=3,r=2] {Item:{id:"minecraft:stone_sword",tag:{ench:[{id:16,lvl:1}]}}}
Be careful regarding the closing parentheses.
Best Answer
Item frame rotation based output. This is not my design.
The item frame does not rotate, an item in the frame does. Some items have to be rotated fully twice(example: maps) in order to output full signal. If using more then one of these devices to form a combination lock, those double rotation items would make it very difficult to unlock.
It is a simple device that uses a comparator to read the signal level of the item frame. If the signal level is too low or high (item rotated improperly) it will not output. It does this based on the length of the redstone dust after the comparator. The easiest way to use the rotation point you want is to rotate the item to the position you want. Continue to run redstone dust after the comparator until you no longer see the dust has signal. Place a torch on the side of the last block with signal. Leave one redstone dust after that block that feeds into a repeater.
In this example a signal of 4 or the arrow pointed down will activate the redstone dust at the very end of the line. In the picture, the lower image is the device sending out a signal.
If you are interested in how it works, the comparator outputs the signal. If the signal is to low, the first torch outputs high(is lit) and this causes the not gate(second torch) to output low(off). If the signal is correct, the first torch turns off, the second torch turns on. If signal is too high, the repeater outputs high which causes the second torch to turn off.
Edit: I located the video I originally saw this on. It's by SethBling.