--Minecraft Pi Edition running on Raspberry Pi + Raspbian environment Display Hello World using the Python library mcpi
Minecraft Pi Edition is a free version of Minecraft developed for learning programming on the Raspberry Pi.
It's probably installed on Raspbian from the beginning, but if you don't have it, install the minecraft-pi package with the apt or apt-get command.
$ sudo apt install minecraft-pi
Loading the package list...Done
Creating a dependency tree
Reading status information...Done
minecraft-pi is already the latest version(0.1.1-6)is.
I think that the Python mcpi package (Minecraft Pi Edition API Python Library) is also installed, but if it is not there, install it with the pip command.
$ sudo pip install mcpi
Looking in indexes: https://pypi.org/simple, https://www.piwheels.org/simple
Requirement already satisfied: mcpi in /usr/lib/python2.7/dist-packages (0.1.1)
$ pip show mcpi
Name: mcpi
Version: 0.1.1
Summary: API for Minecraft Pi
Home-page: http://pi.minecraft.net/
Author: Mojang
Author-email: UNKNOWN
License: UNKNOWN
Location: /usr/lib/python2.7/dist-packages
Requires:
Required-by:
Launch Minecraft Pi Edition and
Create a world and enter it.
Save the following source code and
hello-minecraft.py
from mcpi import minecraft
import mcpi.block as block
mc = minecraft.Minecraft.create("localhost")
pos = mc.player.getPos()
basex = int(pos.x) + 0
basey = int(pos.y) + 6
basez = int(pos.z) + 0
data = [
"# # ### # # ## # # ## ### # ### ",
"# # # # # # # # # # # # # # # # #",
"#### ### # # # # # # # # # ### # # #",
"# # # # # # # # # # # # # # # # #",
"# # ### ### ### ## # # ## # # ### ### "
]
for y, line in enumerate(data):
for x, c in enumerate(line):
if c == "#":
mc.setBlock(basex + x, basey - y, basez, block.DIAMOND_BLOCK.id)
When you run
$ python hello-minecraft.py
HELLO WORLD with diamond blocks appears.
Recommended Posts