From ab0cc1bb4726a393a46f638b2de29b6569bbc9e5 Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Mon, 27 Jun 2011 07:30:02 +0300 Subject: better handling of unknown blocks on client --- src/mapnode.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/mapnode.cpp') diff --git a/src/mapnode.cpp b/src/mapnode.cpp index dae21e7cc..7e2643987 100644 --- a/src/mapnode.cpp +++ b/src/mapnode.cpp @@ -138,6 +138,18 @@ void init_mapnode() f->tiles[j].material_type = initial_material_type; } + /* + Initially set every block to be shown as an unknown block. + Don't touch CONTENT_IGNORE or CONTENT_AIR. + */ + for(u16 i=0; i<=253; i++) + { + ContentFeatures *f = &g_content_features[i]; + f->setAllTextures("unknown_block.png"); + f->setInventoryTextureCube("unknown_block.png", "unknown_block.png", "unknown_block.png"); + f->dug_item = std::string("MaterialItem ")+itos(i)+" 1"; + } + /* Initialize mapnode content */ -- cgit v1.2.3 From ccf5eae7512d3b6601fb056fd8781f5954b09e25 Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Mon, 27 Jun 2011 08:46:54 +0300 Subject: fixed bug in inventory textures caused from better handling of unknown blocks --- src/mapnode.cpp | 1 - 1 file changed, 1 deletion(-) (limited to 'src/mapnode.cpp') diff --git a/src/mapnode.cpp b/src/mapnode.cpp index 7e2643987..1fe231434 100644 --- a/src/mapnode.cpp +++ b/src/mapnode.cpp @@ -146,7 +146,6 @@ void init_mapnode() { ContentFeatures *f = &g_content_features[i]; f->setAllTextures("unknown_block.png"); - f->setInventoryTextureCube("unknown_block.png", "unknown_block.png", "unknown_block.png"); f->dug_item = std::string("MaterialItem ")+itos(i)+" 1"; } -- cgit v1.2.3 From 8f742855a1f7b7679be1987c1b0c469e822c73f1 Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Sat, 2 Jul 2011 01:07:54 +0300 Subject: initial steps in doing content type extension --- src/mapnode.cpp | 92 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 90 insertions(+), 2 deletions(-) (limited to 'src/mapnode.cpp') diff --git a/src/mapnode.cpp b/src/mapnode.cpp index 1fe231434..391e593f9 100644 --- a/src/mapnode.cpp +++ b/src/mapnode.cpp @@ -30,8 +30,8 @@ with this program; if not, write to the Free Software Foundation, Inc., ContentFeatures::~ContentFeatures() { - if(translate_to) - delete translate_to; + /*if(translate_to) + delete translate_to;*/ if(initial_metadata) delete initial_metadata; } @@ -241,6 +241,94 @@ u8 MapNode::getMineral() return MINERAL_NONE; } +u32 MapNode::serializedLength(u8 version) +{ + if(!ser_ver_supported(version)) + throw VersionMismatchException("ERROR: MapNode format not supported"); + + if(version == 0) + return 1; + else if(version <= 9) + return 2; + else + return 3; +} +void MapNode::serialize(u8 *dest, u8 version) +{ + if(!ser_ver_supported(version)) + throw VersionMismatchException("ERROR: MapNode format not supported"); + + u8 actual_d = d; + + // Convert from new version to old + if(version <= 18) + { + // In these versions, CONTENT_IGNORE and CONTENT_AIR + // are 255 and 254 + if(d == CONTENT_IGNORE) + d = 255; + else if(d == CONTENT_AIR) + d = 254; + } + + if(version == 0) + { + dest[0] = actual_d; + } + else if(version <= 9) + { + dest[0] = actual_d; + dest[1] = param; + } + else + { + dest[0] = actual_d; + dest[1] = param; + dest[2] = param2; + } +} +void MapNode::deSerialize(u8 *source, u8 version) +{ + if(!ser_ver_supported(version)) + throw VersionMismatchException("ERROR: MapNode format not supported"); + + if(version == 0) + { + d = source[0]; + } + else if(version == 1) + { + d = source[0]; + // This version doesn't support saved lighting + if(light_propagates() || light_source() > 0) + param = 0; + else + param = source[1]; + } + else if(version <= 9) + { + d = source[0]; + param = source[1]; + } + else + { + d = source[0]; + param = source[1]; + param2 = source[2]; + + // Convert from old version to new + if(version <= 18) + { + // In these versions, CONTENT_IGNORE and CONTENT_AIR + // are 255 and 254 + if(d == 255) + d = CONTENT_IGNORE; + else if(d == 254) + d = CONTENT_AIR; + } + } +} + /* Gets lighting value at face of node -- cgit v1.2.3