1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

Decoration: Add schematic Y-slice probability support

This commit is contained in:
kwolekr 2013-12-01 01:23:39 -05:00
parent de0cdbc01c
commit 20e3d550fa
4 changed files with 108 additions and 47 deletions

View file

@ -475,7 +475,7 @@ int ModApiMapgen::l_create_schematic(lua_State *L)
v3s16 p2 = read_v3s16(L, 2);
sortBoxVerticies(p1, p2);
std::vector<std::pair<v3s16, u8> > probability_list;
std::vector<std::pair<v3s16, u8> > prob_list;
if (lua_istable(L, 3)) {
lua_pushnil(L);
while (lua_next(L, 3)) {
@ -485,22 +485,37 @@ int ModApiMapgen::l_create_schematic(lua_State *L)
lua_pop(L, 1);
u8 prob = getintfield_default(L, -1, "prob", MTSCHEM_PROB_ALWAYS);
probability_list.push_back(std::make_pair(pos, prob));
prob_list.push_back(std::make_pair(pos, prob));
}
lua_pop(L, 1);
}
}
dschem.filename = std::string(lua_tostring(L, 4));
std::vector<std::pair<s16, u8> > slice_prob_list;
if (lua_istable(L, 5)) {
lua_pushnil(L);
while (lua_next(L, 5)) {
if (lua_istable(L, -1)) {
s16 ypos = getintfield_default(L, -1, "ypos", 0);
u8 prob = getintfield_default(L, -1, "prob", MTSCHEM_PROB_ALWAYS);
slice_prob_list.push_back(std::make_pair(ypos, prob));
}
lua_pop(L, 1);
}
}
const char *s = lua_tostring(L, 4);
dschem.filename = std::string(s ? s : "");
if (!dschem.getSchematicFromMap(map, p1, p2)) {
errorstream << "create_schematic: failed to get schematic "
"from map" << std::endl;
return 0;
}
dschem.applyProbabilities(&probability_list, p1);
dschem.applyProbabilities(p1, &prob_list, &slice_prob_list);
dschem.saveSchematicFile(ndef);
actionstream << "create_schematic: saved schematic file '"