Attempts to start teaching a child programming with Minecraft pocket edition







In the yard, autumn and the son more often remain at home, buried in a phone or tablet, poorly reacting to external stimuli. It saddens me. I myself began to program, it seems to me, from the fact that the games went to my first computer BK 0010-01 on cassettes, but the tape recorder did not go. While mining a tape recorder with a suitable linear output, I managed to try Basic, thanks to my father for the first lessons. So when I was able to load the first graphic game with a creak, I looked at it no longer as what I would finally play, but fascinatedly thought how to make my own worse. His son, in his 8 years old, has long devoured the world of video games and YouTube, so it seems that he will not make an impression of starting programming with a trill on the built-in dynamics.







I have come across articles about programming with Minecraft in Python for a long time and then I realized that it was time. Minecraft is one of his favorite games and I thought it would be better to start with this well-developed territory.







However, having run through the information available in the public domain, I realized that everything is very difficult. Found books " Programming with Minecraft. Create your world with Python " in 2017 and " Minecraft. Program your world in Python " in 2018 begin with the installation of Spigot and Bukkit servers, respectively. It turned out that mobile clients that are on android / iphone, they are also pocket edition, they are also bedrock edition, do not work with these servers. You need to buy a client for Windows / Mac, which spoils the whole venture. Firstly, it will no longer be the “native” environment familiar to the son. Secondly, to transfer for the sake of programming to another environment will demonstrate a weakness, perhaps, of the approach, they say the games are separate, the programs are separate. Thirdly, the son will probably want to show his experiments to friends, and it’s mobile versions that are popular with friends. It’s impossible, I decided, since these mobile toys can connect to servers, not everything is lost. And I began to search.







On the first day, my chrome was packed full of tabs, and chaos reigned in my head.

The first one was the open-source Nukkit server, to which the game on my android connected quite successfully. The only point here is that we need the current version of the game (1.12 for today), so I needed to update it first. The server has many plugins, but a plugin suitable for programming, such as described in books, was not found.







True, PyPlugins was found , which seems to run Jython - a version of python in java. But, as I understand it, jython settled on the python 2.7 language version. Set aside this option as unsportsmanlike.







Let's go on the other hand, but how did the authors of the books mean connecting python to the servers? Having carefully studied additional materials for books, since they are freely available, I found the RaspberryJuice plugin, carefully hidden in the plugins directory (not a word about it in the book), it then opens a network socket in anticipation of commands. And the commands are sent by the Python library mcpi . Thanks to the authors, all are open source. It bothered me a bit that the last commit was 2-4 years ago.







But how to connect RaspberryJuice to Nukkit? And here it is searched, don’t laugh, Pokkit is a Nukkit plugin for running plugins for Bukkit. I don’t know why the names are so, but it added me an extra hour of searching, since at first I confused them. It seems now all the parts of the puzzle are in place, but the launch reveals an error: java.lang.NoSuchFieldError: GOLD_SWORD



. It's a shame, because in the description of Pokkit it was noted that RaspberryJuice is on the list of supported ones. Issued a bug . Surprisingly, the answer came quickly - the plugin is out of date. “Everything is rusty here,” the phrase from my favorite movie came to mind. After clarification, the author kindly explained where to get the modern API for bukkit , and then "we really somehow." Forked outdated plugin, pretty quickly replaced all methods that disappeared in the current version of the API, finding a replacement for them. It turned out something like world.getBlockTypeIdAt(loc)



changed to world.getBlockAt(loc).getType().getId()



. However, one point is still significant: earlier it was possible to make a rainbow from the same blocks (as in the example, block.WOOL



), painted in different colors. Now it’s impossible to repaint the blocks, you must take the initially multi-colored blocks ( Material.RED_WOOL



, Material.BLUE_CARPET



). Issued a pull request and found that there are two more pull requests there, both fresh. Next time, check it out first ...







So, the instruction on how to quickly launch this pyramid from Nukkit-Pokkit-RaspberryJuice-mcpi:







  1. We take a suitable server, to which there is access from your mobile Minecraft s. For example, a home computer with an open port of 19132 (the default). It's easier for me on linux, but any OS with java runtime environment is suitable.
  2. Nukkit Server Download the recommended JAR from the "Downloads" link or build your own from the source ( mvn clean package



    ). We put it in a separate directory and simply run java -jar nukkit-1.0-SNAPSHOT.jar



    .
  3. Pokkit plugin. Download the recommended JAR from the Download and usage link or build your own from the source ( mvn clean package



    ). We put in the plugins



    directory, which was formed after step 2. Stop and restart the server, as in step 2.
  4. RaspberryJuice plugin with my patch . Download the recommended JAR from the link or collect your own from the source ( pocket-edition



    branch, mvn clean package



    ). We put in the directory plugins/Pokkit/bukkitPlugins/



    , which was formed after step 3. We stop and restart the server.
  5. We connect mobile minecraft to the server: Play - Servers - Other servers - add a new one or edit the existing one: "server name" - to your taste, "server address" - server IP address from step 1, "port" 19132, if not changed in the config . Save and connect.
  6. Install python 3 and the mcpi library: pip3 install --user py3minepi



    . After that, you can run the examples from books 1 and 2 by simply entering python3 Adventure3/dice.py





UPD: in step 6, you need to install the mcpi library like this: git clone https://github.com/py3minepi/py3minepi.git && cd py3minepi && pip3 install --user .



(at the end the point is needed). This is due to the fact that the author of the plugin has the latest version of python 3.4 registered.







You can try without python (step 6) by connecting to the plug-in with the usual netcat: nc localhost 19132



and entering the commands manually:









My experiments can be seen in the initial picture of this post.







If it rains or night falls and is hard to see, enter the commands time set 0



and weather clear



in the server console.







That's all. It's great that there is open source and now it’s so simple, by searching in the public domain, in a few evenings to build such a pyramid of working programs. I especially want to note the friendliness and almost instant answers in the chats of many projects.







I also found this wonderful video about rendering docker server containers in the Minecraft world:









The son’s containers are unlikely to interest, but blinking with LEDs in response to switching cartoon switches is the thing. I will be glad to advise what else would come up with such an unusual one for teaching programming.








All Articles