]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/script/lua_api/l_env.cpp
Drop content_sao.{cpp,h}
[dragonfireclient.git] / src / script / lua_api / l_env.cpp
index a175569d8bfea347e724852b89e211b11ed43f19..40e50e64a81ee8803928bd12fb6662a963d14fc8 100644 (file)
@@ -17,6 +17,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */
 
+#include <algorithm>
 #include "lua_api/l_env.h"
 #include "lua_api/l_internal.h"
 #include "lua_api/l_nodemeta.h"
@@ -25,7 +26,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "lua_api/l_vmanip.h"
 #include "common/c_converter.h"
 #include "common/c_content.h"
-#include <algorithm>
 #include "scripting_server.h"
 #include "environment.h"
 #include "mapblock.h"
@@ -33,12 +33,13 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "nodedef.h"
 #include "daynightratio.h"
 #include "util/pointedthing.h"
-#include "content_sao.h"
 #include "mapgen/treegen.h"
 #include "emerge.h"
 #include "pathfinder.h"
 #include "face_position_cache.h"
 #include "remoteplayer.h"
+#include "server/luaentity_sao.h"
+#include "server/player_sao.h"
 #ifndef SERVER
 #include "client/client.h"
 #endif
@@ -139,8 +140,7 @@ void LuaLBM::trigger(ServerEnvironment *env, v3s16 p, MapNode n)
 
 int LuaRaycast::l_next(lua_State *L)
 {
-       MAP_LOCK_REQUIRED;
-       GET_ENV_PTR;
+       GET_PLAIN_ENV_PTR;
 
        bool csm = false;
 #ifndef SERVER
@@ -384,7 +384,7 @@ int ModApiEnvMod::l_get_node_or_nil(lua_State *L)
 // timeofday: nil = current time, 0 = night, 0.5 = day
 int ModApiEnvMod::l_get_node_light(lua_State *L)
 {
-       GET_ENV_PTR;
+       GET_PLAIN_ENV_PTR;
 
        // Do it
        v3s16 pos = read_v3s16(L, 1);
@@ -488,10 +488,7 @@ 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)
 {
-       Environment *env = getEnv(L);
-       if (!env) {
-               return 0;
-       }
+       GET_PLAIN_ENV_PTR;
 
        v3s16 pos = read_v3s16(L, 1);
        MapNode n = env->getMap().getNode(pos);
@@ -503,10 +500,7 @@ 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)
 {
-       Environment *env = getEnv(L);
-       if (!env) {
-               return 0;
-       }
+       GET_PLAIN_ENV_PTR;
 
        v3s16 pos = read_v3s16(L, 1);
        MapNode n = env->getMap().getNode(pos);
@@ -551,7 +545,7 @@ int ModApiEnvMod::l_add_node_level(lua_State *L)
 // find_nodes_with_meta(pos1, pos2)
 int ModApiEnvMod::l_find_nodes_with_meta(lua_State *L)
 {
-       GET_ENV_PTR;
+       GET_PLAIN_ENV_PTR;
 
        std::vector<v3s16> positions = env->getMap().findNodesWithMetadata(
                check_v3s16(L, 1), check_v3s16(L, 2));
@@ -643,7 +637,13 @@ int ModApiEnvMod::l_add_item(lua_State *L)
 // get_connected_players()
 int ModApiEnvMod::l_get_connected_players(lua_State *L)
 {
-       GET_ENV_PTR;
+       ServerEnvironment *env = (ServerEnvironment *) getEnv(L);
+       if (!env) {
+               log_deprecated(L, "Calling get_connected_players() at mod load time"
+                               " is deprecated");
+               lua_createtable(L, 0, 0);
+               return 1;
+       }
 
        lua_createtable(L, env->getPlayerCount(), 0);
        u32 i = 0;
@@ -722,10 +722,7 @@ int ModApiEnvMod::l_set_timeofday(lua_State *L)
 // get_timeofday() -> 0...1
 int ModApiEnvMod::l_get_timeofday(lua_State *L)
 {
-       Environment *env = getEnv(L);
-       if (!env) {
-               return 0;
-       }
+       GET_PLAIN_ENV_PTR;
 
        // Do it
        int timeofday_mh = env->getTimeOfDay();
@@ -737,10 +734,7 @@ int ModApiEnvMod::l_get_timeofday(lua_State *L)
 // get_day_count() -> int
 int ModApiEnvMod::l_get_day_count(lua_State *L)
 {
-       Environment *env = getEnv(L);
-       if (!env) {
-               return 0;
-       }
+       GET_PLAIN_ENV_PTR;
 
        lua_pushnumber(L, env->getDayCount());
        return 1;
@@ -761,12 +755,9 @@ 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)
 {
-       Environment *env = getEnv(L);
-       if (!env) {
-               return 0;
-       }
+       GET_PLAIN_ENV_PTR;
 
-       const NodeDefManager *ndef = getGameDef(L)->ndef();
+       const NodeDefManager *ndef = env->getGameDef()->ndef();
        v3s16 pos = read_v3s16(L, 1);
        int radius = luaL_checkinteger(L, 2);
        std::vector<content_t> filter;
@@ -809,20 +800,19 @@ int ModApiEnvMod::l_find_node_near(lua_State *L)
 // nodenames: eg. {"ignore", "group:tree"} or "default:dirt"
 int ModApiEnvMod::l_find_nodes_in_area(lua_State *L)
 {
-       GET_ENV_PTR;
+       GET_PLAIN_ENV_PTR;
 
        v3s16 minp = read_v3s16(L, 1);
        v3s16 maxp = read_v3s16(L, 2);
        sortBoxVerticies(minp, maxp);
 
+       const NodeDefManager *ndef = env->getGameDef()->ndef();
+
 #ifndef SERVER
-       const NodeDefManager *ndef = getClient(L) ? getClient(L)->ndef() : getServer(L)->ndef();
        if (getClient(L)) {
                minp = getClient(L)->CSMClampPos(minp);
                maxp = getClient(L)->CSMClampPos(maxp);
        }
-#else
-       const NodeDefManager *ndef = getServer(L)->ndef();
 #endif
 
        v3s16 cube = maxp - minp + 1;
@@ -886,20 +876,19 @@ int ModApiEnvMod::l_find_nodes_in_area_under_air(lua_State *L)
         * TODO
         */
 
-       GET_ENV_PTR;
+       GET_PLAIN_ENV_PTR;
 
        v3s16 minp = read_v3s16(L, 1);
        v3s16 maxp = read_v3s16(L, 2);
        sortBoxVerticies(minp, maxp);
 
+       const NodeDefManager *ndef = env->getGameDef()->ndef();
+
 #ifndef SERVER
-       const NodeDefManager *ndef = getClient(L) ? getClient(L)->ndef() : getServer(L)->ndef();
        if (getClient(L)) {
                minp = getClient(L)->CSMClampPos(minp);
                maxp = getClient(L)->CSMClampPos(maxp);
        }
-#else
-       const NodeDefManager *ndef = getServer(L)->ndef();
 #endif
 
        v3s16 cube = maxp - minp + 1;
@@ -1028,7 +1017,7 @@ int ModApiEnvMod::l_clear_objects(lua_State *L)
 // line_of_sight(pos1, pos2) -> true/false, pos
 int ModApiEnvMod::l_line_of_sight(lua_State *L)
 {
-       GET_ENV_PTR;
+       GET_PLAIN_ENV_PTR;
 
        // read position 1 from lua
        v3f pos1 = checkFloatPos(L, 1);
@@ -1194,7 +1183,7 @@ int ModApiEnvMod::l_find_path(lua_State *L)
        unsigned int max_jump       = luaL_checkint(L, 4);
        unsigned int max_drop       = luaL_checkint(L, 5);
        PathAlgorithm algo          = PA_PLAIN_NP;
-       if (!lua_isnil(L, 6)) {
+       if (!lua_isnoneornil(L, 6)) {
                std::string algorithm = luaL_checkstring(L,6);
 
                if (algorithm == "A*")