Programmatically build objects with blocks

basil60
Member
 
Posts: 54
Joined: Sat Sep 12, 2015 22:07

Programmatically build objects with blocks

by basil60 » Tue Dec 15, 2015 21:20

Hi

is there a mod to allow kids to programmatically build objects with blocks in Minetest?
For example, using PiMinecraft, one can use the command line to create all sorts of things:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
mc.setBlock(2,3,20, ICE)
mc.setBlock(5,4,20, ICE)
mc.setBlock(5,5,20, ICE)
mc.setBlock(5,6,20, ICE)
mc.setBlock(5,7,20, ICE)
mc.setBlock(5,8,20, ICE)
#using array
blocks = [(7,4),(7,5),(7,6),(8,3),(9,3),(8,7),(9,7),(10,4),(10,5),(10,6)]
mc.setBlocks(blocks)


The idea would be to use problem solving strategies and code to do things more "efficiently".

Keen to hear your suggestions!
 

User avatar
rubenwardy
Member
 
Posts: 4500
Joined: Tue Jun 12, 2012 18:11
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy

Re: Programmatically build objects with blocks

by rubenwardy » Wed Dec 16, 2015 03:34

Have a look at my modding book: http://rubenwardy.com/minetest_modding_book/index.html

Minetest uses lua. To set a block, use:

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
minetest.set_node({x=2, y=3, z=20}, {name="default:ice"})


However, you'll need to do this somewhere. For example, when running a chat command:

Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
minetest.register_chatcommand("a", {
    func = function(name, params)
        minetest.set_node({x=2, y=3, z=20}, {name="default:ice"})
    end
})


I guess there could be nicer ways of doing this. Feel free to suggest things - I can code it if you like.
 

basil60
Member
 
Posts: 54
Joined: Sat Sep 12, 2015 22:07

Re: Programmatically build objects with blocks

by basil60 » Thu Dec 17, 2015 20:57

I tried to paste
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
minetest.register_chatcommand("a", {
    func = function(name, params)
        minetest.set_node({x=50, y=2, z=-450}, {name="default:ice"})
    end
})
into the chat window, without success. I used F5 to get my co-ords. You did say to
However, you'll need to do this somewhere. For example, when running a chat command:

Did I take you too literally??
I'm a minetest noob, but keen to explore aspects that can be used to teach code, in a familiar, fun environment.
 

User avatar
qwertymine3
Member
 
Posts: 194
Joined: Wed Jun 03, 2015 14:33
GitHub: Qwertymine
In-game: qwertymine3

Re: Programmatically build objects with blocks

by qwertymine3 » Thu Dec 17, 2015 21:10

That is lua code for a mod - in order for you to run this you would need to create a mod containing this code. ( and then call the chat command /a)

If you want to be able to run some lua commands in-game you either need to program them into a mod in this style or
you could try using this mod: https://forum.minetest.net/viewtopic.php?f=11&t=9671.

This mod adds a chat command to run lua code from in-game. So to do the above it would be
/lua minetest.set_node({x=50, y=2, z=-450}, {name="default:ice"})

EDIT: WARNINGS
Make sure to give yourself the lua permission before trying this (after you have installed the mod)
/grant singleplayer lua

Be aware that by using this mod ANY lua code can be executed - This may not be suitable for use by untrusted children. - see the mod wiki for more info on this
Avatar by :devnko-ennekappao:
 

basil60
Member
 
Posts: 54
Joined: Sat Sep 12, 2015 22:07

Re: Programmatically build objects with blocks

by basil60 » Thu Dec 17, 2015 22:41

Thanks qwertymine3. Exactly what I was after.
It does seem to have potential for griefing. Any safeguards that can be put in place?
 

User avatar
qwertymine3
Member
 
Posts: 194
Joined: Wed Jun 03, 2015 14:33
GitHub: Qwertymine
In-game: qwertymine3

Re: Programmatically build objects with blocks

by qwertymine3 » Fri Dec 18, 2015 01:12

Do you mean in-world, or possibly to the PC as a whole?

In both cases this would require/could be solved with sandboxing. This would have to be done by editing the LuaCmd mod to change the sandbox it places mods in.

The sandbox for the commands is created in PlayerEnv.lua file of the mod. It would be relatively simple to edit this into a white-list sandbox environment.

I'm not an expert on sandboxing, so I can't really offer my help if you want/need a bullet-proof sandbox environment.
Avatar by :devnko-ennekappao:
 

Sokomine
Member
 
Posts: 2980
Joined: Sun Sep 09, 2012 17:31

Re: Programmatically build objects with blocks

by Sokomine » Tue Jan 19, 2016 22:50

You might want to take a look at Raspberry PI MC API for Python code [raspberryjammod]. The "normal" way of modding is still through writing a lua mod, which is not very difficult.
A list of my mods can be found here.
 


Return to Minetest General

Who is online

Users browsing this forum: Bing [Bot] and 13 guests

cron