MCPcopy Create free account
hub / github.com/Cubitect/cubiomes-viewer / l_getStructures

Function l_getStructures

src/scripts.cpp:116–198  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

114}
115
116static int l_getStructures(lua_State *L)
117{
118 lua_getglobal(L, "_cb_env");
119 SearchThreadEnv *env = (SearchThreadEnv*) lua_touserdata(L, -1);
120 lua_pop(L, 1);
121
122 int styp, x0, z0, x1, z1;
123 z1 = (int) lua_tonumber(L, -1);
124 lua_pop(L, 1);
125 x1 = (int) lua_tonumber(L, -1);
126 lua_pop(L, 1);
127 z0 = (int) lua_tonumber(L, -1);
128 lua_pop(L, 1);
129 x0 = (int) lua_tonumber(L, -1);
130 lua_pop(L, 1);
131 styp = (int) lua_tonumber(L, -1);
132 lua_pop(L, 1);
133
134 if (x0 > x1) std::swap(x0, x1);
135 if (z0 > z1) std::swap(z0, z1);
136
137 StructureConfig sconf;
138 if (!getStructureConfig(styp, env->mc, &sconf) || !validPos(x0, 0, z0) || !validPos(x1, 0, z1))
139 { // bad structure type, mc version or positions
140 return 0;
141 }
142
143 env->init4Dim(sconf.dim);
144
145 if (styp == End_City)
146 {
147 env->prepareSurfaceNoise(DIM_END);
148 }
149
150 // segment area into structure regions
151 double blocksPerRegion = sconf.regionSize * 16.0;
152 int rx0 = (int) floor(x0 / blocksPerRegion);
153 int rz0 = (int) floor(z0 / blocksPerRegion);
154 int rx1 = (int) ceil(x1 / blocksPerRegion);
155 int rz1 = (int) ceil(z1 / blocksPerRegion);
156 int i, j;
157
158 // TODO: process abort signals
159 std::vector<Pos> inst;
160
161 for (j = rz0; j <= rz1; j++)
162 {
163 for (i = rx0; i <= rx1; i++)
164 { // check the structure generation attempt in region (i, j)
165
166 Pos pos;
167 if (!getStructurePos(styp, env->mc, env->seed, i, j, &pos))
168 continue; // this region is not suitable
169 if (pos.x < x0 || pos.x > x1 || pos.z < z0 || pos.z > z1)
170 continue; // structure is outside the specified area
171 if (!isViableStructurePos(styp, &env->g, pos.x, pos.z, 0))
172 continue; // biomes are not viable
173 if (styp == End_City)

Callers

nothing calls this directly

Calls 9

lua_getglobalFunction · 0.85
lua_touserdataFunction · 0.85
validPosFunction · 0.85
lua_createtableFunction · 0.85
lua_pushintegerFunction · 0.85
lua_setfieldFunction · 0.85
lua_setiFunction · 0.85
init4DimMethod · 0.80
prepareSurfaceNoiseMethod · 0.80

Tested by

no test coverage detected