Processing and Minecraft

Hi,
I’m teaching my students basic programming and would like to know if there’s any way to join processing language with minecraft through any mod or something else.
I would like to interact with the world, bot programming, etc…

It would be an awesome way to get them focused hehe.
As minecraft is also java based, it should not be very complicated I think.

4 Likes

Cool!! I had a Raspberry Pi sitting around and got the basic connection working with Minecraft Pi. The process may be similar on Windows/macOS but I don’t have a license (yet).

First, create a new sketch and add a code folder within the sketch’s folder. Next, copy the McPi.jar file from /opt/minecraft-pi/api/java/lib/ to the sketch’s code folder. With a game open, run the following sketch.

import pi.Minecraft;

void setup() {
  Minecraft mc = Minecraft.connect();
}

void draw() {
  // profit
}

I teach mathematics and computer science and would love to help out–just started a project.

2 Likes

At least in the Windows version (but it should work for all OS versions AFAIK), dragging and releasing a “.jar” file on the PDE automatically creates the subfolder “code/” and copy the “.jar” file into it. :coffee:

2 Likes

Nice–yep works on the Pi!

1 Like

Great you are also interested!
I’m using mac licensed version and can’t find the lib to import. anyone?

Made a little progress on macOS this afternoon–might suggest a general solution.

I installed version 1.12.2 of Minecraft, Forge, and the Raspberry Jam Mod, which implements nearly the same API as Minecraft Pi.

I created a world and tried running the rainbow example with Jython from the terminal and it worked! Next, I modified the rainbow example a bit in Python Mode, saved the sketch, then copied the mcpi package to the sketch’s folder. I created another new world, ran the sketch, and clicked on the window that popped up.

import mcpi.minecraft as minecraft
import mcpi.block as block
from math import *

colors = [14, 1, 4, 5, 3, 11, 10]
mc = minecraft.Minecraft.create()
rainbow_height = 60
mc.setBlocks(-64, 0, 0, 64, rainbow_height + len(colors), 0, 0)
            
def draw():
    if mousePressed:
        for x in range(0, 128):
            for colourindex in range(0, len(colors)):
                y = sin((x / 128.0) * pi) * rainbow_height + colourindex
                mc.setBlock(x - 64, y, 0, block.WOOL.id, colors[len(colors) - 1 - colourindex])

Translating the mcpi package to Processing/Java could be a good starting point for something that works cross-platform.

2 Likes

There are so many ways to engage students learning to program.

It all started here:

I have had success with these individually and in combination to create some very cool projects:

  1. Serial communications
    Electronics / Processing.org
  • Processing to\from Ardunio
  • Processing to\from Processing
  • Processing to applications that use serial communications
  • Processing to any hardware that has serial communications
  1. Network Client to Server
    Network / Processing.org

  2. Data from Network and PC
    https://processing.org/tutorials/data/
    XML, JSON, tables, text files, etc.

  3. Sound
    Sound / Processing.org

  4. Interactivity:
    Interactivity / Processing.org

  • keyboard, mouse and check out tools and libraries!
  1. Print
    Print / Processing.org

  2. GUI interface to run a command-line tool
    I used some JAVA directly for this in the Processing applications.
    It was to control my LCD screen colors; I created an interface to a free command-line tool that did this.

  3. Video
    Video / Processing.org

  4. And… check out the tools and libraries in the Processing software!

  5. And… there are other modes like Android mode!
    Ketai libraries:
    http://ketai.org/

I mostly just tinker with it as a hobby and posted some videos here:

:slight_smile:

Do you know how to read data from minecraft? For example: money, x, y, z position, active enchantment …

What form of Minecraft are you running – what version, on what hardware / platform, with what operating system? Did you try the version and example described above?

The version I have is 1.14 on PC x64 bits. Finally, what I want is to send data such as position, life, hunger, strength, that kind of variables towards arduino led matrix. But I have no idea how to read data from minecraft. I will try your example for var if it works on PC.