Skip to content

Commit c163859

Browse files
committedFeb 16, 2014
Schematic: Add force_placement parameter to minetest.place_structure API
1 parent 3570f3e commit c163859

File tree

4 files changed

+12
-7
lines changed

4 files changed

+12
-7
lines changed
 

‎doc/lua_api.txt

+3-1
Original file line numberDiff line numberDiff line change
@@ -1595,11 +1595,13 @@ minetest.create_schematic(p1, p2, probability_list, filename, slice_prob_list)
15951595
^ If slice probability list is nil, no slice probabilities are applied.
15961596
^ Saves schematic in the Minetest Schematic format to filename.
15971597

1598-
minetest.place_schematic(pos, schematic, rotation, replacements)
1598+
minetest.place_schematic(pos, schematic, rotation, replacements, force_placement)
15991599
^ Place the schematic specified by schematic (see: Schematic specifier) at pos.
16001600
^ Rotation can be "0", "90", "180", "270", or "random".
16011601
^ If the rotation parameter is omitted, the schematic is not rotated.
16021602
^ replacements = {{"oldname", "convert_to"}, ...}
1603+
^ force_placement is a boolean indicating whether nodes other than air and
1604+
^ ignore are replaced by the schematic
16031605

16041606
Random:
16051607
minetest.get_connected_players() -> list of ObjectRefs

‎src/mapgen.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,7 @@ void DecoSchematic::blitToVManip(v3s16 p, ManualMapVoxelManipulator *vm,
652652
}
653653

654654

655-
void DecoSchematic::placeStructure(Map *map, v3s16 p) {
655+
void DecoSchematic::placeStructure(Map *map, v3s16 p, bool force_placement) {
656656
assert(schematic != NULL);
657657
ManualMapVoxelManipulator *vm = new ManualMapVoxelManipulator(map);
658658

@@ -673,7 +673,7 @@ void DecoSchematic::placeStructure(Map *map, v3s16 p) {
673673
v3s16 bp2 = getNodeBlockPos(p + s - v3s16(1,1,1));
674674
vm->initialEmerge(bp1, bp2);
675675

676-
blitToVManip(p, vm, rot, true);
676+
blitToVManip(p, vm, rot, force_placement);
677677

678678
std::map<v3s16, MapBlock *> lighting_modified_blocks;
679679
std::map<v3s16, MapBlock *> modified_blocks;

‎src/mapgen.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ class DecoSchematic : public Decoration {
313313
void saveSchematicFile(INodeDefManager *ndef);
314314

315315
bool getSchematicFromMap(Map *map, v3s16 p1, v3s16 p2);
316-
void placeStructure(Map *map, v3s16 p);
316+
void placeStructure(Map *map, v3s16 p, bool force_placement);
317317
void applyProbabilities(v3s16 p0,
318318
std::vector<std::pair<v3s16, u8> > *plist,
319319
std::vector<std::pair<s16, u8> > *splist);

‎src/script/lua_api/l_mapgen.cpp

+6-3
Original file line numberDiff line numberDiff line change
@@ -599,9 +599,8 @@ int ModApiMapgen::l_place_schematic(lua_State *L)
599599
dschem.rotation = (Rotation)rot;
600600

601601
if (lua_istable(L, 4)) {
602-
int index = 4;
603602
lua_pushnil(L);
604-
while (lua_next(L, index) != 0) {
603+
while (lua_next(L, 4) != 0) {
605604
// key at index -2 and value at index -1
606605
lua_rawgeti(L, -1, 1);
607606
std::string replace_from = lua_tostring(L, -1);
@@ -615,6 +614,10 @@ int ModApiMapgen::l_place_schematic(lua_State *L)
615614
}
616615
}
617616

617+
bool force_placement = true;
618+
if (lua_isboolean(L, 5))
619+
force_placement = lua_toboolean(L, 5);
620+
618621
if (!dschem.filename.empty()) {
619622
if (!dschem.loadSchematicFile()) {
620623
errorstream << "place_schematic: failed to load schematic file '"
@@ -624,7 +627,7 @@ int ModApiMapgen::l_place_schematic(lua_State *L)
624627
dschem.resolveNodeNames(ndef);
625628
}
626629

627-
dschem.placeStructure(map, p);
630+
dschem.placeStructure(map, p, force_placement);
628631

629632
return 1;
630633
}

0 commit comments

Comments
 (0)
Please sign in to comment.