@@ -880,6 +880,21 @@ int ModApiEnvMod::l_find_node_near(lua_State *L)
880
880
return 0 ;
881
881
}
882
882
883
+ static void checkArea (v3s16 &minp, v3s16 &maxp)
884
+ {
885
+ auto volume = VoxelArea (minp, maxp).getVolume ();
886
+ // Volume limit equal to 8 default mapchunks, (80 * 2) ^ 3 = 4,096,000
887
+ if (volume > 4096000 ) {
888
+ throw LuaError (" Area volume exceeds allowed value of 4096000" );
889
+ }
890
+
891
+ // Clamp to map range to avoid problems
892
+ #define CLAMP (arg ) core::clamp(arg, (s16)-MAX_MAP_GENERATION_LIMIT, (s16)MAX_MAP_GENERATION_LIMIT)
893
+ minp = v3s16 (CLAMP (minp.X ), CLAMP (minp.Y ), CLAMP (minp.Z ));
894
+ maxp = v3s16 (CLAMP (maxp.X ), CLAMP (maxp.Y ), CLAMP (maxp.Z ));
895
+ #undef CLAMP
896
+ }
897
+
883
898
// find_nodes_in_area(minp, maxp, nodenames, [grouped])
884
899
int ModApiEnvMod::l_find_nodes_in_area (lua_State *L)
885
900
{
@@ -899,13 +914,7 @@ int ModApiEnvMod::l_find_nodes_in_area(lua_State *L)
899
914
}
900
915
#endif
901
916
902
- v3s16 cube = maxp - minp + 1 ;
903
- // Volume limit equal to 8 default mapchunks, (80 * 2) ^ 3 = 4,096,000
904
- if ((u64)cube.X * (u64)cube.Y * (u64)cube.Z > 4096000 ) {
905
- luaL_error (L, " find_nodes_in_area(): area volume"
906
- " exceeds allowed value of 4096000" );
907
- return 0 ;
908
- }
917
+ checkArea (minp, maxp);
909
918
910
919
std::vector<content_t > filter;
911
920
collectNodeIds (L, 3 , ndef, filter);
@@ -1010,13 +1019,7 @@ int ModApiEnvMod::l_find_nodes_in_area_under_air(lua_State *L)
1010
1019
}
1011
1020
#endif
1012
1021
1013
- v3s16 cube = maxp - minp + 1 ;
1014
- // Volume limit equal to 8 default mapchunks, (80 * 2) ^ 3 = 4,096,000
1015
- if ((u64)cube.X * (u64)cube.Y * (u64)cube.Z > 4096000 ) {
1016
- luaL_error (L, " find_nodes_in_area_under_air(): area volume"
1017
- " exceeds allowed value of 4096000" );
1018
- return 0 ;
1019
- }
1022
+ checkArea (minp, maxp);
1020
1023
1021
1024
std::vector<content_t > filter;
1022
1025
collectNodeIds (L, 3 , ndef, filter);
0 commit comments