1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

Implement vector and node conversion in Lua (#12609)

Co-authored-by: sfan5 <sfan5@live.de>
This commit is contained in:
Jude Melton-Houghton 2022-10-18 18:01:44 -04:00 committed by GitHub
parent 23e9f5db43
commit b38ffdec27
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
29 changed files with 191 additions and 167 deletions

View file

@ -220,7 +220,7 @@ int ModApiClient::l_get_node_or_nil(lua_State *L)
MapNode n = getClient(L)->CSMGetNode(pos, &pos_ok);
if (pos_ok) {
// Return node
pushnode(L, n, getClient(L)->ndef());
pushnode(L, n);
} else {
lua_pushnil(L);
}

View file

@ -98,7 +98,7 @@ void LuaABM::trigger(ServerEnvironment *env, v3s16 p, MapNode n,
luaL_checktype(L, -1, LUA_TFUNCTION);
lua_remove(L, -2); // Remove registered_abms[m_id]
push_v3s16(L, p);
pushnode(L, n, env->getGameDef()->ndef());
pushnode(L, n);
lua_pushnumber(L, active_object_count);
lua_pushnumber(L, active_object_count_wider);
@ -140,7 +140,7 @@ void LuaLBM::trigger(ServerEnvironment *env, v3s16 p, MapNode n)
luaL_checktype(L, -1, LUA_TFUNCTION);
lua_remove(L, -2); // Remove registered_lbms[m_id]
push_v3s16(L, p);
pushnode(L, n, env->getGameDef()->ndef());
pushnode(L, n);
int result = lua_pcall(L, 2, 0, error_handler);
if (result)
@ -247,10 +247,9 @@ int ModApiEnvMod::l_set_node(lua_State *L)
{
GET_ENV_PTR;
const NodeDefManager *ndef = env->getGameDef()->ndef();
// parameters
v3s16 pos = read_v3s16(L, 1);
MapNode n = readnode(L, 2, ndef);
MapNode n = readnode(L, 2);
// Do it
bool succeeded = env->setNode(pos, n);
lua_pushboolean(L, succeeded);
@ -263,7 +262,6 @@ int ModApiEnvMod::l_bulk_set_node(lua_State *L)
{
GET_ENV_PTR;
const NodeDefManager *ndef = env->getGameDef()->ndef();
// parameters
if (!lua_istable(L, 1)) {
return 0;
@ -275,7 +273,7 @@ int ModApiEnvMod::l_bulk_set_node(lua_State *L)
return 1;
}
MapNode n = readnode(L, 2, ndef);
MapNode n = readnode(L, 2);
// Do it
bool succeeded = true;
@ -315,10 +313,9 @@ int ModApiEnvMod::l_swap_node(lua_State *L)
{
GET_ENV_PTR;
const NodeDefManager *ndef = env->getGameDef()->ndef();
// parameters
v3s16 pos = read_v3s16(L, 1);
MapNode n = readnode(L, 2, ndef);
MapNode n = readnode(L, 2);
// Do it
bool succeeded = env->swapNode(pos, n);
lua_pushboolean(L, succeeded);
@ -336,7 +333,7 @@ int ModApiEnvMod::l_get_node(lua_State *L)
// Do it
MapNode n = env->getMap().getNode(pos);
// Return node
pushnode(L, n, env->getGameDef()->ndef());
pushnode(L, n);
return 1;
}
@ -353,7 +350,7 @@ int ModApiEnvMod::l_get_node_or_nil(lua_State *L)
MapNode n = env->getMap().getNode(pos, &pos_ok);
if (pos_ok) {
// Return node
pushnode(L, n, env->getGameDef()->ndef());
pushnode(L, n);
} else {
lua_pushnil(L);
}
@ -438,7 +435,7 @@ int ModApiEnvMod::l_place_node(lua_State *L)
IItemDefManager *idef = server->idef();
v3s16 pos = read_v3s16(L, 1);
MapNode n = readnode(L, 2, ndef);
MapNode n = readnode(L, 2);
// Don't attempt to load non-loaded area as of now
MapNode n_old = env->getMap().getNode(pos);

View file

@ -721,3 +721,10 @@ void ModApiItemMod::InitializeAsync(lua_State *L, int top)
API_FCT(get_content_id);
API_FCT(get_name_from_content_id);
}
void ModApiItemMod::InitializeClient(lua_State *L, int top)
{
// all read-only functions
API_FCT(get_content_id);
API_FCT(get_name_from_content_id);
}

View file

@ -174,4 +174,5 @@ private:
public:
static void Initialize(lua_State *L, int top);
static void InitializeAsync(lua_State *L, int top);
static void InitializeClient(lua_State *L, int top);
};

View file

@ -138,7 +138,7 @@ int ModApiParticles::l_add_particle(lua_State *L)
lua_getfield(L, 1, "node");
if (lua_istable(L, -1))
p.node = readnode(L, -1, getGameDef(L)->ndef());
p.node = readnode(L, -1);
lua_pop(L, 1);
p.node_tile = getintfield_default(L, 1, "node_tile", p.node_tile);
@ -289,7 +289,7 @@ int ModApiParticles::l_add_particlespawner(lua_State *L)
lua_getfield(L, 1, "node");
if (lua_istable(L, -1))
p.node = readnode(L, -1, getGameDef(L)->ndef());
p.node = readnode(L, -1);
lua_pop(L, 1);
p.node_tile = getintfield_default(L, 1, "node_tile", p.node_tile);

View file

@ -87,7 +87,7 @@ int ModApiParticlesLocal::l_add_particle(lua_State *L)
lua_getfield(L, 1, "node");
if (lua_istable(L, -1))
p.node = readnode(L, -1, getGameDef(L)->ndef());
p.node = readnode(L, -1);
lua_pop(L, 1);
p.node_tile = getintfield_default(L, 1, "node_tile", p.node_tile);
@ -185,7 +185,7 @@ int ModApiParticlesLocal::l_add_particlespawner(lua_State *L)
lua_getfield(L, 1, "node");
if (lua_istable(L, -1))
p.node = readnode(L, -1, getGameDef(L)->ndef());
p.node = readnode(L, -1);
lua_pop(L, 1);
p.node_tile = getintfield_default(L, 1, "node_tile", p.node_tile);

View file

@ -139,12 +139,10 @@ int LuaVoxelManip::l_get_node_at(lua_State *L)
{
NO_MAP_LOCK_REQUIRED;
const NodeDefManager *ndef = getServer(L)->getNodeDefManager();
LuaVoxelManip *o = checkObject<LuaVoxelManip>(L, 1);
v3s16 pos = check_v3s16(L, 2);
pushnode(L, o->vm->getNodeNoExNoEmerge(pos), ndef);
pushnode(L, o->vm->getNodeNoExNoEmerge(pos));
return 1;
}
@ -152,11 +150,9 @@ int LuaVoxelManip::l_set_node_at(lua_State *L)
{
NO_MAP_LOCK_REQUIRED;
const NodeDefManager *ndef = getServer(L)->getNodeDefManager();
LuaVoxelManip *o = checkObject<LuaVoxelManip>(L, 1);
v3s16 pos = check_v3s16(L, 2);
MapNode n = readnode(L, 3, ndef);
MapNode n = readnode(L, 3);
o->vm->setNodeNoEmerge(pos, n);