Tag Archives: Minecraft

Build a house in Minecraft using Python

via Raspberry Pi

In this tutorial from The MagPi issue 68, Steve Martin takes us through the process of house-building in Minecraft Pi. Get your copy of The MagPi in stores now, or download it as a free PDF here.

Minecraft Pi is provided for free as part of the Raspbian operating system. To start your Minecraft: Pi Edition adventures, try our free tutorial Getting started with Minecraft.

Minecraft Raspberry Pi

Writing programs that create things in Minecraft is not only a great way to learn how to code, but it also means that you have a program that you can run again and again to make as many copies of your Minecraft design as you want. You never need to worry about your creation being destroyed by your brother or sister ever again — simply rerun your program and get it back! Whilst it might take a little longer to write the program than to build one house, once it’s finished you can build as many houses as you want.

Co-ordinates in Minecraft

Let’s start with a review of the coordinate system that Minecraft uses to know where to place blocks. If you are already familiar with this, you can skip to the next section. Otherwise, read on.

Minecraft Raspberry Pi Edition

Plan view of our house design

Minecraft shows us a three-dimensional (3D) view of the world. Imagine that the room you are in is the Minecraft world and you want to describe your location within that room. You can do so with three numbers, as follows:

  • How far across the room are you? As you move from side to side, you change this number. We can consider this value to be our X coordinate.
  • How high off the ground are you? If you are upstairs, or if you jump, this value increases. We can consider this value to be our Y coordinate.
  • How far into the room are you? As you walk forwards or backwards, you change this number. We can consider this value to be our Z coordinate.

You might have done graphs in school with X going across the page and Y going up the page. Coordinates in Minecraft are very similar, except that we have an extra value, Z, for our third dimension. Don’t worry if this still seems a little confusing: once we start to build our house, you will see how these three dimensions work in Minecraft.

Designing our house

It is a good idea to start with a rough design for our house. This will help us to work out the values for the coordinates when we are adding doors and windows to our house. You don’t have to plan every detail of your house right away. It is always fun to enhance it once you have got the basic design written. The image above shows the plan view of the house design that we will be creating in this tutorial. Note that because this is a plan view, it only shows the X and Z co-ordinates; we can’t see how high anything is. Hopefully, you can imagine the house extending up from the screen.

We will build our house close to where the Minecraft player is standing. This a good idea when creating something in Minecraft with Python, as it saves us from having to walk around the Minecraft world to try to find our creation.

Starting our program

Type in the code as you work through this tutorial. You can use any editor you like; we would suggest either Python 3 (IDLE) or Thonny Python IDE, both of which you can find on the Raspberry Pi menu under Programming. Start by selecting the File menu and creating a new file. Save the file with a name of your choice; it must end with .py so that the Raspberry Pi knows that it is a Python program.

It is important to enter the code exactly as it is shown in the listing. Pay particular attention to both the spelling and capitalisation (upper- or lower-case letters) used. You may find that when you run your program the first time, it doesn’t work. This is very common and just means there’s a small error somewhere. The error message will give you a clue about where the error is.

It is good practice to start all of your Python programs with the first line shown in our listing. All other lines that start with a # are comments. These are ignored by Python, but they are a good way to remind us what the program is doing.

The two lines starting with from tell Python about the Minecraft API; this is a code library that our program will be using to talk to Minecraft. The line starting mc = creates a connection between our Python program and the game. Then we get the player’s location broken down into three variables: x, y, and z.

Building the shell of our house

To help us build our house, we define three variables that specify its width, height, and depth. Defining these variables makes it easy for us to change the size of our house later; it also makes the code easier to understand when we are setting the co-ordinates of the Minecraft bricks. For now, we suggest that you use the same values that we have; you can go back and change them once the house is complete and you want to alter its design.

It’s now time to start placing some bricks. We create the shell of our house with just two lines of code! These lines of code each use the setBlocks command to create a complete block of bricks. This function takes the following arguments:

setBlocks(x1, y1, z1, x2, y2, z2, block-id, data)

x1, y1, and z1 are the coordinates of one corner of the block of bricks that we want to create; x1, y1, and z1 are the coordinates of the other corner. The block-id is the type of block that we want to use. Some blocks require another value called data; we will see this being used later, but you can ignore it for now.

We have to work out the values that we need to use in place of x1, y1, z1, x1, y1, z1 for our walls. Note that what we want is a larger outer block made of bricks and that is filled with a slightly smaller block of air blocks. Yes, in Minecraft even air is actually just another type of block.

Once you have typed in the two lines that create the shell of your house, you almost ready to run your program. Before doing so, you must have Minecraft running and displaying the contents of your world. Do not have a world loaded with things that you have created, as they may get destroyed by the house that we are building. Go to a clear area in the Minecraft world before running the program. When you run your program, check for any errors in the ‘console’ window and fix them, repeatedly running the code again until you’ve corrected all the errors.

You should see a block of bricks now, as shown above. You may have to turn the player around in the Minecraft world before you can see your house.

Adding the floor and door

Now, let’s make our house a bit more interesting! Add the lines for the floor and door. Note that the floor extends beyond the boundary of the wall of the house; can you see how we achieve this?

Hint: look closely at how we calculate the x and z attributes as compared to when we created the house shell above. Also note that we use a value of y-1 to create the floor below our feet.

Minecraft doors are two blocks high, so we have to create them in two parts. This is where we have to use the data argument. A value of 0 is used for the lower half of the door, and a value of 8 is used for the upper half (the part with the windows in it). These values will create an open door. If we add 4 to each of these values, a closed door will be created.

Before you run your program again, move to a new location in Minecraft to build the house away from the previous one. Then run it to check that the floor and door are created; you will need to fix any errors again. Even if your program runs without errors, check that the floor and door are positioned correctly. If they aren’t, then you will need to check the arguments so setBlock and setBlocks are exactly as shown in the listing.

Adding windows

Hopefully you will agree that your house is beginning to take shape! Now let’s add some windows. Looking at the plan for our house, we can see that there is a window on each side; see if you can follow along. Add the four lines of code, one for each window.

Now you can move to yet another location and run the program again; you should have a window on each side of the house. Our house is starting to look pretty good!

Adding a roof

The final stage is to add a roof to the house. To do this we are going to use wooden stairs. We will do this inside a loop so that if you change the width of your house, more layers are added to the roof. Enter the rest of the code. Be careful with the indentation: I recommend using spaces and avoiding the use of tabs. After the if statement, you need to indent the code even further. Each indentation level needs four spaces, so below the line with if on it, you will need eight spaces.

Since some of these code lines are lengthy and indented a lot, you may well find that the text wraps around as you reach the right-hand side of your editor window — don’t worry about this. You will have to be careful to get those indents right, however.

Now move somewhere new in your world and run the complete program. Iron out any last bugs, then admire your house! Does it look how you expect? Can you make it better?

Customising your house

Now you can start to customise your house. It is a good idea to use Save As in the menu to save a new version of your program. Then you can keep different designs, or refer back to your previous program if you get to a point where you don’t understand why your new one doesn’t work.

Consider these changes:

  • Change the size of your house. Are you able also to move the door and windows so they stay in proportion?
  • Change the materials used for the house. An ice house placed in an area of snow would look really cool!
  • Add a back door to your house. Or make the front door a double-width door!

We hope that you have enjoyed writing this program to build a house. Now you can easily add a house to your Minecraft world whenever you want to by simply running this program.

Get the complete code for this project here.

Continue your Minecraft journey

Minecraft Pi’s programmable interface is an ideal platform for learning Python. If you’d like to try more of our free tutorials, check out:

You may also enjoy Martin O’Hanlon’s and David Whale’s Adventures in Minecraft, and the Hacking and Making in Minecraft MagPi Essentials guide, which you can download for free or buy in print here.

The post Build a house in Minecraft using Python appeared first on Raspberry Pi.

MagPi 68: an in-depth look at the new Raspberry Pi 3B+

via Raspberry Pi

Hi folks, Rob from The MagPi here! You may remember that a couple of weeks ago, the Raspberry Pi 3 Model B+ was released, the updated version of the Raspberry Pi 3 Model B. It’s better, faster, and stronger than the original and it’s also the main topic in The MagPi issue 68, out now!

Everything you need to know about the new Raspberry Pi 3B+

What goes into ‘plussing’ a Raspberry Pi? We talked to Eben Upton and Roger Thornton about the work that went into making the Raspberry Pi 3B+, and we also have all the benchmarks to show you just how much the new Pi 3B+ has been improved.

Super fighting robots

Did you know that the next Pi Wars is soon? The 2018 Raspberry Pi robotics competition is taking place later in April, and we’ve got a full feature on what to expect, as well as top tips on how to make your own kick-punching robot for the next round.

More to read

Still want more after all that? Well, we have our usual excellent selection of outstanding project showcases, reviews, and tutorials to keep you entertained.

See pictures from Raspberry Pi’s sixth birthday, celebrated around the world!

This includes amazing projects like a custom Pi-powered, Switch-esque retro games console, a Minecraft Pi hack that creates a house at the touch of a button, and the Matrix Voice.

With a Pi and a 3D printer, you can make something as cool as this!

Get The MagPi 68

Issue 68 is available today from WHSmith, Tesco, Sainsbury’s, and Asda. If you live in the US, head over to your local Barnes & Noble or Micro Center in the next few days for a print copy. You can also get the new issue online from our store, or digitally via our Android and iOS apps. And don’t forget, there’s always the free PDF as well.

New subscription offer!

Want to support the Raspberry Pi Foundation and the magazine? We’ve launched a new way to subscribe to the print version of The MagPi: you can now take out a monthly £4 subscription to the magazine, effectively creating a rolling pre-order system that saves you money on each issue.

You can also take out a twelve-month print subscription and get a Pi Zero W, Pi Zero case, and adapter cables absolutely free! This offer does not currently have an end date.

That’s it for now. See you next month!

The post MagPi 68: an in-depth look at the new Raspberry Pi 3B+ appeared first on Raspberry Pi.

Make with Minecraft Pi in The MagPi 58

via Raspberry Pi

Hey folks, Rob here! What a busy month it’s been at The MagPi HQ. While we’ve been replying to your tweets, answering questions on YouTube and fiddling with our AIY Voice Project kits, we’ve managed to put together a whole new magazine for you, with issue 58 of the official Raspberry Pi magazine out in stores today.

The front cover of The MagPi 58

The MagPi 58 features our latest Minecraft Pi hacks!

Minecraft Pi

The MagPi 58 is all about making with Minecraft Pi. We’ve got cool projects and hacks that let you take a selfie and display it in the Minecraft world, play music with Steve jumping on a giant piano, and use special cards to switch skins in an instant. It’s the perfect supplement to our Hacking and Making in Minecraft book!

AIY Voice Projects

It’s been great to see everyone getting excited over the last issue of the magazine, and we love seeing your pictures and videos of your AIY Voice projects. In this issue we’ve included loads of ideas to keep you going with the AIY Projects kit. Don’t forget to send us what you’ve made on Twitter!

Issue 57 of The MagPi, showing the Google AIY Voice Projects Kit

Show us what you’ve made with your AIY Voice Projects Kit

The best of the rest in The MagPi 58

We’ve also got our usual selection of reviews, tutorials, and projects. This includes guides to making file servers and electronic instruments, along with our review of Adafruit’s Joy Bonnet handheld gaming kit.

A page from The MagPi 58 showing information on 'Getting Started with GUIs'

You can get started with GUIs in The MagPi 58

You can grab the latest issue in stores in the UK right now, from WHSmith, Sainsburys, Asda, and Tesco. Copies will be arriving very soon in US stores, including Barnes & Noble and Micro Center. You can also get a copy online from our store, or digitally via our Android or iOS app. Don’t forget, there’s always the free PDF as well.

We hope you enjoy the issue! Now if you’ll excuse us, we need a nap after all the excitement!

The post Make with Minecraft Pi in The MagPi 58 appeared first on Raspberry Pi.

Minecraft Pi (and more) over VNC

via Raspberry Pi

RealVNC have released a free alpha (testing) version of VNC for Raspberry Pi that lets you remotely view and control everything on your Pi, including Minecraft, from a different computer. It works on every generation of Raspberry Pi, including Pi Zero. Here’s a demo:

VNC for Raspberry Pi alpha – playing Minecraft

With the VNC for Raspberry Pi alpha, you can play Minecraft, access the Pi’s text console and switch between workspaces – all over a VNC connection. We’ve also added hardware acceleration, making connections faster and smoother. To try it out, visit RealVNC’s GitHub: https://github.com/RealVNC/raspi-preview.

Previously, it hasn’t been possible to view software that uses a directly rendered overlay – such as Minecraft, the camera module preview and OMXPlayer – over a VNC connection. It’s a feature that lots of people have long wished for, not least because it means that schools and other organisations can use existing equipment, such as laptops, as displays for their Raspberry Pis, so it’s fantastic to see a VNC server that supports it.

Our Head of Curriculum Development, Marc Scott, has spent some time taking a look, and he was impressed:

The performance was great, once the settings had been played with a little, and set-up was easy just by following the instructions on the GitHub repo: https://github.com/RealVNC/raspi-preview#startVnc.

Once this is perfected, it will certainly be fantastic for teachers and students, who will be able to use their existing ICT infrastructure to connect and control their Raspberry Pis.

It’s fair to say the new version has been well received by the Raspberry Pi community so far:

CovAndWarksRaspiJam on Twitter

@RealVNC THIS IS AMAZING!pic.twitter.com/WReVGiRaUl

We’ve been looking forward to this since RealVNC tantalised us with a cracking demo at our fourth birthday party in March, and we’re delighted to see it out there. In releasing a public alpha, RealVNC are hoping for your feedback to help them make it as good as possible, so download it, give it a go and tell them what you think!

The post Minecraft Pi (and more) over VNC appeared first on Raspberry Pi.

Mashup Minecraft with The MagPi #41

via Raspberry Pi

The New Year 2016 edition of the official Raspberry Pi magazine is out now!

Click to find out what else is happening this month!

Click the pic to be magically transported to the pixelated world of The MagPi!

For many of our new readers this marks the magazine’s ‘difficult second album’, which begs the question: how do you top the first magazine in history to to give away a free computer on its cover?

Obviously, we can’t, but what we can do is delivery on one of the promises we made on last month’s cover – learning to code while you play Minecraft. We’ve collected some of our favourite Minecraft ideas and experiments for this month’s cover feature, some of which cross the void between Minecraft’s virtual world and own own. It’s not to be missed!

Elsewhere this issue we celebrate ESA Astronaut Tim Peake’s successful arrival on the International Space Station with some more of our favourite Astro Pi-inspired Sense HAT projects, and we’re helping you get the best possible start to 2016 with 10 New Year’s resolutions made possible with the help of the Raspberry Pi.

Subscriber copies of #41 will be dropping through letterboxes all over the world between Christmas and New Year.

Highlights from #41:

  • Minecraft Mashups
    Stunning Raspberry Pi projects that bring Minecraft’s virtual world to life
  • Your #PiZero projects
    Some of your best ideas and creations made with the $5 computer
  • Sense HAT special
    We celebrate Tim’s successful launch with more games and guides
  • New Year, new you!
    Awesome projects to help keep you honest in 2016
  • And much, much more!
#41 Minecraft Mashups #41 Review #41 Magic 8Ball #41 Project Focus

As always, you can download your copy of The MagPi completely free. Grab it straight from the front page of The MagPi’s website.

Don’t forget though, that like sales of the Raspberry Pi itself, all proceeds from the print and digital editions of the magazine go to help the Foundation achieve its charitable goals. Help us democratise computing!

If you want something more tangible to play with, you’ll be glad to hear you can get the print edition in more stores than ever:

And all good newsagents

US readers will be able to buy the fabled #40 with its free #PiZero covermount from either Barnes & Noble or Micro Center from around the 16th January 2016.

Rather shop online? The Raspberry Pi Swag Store has copies that can be delivered practically anywhere in the world.

If you still want to start a new subscription with #40, with a free #PiZero and a free cable bundle, you can! Just make sure you select the right option when you sign-up online or over the phone.

#41 will be arriving with readers between Christmas and New Year!

MAKE GAMES WITH PYTHON – new e-book out now!
Finally this month we’ve released the second in a new The MagPi Essentials e-book range. This time we’re showing you how to make games with Python on your Raspberry Pi.

Download the e-book for free or help raise funds for The Raspberry Pi Foundation by buying it on Apple & Android devices

It’s available as a free PDF download or as a digital edition on The MagPi app for Android and Apple devices. We’d love to learn about the games and interactive applications you make!

The post Mashup Minecraft with The MagPi #41 appeared first on Raspberry Pi.

Astro Pi on the BBC

via Raspberry Pi

Friday was an exciting day for the Astro Pi mission, which will see British ESA astronaut Tim Peake operate two Astro Pi flight units, each one containing a Raspberry Pi and a Sense HAT, on board the International Space Station! Tim will use the Astro Pis to run experiments and applications designed by UK school students as part of the Astro Pi competition, which ran earlier this year.

We were all absolutely thrilled when we discovered that competition winner Hannah Belshaw would be appearing on BBC One’s very popular live magazine programme, The One Show, along with Tim Peake, who will fly to the ISS to begin his six-month mission, Principia, in December.

The One Show, 06/11/2015

David Walliams and British astronaut Tim Peake join Alex Jones and Adil Ray.

Tim features throughout the first half of the show, and you can find Hannah and hear Tim talk about the Astro Pi mission from 9 minutes 15 seconds. The programme on iPlayer is only made available within the UK, but no matter where you are in the world, you can see from our screenshots that both Hannah and Tim are very happy to be on the show!

Astro Pi competition winner Hannah Belshaw, wearing an actual space suit British ESA astronaut Tim Peake

Tim explained to a peak-time audience that,

[T]his Astro Pi is going to be in various different modules running an experiment each week, and I’m going to send down the data so that during the mission [the schoolchildren] can see the data, see what they’ve managed to achieve, and if they need to modify the code they can send it back up to me and we’ll just keep that going throughout the mission.

We’re enormously excited that school students will be able to communicate with Tim while he’s on the International Space Station!

Hannah, who made her TV appearance wearing a real space suit, entered the Astro Pi competition with her design for a program that captures data from the Astro Pi’s many sensors for visualisation later in a Minecraft world. She entered at the primary-school level, so the code for her entry was written, under her guidance, by Minecraft expert Martin O’Hanlon. Columns of blocks represent environmental measurements such as pressure and humidity, and a giant, blocky model of the Space Station itself represents its movement and orientation, so that it will be possible to play back everything the Astro Pi detects while Tim Peake is running the program in space.

An Astro PI flight unit in its flight case, displaying the icon for Hannah's Astro Pi competition entry, "SpaceCRAFT".

An Astro PI flight unit in its flight case, displaying the icon for Hannah’s Astro Pi competition entry, SpaceCRAFT.

Read more about Hannah’s idea, and find out about the fantastic applications designed and coded by all the other Astro Pi competition winners, on the newly relaunched Astro Pi website! And you can get involved: all the hardware (except for the specially designed, space-grade aluminium flight cases) is available to buy, so that while Tim Peake is operating the Astro Pis in space, you can use exactly the same equipment on Earth.

Also on Friday, Raspberry Pi attended what will be Tim’s final UK press conference before flying to the International Space Station.

Mission Principia media launch

Tim spoke about Astro Pi during the conference, too – you’ll hear him talk about it starting 25 minutes in, with slightly more detail than was possible within The One Show’s format, but we strongly encourage you to listen to as much of the recording as you can, because it’s all tremendously interesting!

Tim will launch on a Soyuz spacecraft from the Baikonur cosmodrome in Kazakhstan at 11:02 GMT on 15 December 2015, along with NASA astronaut Tim Kopra and Russian cosmonaut Yuri Malenchenko. They are expected to rendezvous with the ISS later the same day, at 16:58 GMT. Our Astro Pi flight units should already be there when they arrive, since they’re scheduled for an earlier flight with a planned launch date of 3 December. With both launches just weeks away, we’re immensely excited, not only about the Astro Pi mission, but also about Mission Principia as a whole. We’ll have more to say before launch and during the mission: watch this space!

The post Astro Pi on the BBC appeared first on Raspberry Pi.