How to start a mod?

Schmeldric
Member
 
Posts: 19
Joined: Sat Nov 01, 2014 15:38
In-game: Schmeldric

How to start a mod?

by Schmeldric » Sat Nov 01, 2014 15:54

Hello,

I'm planning to make my students work on a scale model of our school (and the city afterwards).
My first plan was to use Minecraft, but some legal issues made me look for something else, and I've been adviced to have a look at Minetest. Which sounds great!

My students are between 11 and 15 years old, we're in France.
We obtained a data file of the city's heights / buildings / etc. (a X-Z grid of 5 meters step with the according altitude).
The next step is to model the Minetest world accordingly to these data.

So, we need to create a mod. I'm familiar with C/C++ (doing some homebrew with codeblocks) but not much with lua.
I might not have searched enought, but is there a sample "hello world" mod?
I tried to put a print("Hello") in my init.lua file, but it seems more complexe than that...

For now, I'll start with the superflat mod and add the data reading lines...
 

User avatar
Evergreen
Member
 
Posts: 2131
Joined: Sun Jan 06, 2013 01:22
GitHub: 4Evergreen4
IRC: EvergreenTree
In-game: Evergreen

Re: How to start a mod?

by Evergreen » Sat Nov 01, 2014 16:03

Schmeldric wrote:Hello,

I'm planning to make my students work on a scale model of our school (and the city afterwards).
My first plan was to use Minecraft, but some legal issues made me look for something else, and I've been adviced to have a look at Minetest. Which sounds great!

My students are between 11 and 15 years old, we're in France.
We obtained a data file of the city's heights / buildings / etc. (a X-Z grid of 5 meters step with the according altitude).
The next step is to model the Minetest world accordingly to these data.

So, we need to create a mod. I'm familiar with C/C++ (doing some homebrew with codeblocks) but not much with lua.
I might not have searched enought, but is there a sample "hello world" mod?
I tried to put a print("Hello") in my init.lua file, but it seems more complexe than that...

For now, I'll start with the superflat mod and add the data reading lines...

A simple "Hello World" mod would be something like this:
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.chat_send_all("Hello world!")


An issue with this is that it would trigger before the player is actually able to join the server, thus not being able to see the message. print("msg") just prints to the terminal. If you need any help with the api, look at http://dev.minetest.net/Main_Page or https://raw.githubusercontent.com/minet ... ua_api.txt
lua_api.txt is preferrable though, mainly because it is always up to date.
"Help! I searched for a mod but I couldn't find it!"
http://krock-works.16mb.com/MTstuff/modSearch.php
 

User avatar
Topywo
Member
 
Posts: 1718
Joined: Fri May 18, 2012 20:27

Re: How to start a mod?

by Topywo » Sat Nov 01, 2014 16:38

Schmeldric wrote:Hello,

I'm planning to make my students work on a scale model of our school (and the city afterwards).

We obtained a data file of the city's heights / buildings / etc. (a X-Z grid of 5 meters step with the according altitude).
The next step is to model the Minetest world accordingly to these data.

So, we need to create a mod.



- What must the mod be able to do? (There might be mods that can (for a part) do what you want)
- Must the students build the school/city block by block? (There is this mod that makes building on large scale easier, world edit ( viewtopic.php?id=572#p4045 ) )
 

Schmeldric
Member
 
Posts: 19
Joined: Sat Nov 01, 2014 15:38
In-game: Schmeldric

Re: How to start a mod?

by Schmeldric » Sat Nov 01, 2014 22:04

Thanks for these quick answers to my silly/noob questions.

@Evergreen
The print(...) indeed went in the consol box.
But if I have only the line :
minetest.set_node({x=4, y=9, z=20}, {name="default:dirt"})
in my init.lua it doesn't seem to work. Can't yet figure out why...

Thanks for the tutorial link, I'm starting to see how Minetest is built.
One question : is minetest.register_globalstep a way to have a global action instead of using minetest.register_abm on "air" (which meens the callback function will be called as many times as the number of air node... right?)

@Topytwo
The world edit mod might be usefull for misc buildings in deed. For now we'll do the school block by block, but if we go further and build the entire city, buildings will be more anonymous.

what my mod will have to do for a beginning is (in pseudo-C) :
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
data = fopen("filename");
fscanf(data, "%d\t%d\t%f\n", &x, &z, &y); // Lines in the files are like "640800 115000 35.78448"
convert_to_my_coordinates(&x, &z);
setblock(x, y, z, "bedrock");
// Start again at fscanf until end of file


This will build a dot grid (5 meters step) telling my students where ground should be. They will then be able to fill between theses bedrock with the right node according to a picture.
I'm for now translating the above in lua (found io.open and io.read). How can i bind a function to a keystroke?
EDIT: found the "minetest.register_chatcommand("cmd", {chatcommand definition})"
 

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

Re: How to start a mod?

by Sokomine » Sun Nov 02, 2014 16:42

Schmeldric wrote:But if I have only the line :
minetest.set_node({x=4, y=9, z=20}, {name="default:dirt"})
in my init.lua it doesn't seem to work. Can't yet figure out why...

In order for set_node to work, the block the node is to be set at has to be loaded in the server's memory. The main body of the init.lua file is used for registering new types of blocks and other functions.

Schmeldric wrote:One question : is minetest.register_globalstep a way to have a global action instead of using minetest.register_abm on "air" (which meens the callback function will be called as many times as the number of air node... right?)

That's right. register_globalstep is mostly used for mobs which decide where to move next or what else to do. register_abm is usually used in order to change the state of nodes - flowers spreading, nodes reacting to changes in the environment etc.

Schmeldric wrote:This will build a dot grid (5 meters step) telling my students where ground should be. They will then be able to fill between theses bedrock with the right node according to a picture.

Seems what you're looking for is much more like a mapgen than anything else. How large is the area covered by the height data? Depending on that, diffrent approaches might work best. The map usually consists of chunks which are each 80x80x80 nodes (1 node=1m^3) in size. You can set your mapgen to singlenode and then add nodes in minetest.register_on_generated (using i.e. set_node). The function tells you which area has been loaded, and you'll have to take care to set only those "bedrock" nodes that fit into that area.
Another approach would be to use place_schematic. Using that, you can place all your "bedrock" markers in one go - provided it's not too large an area and fits into memory.
A list of my mods can be found here.
 

Schmeldric
Member
 
Posts: 19
Joined: Sat Nov 01, 2014 15:38
In-game: Schmeldric

Re: How to start a mod?

by Schmeldric » Tue Nov 04, 2014 22:53

Thanks for the answers!

For my project, I started from a flatland and added a command "build the ground around me" (with a max_radius).
Works fine.
 

4aiman
Member
 
Posts: 1208
Joined: Mon Jul 30, 2012 05:47

Re: How to start a mod?

by 4aiman » Wed Nov 05, 2014 15:00

Sounds great! Any screenies?
 

Schmeldric
Member
 
Posts: 19
Joined: Sat Nov 01, 2014 15:38
In-game: Schmeldric

Re: How to start a mod?

by Schmeldric » Wed Nov 05, 2014 21:59

Will come soon, I'll try to have students work on the web site :D
 


Return to Modding Discussion

Who is online

Users browsing this forum: No registered users and 38 guests

cron