[Mod] Raspberry PI MC API for Python code [raspberryjammod]

arpruss
Member
Posts: 39
Joined: Sat Sep 26, 2015 14:01
GitHub: arpruss

[Mod] Raspberry PI MC API for Python code [raspberryjammod]

by arpruss » Post

Mod to emulate the Raspberry PI Minecraft API for writing Python code that functions in Minecraft.

Code: MIT License
Sample scripts: Varies (see script)
Mod dependancies: Default

Download: zip file from github for Windows MSVC build of Minetest

If you replace the socket/core.dll file with a a Linux or OS X luasockets library, it should work, but this hasn't been tested.

Once it's installed, you'll want to install a python interpreter. Once python is installed and on the system path, you can drop scripts into mods/raspberryjammod/mcpipy/ and run them with /py scriptname [arguments] from the Minetest chat. (You will need to edit settings.conf in the mod directory if it can't find your Python interpreter. I recommend PyPy for best performance.) Some fun demo scripts to try:
/py borromean
/py render dragon (this will be slow)
/py chess (wield a sword and LEFT-click on pieces and places to move; only works with a sword, and you need to LEFT click, contrary to instructions)
/py fancytree

Finally, if you want to play with (or teach) some simple turtle graphics using Blockly (a graphical programming system), you don't need to install python. Just start a world with raspberryjammod enabled, and go to http://robotblocks.appspot.com.

Image

Image

Image

Image
Last edited by arpruss on Tue Nov 17, 2015 01:56, edited 2 times in total.

User avatar
Don
Member
Posts: 1643
Joined: Sat May 17, 2014 18:40
GitHub: DonBatman
IRC: Batman
In-game: Batman

Re: [WIP][MOD] Emulate Raspberry PI Minecraft API

by Don » Post

Cool.
Many of my mods are now a part of Minetest-mods. A place where you know they are maintained!

A list of my mods can be found here

arpruss
Member
Posts: 39
Joined: Sat Sep 26, 2015 14:01
GitHub: arpruss

Re: [WIP][MOD] Emulate Raspberry PI Minecraft API

by arpruss » Post

I fixed a bunch of bugs and released 0.07.

One thing that now works is importing Minecraft .schematic files, though block translation is incomplete (and block directions aren't translated) as the stone trees show (original: http://www.minecraft-schematics.com/schematic/3379/)

Image

arpruss
Member
Posts: 39
Joined: Sat Sep 26, 2015 14:01
GitHub: arpruss

Re: [WIP][MOD] Raspberry PI Minecraft API for python code

by arpruss » Post

I just added x64 support, so you can now run this on both the 32- and 64-bit versions of Minetest (MSVC + Windows only; if you want to use Linux, you'll still need to throw an appropriate core.so file from your luasocket build into the raspberryjammod/socket/ directory).

arpruss
Member
Posts: 39
Joined: Sat Sep 26, 2015 14:01
GitHub: arpruss

Re: [WIP][MOD] Raspberry PI Minecraft API for python code

by arpruss » Post

I just released 0.10, which includes automatic translation for a bunch more Minecraft block ids/metas. This makes Minecraft schematics import more neatly.

I also added a /top command that moves the player up as needed to get out of structures if a script traps one (e.g., if you draw blocks with the script around the player).

Some fun things to play with is rendering various 3DS and OBJ meshes in Minetest using the render.py script. (The script automatically downloads the mesh as needed.)

Star Trek:
/py render 1701d
/py render bop
/py render defiant
/py render jemcruiser
/py render neghvar

Star Wars:
/py render atat
/py render r2d2
/py render stardestroyer
/py render yt1300

(The directions for rendering meshes with the Minecraft version of my mod may be helpful for making more things like that.)

Image

arpruss
Member
Posts: 39
Joined: Sat Sep 26, 2015 14:01
GitHub: arpruss

Re: [WIP][MOD] Raspberry PI Minecraft API for python code

by arpruss » Post

Version 0.11:
- improved block translation (slabs, trapdoors) from Minecraft to Minetest
- compatibility with secure.enable_security = true in minetest.conf as long as you list raspberryjammod in secure.trusted_mods

Sokomine
Member
Posts: 4276
Joined: Sun Sep 09, 2012 17:31
GitHub: Sokomine
IRC: Sokomine
In-game: Sokomine

Re: [WIP][MOD] Raspberry PI Minecraft API for python code

by Sokomine » Post

arpruss wrote: I just released 0.10, which includes automatic translation for a bunch more Minecraft block ids/metas. This makes Minecraft schematics import more neatly.
You might also be intrested in my mccompat mod which adds extra nodes similar to those in Minecraft. That way, importing Minecraft .schematic files gets easier. handle_schematics also has some basic translations for some node names.
A list of my mods can be found here.

arpruss
Member
Posts: 39
Joined: Sat Sep 26, 2015 14:01
GitHub: arpruss

Re: [WIP][MOD] Raspberry PI Minecraft API for python code

by arpruss » Post

Thanks for the hint! I may look for some more translations there.
Apart from schematics, most of the python scripts use a fairly basic set of blocks.

arpruss
Member
Posts: 39
Joined: Sat Sep 26, 2015 14:01
GitHub: arpruss

Re: [WIP][MOD] Raspberry PI Minecraft API for python code

by arpruss » Post

I just released 0.13.2, which speeds up node drawing by using voxel_manip (sometimes).
I also fixed a bug in the 3D Sierpinski script (/py sierpinski3d).

Image

arpruss
Member
Posts: 39
Joined: Sat Sep 26, 2015 14:01
GitHub: arpruss

Re: [WIP][MOD] Raspberry PI Minecraft API for python code

by arpruss » Post

I just posted a new version with some bug fixes (mainly, missing depends.txt). This version will also work with a special Android build that I'm working on.

arpruss
Member
Posts: 39
Joined: Sat Sep 26, 2015 14:01
GitHub: arpruss

Re: [WIP][MOD] Raspberry PI Minecraft API for python code

by arpruss » Post

I posted a new version with an improved version of Conway's Game of Life.

Run /py life while standing on a large level surface. A large stone fence will be drawn around you for the board. Place any blocks you'd like (in the same plane as the fence). Then hit the ground with a sword to start. (Left-click with the sword. The instructions in the Life script are designed for Minecraft which is why they say to right-click.)

I posted a little video of the Game of Life in action on Youtube.

cantstumphim
New member
Posts: 2
Joined: Sun Jan 17, 2016 23:47

Re: [Mod] Raspberry PI MC API for Python code [raspberryjamm

by cantstumphim » Post

Thank you for bringing this to minetest! It's great fun and my kids love it.

I had some trouble setting it up on linux at first. I downloaded lua 5.1 and luasockets3.0, copied all the lua 5.1 source files into the luasockets3.0 /src folder before compiling luasockets with 'make' and running 'sudo make install'.

The mcpipy python scripts will run well from a terminal and appear in the game but do not run within the minetest application using the built in /py command.

I can't get the mod working at all on a 64 bit linux system - maybe the mod doesn't like a 64 bit luasocket.so shared library?

These are minor issues though and we are really happy with this mod. Thanks again!

arpruss
Member
Posts: 39
Joined: Sat Sep 26, 2015 14:01
GitHub: arpruss

Re: [Mod] Raspberry PI MC API for Python code [raspberryjamm

by arpruss » Post

The /py command is only for Windows right now. I don't have Minetest on a Linux system (unless Android counts) and so it would be hard to get it to work on Linux. If you want a quick-and-dirty fix, you can try editing background_launch() in init.lua to read:

Code: Select all

function background_launch(window_identifier, working_dir, cmd)
    local cmdline
    if is_windows then 
      cmdline = 'start "' .. window_identifier .. '" /D "' .. working_dir .. '" /MIN ' .. cmd
    else
      cmdline = 'cd "' .. working_dir .. '" && ' .. cmd
    end
    minetest.log("action", "launching ["..cmdline.."]")
    ie.os.execute(cmdline)
end
Unfortunately, you still won't be able to interrupt the script using "/py" once it runs. If the script gets stuck, you'll have to kill it manually from the commandline. A super quick-and-dirty solution is just to have kill() run ie.os.execute("killall python"), but that will stop all python scripts run by the current user, which is (literally) overkill. I don't know enough about Linux to know how best to implement the killing of just the scripts for Minetest.



Regarding 64-bit, what error message do you get? Dealing with the socket stuff on various systems is nightmarish. There is a feature request for Minetest to include socket handling as a Minetest Lua API, and that would make this much easier.

cantstumphim
New member
Posts: 2
Joined: Sun Jan 17, 2016 23:47

Re: [Mod] Raspberry PI MC API for Python code [raspberryjamm

by cantstumphim » Post

Thanks, I will pass the lua code on to my son - he's the programmer in the family. It's not too bad tabbing out of the screen and running the scripts from the terminal and the kids have ssh access to the python script folder on our minetest server box.

I got our 64-bit machine working with the mod by re-building a 64 bit version of luasockets3.0 from git and reinstalling minetest from the ubuntu repos. Turns out there's a luasockets package in the repos for ubuntu so I probably didn't have to compile it myself.

The mod seems to pick up core.so from the system folder that luasockets creates when you run 'make install' (/usr/local/lib/lua/5.1/socket/core.so) and it runs fine.

Happy to test stuff for Linux btw, or you could work in a virtual machine of this http://www.ubuntu.com/desktop/developers

Thanks again, we had a blast today making all sorts of weird math shapes and accidentally setting it all on fire.

arpruss
Member
Posts: 39
Joined: Sat Sep 26, 2015 14:01
GitHub: arpruss

Re: [Mod] Raspberry PI MC API for Python code [raspberryjamm

by arpruss » Post

I updated some scripts, and added an pysanka.py script (requires Pillow for Python) that generates an Easter egg from any image. (More information http://www.instructables.com/id/Giant-E ... Minecraft/, though that's aimed at the Minecraft version.)
Attachments
screenshot_20160403_221030.png
screenshot_20160403_221030.png (335.3 KiB) Viewed 7575 times

jocsamazon
New member
Posts: 3
Joined: Tue Sep 20, 2016 14:37

Re: [WIP][MOD] Raspberry PI Minecraft API for python code

by jocsamazon » Post

arpruss wrote:I just added x64 support, so you can now run this on both the 32- and 64-bit versions of Minetest (MSVC + Windows only; if you want to use Linux, you'll still need to throw an appropriate core.so file from your luasocket build into the raspberryjammod/socket/ directory).
Hi. I'm trying to install your mod, but it doesn't works.
First, I install minetest 0.43-win32-msvc from https://github.com/minetest/minetest/re ... 2-msvc.zip (I can't find a newer version compiled with msvc)
Second, I installed Python 3.4.3 and added it to the path
Third, I copied your mod to minetest-0.4.13/mods
When I run any command, for example:
/py donut
Minecraft says:" 2016-09-20 16:30:24: ACTION[ServerThread]: launching [start "minetest-rjm-python
-script" /D "C:\Users\user\Downloads\minetest-0.4.13-win32-msvc\minetest-0.4.1
3\bin\..\mods\raspberryjammod\\mcpipy\" /MIN "python" "C:\Users\user\Downloads
\minetest-0.4.13-win32-msvc\minetest-0.4.13\bin\..\mods\raspberryjammod\\mcpipy\
donut.py" ]"
But nothing is done. I have tried with other commands, but it does nothing.
What am I doing wrong?
Thanks.

arpruss
Member
Posts: 39
Joined: Sat Sep 26, 2015 14:01
GitHub: arpruss

Re: [Mod] Raspberry PI MC API for Python code [raspberryjamm

by arpruss » Post

To see the error message, run one of the scripts from a commandline:
python donut.py
for instance.

The version of the scripts in mcpipy included in the mod does not support python 3.

jocsamazon
New member
Posts: 3
Joined: Tue Sep 20, 2016 14:37

Re: [WIP][MOD] Raspberry PI Minecraft API for python code

by jocsamazon » Post

arpruss wrote:I just added x64 support, so you can now run this on both the 32- and 64-bit versions of Minetest (MSVC + Windows only; if you want to use Linux, you'll still need to throw an appropriate core.so file from your luasocket build into the raspberryjammod/socket/ directory).
Hi.
Can you explain me how to install your mod in Ubuntu Linux?
What files do I need to copy and where?
Thank you.

arpruss
Member
Posts: 39
Joined: Sat Sep 26, 2015 14:01
GitHub: arpruss

Re: [WIP][MOD] Raspberry PI Minecraft API for python code

by arpruss » Post

jocsamazon wrote:(I can't find a newer version compiled with msvc)
What are the official 0.4.14 releases compiled with? I can't get them to work with RaspberryJamMod at all. They include msvc*.dll which suggests its msvc.

jocsamazon
New member
Posts: 3
Joined: Tue Sep 20, 2016 14:37

Re: [Mod] Raspberry PI MC API for Python code [raspberryjamm

by jocsamazon » Post

arpruss wrote:To see the error message, run one of the scripts from a commandline:
python donut.py
for instance.

The version of the scripts in mcpipy included in the mod does not support python 3.
Hi.
Finally, I have configured your mod and it works ok with Windows. I have changed the content of the mcpipy directory of https://github.com/arpruss/raspberryjammod-minetest with the files of https://github.com/arpruss/raspberryjam ... ter/mcpipy (3. Minor formatting/bug fixing may be done to make the script run under both Python 2.7 and 3.x.)

Now it works with Python 3! Nice work!

But it doesn't work with Linux. I'm using Ubuntu 14.04 and I have installed juajit (see:https://github.com/minetest-mods/irc/issues/21), but without any luck. Any ideas?
Thank you.

arpruss
Member
Posts: 39
Joined: Sat Sep 26, 2015 14:01
GitHub: arpruss

Re: [Mod] Raspberry PI MC API for Python code [raspberryjamm

by arpruss » Post

You should post issues on the rjm github page if some script doesn't work on both 2.7 and 3.

leonardo.guidoni
New member
Posts: 1
Joined: Fri Apr 21, 2017 15:15

Re: [Mod] Raspberry PI MC API for Python code [raspberryjamm

by leonardo.guidoni » Post

Hi,
so far I used your mod on minecraft and I really enjoyed! My aim is to program educational minigames and I found the python interface perfects for this aim. Thanks for having produced such nice mod.
Now I would like to move on minetest but I found many problems installing the mod. I am a mac user. I installed lua 5.3 and with this successfully compiled luasocket3.0. Anyway it seems that the mod is not recognising the socket:
17:29:02: ERROR[main]: ========== ERROR FROM LUA ===========
17:29:02: ERROR[main]: Failed to load and run script from
17:29:02: ERROR[main]: /Users/leo/Library/Application Support/minetest/mods/raspberryjammod/init.lua:
17:29:02: ERROR[main]: caught (...)
17:29:02: ERROR[main]: stack traceback:
17:29:02: ERROR[main]: [C]: in function 'require'
17:29:02: ERROR[main]: ...plication Support/minetest/mods/raspberryjammod/init.lua:34: in main chunk
17:29:02: ERROR[main]: ======= END OF ERROR FROM LUA ========
17:29:02: ERROR[main]: Server: Failed to load and run /Users/leo/Library/Application Support/minetest/mods/raspberryjammod/init.lua
17:29:02: ERROR[main]: ModError: ModError: Failed to load and run /Users/leo/Library/Application Support/minetest/mods/raspberryjammod/init.lua

I also tried to move the /usr/local/lib/lua/5.3/socket/core.so into the ./socket directory of raspberryjammod but without success. Could you please help me? It would be really great to export all I have done so far on a free platform.
Thank you.

salahzar
Member
Posts: 24
Joined: Sat Jul 22, 2017 23:10
GitHub: salahzar
IRC: salahzar

Re: [Mod] Raspberry PI MC API for Python code [raspberryjamm

by salahzar » Post

@leonardo.guidoni... did you solve your problem? I have a similar one and don't know how to tackle it..

zargulthewizard
Member
Posts: 249
Joined: Wed Jul 26, 2017 18:10
In-game: zargul

Re: [Mod] Raspberry PI MC API for Python code [raspberryjamm

by zargulthewizard » Post

This looks like fun, but when i tried it on 0.4.15 it failed. Everything was fine until the game was about to finally begin, then minetest crashed alltogether and complained of a missing lua51.dll file. Am about to try with 0.4.16 mobile. Praying it will work.

Error: the init file attempted to index global "ie" (a nil value). Is this just mobile or is this mod broken? I really want this mod to work!

PS: Is there any possibility of completely emulating the Minetest API for python? Like, you have the lua mod and a config file in which you tell the mod to load and run a python script which you have written? And the python script does stuff just like a normal lua mod would?
May God be with you, always.

GRudolph
New member
Posts: 1
Joined: Sun Jul 01, 2018 22:05

Re: [Mod] Raspberry PI MC API for Python code [raspberryjamm

by GRudolph » Post

jocsamazon wrote:
arpruss wrote:To see the error message, run one of the scripts from a commandline:
python donut.py
for instance.

The version of the scripts in mcpipy included in the mod does not support python 3.
Hi.
Finally, I have configured your mod and it works ok with Windows. I have changed the content of the mcpipy directory of https://github.com/arpruss/raspberryjammod-minetest with the files of https://github.com/arpruss/raspberryjam ... ter/mcpipy (3. Minor formatting/bug fixing may be done to make the script run under both Python 2.7 and 3.x.)

Now it works with Python 3! Nice work!

But it doesn't work with Linux. I'm using Ubuntu 14.04 and I have installed juajit (see:https://github.com/minetest-mods/irc/issues/21), but without any luck. Any ideas?
Thank you.
@jocsamazon
I would like to know what specific changes you made in order to run minetest with raspberryjammod?
I am running Windows 10, Minetest 0.4.17.1 and Python 3.6.5.
I have replaced the mcpipy files as you indicated in your post quoted above, but the mod fails to load with the following error, and as a result, I cannot even test the Python scripts.
So how do I fix this error and proceed?


-------------
Separator
-------------

2018-07-01 17:08:49: [Main]: Automatically selecting world at [C:\minetest\bin\..\worlds\world1]
2018-07-01 17:09:01: ERROR[Main]: ModError: Failed to load and run script from C:\minetest\bin\..\mods\raspberryjammod\init.lua:
2018-07-01 17:09:01: ERROR[Main]: C:\minetest\bin\..\mods\raspberryjammod\init.lua:12: attempt to index global 'ie' (a nil value)
2018-07-01 17:09:01: ERROR[Main]: stack traceback:
2018-07-01 17:09:01: ERROR[Main]: C:\minetest\bin\..\mods\raspberryjammod\init.lua:12: in main chunk
2018-07-01 17:09:01: ERROR[Main]: Check debug.txt for details.

Post Reply

Who is online

Users browsing this forum: No registered users and 22 guests