Step 2

Explaining Functions

Now, before we begin, let’s explain functions a little more. We’ll need to for the next code.

Remember a function is a piece of code that has a specific job/purpose/task. Here the setBlock function has the task of setting a block where we want it to.

Some functions need some information to do their job, for example, setBlock needs to know where to place the block and what block to place.

We call this information the function’s parameters.In this example, setBlocks has four paramaters, the three coordiates and the block id.

The setBlocks function

Let’s go over a new function called setBlocks. This function takes seven parameters, it’s a lot, but it needs a lot of information because it does a very cool thing.

The way setBlocks works is we give it two block positions (two sets of coordinates) and it fills all of the space between those blocks with whatever block id we give it.

With this, we very quickly can spawn A LOT of blocks. However, with great power comes great responsibility. Let’s say we made the two block coordinates 100 blocks away from eachother. This would lead to us filling a space of 100x100x100 blocks. That is one million blocks! We did this with one line of code, and this will crash Minecraft on most computers. Be wary of how many blocks you try to create.

Anyway, let’s move on to the actual code!