How to check if a chunk is generated

Post Reply
bell07
Member
Posts: 604
Joined: Sun Sep 04, 2016 15:15
GitHub: bell07

How to check if a chunk is generated

by bell07 » Post

I search for a fast way to check if a chunk is already generated but not loaded, without triggering the generation or loading the chunk.
The minetest.get_node_or_nil() does check only if loaded or not, but I canot distinguish if generated or not.

User avatar
Krock
Developer
Posts: 4650
Joined: Thu Oct 03, 2013 07:48
GitHub: SmallJoker
Location: Switzerland
Contact:

Re: How to check if a chunk is generated

by Krock » Post

You could use the Voxel Manipulator to read a single node. If it's not "ignore", then the mapblock *might* already be generated.
Look, I programmed a bug for you. >> Mod Search Engine << - Mods by Krock - DuckDuckGo mod search bang: !mtmod <keyword here>

bell07
Member
Posts: 604
Joined: Sun Sep 04, 2016 15:15
GitHub: bell07

Re: How to check if a chunk is generated

by bell07 » Post

As I know the Voxel Manipulator does not return the "ignore". The read_from_map() method always return the merged chunk data. That means the generation is triggered. I just need to check "if".

The idea is to enhance my "schemlib" to be able to queue the building structures for "on_generated" processing if the chunk is not generated (or build instantly if chunk is already there).

Sokomine
Member
Posts: 4290
Joined: Sun Sep 09, 2012 17:31
GitHub: Sokomine
IRC: Sokomine
In-game: Sokomine

Re: How to check if a chunk is generated

by Sokomine » Post

In theory you could check the existence of a mapblock on the database level. I'm not sure how practical that'd actually be.
A list of my mods can be found here.

bell07
Member
Posts: 604
Joined: Sun Sep 04, 2016 15:15
GitHub: bell07

Re: How to check if a chunk is generated

by bell07 » Post

Thank you both for answers.
I do not like the low-level access to database beside the API. Ok, now I prepare the work, read the map trough voxel and then check if the work is done. If not, process them on voxel data ..

An other question: A building uses default stone and cobble in his structure. But if I place them trough on_generate, sometimes dirt_with* or sometimes the desert stone is placed. THe coble is sometimes mossy.
Is there a way to avoid this behaviour?

I know about is_ground_content, but I do not like to create own nodes for all usual mapgen nodes.
Image
Attachments
screenshot_20180720_220822.png
screenshot_20180720_220822.png (618.89 KiB) Viewed 497 times

Sokomine
Member
Posts: 4290
Joined: Sun Sep 09, 2012 17:31
GitHub: Sokomine
IRC: Sokomine
In-game: Sokomine

Re: How to check if a chunk is generated

by Sokomine » Post

bell07 wrote: I know about is_ground_content, but I do not like to create own nodes for all usual mapgen nodes.
I'm afraid there is no real solution. Mapgen (or rather cavegen) is just too hungry and will eat through anything it's allowed to. In mg_villages, I do place the area that is affected by cavegen several times by fixing the shell around the current mapblock.
A list of my mods can be found here.

bell07
Member
Posts: 604
Joined: Sun Sep 04, 2016 15:15
GitHub: bell07

Re: How to check if a chunk is generated

by bell07 » Post

OK, the mapgen generation is reserved now for building if such deformations are ok (like temples)..

Found a way to place the building once without interferring with mapgen. The look to buildin chatcommand "emergeblocks" did the trick.

Schemlib code now:

Code: Select all

local function emergeblocks_callback(pos, action, num_calls_remaining, ctx)
	if not ctx.total_blocks then
		ctx.total_blocks   = num_calls_remaining + 1
		ctx.current_blocks = 0
	end
	ctx.current_blocks = ctx.current_blocks + 1

	if ctx.current_blocks == ctx.total_blocks then
		ctx.plan:load_region(ctx.pos, ctx.pos)
		ctx.plan:do_add_chunk_voxel_int()
		local pos_hash = minetest.hash_node_position(ctx.pos)
		mapgen_process[pos_hash] = nil
		if ctx.after_call_func then
			ctx.after_call_func(ctx.plan)
		end
	end
end

--------------------------------------
-- add/build a chunk using VoxelArea
--------------------------------------
function plan_class:do_add_chunk_voxel(plan_pos, after_call_func)
	-- Register for on_generate build
	local chunk_pos = self:get_world_pos(plan_pos)
	local BLOCKSIZE = 16
	chunk_pos.x = (math.floor(chunk_pos.x/BLOCKSIZE))*BLOCKSIZE
	chunk_pos.y = (math.floor(chunk_pos.y/BLOCKSIZE))*BLOCKSIZE
	chunk_pos.z = (math.floor(chunk_pos.z/BLOCKSIZE))*BLOCKSIZE
	minetest.emerge_area(chunk_pos, chunk_pos, emergeblocks_callback, {
		plan = self,
		pos = chunk_pos,
		after_call_func = after_call_func
	})
end

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

Re: How to check if a chunk is generated

by paramat » Post

Use the lua voxel manipulator to load and read a node, if it is 'ignore' the area is not yet generated.

> An other question: A building uses default stone and cobble in his structure. But if I place them trough on_generate, sometimes dirt_with* or sometimes the desert stone is placed. THe coble is sometimes mossy.
Is there a way to avoid this behaviour?

Using dupilcate mod nodes is the only solution, they can always 'drop' normal MTG nodes.
It's always best to use mod nodes as MTG nodes often have undesirable code or ABMs running on them. Also then you can set them to be 'is_ground_content = false' which is essential for mod structures placed during mapgen.

bell07
Member
Posts: 604
Joined: Sun Sep 04, 2016 15:15
GitHub: bell07

Re: How to check if a chunk is generated

by bell07 » Post

paramat wrote:Use the lua voxel manipulator to load and read a node, if it is 'ignore' the area is not yet generated.
This check triggers the generation too. And on faster servers the map can be generated between the VoxelManip and get_node.
Own nodes is not the solution I am search for. The library should be compatible to all nodes, and I cannot clone all registered nodes.

Because of "enhanced" behaviour in mapgen processing I do not try anymore to combine both generations.
And I am happy with minetest.emerge_area() 's calback function now to force the map generation and wait till it is done, because no active re-checking of the generation status needed. This way I can place "New/unaffectedly" buildings.

The next question is to the other direction. Is it possible to re-trigger the mapgen stuff (ores, decoration, caves) on already generated chunks after placement the own building? Will be nice to place temples or other long abadoned buildings

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

Re: How to check if a chunk is generated

by paramat » Post

> This check triggers the generation too.

It shouldn't, only 'emerge_area' does that.

> Is it possible to re-trigger the mapgen stuff (ores, decoration, caves) on already generated chunks

Only ores and decorations, they can be added withn the lua voxel manipulator, see https://github.com/minetest/minetest/bl ... .txt#L3825

Post Reply

Who is online

Users browsing this forum: No registered users and 14 guests