Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add get_surface lua function #640

Closed
wants to merge 3 commits into from

Conversation

Projects
None yet
4 participants
@sapier
Copy link
Contributor

commented Apr 10, 2013

detecting surface from within lua is quite costly this function helps avoiding this

@bas080

This comment has been minimized.

Copy link

commented Apr 13, 2013

I consider this a must. It would improve the development and implementation of biomes.

@bas080

This comment has been minimized.

Copy link

commented Apr 21, 2013

How long before I can start using this?

@sapier

This comment has been minimized.

Copy link
Contributor Author

commented May 25, 2013

rebased to master 20130525

@qznc

View changes

src/environment.cpp Outdated
@@ -861,6 +861,42 @@ bool ServerEnvironment::setNode(v3s16 p, const MapNode &n)
return true;
}

int ServerEnvironment::get_surface(v3s16 basepos, int serachup, bool walkable_only) {

This comment has been minimized.

Copy link
@qznc

qznc Jun 7, 2013

typo: searchup

@proller

This comment has been minimized.

Copy link
Contributor

commented Sep 7, 2013

please rebase

@sapier

This comment has been minimized.

Copy link
Contributor Author

commented Oct 30, 2013

rebased to master 20131030

proller pushed a commit to freeminer/freeminer that referenced this pull request Nov 27, 2013

@sapier

This comment has been minimized.

Copy link
Contributor Author

commented Apr 28, 2014

outdated maybe updated later

@sapier sapier closed this Apr 28, 2014

@sapier sapier reopened this Aug 16, 2014

@sapier sapier force-pushed the minetest:master branch 2 times, most recently to c24e075 Aug 19, 2014

@sapier

This comment has been minimized.

Copy link
Contributor Author

commented Aug 19, 2014

Sorry not worth the time to make a generic evaluation function from it

@sapier sapier closed this Aug 19, 2014

@ghost

This comment has been minimized.

Copy link

commented Jul 26, 2015

so is minetest.get_surface(pos) a go or a no-go?

@ghost

This comment has been minimized.

Copy link

commented Jul 29, 2015

here is the function in lua

-- a lua rewrite of sapier's get_surface() proposal, see:
-- https://github.com/sapier/minetest/blob/c6f814b52a5e2b2f12c76215db3524571c56fe20/src/environment.cpp#L868
function get_surface(basepos, searchup, walkable_only)
    local max = searchup + basepos.y
    local last_node = minetest.get_node(basepos)
    local node = last_node
    local runpos = basepos
    local last_was_walkable = minetest.registered_nodes[node.name].walkable
    while ( runpos.y < max and minetest.get_content_id(node.name) ~= c_air ) do
        runpos.y = runpos.y + 1
        last_node = node
        node = minetest.get_node(runpos)
        if not (walkable_only) then
            if minetest.get_content_id(last_node.name) ~= c_air
            and minetest.get_content_id(last_node.name) ~= c_ignore
            and minetest.get_content_id(node.name) == c_air then
                return runpos.y
            end
        else
            local is_walkable = minetest.registered_nodes[node.name].walkable
            if last_was_walkable and not is_walkable then
                return runpos.y
            end
            last_was_walkable = is_walkable
        end
    end
    return basepos.y - 1
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.