Skip to content

Commit

Permalink
Fix core.get_node_or_nil in emerge env
Browse files Browse the repository at this point in the history
"ignore" does not mean unloaded, we have to properly check it.
  • Loading branch information
sfan5 committed Mar 3, 2024
1 parent 91ea47f commit e734b3f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
5 changes: 0 additions & 5 deletions builtin/emerge/env.lua
Expand Up @@ -31,11 +31,6 @@ function core.get_node(pos)
return core.vmanip:get_node_at(pos)
end

function core.get_node_or_nil(pos)
local node = core.vmanip:get_node_at(pos)
return node.name ~= "ignore" and node
end

function core.get_perlin(seed, octaves, persist, spread)
local params
if type(seed) == "table" then
Expand Down
14 changes: 14 additions & 0 deletions src/script/lua_api/l_env.cpp
Expand Up @@ -1534,6 +1534,19 @@ void ModApiEnv::InitializeClient(lua_State *L, int top)
if (!vm) \
return 0

// get_node_or_nil(pos)
int ModApiEnvVM::l_get_node_or_nil(lua_State *L)
{
GET_VM_PTR;

v3s16 pos = read_v3s16(L, 1);
if (vm->exists(pos))
pushnode(L, vm->getNodeRefUnsafe(pos));
else
lua_pushnil(L);
return 1;
}

// get_node_max_level(pos)
int ModApiEnvVM::l_get_node_max_level(lua_State *L)
{
Expand Down Expand Up @@ -1703,6 +1716,7 @@ MMVManip *ModApiEnvVM::getVManip(lua_State *L)
void ModApiEnvVM::InitializeEmerge(lua_State *L, int top)
{
// other, more trivial functions are in builtin/emerge/env.lua
API_FCT(get_node_or_nil);
API_FCT(get_node_max_level);
API_FCT(get_node_level);
API_FCT(set_node_level);
Expand Down
3 changes: 3 additions & 0 deletions src/script/lua_api/l_env.h
Expand Up @@ -247,6 +247,9 @@ class ModApiEnv : public ModApiEnvBase {
class ModApiEnvVM : public ModApiEnvBase {
private:

// get_node_or_nil(pos)
static int l_get_node_or_nil(lua_State *L);

// get_node_max_level(pos)
static int l_get_node_max_level(lua_State *L);

Expand Down

0 comments on commit e734b3f

Please sign in to comment.