forked from Mirrorlandia_minetest/minetest
Move tool definitions to script
This commit is contained in:
parent
4b8e4dae58
commit
9e1c4533b8
@ -113,6 +113,205 @@ end
|
||||
|
||||
minetest.register_globalstep(on_step)
|
||||
|
||||
minetest.register_tool("WPick", {
|
||||
image = "tool_woodpick.png",
|
||||
basetime = 2.0,
|
||||
dt_weight = 0,
|
||||
dt_crackiness = -0.5,
|
||||
dt_crumbliness = 2,
|
||||
dt_cuttability = 0,
|
||||
basedurability = 50,
|
||||
dd_weight = 0,
|
||||
dd_crackiness = 0,
|
||||
dd_crumbliness = 0,
|
||||
dd_cuttability = 0,
|
||||
})
|
||||
minetest.register_tool("STPick", {
|
||||
image = "tool_stonepick.png",
|
||||
basetime = 1.5,
|
||||
dt_weight = 0,
|
||||
dt_crackiness = -0.5,
|
||||
dt_crumbliness = 2,
|
||||
dt_cuttability = 0,
|
||||
basedurability = 100,
|
||||
dd_weight = 0,
|
||||
dd_crackiness = 0,
|
||||
dd_crumbliness = 0,
|
||||
dd_cuttability = 0,
|
||||
})
|
||||
minetest.register_tool("SteelPick", {
|
||||
image = "tool_steelpick.png",
|
||||
basetime = 1.0,
|
||||
dt_weight = 0,
|
||||
dt_crackiness = -0.5,
|
||||
dt_crumbliness = 2,
|
||||
dt_cuttability = 0,
|
||||
basedurability = 300,
|
||||
dd_weight = 0,
|
||||
dd_crackiness = 0,
|
||||
dd_crumbliness = 0,
|
||||
dd_cuttability = 0,
|
||||
})
|
||||
minetest.register_tool("MesePick", {
|
||||
image = "tool_mesepick.png",
|
||||
basetime = 0,
|
||||
dt_weight = 0,
|
||||
dt_crackiness = 0,
|
||||
dt_crumbliness = 0,
|
||||
dt_cuttability = 0,
|
||||
basedurability = 1337,
|
||||
dd_weight = 0,
|
||||
dd_crackiness = 0,
|
||||
dd_crumbliness = 0,
|
||||
dd_cuttability = 0,
|
||||
})
|
||||
minetest.register_tool("WShovel", {
|
||||
image = "tool_woodshovel.png",
|
||||
basetime = 2.0,
|
||||
dt_weight = 0.5,
|
||||
dt_crackiness = 2,
|
||||
dt_crumbliness = -1.5,
|
||||
dt_cuttability = 0.3,
|
||||
basedurability = 50,
|
||||
dd_weight = 0,
|
||||
dd_crackiness = 0,
|
||||
dd_crumbliness = 0,
|
||||
dd_cuttability = 0,
|
||||
})
|
||||
minetest.register_tool("STShovel", {
|
||||
image = "tool_stoneshovel.png",
|
||||
basetime = 1.5,
|
||||
dt_weight = 0.5,
|
||||
dt_crackiness = 2,
|
||||
dt_crumbliness = -1.5,
|
||||
dt_cuttability = 0.1,
|
||||
basedurability = 100,
|
||||
dd_weight = 0,
|
||||
dd_crackiness = 0,
|
||||
dd_crumbliness = 0,
|
||||
dd_cuttability = 0,
|
||||
})
|
||||
minetest.register_tool("SteelShovel", {
|
||||
image = "tool_steelshovel.png",
|
||||
basetime = 1.0,
|
||||
dt_weight = 0.5,
|
||||
dt_crackiness = 2,
|
||||
dt_crumbliness = -1.5,
|
||||
dt_cuttability = 0.0,
|
||||
basedurability = 300,
|
||||
dd_weight = 0,
|
||||
dd_crackiness = 0,
|
||||
dd_crumbliness = 0,
|
||||
dd_cuttability = 0,
|
||||
})
|
||||
minetest.register_tool("WAxe", {
|
||||
image = "tool_woodaxe.png",
|
||||
basetime = 2.0,
|
||||
dt_weight = 0.5,
|
||||
dt_crackiness = -0.2,
|
||||
dt_crumbliness = 1,
|
||||
dt_cuttability = -0.5,
|
||||
basedurability = 50,
|
||||
dd_weight = 0,
|
||||
dd_crackiness = 0,
|
||||
dd_crumbliness = 0,
|
||||
dd_cuttability = 0,
|
||||
})
|
||||
minetest.register_tool("STAxe", {
|
||||
image = "tool_stoneaxe.png",
|
||||
basetime = 1.5,
|
||||
dt_weight = 0.5,
|
||||
dt_crackiness = -0.2,
|
||||
dt_crumbliness = 1,
|
||||
dt_cuttability = -0.5,
|
||||
basedurability = 100,
|
||||
dd_weight = 0,
|
||||
dd_crackiness = 0,
|
||||
dd_crumbliness = 0,
|
||||
dd_cuttability = 0,
|
||||
})
|
||||
minetest.register_tool("SteelAxe", {
|
||||
image = "tool_steelaxe.png",
|
||||
basetime = 1.0,
|
||||
dt_weight = 0.5,
|
||||
dt_crackiness = -0.2,
|
||||
dt_crumbliness = 1,
|
||||
dt_cuttability = -0.5,
|
||||
basedurability = 300,
|
||||
dd_weight = 0,
|
||||
dd_crackiness = 0,
|
||||
dd_crumbliness = 0,
|
||||
dd_cuttability = 0,
|
||||
})
|
||||
minetest.register_tool("WSword", {
|
||||
image = "tool_woodsword.png",
|
||||
basetime = 3.0,
|
||||
dt_weight = 3,
|
||||
dt_crackiness = 0,
|
||||
dt_crumbliness = 1,
|
||||
dt_cuttability = -1,
|
||||
basedurability = 50,
|
||||
dd_weight = 0,
|
||||
dd_crackiness = 0,
|
||||
dd_crumbliness = 0,
|
||||
dd_cuttability = 0,
|
||||
})
|
||||
minetest.register_tool("STSword", {
|
||||
image = "tool_stonesword.png",
|
||||
basetime = 2.5,
|
||||
dt_weight = 3,
|
||||
dt_crackiness = 0,
|
||||
dt_crumbliness = 1,
|
||||
dt_cuttability = -1,
|
||||
basedurability = 100,
|
||||
dd_weight = 0,
|
||||
dd_crackiness = 0,
|
||||
dd_crumbliness = 0,
|
||||
dd_cuttability = 0,
|
||||
})
|
||||
minetest.register_tool("SteelSword", {
|
||||
image = "tool_steelsword.png",
|
||||
basetime = 2.0,
|
||||
dt_weight = 3,
|
||||
dt_crackiness = 0,
|
||||
dt_crumbliness = 1,
|
||||
dt_cuttability = -1,
|
||||
basedurability = 300,
|
||||
dd_weight = 0,
|
||||
dd_crackiness = 0,
|
||||
dd_crumbliness = 0,
|
||||
dd_cuttability = 0,
|
||||
})
|
||||
minetest.register_tool("", {
|
||||
image = "",
|
||||
basetime = 0.5,
|
||||
dt_weight = 1,
|
||||
dt_crackiness = 0,
|
||||
dt_crumbliness = -1,
|
||||
dt_cuttability = 0,
|
||||
basedurability = 50,
|
||||
dd_weight = 0,
|
||||
dd_crackiness = 0,
|
||||
dd_crumbliness = 0,
|
||||
dd_cuttability = 0,
|
||||
})
|
||||
|
||||
--[[
|
||||
minetest.register_tool("horribletool", {
|
||||
image = "lava.png",
|
||||
basetime = 2.0
|
||||
dt_weight = 0.2
|
||||
dt_crackiness = 0.2
|
||||
dt_crumbliness = 0.2
|
||||
dt_cuttability = 0.2
|
||||
basedurability = 50
|
||||
dd_weight = -5
|
||||
dd_crackiness = -5
|
||||
dd_crumbliness = -5
|
||||
dd_cuttability = -5
|
||||
})
|
||||
--]]
|
||||
|
||||
local TNT = {
|
||||
-- Maybe handle gravity and collision this way? dunno
|
||||
physical = true,
|
||||
|
@ -94,7 +94,6 @@ configure_file(
|
||||
)
|
||||
|
||||
set(common_SRCS
|
||||
content_tool.cpp
|
||||
tooldef.cpp
|
||||
nodedef.cpp
|
||||
luaentity_common.cpp
|
||||
|
@ -1,68 +0,0 @@
|
||||
/*
|
||||
Minetest-c55
|
||||
Copyright (C) 2011 celeron55, Perttu Ahola <celeron55@gmail.com>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
#include "content_tool.h"
|
||||
#include "tooldef.h"
|
||||
|
||||
void content_tool_init(IWritableToolDefManager *mgr)
|
||||
{
|
||||
mgr->registerTool("WPick",
|
||||
ToolDefinition("tool_woodpick.png",
|
||||
ToolDiggingProperties(2.0, 0,-0.5,2,0, 50, 0,0,0,0)));
|
||||
mgr->registerTool("STPick",
|
||||
ToolDefinition("tool_stonepick.png",
|
||||
ToolDiggingProperties(1.5, 0,-0.5,2,0, 100, 0,0,0,0)));
|
||||
mgr->registerTool("SteelPick",
|
||||
ToolDefinition("tool_steelpick.png",
|
||||
ToolDiggingProperties(1.0, 0,-0.5,2,0, 300, 0,0,0,0)));
|
||||
mgr->registerTool("MesePick",
|
||||
ToolDefinition("tool_mesepick.png",
|
||||
ToolDiggingProperties(0, 0,0,0,0, 1337, 0,0,0,0)));
|
||||
mgr->registerTool("WShovel",
|
||||
ToolDefinition("tool_woodshovel.png",
|
||||
ToolDiggingProperties(2.0, 0.5,2,-1.5,0.3, 50, 0,0,0,0)));
|
||||
mgr->registerTool("STShovel",
|
||||
ToolDefinition("tool_stoneshovel.png",
|
||||
ToolDiggingProperties(1.5, 0.5,2,-1.5,0.1, 100, 0,0,0,0)));
|
||||
mgr->registerTool("SteelShovel",
|
||||
ToolDefinition("tool_steelshovel.png",
|
||||
ToolDiggingProperties(1.0, 0.5,2,-1.5,0.0, 300, 0,0,0,0)));
|
||||
mgr->registerTool("WAxe",
|
||||
ToolDefinition("tool_woodaxe.png",
|
||||
ToolDiggingProperties(2.0, 0.5,-0.2,1,-0.5, 50, 0,0,0,0)));
|
||||
mgr->registerTool("STAxe",
|
||||
ToolDefinition("tool_stoneaxe.png",
|
||||
ToolDiggingProperties(1.5, 0.5,-0.2,1,-0.5, 100, 0,0,0,0)));
|
||||
mgr->registerTool("SteelAxe",
|
||||
ToolDefinition("tool_steelaxe.png",
|
||||
ToolDiggingProperties(1.0, 0.5,-0.2,1,-0.5, 300, 0,0,0,0)));
|
||||
mgr->registerTool("WSword",
|
||||
ToolDefinition("tool_woodsword.png",
|
||||
ToolDiggingProperties(3.0, 3,0,1,-1, 50, 0,0,0,0)));
|
||||
mgr->registerTool("STSword",
|
||||
ToolDefinition("tool_stonesword.png",
|
||||
ToolDiggingProperties(2.5, 3,0,1,-1, 100, 0,0,0,0)));
|
||||
mgr->registerTool("SteelSword",
|
||||
ToolDefinition("tool_steelsword.png",
|
||||
ToolDiggingProperties(2.0, 3,0,1,-1, 300, 0,0,0,0)));
|
||||
mgr->registerTool("",
|
||||
ToolDefinition("tooldef.hand.png",
|
||||
ToolDiggingProperties(0.5, 1,0,-1,0, 50, 0,0,0,0)));
|
||||
}
|
||||
|
@ -1,24 +0,0 @@
|
||||
/*
|
||||
Minetest-c55
|
||||
Copyright (C) 2011 celeron55, Perttu Ahola <celeron55@gmail.com>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*/
|
||||
|
||||
class IWritableToolDefManager;
|
||||
|
||||
// Add default tools to manager
|
||||
void content_tool_init(IWritableToolDefManager *mgr);
|
||||
|
@ -49,7 +49,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
#include "main.h" // For g_settings
|
||||
#include "content_mapnode.h" // For content_mapnode_init
|
||||
#include "tooldef.h"
|
||||
#include "content_tool.h" // Default tools
|
||||
#include "content_mapnode.h" // Default nodes
|
||||
|
||||
/*
|
||||
@ -646,8 +645,6 @@ void the_game(
|
||||
|
||||
// Fill node feature table with default definitions
|
||||
content_mapnode_init(tsrc, nodedef);
|
||||
// Set default tool definitions
|
||||
content_tool_init(tooldef);
|
||||
|
||||
/*
|
||||
Create server.
|
||||
|
@ -35,6 +35,7 @@ extern "C" {
|
||||
//#include "luna.h"
|
||||
#include "luaentity_common.h"
|
||||
#include "content_sao.h" // For LuaEntitySAO
|
||||
#include "tooldef.h"
|
||||
|
||||
/*
|
||||
TODO:
|
||||
@ -141,8 +142,8 @@ v3f readFloatPos(lua_State *L, int index)
|
||||
static int l_register_entity(lua_State *L)
|
||||
{
|
||||
const char *name = luaL_checkstring(L, 1);
|
||||
luaL_checktype(L, 2, LUA_TTABLE);
|
||||
infostream<<"register_entity: "<<name<<std::endl;
|
||||
luaL_checktype(L, 2, LUA_TTABLE);
|
||||
|
||||
// Get minetest.registered_entities
|
||||
lua_getglobal(L, "minetest");
|
||||
@ -196,9 +197,99 @@ static int l_register_globalstep(lua_State *L)
|
||||
return 0; /* number of results */
|
||||
}
|
||||
|
||||
#if 0
|
||||
// Clear all registered tools
|
||||
// deregister_tools()
|
||||
static int l_deregister_tools(lua_State *L)
|
||||
{
|
||||
infostream<<"deregister_tools"<<std::endl;
|
||||
|
||||
// Get server from registry
|
||||
lua_getfield(L, LUA_REGISTRYINDEX, "minetest_server");
|
||||
Server *server = (Server*)lua_touserdata(L, -1);
|
||||
// And get the writable tool definition manager from the server
|
||||
IWritableToolDefManager *tooldef =
|
||||
server->getWritableToolDefManager();
|
||||
|
||||
tooldef->clear();
|
||||
|
||||
return 0; /* number of results */
|
||||
}
|
||||
#endif
|
||||
|
||||
// register_tool(name, {lots of stuff})
|
||||
static int l_register_tool(lua_State *L)
|
||||
{
|
||||
const char *name = luaL_checkstring(L, 1);
|
||||
infostream<<"register_tool: "<<name<<std::endl;
|
||||
luaL_checktype(L, 2, LUA_TTABLE);
|
||||
|
||||
// Get server from registry
|
||||
lua_getfield(L, LUA_REGISTRYINDEX, "minetest_server");
|
||||
Server *server = (Server*)lua_touserdata(L, -1);
|
||||
// And get the writable tool definition manager from the server
|
||||
IWritableToolDefManager *tooldef =
|
||||
server->getWritableToolDefManager();
|
||||
|
||||
int table = 2;
|
||||
|
||||
ToolDefinition def;
|
||||
|
||||
lua_getfield(L, table, "image");
|
||||
if(lua_isstring(L, -1))
|
||||
def.imagename = lua_tostring(L, -1);
|
||||
lua_pop(L, 1);
|
||||
|
||||
lua_getfield(L, table, "basetime");
|
||||
def.properties.basetime = lua_tonumber(L, -1);
|
||||
lua_pop(L, 1);
|
||||
|
||||
lua_getfield(L, table, "dt_weight");
|
||||
def.properties.dt_weight = lua_tonumber(L, -1);
|
||||
lua_pop(L, 1);
|
||||
|
||||
lua_getfield(L, table, "dt_crackiness");
|
||||
def.properties.dt_crackiness = lua_tonumber(L, -1);
|
||||
lua_pop(L, 1);
|
||||
|
||||
lua_getfield(L, table, "dt_crumbliness");
|
||||
def.properties.dt_crumbliness = lua_tonumber(L, -1);
|
||||
lua_pop(L, 1);
|
||||
|
||||
lua_getfield(L, table, "dt_cuttability");
|
||||
def.properties.dt_cuttability = lua_tonumber(L, -1);
|
||||
lua_pop(L, 1);
|
||||
|
||||
lua_getfield(L, table, "basedurability");
|
||||
def.properties.basedurability = lua_tonumber(L, -1);
|
||||
lua_pop(L, 1);
|
||||
|
||||
lua_getfield(L, table, "dd_weight");
|
||||
def.properties.dd_weight = lua_tonumber(L, -1);
|
||||
lua_pop(L, 1);
|
||||
|
||||
lua_getfield(L, table, "dd_crackiness");
|
||||
def.properties.dd_crackiness = lua_tonumber(L, -1);
|
||||
lua_pop(L, 1);
|
||||
|
||||
lua_getfield(L, table, "dd_crumbliness");
|
||||
def.properties.dd_crumbliness = lua_tonumber(L, -1);
|
||||
lua_pop(L, 1);
|
||||
|
||||
lua_getfield(L, table, "dd_cuttability");
|
||||
def.properties.dd_cuttability = lua_tonumber(L, -1);
|
||||
lua_pop(L, 1);
|
||||
|
||||
tooldef->registerTool(name, def);
|
||||
|
||||
return 0; /* number of results */
|
||||
}
|
||||
|
||||
static const struct luaL_Reg minetest_f [] = {
|
||||
{"register_entity", l_register_entity},
|
||||
{"register_globalstep", l_register_globalstep},
|
||||
//{"deregister_tools", l_deregister_tools},
|
||||
{"register_tool", l_register_tool},
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
@ -581,6 +672,10 @@ void scriptapi_export(lua_State *L, Server *server)
|
||||
assert(lua_checkstack(L, 20));
|
||||
infostream<<"scriptapi_export"<<std::endl;
|
||||
StackUnroller stack_unroller(L);
|
||||
|
||||
// Store server as light userdata in registry
|
||||
lua_pushlightuserdata(L, server);
|
||||
lua_setfield(L, LUA_REGISTRYINDEX, "minetest_server");
|
||||
|
||||
// Register global functions in table minetest
|
||||
lua_newtable(L);
|
||||
|
@ -43,7 +43,6 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
#include "scriptapi.h"
|
||||
#include "nodedef.h"
|
||||
#include "tooldef.h"
|
||||
#include "content_tool.h" // For content_tool_init
|
||||
|
||||
#define PP(x) "("<<(x).X<<","<<(x).Y<<","<<(x).Z<<")"
|
||||
|
||||
@ -987,9 +986,6 @@ Server::Server(
|
||||
|
||||
infostream<<"m_nodemgr="<<m_nodemgr<<std::endl;
|
||||
|
||||
// Initialize default tool definitions
|
||||
content_tool_init(m_toolmgr);
|
||||
|
||||
// Initialize default node definitions
|
||||
content_mapnode_init(NULL, m_nodemgr);
|
||||
|
||||
@ -4240,6 +4236,15 @@ ITextureSource* Server::getTextureSource()
|
||||
return NULL;
|
||||
}
|
||||
|
||||
IWritableToolDefManager* Server::getWritableToolDefManager()
|
||||
{
|
||||
return m_toolmgr;
|
||||
}
|
||||
IWritableNodeDefManager* Server::getWritableNodeDefManager()
|
||||
{
|
||||
return m_nodemgr;
|
||||
}
|
||||
|
||||
v3f findSpawnPos(ServerMap &map)
|
||||
{
|
||||
//return v3f(50,50,50)*BS;
|
||||
|
@ -490,6 +490,9 @@ public:
|
||||
virtual IToolDefManager* getToolDefManager();
|
||||
virtual INodeDefManager* getNodeDefManager();
|
||||
virtual ITextureSource* getTextureSource();
|
||||
|
||||
IWritableToolDefManager* getWritableToolDefManager();
|
||||
IWritableNodeDefManager* getWritableNodeDefManager();
|
||||
|
||||
private:
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user