5
\$\begingroup\$

I've been teaching Python programming to a friend's son using the book Adventures in Minecraft. This book comes with a starter kit that contains a pre-configured Bukkit (v.1.6.4) server, and targets Minecraft 1.6.4.

My friend's son would like to use a more recent version of Minecraft, unfortunately Bukkit is no longer maintained.

Is there another way to use Python with Minecraft? I've googled a bit but without success. I'm not a player of Minecraft myself so there is a lot of Minecraft terminology that I don't understand.

Thanks

\$\endgroup\$
3
  • \$\begingroup\$ AFAIK not really. Minecraft itself is Java, and the general approach for modding and add ons is to use java. modding the standalone system with python would probably require including a python interpreter and bindings between the java and python environments to your mod package. \$\endgroup\$ Oct 31, 2016 at 12:24
  • \$\begingroup\$ Have you tried if it works with the spigot server? The 2 are basically the same, most plugins work on both \$\endgroup\$
    – Bálint
    Feb 1, 2017 at 6:52
  • 2
    \$\begingroup\$ +1 - this question deserves an up-to-date and detailed answer. \$\endgroup\$
    – Yost777
    Dec 29, 2020 at 8:18

5 Answers 5

4
+50
\$\begingroup\$

There are a wide variety of ways to interact with Minecraft programatically, including an official Javascript "add-on" API to the "bedrock" version of Minecraft, APIs for Minecraft servers, unofficial hacks on the client side to the Java version of Minecraft, and other specialized offerings. They are briefly introduced at Minecraft modding (Wikipedia) and covered in more detail at the Official Minecraft Wiki. (I'd love to see a good comparison of how comprehensive each approach is, and how the APIs compare....)

Here I'll cover just one approach, which explains how to connect with Python to a "Spigot" Minecraft server and manipulate the world and players. It supports a Python 3 API rooted in the Minecraft: Pi Edition for Raspberry Pi described at <Stuff about="code" />: Minecraft.

The full explanation, with videos for a Windows 10 environment, is at Learn Python With Minecraft — Part 1: Setting Up The Environment | by Carlos Argueta | Medium. Here is a quick summary of the steps, as I did them in Debian Linux "Buster" in the standard Crostini virtual environment on a Chromebook (Pixelbook Go):

  • Download Minecraft (Java version)

  • If necessary, download and install Python, e.g. version 3.8

  • Download Carlos' Minecraft server, which seems to be based on Spigot and CraftBukkit, from https://sourceforge.net/projects/learn-python-minecraft-win/files/latest/download

  • Unzip Carlos' server

  • Run python -m pip install minecraftPythonAPI.zip

  • Start the server up via java -Xmx1024M -Xms1024M -jar spigot.jar (Carlos provides a .bat file for that for Windows). When you run spigot for the first time, it automatically creates a new Minecraft world for you

  • Notice which version of Spigot you're running. It is listed towards the top of the output of the java command, and is currently 1.14.4. More specifically in my case: [Server thread/INFO]: This server is running CraftBukkit version git-Spigot-ea7e48b-368f4e9 (MC: 1.14.4) (Implementing API version 1.14.4-R0.1-SNAPSHOT)

  • You need to launch the same version of Java Minecraft as you're running on the server. That requires using the Minecraft launcher, and downloading a different version (currently 1.14.4) as shown in his video number 5.

  • Run the matching version in multiplayer, and add your server, by specifying a network address as "localhost".

  • Note that Minecraft defaults to creative mode

  • Run some Python code like this, which just shows where the player is, and then moves the player:

from mcpi.minecraft import Minecraft
mc = Minecraft.create()
PlayerTile = mc.player.getTilePos()
print(PlayerTile)
mc.player.setTilePos(0, 140, 0)

See also an early demo of the Pi interface but note you have to change two lines to import via mcpi rather than minecraft, e.g.
import mcpi.minecraft as minecraft.

More code snippets are at the github repo Learn-Python-With-Minecraft

A completely different option out there might also be of interest. It allows Python programming for Minecraft version 1.12.2 from 2017, and is supported with these instructions, which covers installing the older version, and handles Python 2.7 or 3: Python Coding for Minecraft : 18 Steps (with Pictures) - Instructables. There are recent comments from the author so it seems to still be relevant.

\$\endgroup\$
2
  • 2
    \$\begingroup\$ Can you summarize the key steps here, so the information isn't lost if the Instructables link ever becomes inaccessible? \$\endgroup\$
    – DMGregory
    Jan 1, 2021 at 18:04
  • \$\begingroup\$ Thanks for the link, but some more detail is needed here please - what environments (going with Python 3 of course), which tools are needed, will it run on Bedrock etc? \$\endgroup\$
    – Yost777
    Jan 2, 2021 at 16:12
1
\$\begingroup\$

Using jycraft and Spigot, I think you could easily get a server up and running with python.

\$\endgroup\$
1
  • 1
    \$\begingroup\$ This answer would be better if it included steps for how to do this. \$\endgroup\$
    – DMGregory
    Jan 1, 2021 at 19:29
1
\$\begingroup\$

Minecraft Education Edition (https://education.minecraft.net/) offers an immersive integration with Python, however this requires an educational account so that's not a general solution for everyone.

Besides this, there are a number of Java environments, but I don't know about Python environments. I did find this article: https://medium.com/@kidargueta/learn-python-with-minecraft-part-1-setting-up-the-environment-fa0c7f9e3ca6

\$\endgroup\$
4
  • 3
    \$\begingroup\$ Can you summarize the key points of that article, so the information is preserved even if the Medium link becomes inaccessible in future? \$\endgroup\$
    – DMGregory
    Jan 1, 2021 at 18:05
  • \$\begingroup\$ For key point / detail, see rewarded answer from @nealmcb \$\endgroup\$
    – Yost777
    Jan 12, 2021 at 11:28
  • \$\begingroup\$ If you don't have anything to add that's not in another answer, would you prefer to delete this answer? \$\endgroup\$
    – DMGregory
    Jan 12, 2021 at 13:36
  • \$\begingroup\$ Minecraft Education Edition is not mentioned elsewhere, and can potentially still be useful for those that have access to it (i.e. students). Obv this was posted before the answer was posted that I rewarded. \$\endgroup\$
    – Yost777
    Jan 12, 2021 at 16:12
0
\$\begingroup\$

Unfortunately, Minecraft mods are (as far as my knowledge goes) coded in Java. But, you might be able to convert the .py files into .jar using a program such as Jython. I steal it from here:

Distributing Python Scripts as Jar Files with Jython

\$\endgroup\$
-1
\$\begingroup\$

You could get a Raspberry Pi which has a special version of Minecraft that can easily be scripted with Python. The default OS for Raspberry Pi's is a Debian fork called Raspbian which comes with the special version of Minecraft preinstalled.

There are tons of tutorials online and Mag Pi #41 is actually dedicated to Minecraft creations.

Here is a link to the tutorial I first used after getting my Pi. It starts with the very basics and will walk him through all the steps involved in creating mods with Minecraft.

https://www.raspberrypi.org/learning/getting-started-with-minecraft-pi/

A Raspberry Pi can be had for ~$35 dollars and most people have all the other peripherals needs(Micro SD card, Micro USB for power, keyboard, mouse, monitor).

As a side note if he ends up liking programming there are tons of cool projects that can be done with a Raspberry Pi with varying degrees of difficulty.

\$\endgroup\$
1
  • 2
    \$\begingroup\$ The Raspberry Pi version of Minecraft is also very old and is not maintained. \$\endgroup\$
    – Bálint
    Feb 1, 2017 at 6:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .