1

I want to create an inverted pyramid hole in the ground down to bedrock, using the /fill command. For this, I would like to know how to use command blocks in a for loop. I would basically like to use command blocks to do this:

for(i=100; i>0; i--)
    /fill -i i -i i i i air

While I am sure some external programs might help me do this, I am doing this to learn how command blocks work, and would like to do this using them only.

I am familiar with basic command blocks, the different types of command blocks, etc. I have also searched Google, YouTube to no avail.

I thought of a possible solution that requires the use of variables, but I could not think of a way to work with them. I could use the scoreboard, but one important requirement then would be to append a number to a string in a command block command.

  • 1
    Have you made any attempt to solve this yourself? Arqade works better when askers show effort to solve their own problems; we see that you have a problem you've worked on, and answerers respond to that. You also get a more specific answer that's tailored exactly to the part you're stuck, and Arqade gets a very specific question. Everybody wins! – Frank Jan 26 '17 at 13:00
  • Yes, and I have edited the question to reflect the same. Thank you for your advice. – 1026501 Jan 26 '17 at 15:07
2

Edit (2019): McIDE is deprecated. Use datapacks and function files instead. You can use scripting languages to generate the .mcfunction files, e. g. Python, NodeJS or PHP.

Original answer (2017):

You can use a generator such as McIDE. It allows you to create lots of command blocks and use loops and funtions of PHP. It takes some setup tho. You need a spigot server and put the plugin in there. As a text Editor i would recommend Atom.

Website: https://simonmeusel.github.io/mcide/

Docs: https://simonmeusel.github.io/mcide/docs/mcide-plugin/installation.html https://simonmeusel.github.io/mcide/docs/mcide-for-atom/installation.html

To create your config use this: https://simonmeusel.github.io/mcide/generator.html

To create your loop you would need a script like this.

<?php
  for ($i = 100; $i > 0; $i--) {
    echo "/fill " . (-i) . " " . i . " " . (-i) . " " . i . " " . i . " " . i . " air";
  }
?>
  • 1
    This seems to have external dependencies (e.g. Bukkit) – Michael Aug 9 at 22:14
  • 1
    Yes it does. Furthermore, the project is deprecated. I recommend using datapacks and function files, which you can combine with scripting languages to generate the function files. – Simon Meusel Aug 11 at 0:04
  • One thing I noticed is that if I make a change to an .mcfunction file, or add a new one, it isn't recognized even if I restart the game. – Michael Aug 11 at 1:55
  • Check if you edit the right file in the right world and the correct .minecraft folder. Then you could try creating a new datapack and check if that one gets loaded. Additionally try using just one file with one command that you are sure it is working. You can also enable the Minecraft console and look for errors there. – Simon Meusel Aug 12 at 13:40
  • well strangely, even /reload doesn't seem to properly bring in the new version. to get it to work i have to edit the manifest and bump versions and then use the new version. but hey, it works and it's saving me tons of time. Thanks! – Michael Aug 12 at 16:40
0

While you can theoretically write a loop without many problems, you sadly can't use any form of variables in Minecraft commands, everything needs to be hardcoded.

The only thing where you can sort of use variables is the scoreboard, and even there it needs some work around.

So no, something like that doesn't exist.


You could possibly achieve what you're trying to do in a different way though, by moving a Entity around and filling the respective block with air. Will take much longer and much more effort but may be possible without hardcoding anything.

  • Your comment about moving an entity around reminds me of SethBling's insane videos where he uses a lot of command blocks and an armor stand. Is that what you are referring to? – 1026501 Jan 26 '17 at 18:23
  • i don't know which video you have in mind, but this isn't something only SethBling did ;) – Plagiatus Jan 27 '17 at 16:48
0

Unfortunately you can't use scoreboard objectives as coordinates, so I don't think there is such a way to do the fill command :/

.


just in case you still want to know how to do a "for loop" with command blocks (unrelated to the pyramid):

Have a scoreboard (i) and an entity (dummy). Set that score for the dummy to 100.

Now you need a few "always active" command blocks:

Repeating block: /testfor @e[name=dummy,score_i_min=1]

Several conditional Chain blocks: doing what you want to do

//Keep in mind that the everything behind one of those blocks won't activate if one of them doesn't work, so there might be a better way to activate those commands//

Conditional chain block at the end:/scoreboard players remove @e[name=dummy,score_i_min=1] i 1

Might not be the cleanest way to do it but it's one way at least.

  • Then just connect the start of chain with end to the loop and voila? – Antoine Hejlík Jan 26 '17 at 17:08
0

Use containers such as chests as variables. Have a command block set the contents of a hopper to one golden sword. Then put a dropper under the hopper. Have a red stone comparater to convert the value of items to redstone output. Make sure that length of redstone is 15 long. However you make your loop remember the comparator output is intended to kill the loop. I put a command block next to the dropper to set the contents to one gold sword to reset the counter to reuse the loop. The loop I described to you does 8 loops then dies because even though the dropper has 9 slots one has to go towards being base value.

0

if you just want a one-time solution, I suggest using excel or google sheets.

I have been making pyramids by using drag-down excel formulas and concatenating the coordinates into a single string per line then pasting the text into a text editor notepad++.

You would just need to mark your height coordinate and execute starting from there.

Beware that it can take some time to process a big function like this in minecraft - I had to wait upwards of 15 minutes to create a Giza size pyramid, and when you get to giza size the fill areas are too large for minecraft to accomplish - you'd need to shrink the fill areas down or do wall-by-wall.

I have also done an inverse pyramid to dry and glass-wall-off Ocean monuments but I never got close to bedrock with that function. If you are just going down can't you just fill the area from zero to the sky with air and not worry about making this a run-time generated loop?

  • I am not following exactly how you are getting the coordinates into minecraft once you have them in a text editor, or what the format is supposed to look like. Can you give an example? – Michael Aug 9 at 22:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.