Skip to content

Commit c6f784f

Browse files
HybridDogparamat
authored andcommittedDec 31, 2018
Add minetest.load_area (#8023)
1 parent aa5ec2e commit c6f784f

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed
 

‎doc/lua_api.txt

+4
Original file line numberDiff line numberDiff line change
@@ -3989,6 +3989,10 @@ Environment access
39893989
* mode = `"quick"`: Clear objects immediately in loaded mapblocks,
39903990
clear objects in unloaded mapblocks only when the
39913991
mapblocks are next activated.
3992+
* `minetest.load_area(pos1[, pos2])`
3993+
* Load the mapblocks containing the area from `pos1` to `pos2`.
3994+
`pos2` defaults to `pos1` if not specified.
3995+
* This function does not trigger map generation.
39923996
* `minetest.emerge_area(pos1, pos2, [callback], [param])`
39933997
* Queue all blocks in the area from `pos1` to `pos2`, inclusive, to be
39943998
asynchronously fetched from memory, loaded from disk, or if inexistent,

‎src/script/lua_api/l_env.cpp

+25
Original file line numberDiff line numberDiff line change
@@ -1047,6 +1047,30 @@ int ModApiEnvMod::l_raycast(lua_State *L)
10471047
return LuaRaycast::create_object(L);
10481048
}
10491049

1050+
// load_area(p1, [p2])
1051+
// load mapblocks in area p1..p2, but do not generate map
1052+
int ModApiEnvMod::l_load_area(lua_State *L)
1053+
{
1054+
GET_ENV_PTR;
1055+
MAP_LOCK_REQUIRED;
1056+
1057+
Map *map = &(env->getMap());
1058+
v3s16 bp1 = getNodeBlockPos(check_v3s16(L, 1));
1059+
if (!lua_istable(L, 2)) {
1060+
map->emergeBlock(bp1);
1061+
} else {
1062+
v3s16 bp2 = getNodeBlockPos(check_v3s16(L, 2));
1063+
sortBoxVerticies(bp1, bp2);
1064+
for (s16 z = bp1.Z; z <= bp2.Z; z++)
1065+
for (s16 y = bp1.Y; y <= bp2.Y; y++)
1066+
for (s16 x = bp1.X; x <= bp2.X; x++) {
1067+
map->emergeBlock(v3s16(x, y, z));
1068+
}
1069+
}
1070+
1071+
return 0;
1072+
}
1073+
10501074
// emerge_area(p1, p2, [callback, context])
10511075
// emerge mapblocks in area p1..p2, calls callback with context upon completion
10521076
int ModApiEnvMod::l_emerge_area(lua_State *L)
@@ -1287,6 +1311,7 @@ void ModApiEnvMod::Initialize(lua_State *L, int top)
12871311
API_FCT(find_nodes_in_area);
12881312
API_FCT(find_nodes_in_area_under_air);
12891313
API_FCT(fix_light);
1314+
API_FCT(load_area);
12901315
API_FCT(emerge_area);
12911316
API_FCT(delete_area);
12921317
API_FCT(get_perlin);

‎src/script/lua_api/l_env.h

+3
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,9 @@ class ModApiEnvMod : public ModApiBase {
135135
// fix_light(p1, p2) -> true/false
136136
static int l_fix_light(lua_State *L);
137137

138+
// load_area(p1)
139+
static int l_load_area(lua_State *L);
140+
138141
// emerge_area(p1, p2)
139142
static int l_emerge_area(lua_State *L);
140143

0 commit comments

Comments
 (0)
Please sign in to comment.