Skip to content

Commit c610643

Browse files
committedFeb 27, 2018
Place schematic (on vmanip): Enable use of 'place center' flags
For 'place schematic' and 'place schematic on vmanip' APIs. Fix 'place center' code to properly centre schematics. Fix some comments.
1 parent 6c9df2f commit c610643

File tree

4 files changed

+40
-18
lines changed

4 files changed

+40
-18
lines changed
 

Diff for: ‎doc/lua_api.txt

+10-2
Original file line numberDiff line numberDiff line change
@@ -3276,7 +3276,7 @@ These functions return the leftover itemstack.
32763276
* If slice probability list equals `nil`, no slice probabilities are applied.
32773277
* Saves schematic in the Minetest Schematic format to filename.
32783278

3279-
* `minetest.place_schematic(pos, schematic, rotation, replacements, force_placement)`
3279+
* `minetest.place_schematic(pos, schematic, rotation, replacements, force_placement, flags)`
32803280
* Place the schematic specified by schematic (see: Schematic specifier) at `pos`.
32813281
* `rotation` can equal `"0"`, `"90"`, `"180"`, `"270"`, or `"random"`.
32823282
* If the `rotation` parameter is omitted, the schematic is not rotated.
@@ -3288,14 +3288,22 @@ These functions return the leftover itemstack.
32883288
will always use the cached version and the replacement list defined for it,
32893289
regardless of whether the file or the replacement list parameter have changed.
32903290
The only way to load the file anew is to restart the server.
3291+
* `flags` is a flag field with the available flags:
3292+
* place_center_x
3293+
* place_center_y
3294+
* place_center_z
32913295

3292-
* `minetest.place_schematic_on_vmanip(vmanip, pos, schematic, rotation, replacement, force_placement)`:
3296+
* `minetest.place_schematic_on_vmanip(vmanip, pos, schematic, rotation, replacement, force_placement, flags)`:
32933297
* This function is analogous to minetest.place_schematic, but places a schematic onto the
32943298
specified VoxelManip object `vmanip` instead of the whole map.
32953299
* Returns false if any part of the schematic was cut-off due to the VoxelManip not
32963300
containing the full area required, and true if the whole schematic was able to fit.
32973301
* Returns nil if the schematic could not be loaded.
32983302
* After execution, any external copies of the VoxelManip contents are invalidated.
3303+
* `flags` is a flag field with the available flags:
3304+
* place_center_x
3305+
* place_center_y
3306+
* place_center_z
32993307

33003308
* `minetest.serialize_schematic(schematic, format, options)`
33013309
* Return the serialized schematic specified by schematic (see: Schematic specifier)

Diff for: ‎src/mapgen/mg_schematic.cpp

+8-8
Original file line numberDiff line numberDiff line change
@@ -188,15 +188,15 @@ bool Schematic::placeOnVManip(MMVManip *vm, v3s16 p, u32 flags,
188188

189189
//// Adjust placement position if necessary
190190
if (flags & DECO_PLACE_CENTER_X)
191-
p.X -= (s.X + 1) / 2;
191+
p.X -= (s.X - 1) / 2;
192192
if (flags & DECO_PLACE_CENTER_Y)
193-
p.Y -= (s.Y + 1) / 2;
193+
p.Y -= (s.Y - 1) / 2;
194194
if (flags & DECO_PLACE_CENTER_Z)
195-
p.Z -= (s.Z + 1) / 2;
195+
p.Z -= (s.Z - 1) / 2;
196196

197197
blitToVManip(vm, p, rot, force_place);
198198

199-
return vm->m_area.contains(VoxelArea(p, p + s - v3s16(1,1,1)));
199+
return vm->m_area.contains(VoxelArea(p, p + s - v3s16(1, 1, 1)));
200200
}
201201

202202
void Schematic::placeOnMap(ServerMap *map, v3s16 p, u32 flags,
@@ -219,16 +219,16 @@ void Schematic::placeOnMap(ServerMap *map, v3s16 p, u32 flags,
219219

220220
//// Adjust placement position if necessary
221221
if (flags & DECO_PLACE_CENTER_X)
222-
p.X -= (s.X + 1) / 2;
222+
p.X -= (s.X - 1) / 2;
223223
if (flags & DECO_PLACE_CENTER_Y)
224-
p.Y -= (s.Y + 1) / 2;
224+
p.Y -= (s.Y - 1) / 2;
225225
if (flags & DECO_PLACE_CENTER_Z)
226-
p.Z -= (s.Z + 1) / 2;
226+
p.Z -= (s.Z - 1) / 2;
227227

228228
//// Create VManip for effected area, emerge our area, modify area
229229
//// inside VManip, then blit back.
230230
v3s16 bp1 = getNodeBlockPos(p);
231-
v3s16 bp2 = getNodeBlockPos(p + s - v3s16(1,1,1));
231+
v3s16 bp2 = getNodeBlockPos(p + s - v3s16(1, 1, 1));
232232

233233
MMVManip vm(map);
234234
vm.initialEmerge(bp1, bp2);

Diff for: ‎src/script/lua_api/l_mapgen.cpp

+16-3
Original file line numberDiff line numberDiff line change
@@ -1529,7 +1529,8 @@ int ModApiMapgen::l_create_schematic(lua_State *L)
15291529
}
15301530

15311531

1532-
// place_schematic(p, schematic, rotation, replacement)
1532+
// place_schematic(p, schematic, rotation,
1533+
// replacements, force_placement, flagstring)
15331534
int ModApiMapgen::l_place_schematic(lua_State *L)
15341535
{
15351536
MAP_LOCK_REQUIRED;
@@ -1565,12 +1566,19 @@ int ModApiMapgen::l_place_schematic(lua_State *L)
15651566
return 0;
15661567
}
15671568

1568-
schem->placeOnMap(map, p, 0, (Rotation)rot, force_placement);
1569+
//// Read flags
1570+
u32 flags = 0;
1571+
read_flags(L, 6, flagdesc_deco, &flags, NULL);
1572+
1573+
schem->placeOnMap(map, p, flags, (Rotation)rot, force_placement);
15691574

15701575
lua_pushboolean(L, true);
15711576
return 1;
15721577
}
15731578

1579+
1580+
// place_schematic_on_vmanip(vm, p, schematic, rotation,
1581+
// replacements, force_placement, flagstring)
15741582
int ModApiMapgen::l_place_schematic_on_vmanip(lua_State *L)
15751583
{
15761584
NO_MAP_LOCK_REQUIRED;
@@ -1606,13 +1614,18 @@ int ModApiMapgen::l_place_schematic_on_vmanip(lua_State *L)
16061614
return 0;
16071615
}
16081616

1617+
//// Read flags
1618+
u32 flags = 0;
1619+
read_flags(L, 7, flagdesc_deco, &flags, NULL);
1620+
16091621
bool schematic_did_fit = schem->placeOnVManip(
1610-
vm, p, 0, (Rotation)rot, force_placement);
1622+
vm, p, flags, (Rotation)rot, force_placement);
16111623

16121624
lua_pushboolean(L, schematic_did_fit);
16131625
return 1;
16141626
}
16151627

1628+
16161629
// serialize_schematic(schematic, format, options={...})
16171630
int ModApiMapgen::l_serialize_schematic(lua_State *L)
16181631
{

Diff for: ‎src/script/lua_api/l_mapgen.h

+6-5
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,10 @@ class ModApiMapgen : public ModApiBase
7070
// get_noiseparam_defaults(name)
7171
static int l_get_noiseparams(lua_State *L);
7272

73-
// set_gen_notify(flagstring)
73+
// set_gen_notify(flags, {deco_id_table})
7474
static int l_set_gen_notify(lua_State *L);
7575

76-
// set_gen_notify(flagstring)
76+
// get_gen_notify()
7777
static int l_get_gen_notify(lua_State *L);
7878

7979
// register_biome({lots of stuff})
@@ -109,11 +109,12 @@ class ModApiMapgen : public ModApiBase
109109
// create_schematic(p1, p2, probability_list, filename)
110110
static int l_create_schematic(lua_State *L);
111111

112-
// place_schematic(p, schematic, rotation, replacements, force_placement)
112+
// place_schematic(p, schematic, rotation,
113+
// replacements, force_placement, flagstring)
113114
static int l_place_schematic(lua_State *L);
114115

115-
// place_schematic_on_vmanip(vm, p, schematic,
116-
// rotation, replacements, force_placement)
116+
// place_schematic_on_vmanip(vm, p, schematic, rotation,
117+
// replacements, force_placement, flagstring)
117118
static int l_place_schematic_on_vmanip(lua_State *L);
118119

119120
// serialize_schematic(schematic, format, options={...})

0 commit comments

Comments
 (0)
Please sign in to comment.