Post your modding questions here

Locked
minetestcr
Member
Posts: 58
Joined: Fri Feb 13, 2015 21:31

Re: Post your modding questions here

by minetestcr » Post

Don wrote:You need paramtype2 set

Code: Select all

paramtype2 = "facedir",
thanks, that's it

DoyleChris
Member
Posts: 253
Joined: Sat Jul 25, 2015 19:54
In-game: DoyleChris

Re: Post your modding questions here

by DoyleChris » Post

Is there a way with Mesecons or DIgilines to have a counter. Example I have a chest where all my Iron Lumps go into. And i want to use a Stack Injector to send a full Stack to a grinder, Then output it to a tube dectector which sends a signal to the counter till it reaches 198 then sends a signal to the injector to send a new stack to the grinder.

Soudon
Member
Posts: 167
Joined: Wed Apr 08, 2015 17:14
In-game: Soudon

Re: Post your modding questions here

by Soudon » Post

Working on a survivial sub game I have the survival mod but I would like to know how to go about adding a temperature gauge/ in snow biomes you get cold being wet you get cold etc and need to have a campfire or some source of fire to dry off/warm up. And if you get too cold you can die from it.

afeys
Member
Posts: 17
Joined: Thu Mar 26, 2015 08:55

Re: Post your modding questions here

by afeys » Post

Hi,

I'm playing around with the minetest.register_on_generated function and I'm stuck with a problem I can 't explain. It is probably some stupid oversight from me, but if anyone can shed some light on it, I'd appreciate it.

I include my cut-down code here, I stripped out as much as possible (like the random x/z coordinates and the calculation of floorlevel,...) and left the bare minimum. What it does (or should do) is put a schematic on the map and tell me by chatmessage where it is. However in most cases it doesn't get placed on the map, and sometimes (very rarely) it does. The schematic file exists at that location on my disk and is not corrupt (I can manually place the schematic from within minetest).

If i remove the place_schematic line and put in some minetest.add_node(next_tower, { name="default:mossycobble"}) lines, these appear without any problems.

I'm now going to check out the minetest.register_decoration function, maybe this is better suited for what I want, but I find it strange that place_schematic doesn't seem to work in the register_on_generated.

Code: Select all

minetest.register_on_generated(function(minp, maxp, seed)
		local debugmessage = ""
		-- don't build towers above 80 or below -10
		if (maxp.y > 80) then return end
		if (maxp.y < -10) then return end

		-- initialize the position of the tower
		local next_tower = {
				x = minp.x + 20,
				y = 20,
				z = minp.z + 20,
		}
			debugmessage = debugmessage .. " drawing tower " .. next_tower.x .. ", " .. next_tower.y .. ", " .. next_tower.z
			minetest.chat_send_all(debugmessage)
			-- put the tower on the map
			minetest.place_schematic(next_tower, "/home/afeys/.minetest/mods/afmodpack/treasuretowers3/schems/ttower1.mts" , rotation)

end)
Added info: if I do a minetest.add_node(next_tower,......) BEFORE i do the place_schematic, then the schematic is shown correctly. Anyone have any ideas what's going on?

afeys
Member
Posts: 17
Joined: Thu Mar 26, 2015 08:55

Re: Post your modding questions here

by afeys » Post

afeys wrote:Hi,
Added info: if I do a minetest.add_node(next_tower,......) BEFORE i do the place_schematic, then the schematic is shown correctly. Anyone have any ideas what's going on?
This was apparently a coincidence.. Still have the same problem.
I wrote some code to 'empty' (using remove_node) the necessary space on the map before doing the place_schematic. The place gets cleared but no schematic is added to the map. (in most cases)

Is there an alternative to place_schematic that does work in the register_on_generated ? Or does a tool exists which converts schematic files into the appropriate set_node commands which I can then copy/paste into my lua code?

User avatar
Ferk
Member
Posts: 337
Joined: Tue Aug 18, 2015 17:18
GitHub: Ferk

Re: Post your modding questions here

by Ferk » Post

There's no reason that I know of that could prevent place_schematic from getting called from on_generated.. I do use it to spawn the dungeon entrances in dungeontest with no problems.. (I was using a spawning abm before, but changed it to remove the "poping up" effect and it seems to work fine). Depending on the chunksize you might have some problems, but not getting anything placed at all is weird.

Maybe you could try changing your chunksize setting and see if it has any repercusions. I think chunks start at -32,-32,-32 (correct me if I'm wrong) and are set by default to be 80 nodes wide (5 blocks of 16 nodes) in all directions. This means the chunk ends at y=45, I guess your tower is taller than that, specially if you are placing it already in y=20

Perhaps your safest bet is to use a placer node with an abm to place the schematic. Even though this would make the building "pop up" to existence when the player walks in.
does a tool exists which converts schematic files into the appropriate set_node commands which I can then copy/paste into my lua code?
The closest thing to that is probably worldedit. It has also the benefit that it will save the metadata as well. The drawback is that it's slower than native place_schematics, and you'll have to include worldedit in your modpack.

How big is your tower? I've also had problems when trying to get the Tutorial world from Wuzzy generated using mts.. it works fine if I use worledit files but mts don't seem to get saved properly at times, specially if it's big. My tutorial world mts was like only 1 KB in size when saved even though it was a big area, and crashed when I tried to place it. But it seems it's not the same problem you had.
{ ☠ Dungeontest ☠ , ᗧ••myarcade•• }

afeys
Member
Posts: 17
Joined: Thu Mar 26, 2015 08:55

Re: Post your modding questions here

by afeys » Post

Thanks for the reply, Ferk.
Ferk wrote:Maybe you could try changing your chunksize setting and see if it has any repercusions. I think chunks start at -32,-32,-32 (correct me if I'm wrong) and are set by default to be 80 nodes wide (5 blocks of 16 nodes) in all directions. This means the chunk ends at y=45, I guess your tower is taller than that, specially if you are placing it already in y=20
That seems like a plausible reason. I'll try again with a much smaller mts file this weekend. Maybe split the tower up in separate mts files per floor or something. I'll see what that does. My tower is 3 floors and a roof, but that could easily be too much according to your explanation.
What is weird though: I have a draw_box function (see below) which draws a 3-D outline (for debugging purposes) around the area where the tower is supposed to be, and that works perfectly, even if the mts file itself isn't shown !

Code: Select all

treasuretowers_draw_box = function(start_pos, end_pos, drawblock)
local inc_x = 1
local inc_y = 1
local inc_z = 1
local blockpos = start_pos
if (start_pos.x > end_pos.x) then
	inc_x = -1
end
if (start_pos.y > end_pos.y) then
	inc_y = -1
end
if (start_pos.z > end_pos.z) then
	inc_z = -1
end
for i= start_pos.x, end_pos.x, inc_x do
	blockpos = {x=i, y=start_pos.y, z=start_pos.z}
	minetest.add_node(blockpos, { name=drawblock})
	blockpos = {x=i, y=start_pos.y, z=end_pos.z}
	minetest.add_node(blockpos, { name=drawblock})
	blockpos = {x=i, y=end_pos.y, z=start_pos.z}
	minetest.add_node(blockpos, { name=drawblock})
	blockpos = {x=i, y=end_pos.y, z=end_pos.z}
	minetest.add_node(blockpos, { name=drawblock})
end
for i= start_pos.y, end_pos.y, inc_y do
	blockpos = {x=start_pos.x, y=i, z=start_pos.z}
	minetest.add_node(blockpos, { name=drawblock})
	blockpos = {x=start_pos.x, y=i, z=end_pos.z}
	minetest.add_node(blockpos, { name=drawblock})
	blockpos = {x=end_pos.x, y=i, z=start_pos.z}
	minetest.add_node(blockpos, { name=drawblock})
	blockpos = {x=end_pos.x, y=i, z=end_pos.z}
	minetest.add_node(blockpos, { name=drawblock})
end
for i= start_pos.z, end_pos.z, inc_z do
	blockpos = {x=start_pos.x, y=start_pos.y, z=i}
	minetest.add_node(blockpos, { name=drawblock})
	blockpos = {x=start_pos.x, y=end_pos.y, z=i}
	minetest.add_node(blockpos, { name=drawblock})
	blockpos = {x=end_pos.x, y=start_pos.y, z=i}
	minetest.add_node(blockpos, { name=drawblock})
	blockpos = {x=end_pos.x, y=end_pos.y, z=i}
	minetest.add_node(blockpos, { name=drawblock})
end

end
Ferk wrote: Perhaps your safest bet is to use a placer node with an abm to place the schematic. Even though this would make the building "pop up" to existence when the player walks in.
Yep, that was my previous approach and it worked perfectly. I had defined a rare ore which spawns in dirt_with_grass blocks and then an abm to replace that block with my tower.
The "pop up" effect was really annoying, even after I added some particles to simulate a 'magic' effect.
Ferk wrote: How big is your tower? I've also had problems when trying to get the Tutorial world from Wuzzy generated using mts.. it works fine if I use worledit files but mts don't seem to get saved properly at times, specially if it's big. My tutorial world mts was like only 1 KB in size when saved even though it was a big area, and crashed when I tried to place it. But it seems it's not the same problem you had.
I started with a rather small tower, the file is 736 bytes. dimensions are 13x13 and 20 high.
Maybe I'll write a function which processes the .we fileformat and uses set_node to build my tower.


Edit:
I've tried it with a small 3x3x2 mts file and have the same problem. I'm dumping mts files, and going to write a .we drawing function. I'll have a look at WorldEdit and see how they do it.

User avatar
firefox
Member
Posts: 1583
Joined: Wed Jan 14, 2015 07:34
In-game: Red_Fox
Location: Xanadu

Re: Post your modding questions here

by firefox » Post

Lord of the Test has buildings in the mapgen (some of them are quite large).
they are all saved as .we files i guess the game also use worldedit to place them on the map.

maybe that helps...
=(^.^)= nyan~

afeys
Member
Posts: 17
Joined: Thu Mar 26, 2015 08:55

Re: Post your modding questions here

by afeys » Post

firefox wrote:Lord of the Test has buildings in the mapgen (some of them are quite large).
they are all saved as .we files i guess the game also use worldedit to place them on the map.

maybe that helps...
Thanks for the info, firefox. I'll have a look at their code.

User avatar
Ferk
Member
Posts: 337
Joined: Tue Aug 18, 2015 17:18
GitHub: Ferk

Re: Post your modding questions here

by Ferk » Post

afeys wrote:I'm dumping mts files, and going to write a .we drawing function. I'll have a look at WorldEdit and see how they do it.
You could add serialize.lua and common.lua from here: https://github.com/Uberi/Minetest-World ... /worldedit
Maybe merge the two files into one and replace s/worldedit/afeysmod/g
Then use the worldedit.serialize and worldedit.deserialize functions (or you can remove the whole serialize part and only use deserialize). They work with strings, you just need to write/read them to files.

Note also that worldedit is AGPL, only use their code if your license is compatible.
{ ☠ Dungeontest ☠ , ᗧ••myarcade•• }

User avatar
paramat
Developer
Posts: 3691
Joined: Sun Oct 28, 2012 00:05
GitHub: paramat
IRC: paramat
Location: UK

Re: Post your modding questions here

by paramat » Post

afeys, in 'place schematic' you should get the modpath like this (here the mod is called 'projects' and 'schematics' is the schematic folder) hope this works:

local path = minetest.get_modpath("projects") .. "/schematics/flat.mts"
minetest.place_schematic({x=x-6, y=y-1, z=z+1}, path, 90, nil, true)

afeys
Member
Posts: 17
Joined: Thu Mar 26, 2015 08:55

Re: Post your modding questions here

by afeys » Post

paramat wrote:afeys, in 'place schematic' you should get the modpath like this (here the mod is called 'projects' and 'schematics' is the schematic folder) hope this works:

local path = minetest.get_modpath("projects") .. "/schematics/flat.mts"
minetest.place_schematic({x=x-6, y=y-1, z=z+1}, path, 90, nil, true)
Hi Paramat,

thanks for your answer. That was the way I was doing it in my mod. I just hardcoded the path in my cut-down code to make my testcase as simple as possible in an effort to find out what was going wrong.
I have now removed the place_schematic completely and code my own version in lua which reads the .we file data and does a minetest.add_node for each block. And again, sometimes the structure gets placed and other times it doesn't get placed. It is slowly driving me crazy.

Is it possible that my minetest.register_on_generated gets called before any biome (or other mod) register_on_generated function gets called and that whatever I put in the world gets overwritten/undone by another mod?
I have noticed that structures which get generated above water (sea) are shown (I have removed any checks to see if the structure is on solid ground), but structures which get generated in a jungle biome (for example) are not visible.

Also: for a test, I replace the groundlevel node at the x/z coordinates where my building is supposed to be generated with a mossy cobblestone block. And that block is always present. Anything which generates above ground is missing.

Is there a way to make sure that my mod's register_on_generated gets called after any biome generation ?

afeys
Member
Posts: 17
Joined: Thu Mar 26, 2015 08:55

Re: Post your modding questions here

by afeys » Post

just to let you know: I've solved it by placing my buildings using voxelmanip instead of place_schematics or add_node.

Buildings get generated now 100% of the time (at least during my test)

User avatar
paramat
Developer
Posts: 3691
Joined: Sun Oct 28, 2012 00:05
GitHub: paramat
IRC: paramat
Location: UK

Re: Post your modding questions here

by paramat » Post

The problem might be because 'place schematic' is not meant to be used during mapgen, because it has it's own lighting update, what we need is a feature to add a schematic to the luavoxelmanipulator, much like the way you're doing it from a .we file. Because there is no unnecessary duplicated lighting update your method may even be faster than 'place schematic'.

'On generated' is always run after core biome generation.

User avatar
paramat
Developer
Posts: 3691
Joined: Sun Oct 28, 2012 00:05
GitHub: paramat
IRC: paramat
Location: UK

Re: Post your modding questions here

by paramat » Post

afeys and others, the new feature will soon be added https://github.com/minetest/minetest/pull/3339
"This commit adds a new API function minetest.place_schematic_on_vmanip()"

afeys
Member
Posts: 17
Joined: Thu Mar 26, 2015 08:55

Re: Post your modding questions here

by afeys » Post

paramat wrote:afeys and others, the new feature will soon be added https://github.com/minetest/minetest/pull/3339
"This commit adds a new API function minetest.place_schematic_on_vmanip()"
Brilliant !
Thanks

User avatar
Ferk
Member
Posts: 337
Joined: Tue Aug 18, 2015 17:18
GitHub: Ferk

Re: Post your modding questions here

by Ferk » Post

That minetest.place_schematic_on_vmanip() looks nice.
Specially combined with control of the chunksize from lua (which I think it's also a feature in next version), I'll check it out this weekend to generate Wuzzy Tutorial world in chunks. Also it could be useful for Dungeontest as well.

Btw, is a version string exposed anywhere in the api to know what minetest version the server runs? it looks like it's available for the clients but not for the server.
It would be nice to have the version so the mod can exit gracefully if the engine is too old for it to run. But yeah just "nice-to-have", not very important.
{ ☠ Dungeontest ☠ , ᗧ••myarcade•• }

User avatar
paramat
Developer
Posts: 3691
Joined: Sun Oct 28, 2012 00:05
GitHub: paramat
IRC: paramat
Location: UK

Re: Post your modding questions here

by paramat » Post

minetest.place_schematic_on_vmanip() can be used with either the 'mapgen object voxelmanip' or the 'non mapgen object voxelmanip'. Use the function immediately after 'set data' and before any of: 'set lighting', 'calc lighting', 'write to map'.

User avatar
rubenwardy
Moderator
Posts: 6278
Joined: Tue Jun 12, 2012 18:11
GitHub: rubenwardy
IRC: rubenwardy
In-game: rubenwardy
Location: United Kingdom
Contact:

Re: Post your modding questions here

by rubenwardy » Post

Ferk wrote:Btw, is a version string exposed anywhere in the api to know what minetest version the server runs? it looks like it's available for the clients but not for the server.
It would be nice to have the version so the mod can exit gracefully if the engine is too old for it to run. But yeah just "nice-to-have", not very important.
It's not possible to get a version string in order to stop abuse like this. Version strings are for informational use,not for checking for features. Check that the function exists instead by doing

if minetest.func then

Note no brackets or colon.

User avatar
Ferk
Member
Posts: 337
Joined: Tue Aug 18, 2015 17:18
GitHub: Ferk

Re: Post your modding questions here

by Ferk » Post

@rubenwardy good point. I was doing already something like that when using minetest.wallmounted_to_dir(), only available in latest git.

Though being able to enforce a chunksize in minetest.set_mapgen_params is not that easy to check for, but I guess it's not a big deal, if I just want to throw an error checking for the other function would suffice.
{ ☠ Dungeontest ☠ , ᗧ••myarcade•• }

User avatar
Ferk
Member
Posts: 337
Joined: Tue Aug 18, 2015 17:18
GitHub: Ferk

Re: Post your modding questions here

by Ferk » Post

I was experimenting with the minetest.place_schematic_on_vmanip to place the tutorial world schematics within a singlenode mapgen. Works fine. I'm doing vmanip:calc_lighting() and vmanip:write_to_map() right after the schematics are placed and it works well.

However, I don't think the lighting is completely correct. It seems to render as if it was nighttime all the time, even though the sun should be right up, the sky turns gray when I'm not looking directly into it. I guess the engine seems to think I'm in an underground even though the Tutorial world map is completely exposed (the player spawn is enclosed though, not sure if that's relevant).

Any ideas?
{ ☠ Dungeontest ☠ , ᗧ••myarcade•• }

User avatar
paramat
Developer
Posts: 3691
Joined: Sun Oct 28, 2012 00:05
GitHub: paramat
IRC: paramat
Location: UK

Re: Post your modding questions here

by paramat » Post

When the chunk above has not been generated yet, lighting is assumed from whether y is above or below water_level, so set water_level = -31000 in mapgen params, also set the flag 'nolight' to avoid an unnecessary 2nd lighting calculation before schematics are placed.
See new vm docs https://github.com/minetest/minetest/bl ... .txt#L2814

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

Re: Post your modding questions here

by Don » Post

Is there a way to change the inventory slots in formspec like you can with buttons?
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

User avatar
Ferk
Member
Posts: 337
Joined: Tue Aug 18, 2015 17:18
GitHub: Ferk

Re: Post your modding questions here

by Ferk » Post

paramat wrote:When the chunk above has not been generated yet, lighting is assumed from whether y is above or below water_level
Thanks for the explanation! I did some tests flying around generating higher chunks and what you said seems to be the reason. After flying above and placing the schematic a second time the nodes get properly lighted up.

However, setting water_level = -31000 using minetest.set_mapgen_params didn't have any effect:

Code: Select all

minetest.register_on_mapgen_init(function(mgparams)
	minetest.set_mapgen_params({mgname="singlenode", water_level = -31000, flags = "nolight" })
end)
Do I need to do something else for the light to be calculated right?

if I run minetest.emerge_area to load the chunk above before loading the schematic it works, from a chatcommand. But it won't work in register_on_generated, since I guess the voxelmanip area is already loaded by the time I can add the chunks above to the queue. Also running the emerge slows things down a bit.
Thanks for that as well, the lua_api.txt file is pretty awesome. Much better than the outdated dev wiki.
{ ☠ Dungeontest ☠ , ᗧ••myarcade•• }

User avatar
jp
Member
Posts: 798
Joined: Wed Dec 18, 2013 09:03
GitHub: kilbith
Location: France

Re: Post your modding questions here

by jp » Post

Don wrote:Is there a way to change the inventory slots in formspec like you can with buttons?
You don't really change a slot, but an item stack.

Code: Select all

<some meta getter>:set_stack(<list>, <index>, <itemstack>)

Locked

Who is online

Users browsing this forum: No registered users and 2 guests