From 62164d955ce739e87165bb90b1439807aca5ca55 Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Wed, 16 Nov 2011 15:23:25 +0200 Subject: [PATCH] Initial node definition stuff --- data/mods/default/init.lua | 5 ++++ src/scriptapi.cpp | 61 ++++++++++++++++++++++++++++++++++++-- 2 files changed, 63 insertions(+), 3 deletions(-) diff --git a/data/mods/default/init.lua b/data/mods/default/init.lua index a60979ff4..c2e1d3300 100644 --- a/data/mods/default/init.lua +++ b/data/mods/default/init.lua @@ -316,6 +316,11 @@ minetest.register_tool("horribletool", { }) --]] +minetest.register_node("somenode", { + tile_images = {"lava.png", "mese.png", "stone.png", "grass.png", "cobble.png", "tree_top.png"}, + inventory_image = "treeprop.png" +}) + local TNT = { -- Maybe handle gravity and collision this way? dunno physical = true, diff --git a/src/scriptapi.cpp b/src/scriptapi.cpp index 7074160fd..b37c50bc0 100644 --- a/src/scriptapi.cpp +++ b/src/scriptapi.cpp @@ -36,6 +36,7 @@ extern "C" { #include "luaentity_common.h" #include "content_sao.h" // For LuaEntitySAO #include "tooldef.h" +#include "nodedef.h" /* TODO: @@ -46,7 +47,13 @@ TODO: - Blink effect - Spritesheets and animation - LuaNodeMetadata - blockdef.has_metadata = true/false + blockdef.metadata_type = + "" + "sign" + "furnace" + "chest" + "locked_chest" + "lua" - Stores an inventory and stuff in a Settings object meta.inventory_add_list("main") blockdef.on_inventory_modified @@ -224,6 +231,7 @@ static int l_register_tool(lua_State *L) const char *name = luaL_checkstring(L, 1); infostream<<"register_tool: "<getWritableToolDefManager(); - int table = 2; - ToolDefinition def; lua_getfield(L, table, "image"); @@ -282,7 +288,55 @@ static int l_register_tool(lua_State *L) lua_pop(L, 1); tooldef->registerTool(name, def); + return 0; /* number of results */ +} + +// register_node(name, {lots of stuff}) +static int l_register_node(lua_State *L) +{ + const char *name = luaL_checkstring(L, 1); + infostream<<"register_node: "<getWritableNodeDefManager(); + + ContentFeatures f; + f.name = name; + + lua_getfield(L, table0, "tile_images"); + if(lua_istable(L, -1)){ + int table = lua_gettop(L); + lua_pushnil(L); + int i = 0; + while(lua_next(L, table) != 0){ + // key at index -2 and value at index -1 + if(lua_isstring(L, -1)) + f.tname_tiles[i] = lua_tostring(L, -1); + else + f.tname_tiles[i] = ""; + // removes value, keeps key for next iteration + lua_pop(L, 1); + i++; + if(i==6){ + lua_pop(L, 1); + break; + } + } + } + lua_pop(L, 1); + + lua_getfield(L, table0, "inventory_image"); + if(lua_isstring(L, -1)) + f.tname_inventory = lua_tostring(L, -1); + lua_pop(L, 1); + nodedef->set(name, f); return 0; /* number of results */ } @@ -291,6 +345,7 @@ static const struct luaL_Reg minetest_f [] = { {"register_globalstep", l_register_globalstep}, //{"deregister_tools", l_deregister_tools}, {"register_tool", l_register_tool}, + {"register_node", l_register_node}, {NULL, NULL} }; -- 2.25.1