bool Schematic::getSchematicFromMap(Map *map, v3s16 p1, v3s16 p2) { MMVManip *vm = new MMVManip(map); v3s16 bp1 = getNodeBlockPos(p1); v3s16 bp2 = getNodeBlockPos(p2); vm->initialEmerge(bp1, bp2); size = p2 - p1 + 1; slice_probs = new u8[size.Y]; for (s16 y = 0; y != size.Y; y++) slice_probs[y] = MTSCHEM_PROB_ALWAYS; schemdata = new MapNode[size.X * size.Y * size.Z]; u32 i = 0; for (s16 z = p1.Z; z <= p2.Z; z++) for (s16 y = p1.Y; y <= p2.Y; y++) { u32 vi = vm->m_area.index(p1.X, y, z); for (s16 x = p1.X; x <= p2.X; x++, i++, vi++) { schemdata[i] = vm->m_data[vi]; schemdata[i].param1 = MTSCHEM_PROB_ALWAYS; } } delete vm; return true; }
int LuaVoxelManip::l_read_from_map(lua_State *L) { LuaVoxelManip *o = checkobject(L, 1); MMVManip *vm = o->vm; v3s16 bp1 = getNodeBlockPos(read_v3s16(L, 2)); v3s16 bp2 = getNodeBlockPos(read_v3s16(L, 3)); sortBoxVerticies(bp1, bp2); vm->initialEmerge(bp1, bp2); push_v3s16(L, vm->m_area.MinEdge); push_v3s16(L, vm->m_area.MaxEdge); return 2; }
void Schematic::placeStructure(Map *map, v3s16 p, u32 flags, Rotation rot, bool force_place) { assert(schemdata != NULL); // Pre-condition sanity_check(m_ndef != NULL); MMVManip *vm = new MMVManip(map); if (rot == ROTATE_RAND) rot = (Rotation)myrand_range(ROTATE_0, ROTATE_270); v3s16 s = (rot == ROTATE_90 || rot == ROTATE_270) ? v3s16(size.Z, size.Y, size.X) : size; if (flags & DECO_PLACE_CENTER_X) p.X -= (s.X + 1) / 2; if (flags & DECO_PLACE_CENTER_Y) p.Y -= (s.Y + 1) / 2; if (flags & DECO_PLACE_CENTER_Z) p.Z -= (s.Z + 1) / 2; v3s16 bp1 = getNodeBlockPos(p); v3s16 bp2 = getNodeBlockPos(p + s - v3s16(1,1,1)); vm->initialEmerge(bp1, bp2); blitToVManip(p, vm, rot, force_place); std::map<v3s16, MapBlock *> lighting_modified_blocks; std::map<v3s16, MapBlock *> modified_blocks; vm->blitBackAll(&modified_blocks); // TODO: Optimize this by using Mapgen::calcLighting() instead lighting_modified_blocks.insert(modified_blocks.begin(), modified_blocks.end()); map->updateLighting(lighting_modified_blocks, modified_blocks); MapEditEvent event; event.type = MEET_OTHER; for (std::map<v3s16, MapBlock *>::iterator it = modified_blocks.begin(); it != modified_blocks.end(); ++it) event.modified_blocks.insert(it->first); map->dispatchEvent(&event); }