[SOLVED]place sign inside "minetest.register_on_generated"

Post Reply
User avatar
Smitje
Member
Posts: 22
Joined: Wed Nov 14, 2012 20:42

[SOLVED]place sign inside "minetest.register_on_generated"

by Smitje » Post

Hi all, Happy new year!

Im looking to place a sign from inside "minetest.register_on_generated(..." larger snippet below
I can place sand using: ...minetest.get_content_id("default:sand")...
but signs using:...minetest.get_content_id("default:sign")...
don't show. There arn't any error warnings afaik, Do I need other attributes, is the name wrong, I have no clue

I also want to add some text. The idea is I want to check some values calculated in the script from inside the game at multiple positions for debugging purposes. other suggestions are very welcome.

Cheers, Smitje

Code: Select all

minetest.register_on_generated(function(minp, maxp, seed)
	if minp.y < YMIN or maxp.y > YMAX then
		return  -- The chunk is outside the set height band (YMIN YMAX)
	end

	local t1 = os.clock()
	local x1 = maxp.x
	local y1 = maxp.y
	local z1 = maxp.z
	local x0 = minp.x
	local y0 = minp.y
	local z0 = minp.z

	local vm, emin, emax = minetest.get_mapgen_object("voxelmanip")
	local area = VoxelArea:new{MinEdge=emin, MaxEdge=emax}
	local data = vm:get_data()

	local c_testmarker = minetest.get_content_id("citygen:testmarker")
	
	local chunck_name = tostring(x0)..","..tostring(z0)

    print(chunck_name)
    print("block "..x0.." "..y0.." "..z0.." # "..x1.." "..y1.." "..z1.."   ")

    
    --
    print("seed ")
    print(citygen_get_vseed(x0, z0))
    
    
    -- create seed markers
    hmap = minetest.get_mapgen_object("heightmap")
    if citygen.known_chuncks[chunck_name]["status"] == "hasseed" then
        local ch_seedx, ch_seedz = citygen_get_vseed(x0, z0)
        local h02 = citygen_get_h(ch_seedx, ch_seedz, x0, z0)
        if h02 <= y1 and h02 >= y0 then
            for k = 1, 4 do
                local vi = area:index(ch_seedx, h02+k, ch_seedz)
                data[vi] = c_testmarker
            end
            local vi = area:index(ch_seedx, h02+5, ch_seedz)
            data[vi] = minetest.get_content_id("default:sign")
            --print(dump(minetest.get_content_id("default:sand")))
        end
    end

	-- end of the citygen stuff ------------
	
	vm:set_data(data)
	vm:set_lighting({day=0, night=0})
	vm:calc_lighting()
	vm:write_to_map(data)
	local chugent = math.ceil((os.clock() - t1) * 1000)
	print ("[hfind] "..chugent.." ms\n")
Last edited by Smitje on Tue Jan 05, 2016 21:01, edited 1 time in total.

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

Re: place sign inside "minetest.register_on_generated"

by Krock » Post

It's called "default:sign_wall" (MTG reference)

To add text to your sign, you must get and set the metadata of your sign.
The following code is not tested, so there might be some problems.

Code: Select all

local sign_positions = {} -- For more than 1 sign per block
-- create seed markers


data[vi] = minetest.get_content_id("default:sign_wall")
table.insert(sign_positions, area:position(vi))


print ("[hfind] "..chugent.." ms\n")
local text = "Sign text"
for i,v in ipairs(sign_positions) do
	local meta = minetest.get_meta(v)
	meta:set_string("formspec", "field[text;;${text}]")
	meta:set_string("text", text)
	meta:set_string("infotext", '"' .. text .. '"')
end
Look, I programmed a bug for you. >> Mod Search Engine << - Mods by Krock - DuckDuckGo mod search bang: !mtmod <keyword here>

User avatar
Smitje
Member
Posts: 22
Joined: Wed Nov 14, 2012 20:42

Re: place sign inside "minetest.register_on_generated"

by Smitje » Post

Thanks!

I used it like this and that works:
I think using the table as suggested would put the same text on all signs.

Code: Select all

            local vi = area:index(ch_seedx, h02+4, ch_seedz)
            data[vi] = minetest.get_content_id("default:sign_wall")
            local text = dump(area:position(vi)).." seed "..ch_seedx..", "..ch_seedy
            local meta = minetest.get_meta(area:position(vi))
            meta:set_string("formspec", "field[text;;${text}]")
            meta:set_string("text", text)
            meta:set_string("infotext", '"' .. text .. '"')

User avatar
Smitje
Member
Posts: 22
Joined: Wed Nov 14, 2012 20:42

Re: [SOLVED]place sign inside "minetest.register_on_generate

by Smitje » Post

Not quite generic or elegant but useful in my case:
x and z are coordinates in the block or chunk or what is it called (1-80)

Code: Select all

function setsign(x, z, x0, z0, area, data, text)
    local h = citygen_get_h(x, z, x0, z0)+1
    local vi = area:index(x, h, z)
    data[vi] = minetest.get_content_id("default:sign_wall")
    local meta = minetest.get_meta(area:position(vi))
    meta:set_string("formspec", "field[text;;${text}]")
    meta:set_string("text", text)
    meta:set_string("infotext", '"' .. text .. '"')
end


minetest.register_on_generated(function(minp, maxp, seed)
	if minp.y < YMIN or maxp.y > YMAX then
		return  -- The chunk is outside the set height band (YMIN YMAX)
	end

	local t1 = os.clock()
	local x1 = maxp.x
	local y1 = maxp.y
	local z1 = maxp.z
	local x0 = minp.x
	local y0 = minp.y
	local z0 = minp.z

	local vm, emin, emax = minetest.get_mapgen_object("voxelmanip")
	local area = VoxelArea:new{MinEdge=emin, MaxEdge=emax}
	local data = vm:get_data()

...

    setsign(x, z, x0, z0, area, data, "your text here")

...


Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests