diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/client/client.cpp | 13 | ||||
-rw-r--r-- | src/client/client.h | 1 | ||||
-rw-r--r-- | src/script/cpp_api/s_item.h | 1 | ||||
-rw-r--r-- | src/script/lua_api/l_env.cpp | 37 | ||||
-rw-r--r-- | src/script/scripting_client.cpp | 1 |
5 files changed, 47 insertions, 6 deletions
diff --git a/src/client/client.cpp b/src/client/client.cpp index 89873ade3..36d4f8df9 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -1337,6 +1337,19 @@ int Client::CSMClampRadius(v3s16 pos, int radius) return std::min<int>(radius, m_csm_restriction_noderange - distance); } +v3s16 Client::CSMClampPos(v3s16 pos) +{ + if (!checkCSMRestrictionFlag(CSMRestrictionFlags::CSM_RF_LOOKUP_NODES)) + return pos; + v3s16 ppos = floatToInt(m_env.getLocalPlayer()->getPosition(), BS); + const int range = m_csm_restriction_noderange; + return v3s16( + core::clamp<int>(pos.X, (int)ppos.X - range, (int)ppos.X + range), + core::clamp<int>(pos.Y, (int)ppos.Y - range, (int)ppos.Y + range), + core::clamp<int>(pos.Z, (int)ppos.Z - range, (int)ppos.Z + range) + ); +} + void Client::addNode(v3s16 p, MapNode n, bool remove_metadata) { //TimeTaker timer1("Client::addNode()"); diff --git a/src/client/client.h b/src/client/client.h index 5f3362509..5144af69f 100644 --- a/src/client/client.h +++ b/src/client/client.h @@ -264,6 +264,7 @@ public: // helpers to enforce CSM restrictions MapNode CSMGetNode(v3s16 p, bool *is_valid_position); int CSMClampRadius(v3s16 pos, int radius); + v3s16 CSMClampPos(v3s16 pos); void addNode(v3s16 p, MapNode n, bool remove_metadata = true); diff --git a/src/script/cpp_api/s_item.h b/src/script/cpp_api/s_item.h index ad229f73e..25a3501f9 100644 --- a/src/script/cpp_api/s_item.h +++ b/src/script/cpp_api/s_item.h @@ -51,7 +51,6 @@ public: protected: friend class LuaItemStack; friend class ModApiItemMod; - friend class LuaRaycast; bool getItemCallback(const char *name, const char *callbackname, const v3s16 *p = nullptr); /*! diff --git a/src/script/lua_api/l_env.cpp b/src/script/lua_api/l_env.cpp index 203ffcfdc..762612af4 100644 --- a/src/script/lua_api/l_env.cpp +++ b/src/script/lua_api/l_env.cpp @@ -140,17 +140,20 @@ void LuaLBM::trigger(ServerEnvironment *env, v3s16 p, MapNode n) int LuaRaycast::l_next(lua_State *L) { MAP_LOCK_REQUIRED; - - ScriptApiItem *script = getScriptApi<ScriptApiItem>(L); GET_ENV_PTR; + bool csm = false; +#ifndef SERVER + csm = getClient(L) != nullptr; +#endif + LuaRaycast *o = checkobject(L, 1); PointedThing pointed; env->continueRaycast(&o->state, &pointed); if (pointed.type == POINTEDTHING_NOTHING) lua_pushnil(L); else - script->pushPointedThing(pointed, true); + push_pointed_thing(L, pointed, csm, true); return 1; } @@ -793,11 +796,20 @@ int ModApiEnvMod::l_find_nodes_in_area(lua_State *L) { GET_ENV_PTR; - const NodeDefManager *ndef = getServer(L)->ndef(); v3s16 minp = read_v3s16(L, 1); v3s16 maxp = read_v3s16(L, 2); sortBoxVerticies(minp, maxp); +#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; // Volume limit equal to 8 default mapchunks, (80 * 2) ^ 3 = 4,096,000 if ((u64)cube.X * (u64)cube.Y * (u64)cube.Z > 4096000) { @@ -861,11 +873,20 @@ int ModApiEnvMod::l_find_nodes_in_area_under_air(lua_State *L) GET_ENV_PTR; - const NodeDefManager *ndef = getServer(L)->ndef(); v3s16 minp = read_v3s16(L, 1); v3s16 maxp = read_v3s16(L, 2); sortBoxVerticies(minp, maxp); +#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; // Volume limit equal to 8 default mapchunks, (80 * 2) ^ 3 = 4,096,000 if ((u64)cube.X * (u64)cube.Y * (u64)cube.Z > 4096000) { @@ -1326,8 +1347,14 @@ void ModApiEnvMod::Initialize(lua_State *L, int top) void ModApiEnvMod::InitializeClient(lua_State *L, int top) { + API_FCT(get_node_light); API_FCT(get_timeofday); API_FCT(get_node_max_level); API_FCT(get_node_level); + API_FCT(find_nodes_with_meta); API_FCT(find_node_near); + API_FCT(find_nodes_in_area); + API_FCT(find_nodes_in_area_under_air); + API_FCT(line_of_sight); + API_FCT(raycast); } diff --git a/src/script/scripting_client.cpp b/src/script/scripting_client.cpp index c3e0ca373..1288b1df7 100644 --- a/src/script/scripting_client.cpp +++ b/src/script/scripting_client.cpp @@ -69,6 +69,7 @@ void ClientScripting::InitializeModApi(lua_State *L, int top) { LuaItemStack::Register(L); ItemStackMetaRef::Register(L); + LuaRaycast::Register(L); StorageRef::Register(L); LuaMinimap::Register(L); NodeMetaRef::RegisterClient(L); |