aboutsummaryrefslogtreecommitdiff
path: root/src/script/lua_api
diff options
context:
space:
mode:
authorJude Melton-Houghton <jwmhjwmh@gmail.com>2022-10-18 18:01:44 -0400
committerGitHub <noreply@github.com>2022-10-18 18:01:44 -0400
commitb38ffdec279bcded98e34f5116c8d676aa9f73a7 (patch)
tree31cafdb009b2f81b61a96286a3800a8e408f8f3d /src/script/lua_api
parent23e9f5db4330a6efee5270160a3959422926ce77 (diff)
downloadminetest-b38ffdec279bcded98e34f5116c8d676aa9f73a7.tar.xz
Implement vector and node conversion in Lua (#12609)
Co-authored-by: sfan5 <sfan5@live.de>
Diffstat (limited to 'src/script/lua_api')
-rw-r--r--src/script/lua_api/l_client.cpp2
-rw-r--r--src/script/lua_api/l_env.cpp19
-rw-r--r--src/script/lua_api/l_item.cpp7
-rw-r--r--src/script/lua_api/l_item.h1
-rw-r--r--src/script/lua_api/l_particles.cpp4
-rw-r--r--src/script/lua_api/l_particles_local.cpp4
-rw-r--r--src/script/lua_api/l_vmanip.cpp8
7 files changed, 23 insertions, 22 deletions
diff --git a/src/script/lua_api/l_client.cpp b/src/script/lua_api/l_client.cpp
index 9f776ae28..a1828a03b 100644
--- a/src/script/lua_api/l_client.cpp
+++ b/src/script/lua_api/l_client.cpp
@@ -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);
}
diff --git a/src/script/lua_api/l_env.cpp b/src/script/lua_api/l_env.cpp
index b40ccf518..642101166 100644
--- a/src/script/lua_api/l_env.cpp
+++ b/src/script/lua_api/l_env.cpp
@@ -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);
diff --git a/src/script/lua_api/l_item.cpp b/src/script/lua_api/l_item.cpp
index f33dd1fef..549f17261 100644
--- a/src/script/lua_api/l_item.cpp
+++ b/src/script/lua_api/l_item.cpp
@@ -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);
+}
diff --git a/src/script/lua_api/l_item.h b/src/script/lua_api/l_item.h
index a4cc706d8..aa7d028da 100644
--- a/src/script/lua_api/l_item.h
+++ b/src/script/lua_api/l_item.h
@@ -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);
};
diff --git a/src/script/lua_api/l_particles.cpp b/src/script/lua_api/l_particles.cpp
index 21f27bf8f..06511df07 100644
--- a/src/script/lua_api/l_particles.cpp
+++ b/src/script/lua_api/l_particles.cpp
@@ -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);
diff --git a/src/script/lua_api/l_particles_local.cpp b/src/script/lua_api/l_particles_local.cpp
index 62cbab8e9..43304b7a7 100644
--- a/src/script/lua_api/l_particles_local.cpp
+++ b/src/script/lua_api/l_particles_local.cpp
@@ -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);
diff --git a/src/script/lua_api/l_vmanip.cpp b/src/script/lua_api/l_vmanip.cpp
index 8f40b7d4a..f6d11088e 100644
--- a/src/script/lua_api/l_vmanip.cpp
+++ b/src/script/lua_api/l_vmanip.cpp
@@ -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);