Schematic: Add force_placement parameter to minetest.place_structure API
authorkwolekr <kwolekr@minetest.net>
Sun, 16 Feb 2014 00:46:57 +0000 (19:46 -0500)
committerkwolekr <kwolekr@minetest.net>
Sun, 16 Feb 2014 00:46:57 +0000 (19:46 -0500)
doc/lua_api.txt
src/mapgen.cpp
src/mapgen.h
src/script/lua_api/l_mapgen.cpp

index 4e645ada3e1d139a2c7e63a9e3f440449b52ea66..0e2f6360e43c9bed121f7f49a87a1690fb54fb5a 100644 (file)
@@ -1595,11 +1595,13 @@ minetest.create_schematic(p1, p2, probability_list, filename, slice_prob_list)
    ^ If slice probability list is nil, no slice probabilities are applied.
 ^ Saves schematic in the Minetest Schematic format to filename.
 
-minetest.place_schematic(pos, schematic, rotation, replacements)
+minetest.place_schematic(pos, schematic, rotation, replacements, force_placement)
 ^ Place the schematic specified by schematic (see: Schematic specifier) at pos.
 ^ Rotation can be "0", "90", "180", "270", or "random".
 ^ If the rotation parameter is omitted, the schematic is not rotated.
 ^ replacements = {{"oldname", "convert_to"}, ...}
+^ force_placement is a boolean indicating whether nodes other than air and
+^ ignore are replaced by the schematic
 
 Random:
 minetest.get_connected_players() -> list of ObjectRefs
index 95a2f4029e326133735af3ebb302edac50a163b6..a7e9d2e04ced9afc09ba2053b61f1f85813ea87e 100644 (file)
@@ -652,7 +652,7 @@ void DecoSchematic::blitToVManip(v3s16 p, ManualMapVoxelManipulator *vm,
 }
 
 
-void DecoSchematic::placeStructure(Map *map, v3s16 p) {
+void DecoSchematic::placeStructure(Map *map, v3s16 p, bool force_placement) {
        assert(schematic != NULL);
        ManualMapVoxelManipulator *vm = new ManualMapVoxelManipulator(map);
 
@@ -673,7 +673,7 @@ void DecoSchematic::placeStructure(Map *map, v3s16 p) {
        v3s16 bp2 = getNodeBlockPos(p + s - v3s16(1,1,1));
        vm->initialEmerge(bp1, bp2);
 
-       blitToVManip(p, vm, rot, true);
+       blitToVManip(p, vm, rot, force_placement);
 
        std::map<v3s16, MapBlock *> lighting_modified_blocks;
        std::map<v3s16, MapBlock *> modified_blocks;
index 037cdd1f915f3a95c7c4d7db01b5dd65fac92287..9bc162fe0fd8a53d81d3478b8774666efc0ff9fa 100644 (file)
@@ -313,7 +313,7 @@ public:
        void saveSchematicFile(INodeDefManager *ndef);
 
        bool getSchematicFromMap(Map *map, v3s16 p1, v3s16 p2);
-       void placeStructure(Map *map, v3s16 p);
+       void placeStructure(Map *map, v3s16 p, bool force_placement);
        void applyProbabilities(v3s16 p0,
                std::vector<std::pair<v3s16, u8> > *plist,
                std::vector<std::pair<s16, u8> > *splist);
index a7af856dea29ced98bde6373d0b8d638b7094c20..d34620056bb61104f8272e4ff8a548d70e4d8a76 100644 (file)
@@ -599,9 +599,8 @@ int ModApiMapgen::l_place_schematic(lua_State *L)
        dschem.rotation = (Rotation)rot;
 
        if (lua_istable(L, 4)) {
-               int index = 4;
                lua_pushnil(L);
-               while (lua_next(L, index) != 0) {
+               while (lua_next(L, 4) != 0) {
                        // key at index -2 and value at index -1
                        lua_rawgeti(L, -1, 1);
                        std::string replace_from = lua_tostring(L, -1);
@@ -615,6 +614,10 @@ int ModApiMapgen::l_place_schematic(lua_State *L)
                }
        }
 
+       bool force_placement = true;
+       if (lua_isboolean(L, 5))
+               force_placement = lua_toboolean(L, 5);
+
        if (!dschem.filename.empty()) {
                if (!dschem.loadSchematicFile()) {
                        errorstream << "place_schematic: failed to load schematic file '"
@@ -624,7 +627,7 @@ int ModApiMapgen::l_place_schematic(lua_State *L)
                dschem.resolveNodeNames(ndef);
        }
 
-       dschem.placeStructure(map, p);
+       dschem.placeStructure(map, p, force_placement);
 
        return 1;
 }