Esempio n. 1
0
// place_schematic(p, schematic, rotation)
int ModApiBasic::l_place_schematic(lua_State *L)
{
	DecoSchematic dschem;

	Map *map = &(getEnv(L)->getMap());
	INodeDefManager *ndef = getServer(L)->getNodeDefManager();

	v3s16 p = read_v3s16(L, 1);
	if (!read_schematic(L, 2, &dschem, getServer(L)))
		return 0;
		
	Rotation rot = ROTATE_0;
	if (lua_isstring(L, 3))
		string_to_enum(es_Rotation, (int &)rot, std::string(lua_tostring(L, 3)));
		
	dschem.rotation = rot;

	if (!dschem.filename.empty()) {
		if (!dschem.loadSchematicFile()) {
			errorstream << "place_schematic: failed to load schematic file '"
				<< dschem.filename << "'" << std::endl;
			return 0;
		}
		dschem.resolveNodeNames(ndef);
	}
	
	dschem.placeStructure(map, p);

	return 1;
}
Esempio n. 2
0
// place_schematic(p, schematic, rotation, replacement)
int ModApiMapgen::l_place_schematic(lua_State *L)
{
	DecoSchematic dschem;

	Map *map = &(getEnv(L)->getMap());
	INodeDefManager *ndef = getServer(L)->getNodeDefManager();

	v3s16 p = read_v3s16(L, 1);
	if (!read_schematic(L, 2, &dschem, getServer(L)))
		return 0;

	int rot = ROTATE_0;
	if (lua_isstring(L, 3))
		string_to_enum(es_Rotation, rot, std::string(lua_tostring(L, 3)));

	dschem.rotation = (Rotation)rot;

	if (lua_istable(L, 4)) {
		lua_pushnil(L);
		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);
			lua_pop(L, 1);
			lua_rawgeti(L, -1, 2);
			std::string replace_to = lua_tostring(L, -1);
			lua_pop(L, 1);
			dschem.replacements[replace_from] = replace_to;
			// removes value, keeps key for next iteration
			lua_pop(L, 1);
		}
	}

	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 '"
				<< dschem.filename << "'" << std::endl;
			return 0;
		}
		dschem.resolveNodeNames(ndef);
	}

	dschem.placeStructure(map, p, force_placement);

	return 1;
}