summaryrefslogtreecommitdiff
path: root/src/script
diff options
context:
space:
mode:
Diffstat (limited to 'src/script')
-rw-r--r--src/script/clientscripting.cpp2
-rw-r--r--src/script/cpp_api/s_client.cpp5
-rw-r--r--src/script/cpp_api/s_client.h4
-rw-r--r--src/script/lua_api/l_env.cpp44
-rw-r--r--src/script/lua_api/l_env.h1
-rw-r--r--src/script/lua_api/l_internal.h10
6 files changed, 46 insertions, 20 deletions
diff --git a/src/script/clientscripting.cpp b/src/script/clientscripting.cpp
index 8bf1b68b1..df30a7253 100644
--- a/src/script/clientscripting.cpp
+++ b/src/script/clientscripting.cpp
@@ -22,6 +22,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "client.h"
#include "cpp_api/s_internal.h"
#include "lua_api/l_client.h"
+#include "lua_api/l_env.h"
#include "lua_api/l_minimap.h"
#include "lua_api/l_storage.h"
#include "lua_api/l_sound.h"
@@ -62,6 +63,7 @@ void ClientScripting::InitializeModApi(lua_State *L, int top)
ModApiClient::Initialize(L, top);
ModApiSound::Initialize(L, top);
ModApiStorage::Initialize(L, top);
+ ModApiEnvMod::InitializeClient(L, top);
LuaItemStack::Register(L);
StorageRef::Register(L);
diff --git a/src/script/cpp_api/s_client.cpp b/src/script/cpp_api/s_client.cpp
index 154dd6194..666fd693d 100644
--- a/src/script/cpp_api/s_client.cpp
+++ b/src/script/cpp_api/s_client.cpp
@@ -177,3 +177,8 @@ bool ScriptApiClient::on_punchnode(v3s16 p, MapNode node)
bool blocked = lua_toboolean(L, -1);
return blocked;
}
+
+void ScriptApiClient::setEnv(ClientEnvironment *env)
+{
+ ScriptApiBase::setEnv(env);
+}
diff --git a/src/script/cpp_api/s_client.h b/src/script/cpp_api/s_client.h
index 93e9558f2..2369efe3e 100644
--- a/src/script/cpp_api/s_client.h
+++ b/src/script/cpp_api/s_client.h
@@ -29,6 +29,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include <cstdint>
#endif
+class ClientEnvironment;
+
class ScriptApiClient: virtual public ScriptApiBase
{
public:
@@ -47,5 +49,7 @@ public:
bool on_dignode(v3s16 p, MapNode node);
bool on_punchnode(v3s16 p, MapNode node);
+
+ void setEnv(ClientEnvironment *env);
};
#endif
diff --git a/src/script/lua_api/l_env.cpp b/src/script/lua_api/l_env.cpp
index 14df558d3..4fad7b37c 100644
--- a/src/script/lua_api/l_env.cpp
+++ b/src/script/lua_api/l_env.cpp
@@ -347,7 +347,10 @@ int ModApiEnvMod::l_punch_node(lua_State *L)
// pos = {x=num, y=num, z=num}
int ModApiEnvMod::l_get_node_max_level(lua_State *L)
{
- GET_ENV_PTR;
+ Environment *env = getEnv(L);
+ if (!env) {
+ return 0;
+ }
v3s16 pos = read_v3s16(L, 1);
MapNode n = env->getMap().getNodeNoEx(pos);
@@ -359,7 +362,10 @@ int ModApiEnvMod::l_get_node_max_level(lua_State *L)
// pos = {x=num, y=num, z=num}
int ModApiEnvMod::l_get_node_level(lua_State *L)
{
- GET_ENV_PTR;
+ Environment *env = getEnv(L);
+ if (!env) {
+ return 0;
+ }
v3s16 pos = read_v3s16(L, 1);
MapNode n = env->getMap().getNodeNoEx(pos);
@@ -558,11 +564,14 @@ int ModApiEnvMod::l_set_timeofday(lua_State *L)
// get_timeofday() -> 0...1
int ModApiEnvMod::l_get_timeofday(lua_State *L)
{
- GET_ENV_PTR;
+ Environment *env = getEnv(L);
+ if (!env) {
+ return 0;
+ }
// Do it
int timeofday_mh = env->getTimeOfDay();
- float timeofday_f = (float)timeofday_mh / 24000.0;
+ float timeofday_f = (float)timeofday_mh / 24000.0f;
lua_pushnumber(L, timeofday_f);
return 1;
}
@@ -570,7 +579,10 @@ int ModApiEnvMod::l_get_timeofday(lua_State *L)
// get_day_count() -> int
int ModApiEnvMod::l_get_day_count(lua_State *L)
{
- GET_ENV_PTR;
+ Environment *env = getEnv(L);
+ if (!env) {
+ return 0;
+ }
lua_pushnumber(L, env->getDayCount());
return 1;
@@ -591,9 +603,12 @@ int ModApiEnvMod::l_get_gametime(lua_State *L)
// nodenames: eg. {"ignore", "group:tree"} or "default:dirt"
int ModApiEnvMod::l_find_node_near(lua_State *L)
{
- GET_ENV_PTR;
+ Environment *env = getEnv(L);
+ if (!env) {
+ return 0;
+ }
- INodeDefManager *ndef = getServer(L)->ndef();
+ INodeDefManager *ndef = getGameDef(L)->ndef();
v3s16 pos = read_v3s16(L, 1);
int radius = luaL_checkinteger(L, 2);
std::set<content_t> filter;
@@ -611,13 +626,13 @@ int ModApiEnvMod::l_find_node_near(lua_State *L)
ndef->getIds(lua_tostring(L, 3), filter);
}
- for(int d=1; d<=radius; d++){
+ for (int d=1; d<=radius; d++){
std::vector<v3s16> list = FacePositionCache::getFacePositions(d);
- for(std::vector<v3s16>::iterator i = list.begin();
+ for (std::vector<v3s16>::iterator i = list.begin();
i != list.end(); ++i){
v3s16 p = pos + (*i);
content_t c = env->getMap().getNodeNoEx(p).getContent();
- if(filter.count(c) != 0){
+ if (filter.count(c) != 0){
push_v3s16(L, p);
return 1;
}
@@ -1087,3 +1102,12 @@ void ModApiEnvMod::Initialize(lua_State *L, int top)
API_FCT(forceload_block);
API_FCT(forceload_free_block);
}
+
+void ModApiEnvMod::InitializeClient(lua_State *L, int top)
+{
+ API_FCT(get_timeofday);
+ API_FCT(get_day_count);
+ API_FCT(get_node_max_level);
+ API_FCT(get_node_level);
+ API_FCT(find_node_near);
+}
diff --git a/src/script/lua_api/l_env.h b/src/script/lua_api/l_env.h
index 322959411..38b2282d7 100644
--- a/src/script/lua_api/l_env.h
+++ b/src/script/lua_api/l_env.h
@@ -173,6 +173,7 @@ private:
public:
static void Initialize(lua_State *L, int top);
+ static void InitializeClient(lua_State *L, int top);
static struct EnumString es_ClearObjectsMode[];
};
diff --git a/src/script/lua_api/l_internal.h b/src/script/lua_api/l_internal.h
index c610dc5a3..b7627619e 100644
--- a/src/script/lua_api/l_internal.h
+++ b/src/script/lua_api/l_internal.h
@@ -37,16 +37,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#define MAP_LOCK_REQUIRED
#define NO_MAP_LOCK_REQUIRED
-/*
-#if (defined(WIN32) || defined(_WIN32_WCE))
- #define NO_MAP_LOCK_REQUIRED
-#else
- #include "profiler.h"
- #define NO_MAP_LOCK_REQUIRED \
- ScopeProfiler nolocktime(g_profiler,"Scriptapi: unlockable time",SPT_ADD)
-#endif
-*/
-
#define GET_ENV_PTR_NO_MAP_LOCK \
ServerEnvironment *env = (ServerEnvironment *)getEnv(L); \
if (env == NULL) \