How to Code Blocks in Minecraft Pi

How to Code Blocks in Minecraft Pi

Learn how to code blocks in Minecraft on the Raspberry Pi. You are able to to select blocks from an inventory
(by pressing the e key on your keyboard) and then dropping them to build structures. This
is one of the joys of Minecraft. But today I am going to show you how you can
code blocks to appear using Minecraft Pi on the Raspberry Pi. Minecraft blocks have three coordinates. X,
y and z. They are 3 dimensional objects. In the last video in this series, I showed you
how to use x, y and z coordinates in minecraft pi to find your players location. We can use
a similar mindset to place blocks. If this is your first time programming minecraft
then I suggest you watch the first episode on getting started before following what we
do here. In a Python 3 new text file, I’ve already
written out the code needed to connect to minecraft and use the API. Next, I’m going
to find the players location in the game world and store that information in the variables
x, y and z like we did in the previous video. Then I want to add a line of code that places
a block just in front of the player. We do this by using the syntax mc.setBlock. Notice the capital letter used for Block. Inside
brackets type x+1, y, z, and then 1. This tells the computer where to place the block on the
x, y and z coordinates in relation to the player (we specified one block away from the
player using x+1). Save this file and then load a new world in Minecraft on your raspberry
pi. Once loaded use the tab key on your keyboard to release the mouse, and click on run and
run module in python to run your code. You should see a stone block appear nearby. It might be in front of you or you may need to spin around to look for it. Each time you want a block to appear you need to run the program again. The number 1 in our code represents the stone
block. Each block in Minecraft has a different block ID. We can change this value in our
code to change the type of block. Here I’m changing the value 1 to the value 103. It
is one of my favourite block types…. Melon. You can find a list of all the blocks on the
Minecraft wiki. There is even a really handy image that you can see to help you remember
the block ID numbers. This is really useful when you want to code structures like buildings. When I write my minecraft pi programs, I often
use a variable name to reference the blocks I am using. This is helpful if I use lots
of block types. Here you can see I’ve added the label wood, and stored the block ID 17
in it. In my line of code to set the block instead of writing the block ID after the
coordinates, I’ve written wood and when I run the code it works in exactly the same
way. Some blocks in minecraft have extra attributes.
For example wool. Here I’ve changed my wood variable to wool and stored the block ID 35
in it. Then to select the colour of the wool I need to add another value in my set block
code. 1 gives us an orange wool block. If we change the value to 2 a pink wool block will appear and if I change the value to 3 a blue wool block will appear. What
other colours can you create? So that is how to set a single block of different
type in Minecraft Pi. In the next episode I’ll show you how to make a trail of blocks
before we start to look at how to set multiple blocks! My name is Carrie Anne, and you’ve been watching
the Geek Gurl Diaries!

5 Replies to “How to Code Blocks in Minecraft Pi”

  1. nice to see how it works CA can you do a few more for us please. how to code a whole house etc as a single build instead of block by block.

Leave a Reply

Your email address will not be published. Required fields are marked *