Now that we have our coordinates of our player, we can use them to spawn a block!
On line 8 we see another function called “mc.setBlock”.
This function takes 4 numbers, the 3 coordinates of where to place a block, and the id of the block (every block in Minecraft has a number, 57 is diamond.)
Here, we give it the 3 coordinates of our player; however, we subtract 1 from y, why is that?
This is because we don’t want the block to spawn inside the player, but under. To do this, we say subtract 1 from y because y is up/down.
Now that we have this code done, let’s test it!
At the top of Visual Studio Code, click Run and then click Run Without Debugging
Once you have done this, go into Minecraft and you should see a diamond block appear under you! If not, double check your code and be sure to save it as well. (File->Save or Ctrl+S)
Now you may be thinking that this was a lot of work to just make one block appear, why would we ever code this? This is just the beginning, now that we know how to code one block, we can apply these same concepts to do a lot more cooler things that would be impossible without code. Don’t worry, we’ll see the power of coding very soon.