Page 1 of 2

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

Posted: Sun Sep 27, 2015 17:13
by arpruss
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

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

Posted: Sun Sep 27, 2015 23:01
by Don
Cool.

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

Posted: Mon Sep 28, 2015 13:55
by arpruss
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

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

Posted: Tue Sep 29, 2015 01:40
by arpruss
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).

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

Posted: Wed Sep 30, 2015 03:32
by arpruss
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

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

Posted: Thu Oct 01, 2015 12:15
by arpruss
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

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

Posted: Sat Oct 03, 2015 15:03
by Sokomine
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.

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

Posted: Sat Oct 03, 2015 15:29
by arpruss
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.

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

Posted: Tue Oct 06, 2015 18:51
by arpruss
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

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

Posted: Sat Oct 31, 2015 21:14
by arpruss
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.

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

Posted: Mon Nov 02, 2015 15:31
by arpruss
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.

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

Posted: Mon Jan 18, 2016 00:07
by cantstumphim
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!

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

Posted: Mon Jan 18, 2016 18:16
by arpruss
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.

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

Posted: Tue Jan 19, 2016 00:04
by cantstumphim
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.

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

Posted: Mon Apr 04, 2016 03:23
by arpruss
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.)

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

Posted: Tue Sep 20, 2016 14:48
by jocsamazon
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.

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

Posted: Tue Sep 20, 2016 15:05
by arpruss
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.

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

Posted: Tue Sep 20, 2016 17:34
by jocsamazon
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.

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

Posted: Tue Sep 20, 2016 19:33
by arpruss
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.

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

Posted: Wed Sep 21, 2016 17:13
by jocsamazon
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.

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

Posted: Thu Sep 22, 2016 14:44
by arpruss
You should post issues on the rjm github page if some script doesn't work on both 2.7 and 3.

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

Posted: Fri Apr 21, 2017 15:30
by leonardo.guidoni
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.

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

Posted: Sun Aug 13, 2017 08:17
by salahzar
@leonardo.guidoni... did you solve your problem? I have a similar one and don't know how to tackle it..

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

Posted: Tue Nov 21, 2017 03:16
by zargulthewizard
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?

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

Posted: Sun Jul 01, 2018 23:25
by GRudolph
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.