Skip to content

Commit

Permalink
Add node definitions in Lua and do not use content_mapnode_init anymo…
Browse files Browse the repository at this point in the history
…re (except in test.cpp)
  • Loading branch information
kahrl authored and celeron55 committed Nov 29, 2011
1 parent 1f53ca5 commit c1479a2
Show file tree
Hide file tree
Showing 9 changed files with 452 additions and 40 deletions.
432 changes: 432 additions & 0 deletions data/mods/default/init.lua

Large diffs are not rendered by default.

9 changes: 0 additions & 9 deletions src/content_mapnode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion src/content_mapnode.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 6 additions & 3 deletions src/environment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand Down Expand Up @@ -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)
{
Expand All @@ -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);
Expand Down
3 changes: 1 addition & 2 deletions src/mapgen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 0 additions & 5 deletions src/nodedef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "";
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -329,7 +326,6 @@ class CNodeDefManager: public IWritableNodeDefManager
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;
Expand All @@ -348,7 +344,6 @@ class CNodeDefManager: public IWritableNodeDefManager
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;
Expand Down
3 changes: 0 additions & 3 deletions src/nodedef.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
25 changes: 11 additions & 14 deletions src/scriptapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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);
Expand Down
3 changes: 0 additions & 3 deletions src/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c1479a2

Please sign in to comment.