mirror of
https://github.com/luanti-org/luanti.git
synced 2025-07-02 16:38:41 +00:00
Add node definitions in Lua and do not use content_mapnode_init anymore (except in test.cpp)
This commit is contained in:
parent
1f53ca5f4c
commit
c1479a2732
9 changed files with 452 additions and 40 deletions
|
@ -478,7 +478,6 @@ void content_mapnode_init(IWritableNodeDefManager *nodemgr)
|
|||
f.setInventoryTexture("junglegrass.png");
|
||||
f.light_propagates = true;
|
||||
f.param_type = CPT_LIGHT;
|
||||
f.air_equivalent = false; // grass grows underneath
|
||||
f.dug_item = std::string("MaterialItem2 ")+itos(i)+" 1";
|
||||
f.walkable = false;
|
||||
setLeavesLikeMaterialProperties(f.material, 1.0);
|
||||
|
@ -568,7 +567,6 @@ void content_mapnode_init(IWritableNodeDefManager *nodemgr)
|
|||
f.param_type = CPT_LIGHT;
|
||||
f.is_ground_content = true;
|
||||
f.dug_item = std::string("MaterialItem2 ")+itos(i)+" 1";
|
||||
f.air_equivalent = true; // grass grows underneath
|
||||
f.selection_box.type = NODEBOX_FIXED;
|
||||
f.selection_box.fixed = core::aabbox3d<f32>(
|
||||
-BS/7, -BS/2, -BS/7, BS/7, BS/2, BS/7);
|
||||
|
@ -589,7 +587,6 @@ void content_mapnode_init(IWritableNodeDefManager *nodemgr)
|
|||
f.param_type = CPT_LIGHT;
|
||||
f.is_ground_content = true;
|
||||
f.dug_item = std::string("MaterialItem2 ")+itos(i)+" 1";
|
||||
f.air_equivalent = true; // grass grows underneath
|
||||
f.walkable = false;
|
||||
f.selection_box.type = NODEBOX_FIXED;
|
||||
f.furnace_burntime = 5;
|
||||
|
@ -607,7 +604,6 @@ void content_mapnode_init(IWritableNodeDefManager *nodemgr)
|
|||
f.is_ground_content = true;
|
||||
f.dug_item = std::string("MaterialItem ")+itos(i)+" 1";
|
||||
f.wall_mounted = true;
|
||||
f.air_equivalent = true;
|
||||
f.walkable = false;
|
||||
f.climbable = true;
|
||||
f.selection_box.type = NODEBOX_WALLMOUNTED;
|
||||
|
@ -665,7 +661,6 @@ void content_mapnode_init(IWritableNodeDefManager *nodemgr)
|
|||
f.pointable = false;
|
||||
f.diggable = false;
|
||||
f.buildable_to = true;
|
||||
f.air_equivalent = true;
|
||||
nodemgr->set(i, f);
|
||||
|
||||
i = CONTENT_WATER;
|
||||
|
@ -774,7 +769,6 @@ void content_mapnode_init(IWritableNodeDefManager *nodemgr)
|
|||
f.sunlight_propagates = true;
|
||||
f.walkable = false;
|
||||
f.wall_mounted = true;
|
||||
f.air_equivalent = true;
|
||||
f.dug_item = std::string("MaterialItem2 ")+itos(i)+" 1";
|
||||
f.light_source = LIGHT_MAX-1;
|
||||
f.selection_box.type = NODEBOX_WALLMOUNTED;
|
||||
|
@ -799,7 +793,6 @@ void content_mapnode_init(IWritableNodeDefManager *nodemgr)
|
|||
f.sunlight_propagates = true;
|
||||
f.walkable = false;
|
||||
f.wall_mounted = true;
|
||||
f.air_equivalent = true;
|
||||
f.dug_item = std::string("MaterialItem2 ")+itos(i)+" 1";
|
||||
f.metadata_name = "sign";
|
||||
setConstantMaterialProperties(f.material, 0.5);
|
||||
|
@ -920,7 +913,6 @@ void content_mapnode_init(IWritableNodeDefManager *nodemgr)
|
|||
f.param_type = CPT_LIGHT;
|
||||
f.dug_item = std::string("MaterialItem2 ")+itos(i)+" 1";
|
||||
f.light_propagates = true;
|
||||
f.air_equivalent = false;
|
||||
f.walkable = false;
|
||||
setConstantMaterialProperties(f.material, 0.0);
|
||||
f.furnace_burntime = 10;
|
||||
|
@ -937,7 +929,6 @@ void content_mapnode_init(IWritableNodeDefManager *nodemgr)
|
|||
f.light_propagates = true;
|
||||
f.sunlight_propagates = true;
|
||||
f.walkable = false;
|
||||
f.air_equivalent = true;
|
||||
f.dug_item = std::string("CraftItem apple 1");
|
||||
setConstantMaterialProperties(f.material, 0.0);
|
||||
f.furnace_burntime = 3;
|
||||
|
|
|
@ -28,7 +28,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
|
||||
class IWritableNodeDefManager;
|
||||
|
||||
// Initialize default (legacy) node definitions
|
||||
// Initialize legacy node definitions
|
||||
// Not used used anywhere else than in test.cpp (and SHALL NOT BE)
|
||||
void content_mapnode_init(IWritableNodeDefManager *nodemgr);
|
||||
|
||||
// Backwards compatibility for non-extended content types in v19
|
||||
|
|
|
@ -644,7 +644,8 @@ void ServerEnvironment::activateBlock(MapBlock *block, u32 additional_dtime)
|
|||
if(dtime_s > 300)
|
||||
{
|
||||
MapNode n_top = block->getNodeNoEx(p0+v3s16(0,1,0));
|
||||
if(m_gamedef->ndef()->get(n_top).air_equivalent &&
|
||||
if(m_gamedef->ndef()->get(n_top).light_propagates &&
|
||||
!m_gamedef->ndef()->get(n_top).isLiquid() &&
|
||||
n_top.getLight(LIGHTBANK_DAY, m_gamedef->ndef()) >= 13)
|
||||
{
|
||||
n.setContent(LEGN(m_gamedef->ndef(), "CONTENT_GRASS"));
|
||||
|
@ -1018,7 +1019,8 @@ void ServerEnvironment::step(float dtime)
|
|||
if(myrand()%20 == 0)
|
||||
{
|
||||
MapNode n_top = m_map->getNodeNoEx(p+v3s16(0,1,0));
|
||||
if(m_gamedef->ndef()->get(n_top).air_equivalent &&
|
||||
if(m_gamedef->ndef()->get(n_top).light_propagates &&
|
||||
!m_gamedef->ndef()->get(n_top).isLiquid() &&
|
||||
n_top.getLightBlend(getDayNightRatio(),
|
||||
m_gamedef->ndef()) >= 13)
|
||||
{
|
||||
|
@ -1035,7 +1037,8 @@ void ServerEnvironment::step(float dtime)
|
|||
//if(myrand()%20 == 0)
|
||||
{
|
||||
MapNode n_top = m_map->getNodeNoEx(p+v3s16(0,1,0));
|
||||
if(m_gamedef->ndef()->get(n_top).air_equivalent == false)
|
||||
if(m_gamedef->ndef()->get(n_top).light_propagates == false ||
|
||||
m_gamedef->ndef()->get(n_top).isLiquid())
|
||||
{
|
||||
n.setContent(LEGN(m_gamedef->ndef(), "CONTENT_MUD"));
|
||||
m_map->addNodeWithEvent(p, n);
|
||||
|
|
|
@ -2222,8 +2222,7 @@ void make_block(BlockMakeData *data)
|
|||
{
|
||||
u32 i = data->vmanip->m_area.index(p);
|
||||
MapNode *n = &data->vmanip->m_data[i];
|
||||
if(data->nodedef->get(*n).is_ground_content
|
||||
|| n->getContent() == LEGN(ndef, "CONTENT_JUNGLETREE"))
|
||||
if(data->nodedef->get(*n).is_ground_content)
|
||||
{
|
||||
found = true;
|
||||
break;
|
||||
|
|
|
@ -137,7 +137,6 @@ void ContentFeatures::reset()
|
|||
climbable = false;
|
||||
buildable_to = false;
|
||||
wall_mounted = false;
|
||||
air_equivalent = false;
|
||||
often_contains_mineral = false;
|
||||
dug_item = "";
|
||||
extra_dug_item = "";
|
||||
|
@ -185,7 +184,6 @@ void ContentFeatures::serialize(std::ostream &os)
|
|||
writeU8(os, climbable);
|
||||
writeU8(os, buildable_to);
|
||||
writeU8(os, wall_mounted);
|
||||
writeU8(os, air_equivalent);
|
||||
writeU8(os, often_contains_mineral);
|
||||
os<<serializeString(dug_item);
|
||||
os<<serializeString(extra_dug_item);
|
||||
|
@ -237,7 +235,6 @@ void ContentFeatures::deSerialize(std::istream &is, IGameDef *gamedef)
|
|||
climbable = readU8(is);
|
||||
buildable_to = readU8(is);
|
||||
wall_mounted = readU8(is);
|
||||
air_equivalent = readU8(is);
|
||||
often_contains_mineral = readU8(is);
|
||||
dug_item = deSerializeString(is);
|
||||
extra_dug_item = deSerializeString(is);
|
||||
|
@ -329,7 +326,6 @@ public:
|
|||
f.pointable = false;
|
||||
f.diggable = false;
|
||||
f.buildable_to = true;
|
||||
f.air_equivalent = true;
|
||||
// Insert directly into containers
|
||||
content_t c = CONTENT_AIR;
|
||||
m_content_features[c] = f;
|
||||
|
@ -348,7 +344,6 @@ public:
|
|||
f.diggable = false;
|
||||
// A way to remove accidental CONTENT_IGNOREs
|
||||
f.buildable_to = true;
|
||||
f.air_equivalent = true;
|
||||
// Insert directly into containers
|
||||
content_t c = CONTENT_IGNORE;
|
||||
m_content_features[c] = f;
|
||||
|
|
|
@ -174,9 +174,6 @@ struct ContentFeatures
|
|||
// If true, param2 is set to direction when placed. Used for torches.
|
||||
// NOTE: the direction format is quite inefficient and should be changed
|
||||
bool wall_mounted;
|
||||
// If true, node is equivalent to air. Torches are, air is. Water is not.
|
||||
// Is used for example to check whether a mud block can have grass on.
|
||||
bool air_equivalent;
|
||||
// Whether this content type often contains mineral.
|
||||
// Used for texture atlas creation.
|
||||
// Currently only enabled for CONTENT_STONE.
|
||||
|
|
|
@ -212,27 +212,27 @@ static video::SColor readARGB8(lua_State *L, int index)
|
|||
return color;
|
||||
}
|
||||
|
||||
static core::aabbox3d<f32> read_aabbox3df32(lua_State *L, int index)
|
||||
static core::aabbox3d<f32> read_aabbox3df32(lua_State *L, int index, f32 scale)
|
||||
{
|
||||
core::aabbox3d<f32> box;
|
||||
if(lua_istable(L, -1)){
|
||||
lua_rawgeti(L, -1, 1);
|
||||
box.MinEdge.X = lua_tonumber(L, -1);
|
||||
box.MinEdge.X = lua_tonumber(L, -1) * scale;
|
||||
lua_pop(L, 1);
|
||||
lua_rawgeti(L, -1, 2);
|
||||
box.MinEdge.Y = lua_tonumber(L, -1);
|
||||
box.MinEdge.Y = lua_tonumber(L, -1) * scale;
|
||||
lua_pop(L, 1);
|
||||
lua_rawgeti(L, -1, 3);
|
||||
box.MinEdge.Z = lua_tonumber(L, -1);
|
||||
box.MinEdge.Z = lua_tonumber(L, -1) * scale;
|
||||
lua_pop(L, 1);
|
||||
lua_rawgeti(L, -1, 4);
|
||||
box.MaxEdge.X = lua_tonumber(L, -1);
|
||||
box.MaxEdge.X = lua_tonumber(L, -1) * scale;
|
||||
lua_pop(L, 1);
|
||||
lua_rawgeti(L, -1, 5);
|
||||
box.MaxEdge.Y = lua_tonumber(L, -1);
|
||||
box.MaxEdge.Y = lua_tonumber(L, -1) * scale;
|
||||
lua_pop(L, 1);
|
||||
lua_rawgeti(L, -1, 6);
|
||||
box.MaxEdge.Z = lua_tonumber(L, -1);
|
||||
box.MaxEdge.Z = lua_tonumber(L, -1) * scale;
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
return box;
|
||||
|
@ -600,9 +600,6 @@ static int l_register_node(lua_State *L)
|
|||
// If true, param2 is set to direction when placed. Used for torches.
|
||||
// NOTE: the direction format is quite inefficient and should be changed
|
||||
getboolfield(L, table0, "wall_mounted", f.wall_mounted);
|
||||
// If true, node is equivalent to air. Torches are, air is. Water is not.
|
||||
// Is used for example to check whether a mud block can have grass on.
|
||||
getboolfield(L, table0, "air_equivalent", f.air_equivalent);
|
||||
// Whether this content type often contains mineral.
|
||||
// Used for texture atlas creation.
|
||||
// Currently only enabled for CONTENT_STONE.
|
||||
|
@ -643,22 +640,22 @@ static int l_register_node(lua_State *L)
|
|||
|
||||
lua_getfield(L, -1, "fixed");
|
||||
if(lua_istable(L, -1))
|
||||
f.selection_box.fixed = read_aabbox3df32(L, -1);
|
||||
f.selection_box.fixed = read_aabbox3df32(L, -1, BS);
|
||||
lua_pop(L, 1);
|
||||
|
||||
lua_getfield(L, -1, "wall_top");
|
||||
if(lua_istable(L, -1))
|
||||
f.selection_box.wall_top = read_aabbox3df32(L, -1);
|
||||
f.selection_box.wall_top = read_aabbox3df32(L, -1, BS);
|
||||
lua_pop(L, 1);
|
||||
|
||||
lua_getfield(L, -1, "wall_bottom");
|
||||
if(lua_istable(L, -1))
|
||||
f.selection_box.wall_bottom = read_aabbox3df32(L, -1);
|
||||
f.selection_box.wall_bottom = read_aabbox3df32(L, -1, BS);
|
||||
lua_pop(L, 1);
|
||||
|
||||
lua_getfield(L, -1, "wall_side");
|
||||
if(lua_istable(L, -1))
|
||||
f.selection_box.wall_side = read_aabbox3df32(L, -1);
|
||||
f.selection_box.wall_side = read_aabbox3df32(L, -1, BS);
|
||||
lua_pop(L, 1);
|
||||
}
|
||||
lua_pop(L, 1);
|
||||
|
|
|
@ -1021,9 +1021,6 @@ Server::Server(
|
|||
|
||||
infostream<<"m_nodedef="<<m_nodedef<<std::endl;
|
||||
|
||||
// Initialize default node definitions
|
||||
content_mapnode_init(m_nodedef);
|
||||
|
||||
// Path to builtin.lua
|
||||
std::string builtinpath = porting::path_data + DIR_DELIM + "builtin.lua";
|
||||
// Add default global mod path
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue