Post your modding questions here

Locked
User avatar
rubenwardy
Moderator
Posts: 6271
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

This is, afaik, due to overgeneration, which causes the c++ mapgen to override your blocks. Paramat is the one to talk to about this.

User avatar
Hybrid Dog
Member
Posts: 2768
Joined: Thu Nov 01, 2012 12:46
GitHub: HybridDog

Re: Post your modding questions here

by Hybrid Dog » Post

rubenwardy wrote:This is, afaik, due to overgeneration, which causes the c++ mapgen to override your blocks. Paramat is the one to talk to about this.
ls overgeneration also the reason for usual trees in the meow heaven?
Image
Attachments
nhvbugtree.png
(303.34 KiB) Not downloaded yet

‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪

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

Hybrid Dog yes probably.

All core mapgens work on the 80^3 node mapchunk plus a 16 node deep shell that extends into / overlaps neighbouring mapchunks. Dungeons, large caves and mgv6 dirt/grass all 'overgenerate' into the shell sometimes.

In your code emin emax are the shell limits, minp maxp are the mapchunk limits try:

Code: Select all

   local data = vm:get_data(emin, emax)
   
   for i in area:iterp(emin, emax) do
It might help.

User avatar
Hybrid Dog
Member
Posts: 2768
Joined: Thu Nov 01, 2012 12:46
GitHub: HybridDog

Re: Post your modding questions here

by Hybrid Dog » Post

paramat wrote:Hybrid Dog yes probably.

All core mapgens work on the 80^3 node mapchunk plus a 16 node deep shell that extends into / overlaps neighbouring mapchunks. Dungeons, large caves and mgv6 dirt/grass all 'overgenerate' into the shell sometimes.

In your code emin emax are the shell limits, minp maxp are the mapchunk limits try:

Code: Select all

   local data = vm:get_data(emin, emax)
   
   for i in area:iterp(emin, emax) do
It might help.
it would cause unnecessary lag, l guess, the map would become generated more than one time at the same place

‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪

User avatar
Ben
Member
Posts: 160
Joined: Tue Mar 31, 2015 20:09

Re: Post your modding questions here

by Ben » Post

Hybrid Dog wrote: as far as l know the client needs to load the chunk, not the server
there's a function to forceload a chunk: dev.minetest.net/minetest.forceload_block
Thanks, and sorry for the late reply, but forceload is a mechanism to keep a block loaded "forever", right? So that's not what I'm looking for. Thanks, though!

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

Re: Post your modding questions here

by Ferk » Post

Sane wrote:

Code: Select all

--[[ 
Node placer - Places a node on the surface, at a random position in the mg block that contains a grid point defined by cell_size

published under Creative Commons CC0 license.
--]]

-- cell_size  must be bigger then mg block size (80) to work.
local cell_size = 150
local item_id = minetest.get_content_id("default:steelblock")

minetest.register_on_generated(function(minp, maxp, seed)
	-- If the next_hotspot is not within this mg block then exit
	local next_hotspot = { 
		x = math.ceil(minp.x / cell_size) * cell_size,
		y = math.ceil(minp.y / cell_size) * cell_size,
		z = math.ceil(minp.z / cell_size) * cell_size
	}
	if next_hotspot.x > maxp.x or
		next_hotspot.y > maxp.y or
		next_hotspot.z > maxp.z then return end
	
	-- Place the object somewhere in this block

	local vm, emin, emax = minetest.get_mapgen_object("voxelmanip")
	local va = VoxelArea:new{MinEdge=emin, MaxEdge=emax}
	local vd = vm:get_data()
	
	local r = PcgRandom(seed) -- this ensures that you get the same results each time you generate the world anew.
	local item_pos = {
		x = r:next(minp.x, maxp.x),
		y = r:next(minp.y, maxp.y),
		z = r:next(minp.z, maxp.z),
	}

	-- This is to optimize, because getting the height map is expensive
	if minp.y > -200 and maxp.y < 200 then
		local hm = minetest.get_mapgen_object("heightmap")
		local hz = (item_pos.z - minp.z) * 80
		local hx = (item_pos.x - minp.x) % 80
		local height = hm[1 + hx + hz]
		item_pos.y = height + 1
	end

	vd[va:indexp(item_pos)] = item_id

	--
	vm:set_data(vd)
	--vm:calc_lighting()
	--vm:update_liquids()
	vm:write_to_map()
	--vm:update_map()
	--
end)
I haven't tested your code, but since you are calculating next_hotspot in all 3 dimensions, wouldn't a new block be created in the same area in the surface when a chunk gets generated further down close to the hotspot below?

I know you have checks to avoid placing it in the surface if it's below -200 and above 200 but with a cell_size of 150 you still can have 2 hotspots in there.

Also, if it's below -200 or above 200, it would place the node in a random location, even if it's in the sky or underground, no?
{ ☠ Dungeontest ☠ , ᗧ••myarcade•• }

User avatar
Sane
Member
Posts: 103
Joined: Tue Jun 17, 2014 09:31
GitHub: mt-sane
In-game: Sane

Re: Post your modding questions here

by Sane » Post

GunshipPenguin wrote:This code does work, but I find that certian nodes are not replaced by limit:limit_node like I want them to be.
Maybe those nodes where generated after your mod already ran. Do you have default in your depends.txt.
Trying to stay me.

User avatar
Sane
Member
Posts: 103
Joined: Tue Jun 17, 2014 09:31
GitHub: mt-sane
In-game: Sane

Re: Post your modding questions here

by Sane » Post

Ferk wrote:I haven't tested your code, but since you are calculating next_hotspot in all 3 dimensions, wouldn't a new block be created in the same area in the surface when a chunk gets generated further down close to the hotspot below?
The hotspot is a single coordinate so it can only be in one mapgen block.
Ferk wrote:I know you have checks to avoid placing it in the surface if it's below -200 and above 200 ...
No, the purpose of of the checks is to avoid getting the hightmap unnecessarily. Just a performance thing.
Ferk wrote:Also, if it's below -200 or above 200, it would place the node in a random location, even if it's in the sky or underground, no?
Yes this is what it does.
Trying to stay me.

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

Re: Post your modding questions here

by Ferk » Post

Sane wrote:The hotspot is a single coordinate so it can only be in one mapgen block.
Yes, but after each hotspot is found, a node is placed at the surface (using the heightmap) whenever the chunk that is getting generated is between -200 and 200 (the node in the surface might not be part of the chunk generated).

If this is the case then it's possible for 2 nodes to be placed at heightmap level next to each other, even though the goal was to have them separated by 150 nodes. The hotspots might be separated by that much (in the Y axis), but not the nodes you are placing.

I think it would be better to calculate 2D hotspots(only X and Z coordinates) and then after getting the heightmap check that the node is within the chunk that you are generating before placing it. That way you ensure you only place one node once on each X-Z division and only at surface level.
Sane wrote:No, the purpose of of the checks is to avoid getting the hightmap unnecessarily. Just a performance thing.
I know, the fact that this also limits the amount of nodes that get placed in the surface is just an after-effect. Perhaps because you added this it's less noticeable, since only 2 nodes would be created on each 150x150 area in the surface. But still there's a chance they would be next to each other (also, even though the area is 150 the randomness in the X and Z axis when placing the node is limited to the currently generating chunk, which might not be that big).
{ ☠ Dungeontest ☠ , ᗧ••myarcade•• }

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

I just tested it and it does place 2 nodes close together. I found 3 within a 50 node radius.
The question is how to fix this. I need the nodes to be seperated. If they are close then it will cause an issue with what they do.
Thanks for all your help on this!
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
Sane
Member
Posts: 103
Joined: Tue Jun 17, 2014 09:31
GitHub: mt-sane
In-game: Sane

Re: Post your modding questions here

by Sane » Post

Ferk wrote:
Sane wrote:The hotspot is a single coordinate so it can only be in one mapgen block.
Yes, but after each hotspot is found, a node is placed at the surface (using the heightmap) whenever the chunk that is getting generated is between -200 and 200 (the node in the surface might not be part of the chunk generated).

If this is the case then it's possible for 2 nodes to be placed at heightmap level next to each other, even though the goal was to have them separated by 150 nodes. The hotspots might be separated by that much, but not the nodes you are placing.
That's right.

The code is a reply to Don, who wanted to place a node at a 1000 nodes spacing. The intend of the source is to give an general impression on how to go about to solve a thing like that. It is not thought to be the solution.

Thank you for your interest. Feel free to optimize and extend the code to a working condition.
Trying to stay me.

User avatar
Sane
Member
Posts: 103
Joined: Tue Jun 17, 2014 09:31
GitHub: mt-sane
In-game: Sane

Re: Post your modding questions here

by Sane » Post

Don wrote:I just tested it and it does place 2 nodes close together. I found 3 within a 50 node radius.
That's odd. That should not be possible.
Could you send the coordinates and the grid size you test with?
Don wrote:The question is how to fix this. I need the nodes to be seperated. If they are close then it will cause an issue with what they do.
The code places the node within a mapgen block. That is a 80x80x80 volume. So if you stay with a 1000er spacing you should be safe,
Don wrote:Thanks for all your help on this!
You are very welcome.
Trying to stay me.

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

Re: Post your modding questions here

by Ferk » Post

Sane wrote:The code is a reply to Don, who wanted to place a node at a 1000 nodes spacing. The intend of the source is to give an general impression on how to go about to solve a thing like that. It is not thought to be the solution.
Yes, I know. And thanks for that, I'm interested as well because something like this would also be useful for my project. I would like to place an entrance to an underground dungeon in the surface in specific X,Z positions at fixed distances.

This is what I'm doing in my register_on_generated for that:

Code: Select all

if (minp.y > dungeon_rooms.origin.y) then

        -- avoid the calculation when too high up
        if (minp.y > 200) then return end

        local cell_size = {
            x = dungeon_rooms.stairs_distance * dungeon_rooms.room_area.x,
            z = dungeon_rooms.stairs_distance * dungeon_rooms.room_area.z,
        }

        local next_entrance = {
            x = maxp.x - (maxp.x % cell_size.x),
            z = maxp.z - (maxp.z % cell_size.z),
        }

        if (minp.x < next_entrance.x) and (minp.z < next_entrance.z) then

            -- Put the entrance spawner on ground level
            local hm = minetest.get_mapgen_object("heightmap")
            local hz = (next_entrance.z - minp.z) * 80
            local hx = (next_entrance.x - minp.x) % 80
            next_entrance.y = hm[1 + hx + hz]

            -- But only if it's in the generating chunk
            if (next_entrance.y < maxp.y) and (next_entrance.y > minp.y) then
                 minetest.set_node(next_entrance, minetest.get_content_id("dungeon_rooms:entrance_spawner"))
            end
        end
else 
   [......]
end
However, for some reason my heighmap is always -31000, for every value of the array... I'm not sure why that's happening.
{ ☠ Dungeontest ☠ , ᗧ••myarcade•• }

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

I screwed up. I commented out the part of my code. I still had nodes spawning.
I have just your code running now. I have been looking for around a half hour and can not find one. I will let you know if I do find one. I have to make supper now. I will get back to it this evening.
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

Don wrote:I have been looking for around a half hour and can not find one.
Can you print out the value of your coordinates, or at least the item_pos.y after the heighmap calculation?

Code: Select all

minetest.log("action","Placing node at " .. item_pos.x .. ",".. item_pos.y .. ",".. item_pos.z)
Perhaps, like me, your heightmap returns -31000.

I can't find proper documentation regarding minetest.get_mapgen_object("heightmap").

Also, how sure can we be that a chunk is gonna be 80x80? there's a "chunksize" configuration option in minetest.conf. Potentially, a mapgen relying on a hardcoded 80x80 chunk size could be messed up if people changed their settings. Maybe we should use "(maxp.x - minp.x)"
{ ☠ Dungeontest ☠ , ᗧ••myarcade•• }

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

It is saying that it is placing a node but when I check the location there is nothing there.

Code: Select all

2015-09-24 17:33:06: ACTION[Emerge-0]: Placing node at 1962,-4,-2100
action	Placing node at 1962,-4,-2100
2015-09-24 17:33:06: ACTION[Emerge-0]: Placing node at 1784,10,-2053
action	Placing node at 1784,10,-2053
2015-09-24 17:33:12: ACTION[Emerge-0]: Placing node at 1742,-4,-2197
action	Placing node at 1742,-4,-2197
2015-09-24 17:33:14: ACTION[Emerge-0]: Placing node at 1944,0,-2207
action	Placing node at 1944,0,-2207
2015-09-24 17:33:22: ACTION[Emerge-0]: Placing node at 1754,7,-2368
action	Placing node at 1754,7,-2368
2015-09-24 17:33:24: ACTION[Emerge-0]: Placing node at 1956,15,-2390
action	Placing node at 1956,15,-2390
2015-09-24 17:33:38: ACTION[Emerge-0]: Placing node at 1676,12,-2353
action	Placing node at 1676,12,-2353
2015-09-24 17:33:39: ACTION[Emerge-0]: Placing node at 1699,-7,-2582
action	Placing node at 1699,-7,-2582
2015-09-24 17:33:40: ACTION[Emerge-0]: Placing node at 1767,12,-2590
action	Placing node at 1767,12,-2590
2015-09-24 17:33:49: ACTION[Emerge-0]: Placing node at 1696,48,-2726
action	Placing node at 1696,48,-2726
2015-09-24 17:33:50: ACTION[Emerge-0]: Placing node at 1765,48,-2748
action	Placing node at 1765,48,-2748
2015-09-24 17:33:54: ACTION[Emerge-0]: Placing node at 1540,17,-2518
action	Placing node at 1540,17,-2518
2015-09-24 17:33:56: ACTION[Emerge-0]: Placing node at 1564,5,-2709
action	Placing node at 1564,5,-2709
2015-09-24 17:35:46: ACTION[Emerge-0]: Placing node at 1329,9,-2690
action	Placing node at 1329,9,-2690
2015-09-24 17:35:56: ACTION[Emerge-0]: Placing node at 1362,19,-2533
action	Placing node at 1362,19,-2533
2015-09-24 17:36:00: ACTION[Emerge-0]: Placing node at 1241,4,-2549
action	Placing node at 1241,4,-2549
2015-09-24 17:36:01: ACTION[Emerge-0]: Placing node at 1212,-2,-2748
action	Placing node at 1212,-2,-2748
2015-09-24 17:36:39: ACTION[Emerge-0]: Placing node at 1402,-4,-2839
action	Placing node at 1402,-4,-2839
2015-09-24 17:36:40: ACTION[Emerge-0]: Placing node at 1185,-19,-2882
action	Placing node at 1185,-19,-2882
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

Don wrote:It is saying that it is placing a node but when I check the location there is nothing there.
Strange. The minetes.log line is right before setting The "vd[va:indexp(item_pos)]" value, right? The node should be there then if you do vm:set_data and vm:write_to_map.. And your Y coordinates look reasonable, not sure why mines are so off.
Perhaps my underground mapgen messes up The heightmap calculation?
{ ☠ Dungeontest ☠ , ᗧ••myarcade•• }

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

I had the minetest.log in a different spot. I moved it but got the same result. I can give myself the node and place it in the world. I have an abm running to place a schematic when it finds the node. When I place the node the schematic is placed. I am watching the terminal and seeing the node being placed like the code says above but I can not find any. I have checked it with mapgen v6 and v7. Both were new maps with no other mods running. I am not getting any errors in debug.
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
Hybrid Dog
Member
Posts: 2768
Joined: Thu Nov 01, 2012 12:46
GitHub: HybridDog

Re: Post your modding questions here

by Hybrid Dog » Post

Ben wrote:
Hybrid Dog wrote: as far as l know the client needs to load the chunk, not the server
there's a function to forceload a chunk: dev.minetest.net/minetest.forceload_block
Thanks, and sorry for the late reply, but forceload is a mechanism to keep a block loaded "forever", right? So that's not what I'm looking for. Thanks, though!
there's a better way
https://github.com/minetest/minetest/co ... t-13428878
obviously calling the vmanip:read_from_map(minp,maxp) makes minetest. Get node work in those chunk(s).

‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪

User avatar
Hybrid Dog
Member
Posts: 2768
Joined: Thu Nov 01, 2012 12:46
GitHub: HybridDog

Re: Post your modding questions here

by Hybrid Dog » Post

Ferk wrote:
Don wrote:It is saying that it is placing a node but when I check the location there is nothing there.
Strange. The minetes.log line is right before setting The "vd[va:indexp(item_pos)]" value, right? The node should be there then if you do vm:set_data and vm:write_to_map.. And your Y coordinates look reasonable, not sure why mines are so off.
Perhaps my underground mapgen messes up The heightmap calculation?
maybe you somewhere didn't round the position before using it for the area index

‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪

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

Re: Post your modding questions here

by Ferk » Post

Hybrid Dog wrote:maybe you somewhere didn't round the position before using it for the area index
You mean for my case or for Don's?

In my case, even though I use an area index for checking the heighmap (not for placing the node itself, since I'm not using voxelmanip), I've even tried printing straight "minetest.get_mapgen_object("heightmap")[1]" in the on_generated and even that returns -31000. It's not just that the Y coordinate is a bit off, it's in the complete lower limit of the map because I can't get the height.

Maybe it's because my "flat" flag is on? I think I have it enabled, but I didn't see much difference anyway so I thought it wasn't really taking effect.

In Don's case, he's printing out the item_pos values before using them and they all seem to be integers.
Last edited by Ferk on Fri Sep 25, 2015 14:09, edited 1 time in total.
{ ☠ Dungeontest ☠ , ᗧ••myarcade•• }

User avatar
Hybrid Dog
Member
Posts: 2768
Joined: Thu Nov 01, 2012 12:46
GitHub: HybridDog

Re: Post your modding questions here

by Hybrid Dog » Post

you use mgv6, don't you?

‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪‮
‮‪

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

Re: Post your modding questions here

by Ferk » Post

Hybrid Dog wrote:you use mgv6, don't you?
I don't recall if I was using mgv6 or mgv7.. but definitely not singlenode.

I will try to check it further later when I reach home.
{ ☠ 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

Ok, I just made a very simple mod called "heighmaptest" with only 5 lines in its init.lua:

Code: Select all

minetest.register_on_generated(function(minp, maxp, seed)
	if minp.y > -5 and maxp.y < 200 then
	    minetest.log("action"," heighmap 1 : " .. minetest.get_mapgen_object("heightmap")[1]);
	end		
end)
I always get "heighmap 1 : -31000" as output. Even in a completely vanilla Minetest with no other mods and no minetest.conf, just using default mapgen v6. What am I doing wrong?

EDIT: Ok, after some more testing I'm starting to understand....

The heighmap only takes into account the nodes of the currently loading chunk. This means that if your whole chunk is in the underground the heigh is just gonna be the heigh of the top of the chunk (not the surface of the world), and if your chunk happens to be somewhere in the air above the land where there are no blocks, the heigh is -31000 because it would be the same as a singlenode map for that chunk.

This means the heighmap is actually quite an unreliable way to find out where's the surface. The center of a mountain could be reported to be the height if you are unlucky enough to have checked an area of the chunk that is right behind the mountain. You would have no way to know if that heigh is actually the surface or not unless you check the chunk above to see if it's maybe all air or it's a mountain.

So what's the right way to place something in the surface then?

Maybe I will place the node at y == 5 and let the ABM that spawns the entrance carve its way up and/or down before placing the schematic. I have to add a ladder anyway.
{ ☠ 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

Code: Select all

   if minp.y > -5 and maxp.y < 200 then
minp.y of the surface mapchunk is -32, so this code only acts on empty mapchunks, mgv6 doesn't rise above the surface mapchunk (-32 to 47).
Perhaps just ignore any heightmap value of y = 47 as that is usually inside a mountain (not in mgv6 though because of the above fact).

Locked

Who is online

Users browsing this forum: No registered users and 1 guest