ore->ore_name = getstringfield_default(L, index, "ore", "");
ore->ore_param2 = (u8)getintfield_default(L, index, "ore_param2", 0);
- ore->wherein_name = getstringfield_default(L, index, "wherein", "");
ore->clust_scarcity = getintfield_default(L, index, "clust_scarcity", 1);
ore->clust_num_ores = getintfield_default(L, index, "clust_num_ores", 1);
ore->clust_size = getintfield_default(L, index, "clust_size", 0);
ore->flags = getflagsfield(L, index, "flags", flagdesc_ore);
ore->nthresh = getfloatfield_default(L, index, "noise_threshhold", 0.);
+ lua_getfield(L, index, "wherein");
+ if (lua_istable(L, -1)) {
+ int i = lua_gettop(L);
+ lua_pushnil(L);
+ while(lua_next(L, i) != 0) {
+ ore->wherein_names.push_back(lua_tostring(L, -1));
+ lua_pop(L, 1);
+ }
+ } else if (lua_isstring(L, -1)) {
+ ore->wherein_names.push_back(lua_tostring(L, -1));
+ } else {
+ ore->wherein_names.push_back("");
+ }
+ lua_pop(L, 1);
+
lua_getfield(L, index, "noise_params");
ore->np = read_noiseparams(L, -1);
lua_pop(L, 1);
dschem->flags = getflagsfield(L, index, "flags", flagdesc_deco_schematic);
dschem->rotation = (Rotation)getenumfield(L, index,
"rotation", es_Rotation, ROTATE_0);
-
+
+ lua_getfield(L, index, "replacements");
+ if (lua_istable(L, -1)) {
+ int i = lua_gettop(L);
+ lua_pushnil(L);
+ while (lua_next(L, i) != 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);
+ }
+ }
+ lua_pop(L, 1);
+
lua_getfield(L, index, "schematic");
if (!read_schematic(L, -1, dschem, getServer(L))) {
delete dschem;
v3s16 p2 = read_v3s16(L, 2);
sortBoxVerticies(p1, p2);
- std::vector<std::pair<v3s16, s16> > probability_list;
+ std::vector<std::pair<v3s16, u8> > probability_list;
if (lua_istable(L, 3)) {
lua_pushnil(L);
while (lua_next(L, 3)) {
v3s16 pos = read_v3s16(L, -1);
lua_pop(L, 1);
- s16 prob = getintfield_default(L, -1, "prob", 0);
- if (prob < -1 || prob >= UCHAR_MAX) {
- errorstream << "create_schematic: probability value of "
- << prob << " at " << PP(pos) << " out of range" << std::endl;
- } else {
- probability_list.push_back(std::make_pair(pos, prob));
- }
+ u8 prob = getintfield_default(L, -1, "prob", 0xFF);
+ probability_list.push_back(std::make_pair(pos, prob));
}
lua_pop(L, 1);
}
-// place_schematic(p, schematic, rotation)
+// place_schematic(p, schematic, rotation, replacement)
int ModApiBasic::l_place_schematic(lua_State *L)
{
DecoSchematic dschem;
dschem.rotation = rot;
+ if (lua_istable(L, 4)) {
+ int index = 4;
+ lua_pushnil(L);
+ while (lua_next(L, index) != 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);
+ }
+ }
+
if (!dschem.filename.empty()) {
if (!dschem.loadSchematicFile()) {
errorstream << "place_schematic: failed to load schematic file '"