Fix core.get_node_or_nil in emerge env

"ignore" does not mean unloaded, we have to properly check it.
This commit is contained in:
sfan5 2024-02-24 09:49:42 +01:00
parent 91ea47fddf
commit e734b3f0d8
3 changed files with 17 additions and 5 deletions

@ -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

@ -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)
{
@ -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);

@ -247,6 +247,9 @@ public:
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);