Register_on_generated?

Gatharoth
Member
 
Posts: 196
Joined: Thu Dec 22, 2011 02:54

Register_on_generated?

by Gatharoth » Tue Mar 20, 2012 18:28

Okay, so I'm trying to make a flat land for creative mode; So that way I don't have to clear out a bunch of blocks in order to get my base-area.

But the things I've tried have resulted in a crash.

I've looked at both gemstones and moreores to see how they did it, but I have no idea where their first "for X x do" comes from. (I mean the things in between the "for and "do")

So I tried to write a spin-off of their code; however it did not work, and resulted in a crash.

Here is the crash error
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
11:21:22: ERROR[ServerThread]: ERROR: An unhandled exception occurred: Access violation

In thread e14:
C:\tmp\minetest\src\server.cpp:118: ServerThread::Thread: Assertion '0' failed.
Debug stacks:
DEBUG STACK FOR THREAD 7fc:
#0  MeshUpdateThread::Thread
DEBUG STACK FOR THREAD 988:


And here's the code
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
local flatland = function( minp, maxp )
    local start = -30000
    local final = 30000
    local pos = {
        x = minp.x,
        y = minp.y,
        z = minp.z,
    }       
    while start < final do
        if pos.y > 0 then
            minetest.env:remove_node(pos)
        end
        pos = {
            x = pos.x + 1,
            y = pos.y + 1,
            z = pos.z + 1,
        }
        start = start + 1
    end
end

minetest.register_on_generated( flatland )


Anyone care to explain to me how minetest.register_on_generated works? Because I'm currently lost.
 

randomproof
Member
 
Posts: 214
Joined: Thu Nov 17, 2011 06:31

by randomproof » Tue Mar 20, 2012 19:46

Here look at this code:
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.register_on_generated(
function(minp, maxp)
    max_add = 20
    for x = minp.x,maxp.x do
    for y = minp.y,maxp.y do
    for z = minp.z,maxp.z do
        pos = {x=x, y=y, z=z}
        if minetest.env:get_node(pos).name == "default:stone_with_iron" then
            max_check = 5
            while max_check do
                pos_i = {x=pos.x + math.random(-1, 1), y=pos.y + math.random(-1, 1), z=pos.z + math.random(-1, 1)}
                if minetest.env:get_node(pos_i).name == "default:stone" then
                    minetest.env:add_node(pos_i, {name="default:stone_with_iron"})
                    --print ("[Extra Iron] Added extra iron!")
                    max_add = max_add - 1
                    break
                end
                max_check = max_check - 1
            end
        end
       
        if max_add == 0 then
            return
        end
    end
    end
    end
end
)


You need to cycle through minp.x to maxp.x (similarly for y and z). Basically, you are getting 2 points that represent the two opposite points in a cube. You should only be messing with nodes in between these two points.

You want something like this:
(Everything above y=0 becomes air and everything y<=0 becomes dirt)
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.register_on_generated(
function(minp, maxp)
    for x = minp.x,maxp.x do
    for y = minp.y,maxp.y do
    for z = minp.z,maxp.z do
        pos = {x=x, y=y, z=z}
        if y > 0 then
            minetest.env:remove_node(pos)
        else
            minetest.env:add_node(pos, {name="default:dirt"})
        end
    end
    end
    end
end)
 

Gatharoth
Member
 
Posts: 196
Joined: Thu Dec 22, 2011 02:54

by Gatharoth » Tue Mar 20, 2012 22:19

randomproof wrote:Here look at this code:
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.register_on_generated(
function(minp, maxp)
    max_add = 20
    for x = minp.x,maxp.x do
    for y = minp.y,maxp.y do
    for z = minp.z,maxp.z do
        pos = {x=x, y=y, z=z}
        if minetest.env:get_node(pos).name == "default:stone_with_iron" then
            max_check = 5
            while max_check do
                pos_i = {x=pos.x + math.random(-1, 1), y=pos.y + math.random(-1, 1), z=pos.z + math.random(-1, 1)}
                if minetest.env:get_node(pos_i).name == "default:stone" then
                    minetest.env:add_node(pos_i, {name="default:stone_with_iron"})
                    --print ("[Extra Iron] Added extra iron!")
                    max_add = max_add - 1
                    break
                end
                max_check = max_check - 1
            end
        end
       
        if max_add == 0 then
            return
        end
    end
    end
    end
end
)


You need to cycle through minp.x to maxp.x (similarly for y and z). Basically, you are getting 2 points that represent the two opposite points in a cube. You should only be messing with nodes in between these two points.

You want something like this:
(Everything above y=0 becomes air and everything y<=0 becomes dirt)
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.register_on_generated(
function(minp, maxp)
    for x = minp.x,maxp.x do
    for y = minp.y,maxp.y do
    for z = minp.z,maxp.z do
        pos = {x=x, y=y, z=z}
        if y > 0 then
            minetest.env:remove_node(pos)
        else
            minetest.env:add_node(pos, {name="default:dirt"})
        end
    end
    end
    end
end)


Ah, I see. Alright thanks :D
 


Return to WIP Mods

Who is online

Users browsing this forum: No registered users and 75 guests

cron