Is it possible to connect a Minecraft Python script to a specific active game window when multiple game windows are currently open?

For example, I have three different open games on one Raspberry Pi connected to another Raspberry Pi hosting as a Minecraft server. The idea is to have two of the active windows follow different players while I play the game with the third window.

#specify ip address and port
mc = minecraft.Minecraft.create("", 4711)

#set camera mode to follow for a specific player

The script always attaches to the first active game. I'd like to be able to write different scripts for different active games. If I could target a game in code, great. Otherwise, is there some command line magic or other solution that will do the trick?

1 Answer 1


The only two arguments that create() provides are host IP and port. If you require running on a single Raspberry Pi, this practically rules out using the first one.

Tip: You can use strace -f /opt/minecraft-pi/minecraft-pi to get a log of all files that the program touches on startup. Apparently it does touch options.txt like other Minecraft editions. strings minecraft-pi can be used to find possible options, but there do not appear to be any to control the port number.

So if we resort to modifying the executable:

sudo apt install hexedit
cd /opt/minecraft-pi/
sudo cp minecraft-pi minecraft-pi-4712
sudo hexedit minecraft-pi-4712

The default port 4711 is 0x1267 in hex, which gets stored as 0x67, 0x12, 0x00, 0x00 in little endian. Search for 67120000 in hexedit, change all four instances to 68120000, and save the modified binary. Then when you run:


and start a game, you can connect to that instance on port 4712 while the existing ./minecraft-pi still listens on port 4711.

(Note: If the new binary gives you a "failed to add service" error, it likely requires the wrapper. See the helper script at /usr/bin/minecraft-pi)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.