Skip to content

Commit

Permalink
Construct the whole box.
Browse files Browse the repository at this point in the history
  • Loading branch information
dulsi committed Oct 27, 2016
1 parent eddd96c commit 012dac2
Showing 1 changed file with 58 additions and 14 deletions.
72 changes: 58 additions & 14 deletions drone.c
Expand Up @@ -12,22 +12,66 @@ duk_ret_t drone_box(duk_context *ctx)
duk_get_prop_string(ctx, -1, "z");
int z = duk_to_int(ctx, -1);
duk_remove(ctx, -1);
duk_get_prop_string(ctx, -1, "facing");
int facing = duk_to_int(ctx, -1);
duk_remove(ctx, -1);
int blockID = duk_to_int(ctx, -5);
int w = duk_to_int(ctx, -4);
int h = duk_to_int(ctx, -3);
int d = duk_to_int(ctx, -2);
if (w < 1)
w = 1;
if (h < 1)
h = 1;
if (d < 1)
d = 1;
const char *nodeName = blockID_to_node_name(blockID);
lua_getfield(Lg, LUA_GLOBALSINDEX, "minetest"); // [minetest]
lua_getfield(Lg, -1, "set_node"); // [minetest get_player_by_name]
lua_remove(Lg, -2); // [get_player_by_name]
lua_newtable(Lg);
lua_pushnumber(Lg, x);
lua_setfield(Lg, -2, "x");
lua_pushnumber(Lg, y);
lua_setfield(Lg, -2, "y");
lua_pushnumber(Lg, z);
lua_setfield(Lg, -2, "z");
lua_newtable(Lg);
lua_pushstring(Lg, nodeName);
lua_setfield(Lg, -2, "name");
lua_call(Lg, 2, 0);
lua_getfield(Lg, -1, "set_node"); // [minetest new_node]
lua_remove(Lg, -2); // [set_node]
for (int changeW = 0; changeW < w; changeW++)
{
for (int changeH = 0; changeH < h; changeH++)
{
for (int changeD = 0; changeD < d; changeD++)
{
lua_pushvalue(Lg, -1); // [set_node set_node]
lua_newtable(Lg);
int fx = x;
int fz = z;
switch (facing)
{
case 0:
fx -= changeD;
fz += changeW;
break;
case 1:
fz += changeD;
fx += changeW;
break;
case 2:
fx += changeD;
fz -= changeW;
break;
case 3:
fz -= changeD;
fx -= changeW;
break;
};
lua_pushnumber(Lg, fx);
lua_setfield(Lg, -2, "x");
lua_pushnumber(Lg, y + changeH);
lua_setfield(Lg, -2, "y");
lua_pushnumber(Lg, fz);
lua_setfield(Lg, -2, "z");
lua_newtable(Lg);
lua_pushstring(Lg, nodeName);
lua_setfield(Lg, -2, "name");
lua_call(Lg, 2, 0);
}
}
}
lua_remove(Lg, -1);
return 0;
}

Expand Down Expand Up @@ -89,7 +133,7 @@ duk_ret_t drone_constructor(duk_context *ctx)
{
if (zv > 0)
{
facing = 0;
facing = 1;
z += 2;
}
else
Expand Down

0 comments on commit 012dac2

Please sign in to comment.