[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 » Sun Sep 27, 2015 17:13

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: 1642
Joined: Sat May 17, 2014 18:40
GitHub: DonBatman
IRC: Batman
In-game: Batman

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

by Don » Sun Sep 27, 2015 23:01

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

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 » Tue Sep 29, 2015 01:40

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

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

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: 3334
Joined: Sun Sep 09, 2012 17:31

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

by Sokomine » Sat Oct 03, 2015 15:03

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 » Sat Oct 03, 2015 15:29

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

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 » Sat Oct 31, 2015 21:14

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 » Mon Nov 02, 2015 15:31

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 » Mon Jan 18, 2016 00:07

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 » Mon Jan 18, 2016 18:16

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 » Tue Jan 19, 2016 00:04

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 » Mon Apr 04, 2016 03:23

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-Easter-Eggs-in-Minecraft/, though that's aimed at the Minecraft version.)
Attachments
screenshot_20160403_221030.png
(335.3 KiB) Not downloaded yet
 

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

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

by jocsamazon » Tue Sep 20, 2016 14:48

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 » Tue Sep 20, 2016 15:05

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 » Tue Sep 20, 2016 17:34

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 » Tue Sep 20, 2016 19:33

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 » Wed Sep 21, 2016 17:13

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 » Thu Sep 22, 2016 14:44

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 » Fri Apr 21, 2017 15:30

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: 20
Joined: Sat Jul 22, 2017 23:10
IRC: salahzar

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

by salahzar » Sun Aug 13, 2017 08:17

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


Return to Mod Releases



Who is online

Users browsing this forum: Bing [Bot], Majestic-12 [Bot] and 3 guests