Minecraft – How to make the redstone repeat a task x times and reset it self

minecraft-java-editionminecraft-redstone

So I'm trying to make a redstone circuit that can repeat a task x amount of times and then reset it self.

I was thinking of using a dropper and a hopper and use the hopper redstone signal (retrieved by a comparator) to check the amount, so lets say I need it to repeat a task 20 times, I place 20 items inside (along with the 3 items that are already inside the hopper, so it emits a 2 long signal once it has the 20 items from the dropper, I know how to do that part, but to the question, how can I make it reset to 3 on the hopper and 20 to the dropper?

The main question is the one described in the first paragraph and the title, the second one would be good to know, but idk if its possible.

Best Answer

As with most counting problems in Minecraft, the answer is eggs.

Take a look at my sample setup.

enter image description here

Redstone explanation

  1. 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.

  2. 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.

  3. 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.

  4. 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.