← All journal articles

Building UFOs in Minecraft using Python

Building UFOs in Minecraft

Minecraft is a popular sandbox game that allows users to create their own worlds, structures, and mechanisms. Python is a high-level programming language that is often used in a variety of fields, including science, finance, machine learning, and game development. In Minecraft, it is primarily used to create mods — custom modifications that add new features and capabilities to the game. With Python, you can create your own mods for Minecraft and even extend the functionality of existing mods.

In this article, we'll show you how to create a UFO in Minecraft using Python and a special library for interacting with the game - mcpi.

To connect Python to Minecraft, we use Python's free mode on our website progkids.com, but you can also use third-party libraries like mcpi.

Let's now write the code for the UFO project.

After importing the necessary libraries, we declare variables containing block ids and clear the area (fill the floor with hellstone, everything above the floor with air).

b1 = 169 b2 = 95 b3 = 165 color = 9 world.setCuboid(-63, 0, -63, 63, 50, 63, 0) world.setCuboid(-63, -1, -63, 63, -1, 63, 87)

Next, we declare variables for radius, height, and a counter variable.

r = 25 y = 60 i = 0

Preparation is over! You can start building.

Let's start with the plate itself:

for i in range(8): world.buildSphere(0, y, 0, r, b1) world.setCuboid(-r, y + 1 + i, -r, r, y + r, r, 0) world.setCuboid(-r, y - 1 - i, -r, r, y - r - i, r, 0) r -=1

With each iteration of the cycle, the radius of the spheres becomes smaller by one.

The result of the cycle:

Строительство НЛО в Minecraft

The next step is to build the upper part and floor for UFOs. To do this, we can use the BuildSphere and SetCuboID methods.

world.buildSphere(0, y, 0, r, b2, color) world.setCuboid(-r, y - 8, -r, r, y - r, r, 0) world.setCuboid(-13, y - 7, -13, 13, y - 7, 13, b1)
Строительство НЛО в Minecraft

Our flying saucer is almost ready! It remains to finish writing a program for building a beam coming from a UFO. It should look something like this:

This can be done using a cycle with spheres: each repetition of the cycle, their radius increases and their height decreases. Code example:

y1 = y - 9 r = 1 while y1 > 0: world.buildSphere(0, y1, 0, r, b3) y1 -= 4 r += 1

At this point, our project is ready! Its final form is:

Строительство НЛО в Minecraft

This is what the full program code looks like:

import mc from mc import * world.setTime(18000) b1 = 169 b2 = 95 b3 = 165 color = 9 world.setCuboid(-63, 0, -63, 63, 50, 63, 0) world.setCuboid(-63, -1, -63, 63, -1, 63, 87) r = 25 y = 60 i = 0 for i in range(8): world.buildSphere(0, y, 0, r, b1) world.setCuboid(-r, y + 1 + i, -r, r, y + r, r, 0) world.setCuboid(-r, y - 1 - i, -r, r, y - r - i, r, 0) r -=1 world.buildSphere(0, y, 0, r, b2, color) world.setCuboid(-r, y - 8, -r, r, y - r, r, 0) world.setCuboid(-13, y - 7, -13, 13, y - 7, 13, b1) y1 = y - 9 r = 1 while y1 > 0: world.buildSphere(0, y1, 0, r, b3) y1 -= 4 r += 1

Ref. for a ready-made UFO project, sign up at progkids.com to open the link.

Programming in Minecraft can be a very interesting and exciting activity. Using Python, you can create your own games and mods that are unique and interesting for players around the world. If you want to start coding in Minecraft, sign up for a trial class at our progkids.com school!

You can also read

Courses for kids

Progkids обратная связь

It's easy to sign up for a free class

Already in the first lesson, we'll dive into the basics of development and create a small project that your child will want to brag about.

Submit a request

ok image
Ваша заявка отправлена. Скоро мы свяжемся с Вами
Ошибка при отправке формы