for(s16 z = min_z; z <= max_z; z++)
{
v3s16 p(x,y,z);
- try{
+
+ bool is_position_valid;
+ MapNode n = map->getNodeNoEx(p, &is_position_valid);
+
+ if (is_position_valid) {
// Object collides into walkable nodes
- MapNode n = map->getNode(p);
+
const ContentFeatures &f = gamedef->getNodeDefManager()->get(n);
if(f.walkable == false)
continue;
is_object.push_back(false);
}
}
- catch(InvalidPositionException &e)
- {
+ else {
// Collide with unloaded nodes
aabb3f box = getNodeBox(p, BS);
cboxes.push_back(box);
m_spritenode->setVisible(true);
m_spritenode->setSize(size);
/* Update brightness */
- u8 light = 64;
- try{
- MapNode n = env->getMap().getNode(floatToInt(pos, BS));
- light = decode_light(n.getLightBlend(env->getDayNightRatio(),
- env->getGameDef()->ndef()));
- }
- catch(InvalidPositionException &e){}
+ u8 light;
+ bool pos_ok;
+ MapNode n = env->getMap().getNodeNoEx(floatToInt(pos, BS), &pos_ok);
+ light = pos_ok ? decode_light(n.getLightBlend(env->getDayNightRatio(),
+ env->getGameDef()->ndef()))
+ : 64;
video::SColor color(255,light,light,light);
m_spritenode->setColor(color);
}
// (day: LIGHT_SUN, night: 0)
MapNode node_at_lplayer(CONTENT_AIR, 0x0f, 0);
- try {
- v3s16 p = lplayer->getLightPosition();
- node_at_lplayer = m_map->getNode(p);
- } catch (InvalidPositionException &e) {}
+ v3s16 p = lplayer->getLightPosition();
+ node_at_lplayer = m_map->getNodeNoEx(p);
u16 light = getInteriorLight(node_at_lplayer, 0, m_gamedef->ndef());
u8 day = light & 0xff;
{
// Update lighting
u8 light = 0;
- try{
- // Get node at head
- v3s16 p = obj->getLightPosition();
- MapNode n = m_map->getNode(p);
+ bool pos_ok;
+
+ // Get node at head
+ v3s16 p = obj->getLightPosition();
+ MapNode n = m_map->getNodeNoEx(p, &pos_ok);
+ if (pos_ok)
light = n.getLightBlend(day_night_ratio, m_gamedef->ndef());
- }
- catch(InvalidPositionException &e){
+ else
light = blend_light(day_night_ratio, LIGHT_SUN, 0);
- }
+
obj->updateLight(light);
}
}
object->addToScene(m_smgr, m_texturesource, m_irr);
{ // Update lighting immediately
u8 light = 0;
- try{
- // Get node at head
- v3s16 p = object->getLightPosition();
- MapNode n = m_map->getNode(p);
+ bool pos_ok;
+
+ // Get node at head
+ v3s16 p = object->getLightPosition();
+ MapNode n = m_map->getNodeNoEx(p, &pos_ok);
+ if (pos_ok)
light = n.getLightBlend(getDayNightRatio(), m_gamedef->ndef());
- }
- catch(InvalidPositionException &e){
+ else
light = blend_light(getDayNightRatio(), LIGHT_SUN, 0);
- }
+
object->updateLight(light);
}
return object->getId();
for (s16 z = zstart; z <= zend; z++)
for (s16 x = xstart; x <= xend; x++) {
MapNode n;
+ bool is_valid_position;
- try {
- n = map.getNode(v3s16(x, y, z));
- } catch (InvalidPositionException &e) {
+ n = map.getNodeNoEx(v3s16(x, y, z), &is_valid_position);
+ if (!is_valid_position)
continue;
- }
if (!isPointableNode(n, client, liquids_pointable))
continue;
std::string prediction = playeritem_def.node_placement_prediction;
INodeDefManager *nodedef = client.ndef();
ClientMap &map = client.getEnv().getClientMap();
+ MapNode node;
+ bool is_valid_position;
+
+ node = map.getNodeNoEx(nodepos, &is_valid_position);
+ if (!is_valid_position)
+ return false;
- if (prediction != "" && !nodedef->get(map.getNode(nodepos)).rightclickable) {
+ if (prediction != "" && !nodedef->get(node).rightclickable) {
verbosestream << "Node placement prediction for "
<< playeritem_def.name << " is "
<< prediction << std::endl;
v3s16 p = neighbourpos;
// Place inside node itself if buildable_to
- try {
- MapNode n_under = map.getNode(nodepos);
-
+ MapNode n_under = map.getNodeNoEx(nodepos, &is_valid_position);
+ if (is_valid_position)
+ {
if (nodedef->get(n_under).buildable_to)
p = nodepos;
- else if (!nodedef->get(map.getNode(p)).buildable_to)
- return false;
- } catch (InvalidPositionException &e) {}
+ else {
+ node = map.getNodeNoEx(p, &is_valid_position);
+ if (is_valid_position &&!nodedef->get(node).buildable_to)
+ return false;
+ }
+ }
// Find id of predicted node
content_t id;
else
pp = p + v3s16(0, -1, 0);
- if (!nodedef->get(map.getNode(pp)).walkable)
+ if (!nodedef->get(map.getNodeNoEx(pp)).walkable)
return false;
}
if (meta) {
infotext = narrow_to_wide(meta->getString("infotext"));
} else {
- MapNode n = map.getNode(nodepos);
+ MapNode n = map.getNodeNoEx(nodepos);
if (nodedef_manager->get(n).tiledef[0].name == "unknown_node.png") {
infotext = L"Unknown node: ";
}
if (playeritem_def.node_placement_prediction == "" ||
- nodedef_manager->get(map.getNode(nodepos)).rightclickable)
+ nodedef_manager->get(map.getNodeNoEx(nodepos)).rightclickable)
client->interact(3, pointed); // Report to server
}
}
LocalPlayer *player = client->getEnv().getLocalPlayer();
ClientMap &map = client->getEnv().getClientMap();
- MapNode n = client->getEnv().getClientMap().getNode(nodepos);
+ MapNode n = client->getEnv().getClientMap().getNodeNoEx(nodepos);
// NOTE: Similar piece of code exists on the server side for
// cheat detection.
infostream << "Digging completed" << std::endl;
client->interact(2, pointed);
client->setCrack(-1, v3s16(0, 0, 0));
- MapNode wasnode = map.getNode(nodepos);
- client->removeNode(nodepos);
+ bool is_valid_position;
+ MapNode wasnode = map.getNodeNoEx(nodepos, &is_valid_position);
+ if (is_valid_position)
+ client->removeNode(nodepos);
if (g_settings->getBool("enable_particles")) {
const ContentFeatures &features =
Collision detection
*/
+ bool is_valid_position;
+ MapNode node;
+ v3s16 pp;
+
/*
Check if player is in liquid (the oscillating value)
*/
- try{
- // If in liquid, the threshold of coming out is at higher y
- if(in_liquid)
- {
- v3s16 pp = floatToInt(position + v3f(0,BS*0.1,0), BS);
- in_liquid = nodemgr->get(map->getNode(pp).getContent()).isLiquid();
- liquid_viscosity = nodemgr->get(map->getNode(pp).getContent()).liquid_viscosity;
- }
- // If not in liquid, the threshold of going in is at lower y
- else
- {
- v3s16 pp = floatToInt(position + v3f(0,BS*0.5,0), BS);
- in_liquid = nodemgr->get(map->getNode(pp).getContent()).isLiquid();
- liquid_viscosity = nodemgr->get(map->getNode(pp).getContent()).liquid_viscosity;
+
+ // If in liquid, the threshold of coming out is at higher y
+ if (in_liquid)
+ {
+ pp = floatToInt(position + v3f(0,BS*0.1,0), BS);
+ node = map->getNodeNoEx(pp, &is_valid_position);
+ if (is_valid_position) {
+ in_liquid = nodemgr->get(node.getContent()).isLiquid();
+ liquid_viscosity = nodemgr->get(node.getContent()).liquid_viscosity;
+ } else {
+ in_liquid = false;
}
}
- catch(InvalidPositionException &e)
+ // If not in liquid, the threshold of going in is at lower y
+ else
{
- in_liquid = false;
+ pp = floatToInt(position + v3f(0,BS*0.5,0), BS);
+ node = map->getNodeNoEx(pp, &is_valid_position);
+ if (is_valid_position) {
+ in_liquid = nodemgr->get(node.getContent()).isLiquid();
+ liquid_viscosity = nodemgr->get(node.getContent()).liquid_viscosity;
+ } else {
+ in_liquid = false;
+ }
}
+
/*
Check if player is in liquid (the stable value)
*/
- try{
- v3s16 pp = floatToInt(position + v3f(0,0,0), BS);
- in_liquid_stable = nodemgr->get(map->getNode(pp).getContent()).isLiquid();
- }
- catch(InvalidPositionException &e)
- {
+ pp = floatToInt(position + v3f(0,0,0), BS);
+ node = map->getNodeNoEx(pp, &is_valid_position);
+ if (is_valid_position) {
+ in_liquid_stable = nodemgr->get(node.getContent()).isLiquid();
+ } else {
in_liquid_stable = false;
}
Check if player is climbing
*/
- try {
- v3s16 pp = floatToInt(position + v3f(0,0.5*BS,0), BS);
- v3s16 pp2 = floatToInt(position + v3f(0,-0.2*BS,0), BS);
- is_climbing = ((nodemgr->get(map->getNode(pp).getContent()).climbable ||
- nodemgr->get(map->getNode(pp2).getContent()).climbable) && !free_move);
- }
- catch(InvalidPositionException &e)
- {
+
+ pp = floatToInt(position + v3f(0,0.5*BS,0), BS);
+ v3s16 pp2 = floatToInt(position + v3f(0,-0.2*BS,0), BS);
+ node = map->getNodeNoEx(pp, &is_valid_position);
+ bool is_valid_position2;
+ MapNode node2 = map->getNodeNoEx(pp2, &is_valid_position2);
+
+ if (!(is_valid_position && is_valid_position2)) {
is_climbing = false;
+ } else {
+ is_climbing = (nodemgr->get(node.getContent()).climbable
+ || nodemgr->get(node2.getContent()).climbable) && !free_move;
}
+
/*
Collision uncertainty radius
Make it a bit larger than the maximum distance of movement
max_axis_distance_f > 0.5*BS + sneak_max + 0.1*BS)
continue;
- try{
- // The node to be sneaked on has to be walkable
- if(nodemgr->get(map->getNode(p)).walkable == false)
- continue;
- // And the node above it has to be nonwalkable
- if(nodemgr->get(map->getNode(p+v3s16(0,1,0))).walkable == true) {
- continue;
- }
- if (!physics_override_sneak_glitch) {
- if (nodemgr->get(map->getNode(p+v3s16(0,2,0))).walkable)
- continue;
- }
- }
- catch(InvalidPositionException &e)
- {
+
+ // The node to be sneaked on has to be walkable
+ node = map->getNodeNoEx(p, &is_valid_position);
+ if (!is_valid_position || nodemgr->get(node).walkable == false)
continue;
+ // And the node above it has to be nonwalkable
+ node = map->getNodeNoEx(p + v3s16(0,1,0), &is_valid_position);
+ if (!is_valid_position || nodemgr->get(node).walkable) {
+ continue;
+ }
+ if (!physics_override_sneak_glitch) {
+ node =map->getNodeNoEx(p + v3s16(0,2,0), &is_valid_position);
+ if (!is_valid_position || nodemgr->get(node).walkable)
+ continue;
}
min_distance_f = distance_f;
}
// Returns a CONTENT_IGNORE node if not found
-MapNode Map::getNodeNoEx(v3s16 p)
+MapNode Map::getNodeNoEx(v3s16 p, bool *is_valid_position)
{
v3s16 blockpos = getNodeBlockPos(p);
MapBlock *block = getBlockNoCreateNoEx(blockpos);
- if(block == NULL)
+ if (block == NULL) {
+ if (is_valid_position != NULL)
+ *is_valid_position = false;
return MapNode(CONTENT_IGNORE);
+ }
+
v3s16 relpos = p - blockpos*MAP_BLOCKSIZE;
- return block->getNodeNoCheck(relpos);
+ bool is_valid_p;
+ MapNode node = block->getNodeNoCheck(relpos, &is_valid_p);
+ if (is_valid_position != NULL)
+ *is_valid_position = is_valid_p;
+ return node;
}
+#if 0
+// Deprecated
// throws InvalidPositionException if not found
+// TODO: Now this is deprecated, getNodeNoEx should be renamed
MapNode Map::getNode(v3s16 p)
{
v3s16 blockpos = getNodeBlockPos(p);
MapBlock *block = getBlockNoCreateNoEx(blockpos);
- if(block == NULL)
+ if (block == NULL)
throw InvalidPositionException();
v3s16 relpos = p - blockpos*MAP_BLOCKSIZE;
- return block->getNodeNoCheck(relpos);
+ bool is_valid_position;
+ MapNode node = block->getNodeNoCheck(relpos, &is_valid_position);
+ if (!is_valid_position)
+ throw InvalidPositionException();
+ return node;
}
+#endif
// throws InvalidPositionException if not found
void Map::setNode(v3s16 p, MapNode & n)
v3s16 relpos = p - blockpos*MAP_BLOCKSIZE;
// Never allow placing CONTENT_IGNORE, it fucks up stuff
if(n.getContent() == CONTENT_IGNORE){
+ bool temp_bool;
errorstream<<"Map::setNode(): Not allowing to place CONTENT_IGNORE"
<<" while trying to replace \""
- <<m_gamedef->ndef()->get(block->getNodeNoCheck(relpos)).name
+ <<m_gamedef->ndef()->get(block->getNodeNoCheck(relpos, &temp_bool)).name
<<"\" at "<<PP(p)<<" (block "<<PP(blockpos)<<")"<<std::endl;
debug_stacks_print_to(infostream);
return;
// Get the block where the node is located
v3s16 blockpos = getNodeBlockPos(n2pos);
- try
- {
- // Only fetch a new block if the block position has changed
- try{
- if(block == NULL || blockpos != blockpos_last){
- block = getBlockNoCreate(blockpos);
- blockpos_last = blockpos;
+ // Only fetch a new block if the block position has changed
+ try {
+ if(block == NULL || blockpos != blockpos_last){
+ block = getBlockNoCreate(blockpos);
+ blockpos_last = blockpos;
- block_checked_in_modified = false;
- blockchangecount++;
- }
- }
- catch(InvalidPositionException &e)
- {
- continue;
+ block_checked_in_modified = false;
+ blockchangecount++;
}
+ }
+ catch(InvalidPositionException &e) {
+ continue;
+ }
- // Calculate relative position in block
- v3s16 relpos = n2pos - blockpos * MAP_BLOCKSIZE;
- // Get node straight from the block
- MapNode n2 = block->getNode(relpos);
+ // Calculate relative position in block
+ v3s16 relpos = n2pos - blockpos * MAP_BLOCKSIZE;
+ // Get node straight from the block
+ bool is_valid_position;
+ MapNode n2 = block->getNode(relpos, &is_valid_position);
+ if (!is_valid_position)
+ continue;
- bool changed = false;
+ bool changed = false;
- //TODO: Optimize output by optimizing light_sources?
+ //TODO: Optimize output by optimizing light_sources?
+ /*
+ If the neighbor is dimmer than what was specified
+ as oldlight (the light of the previous node)
+ */
+ if(n2.getLight(bank, nodemgr) < oldlight)
+ {
/*
- If the neighbor is dimmer than what was specified
- as oldlight (the light of the previous node)
+ And the neighbor is transparent and it has some light
*/
- if(n2.getLight(bank, nodemgr) < oldlight)
+ if(nodemgr->get(n2).light_propagates
+ && n2.getLight(bank, nodemgr) != 0)
{
/*
- And the neighbor is transparent and it has some light
+ Set light to 0 and add to queue
*/
- if(nodemgr->get(n2).light_propagates
- && n2.getLight(bank, nodemgr) != 0)
- {
- /*
- Set light to 0 and add to queue
- */
-
- u8 current_light = n2.getLight(bank, nodemgr);
- n2.setLight(bank, 0, nodemgr);
- block->setNode(relpos, n2);
-
- unlighted_nodes[n2pos] = current_light;
- changed = true;
-
- /*
- Remove from light_sources if it is there
- NOTE: This doesn't happen nearly at all
- */
- /*if(light_sources.find(n2pos))
- {
- infostream<<"Removed from light_sources"<<std::endl;
- light_sources.remove(n2pos);
- }*/
- }
- /*// DEBUG
- if(light_sources.find(n2pos) != NULL)
- light_sources.remove(n2pos);*/
- }
- else{
- light_sources.insert(n2pos);
- }
+ u8 current_light = n2.getLight(bank, nodemgr);
+ n2.setLight(bank, 0, nodemgr);
+ block->setNode(relpos, n2);
- // Add to modified_blocks
- if(changed == true && block_checked_in_modified == false)
- {
- // If the block is not found in modified_blocks, add.
- if(modified_blocks.find(blockpos) == modified_blocks.end())
+ unlighted_nodes[n2pos] = current_light;
+ changed = true;
+
+ /*
+ Remove from light_sources if it is there
+ NOTE: This doesn't happen nearly at all
+ */
+ /*if(light_sources.find(n2pos))
{
- modified_blocks[blockpos] = block;
- }
- block_checked_in_modified = true;
+ infostream<<"Removed from light_sources"<<std::endl;
+ light_sources.remove(n2pos);
+ }*/
}
+
+ /*// DEBUG
+ if(light_sources.find(n2pos) != NULL)
+ light_sources.remove(n2pos);*/
}
- catch(InvalidPositionException &e)
+ else{
+ light_sources.insert(n2pos);
+ }
+
+ // Add to modified_blocks
+ if(changed == true && block_checked_in_modified == false)
{
- continue;
+ // If the block is not found in modified_blocks, add.
+ if(modified_blocks.find(blockpos) == modified_blocks.end())
+ {
+ modified_blocks[blockpos] = block;
+ }
+ block_checked_in_modified = true;
}
}
}
v3s16 blockpos = getNodeBlockPos(pos);
// Only fetch a new block if the block position has changed
- try{
+ try {
if(block == NULL || blockpos != blockpos_last){
block = getBlockNoCreate(blockpos);
blockpos_last = blockpos;
blockchangecount++;
}
}
- catch(InvalidPositionException &e)
- {
+ catch(InvalidPositionException &e) {
continue;
}
v3s16 relpos = pos - blockpos_last * MAP_BLOCKSIZE;
// Get node straight from the block
- MapNode n = block->getNode(relpos);
+ bool is_valid_position;
+ MapNode n = block->getNode(relpos, &is_valid_position);
- u8 oldlight = n.getLight(bank, nodemgr);
+ u8 oldlight = is_valid_position ? n.getLight(bank, nodemgr) : 0;
u8 newlight = diminish_light(oldlight);
// Loop through 6 neighbors
// Get the block where the node is located
v3s16 blockpos = getNodeBlockPos(n2pos);
- try
- {
- // Only fetch a new block if the block position has changed
- try{
- if(block == NULL || blockpos != blockpos_last){
- block = getBlockNoCreate(blockpos);
- blockpos_last = blockpos;
+ // Only fetch a new block if the block position has changed
+ try {
+ if(block == NULL || blockpos != blockpos_last){
+ block = getBlockNoCreate(blockpos);
+ blockpos_last = blockpos;
- block_checked_in_modified = false;
- blockchangecount++;
- }
- }
- catch(InvalidPositionException &e)
- {
- continue;
+ block_checked_in_modified = false;
+ blockchangecount++;
}
+ }
+ catch(InvalidPositionException &e) {
+ continue;
+ }
- // Calculate relative position in block
- v3s16 relpos = n2pos - blockpos * MAP_BLOCKSIZE;
- // Get node straight from the block
- MapNode n2 = block->getNode(relpos);
+ // Calculate relative position in block
+ v3s16 relpos = n2pos - blockpos * MAP_BLOCKSIZE;
+ // Get node straight from the block
+ MapNode n2 = block->getNode(relpos, &is_valid_position);
+ if (!is_valid_position)
+ continue;
- bool changed = false;
- /*
- If the neighbor is brighter than the current node,
- add to list (it will light up this node on its turn)
- */
- if(n2.getLight(bank, nodemgr) > undiminish_light(oldlight))
+ bool changed = false;
+ /*
+ If the neighbor is brighter than the current node,
+ add to list (it will light up this node on its turn)
+ */
+ if(n2.getLight(bank, nodemgr) > undiminish_light(oldlight))
+ {
+ lighted_nodes.insert(n2pos);
+ changed = true;
+ }
+ /*
+ If the neighbor is dimmer than how much light this node
+ would spread on it, add to list
+ */
+ if(n2.getLight(bank, nodemgr) < newlight)
+ {
+ if(nodemgr->get(n2).light_propagates)
{
+ n2.setLight(bank, newlight, nodemgr);
+ block->setNode(relpos, n2);
lighted_nodes.insert(n2pos);
changed = true;
}
- /*
- If the neighbor is dimmer than how much light this node
- would spread on it, add to list
- */
- if(n2.getLight(bank, nodemgr) < newlight)
- {
- if(nodemgr->get(n2).light_propagates)
- {
- n2.setLight(bank, newlight, nodemgr);
- block->setNode(relpos, n2);
- lighted_nodes.insert(n2pos);
- changed = true;
- }
- }
+ }
- // Add to modified_blocks
- if(changed == true && block_checked_in_modified == false)
+ // Add to modified_blocks
+ if(changed == true && block_checked_in_modified == false)
+ {
+ // If the block is not found in modified_blocks, add.
+ if(modified_blocks.find(blockpos) == modified_blocks.end())
{
- // If the block is not found in modified_blocks, add.
- if(modified_blocks.find(blockpos) == modified_blocks.end())
- {
- modified_blocks[blockpos] = block;
- }
- block_checked_in_modified = true;
+ modified_blocks[blockpos] = block;
}
- }
- catch(InvalidPositionException &e)
- {
- continue;
+ block_checked_in_modified = true;
}
}
}
// Get the position of the neighbor node
v3s16 n2pos = p + dirs[i];
MapNode n2;
- try{
- n2 = getNode(n2pos);
- }
- catch(InvalidPositionException &e)
- {
+ bool is_valid_position;
+ n2 = getNodeNoEx(n2pos, &is_valid_position);
+ if (!is_valid_position)
continue;
- }
+
if(n2.getLight(bank, nodemgr) > brightest_light || found_something == false){
brightest_light = n2.getLight(bank, nodemgr);
brightest_pos = n2pos;
}
v3s16 relpos = pos - blockpos*MAP_BLOCKSIZE;
- MapNode n = block->getNode(relpos);
+ bool is_valid_position;
+ MapNode n = block->getNode(relpos, &is_valid_position);
+ if (!is_valid_position)
+ break;
if(nodemgr->get(n).sunlight_propagates)
{
for(s16 x=0; x<MAP_BLOCKSIZE; x++)
for(s16 y=0; y<MAP_BLOCKSIZE; y++)
{
-
- try{
- v3s16 p(x,y,z);
- MapNode n = block->getNode(p);
- u8 oldlight = n.getLight(bank, nodemgr);
- n.setLight(bank, 0, nodemgr);
- block->setNode(p, n);
-
- // If node sources light, add to list
- u8 source = nodemgr->get(n).light_source;
- if(source != 0)
- light_sources.insert(p + posnodes);
-
- // Collect borders for unlighting
- if((x==0 || x == MAP_BLOCKSIZE-1
- || y==0 || y == MAP_BLOCKSIZE-1
- || z==0 || z == MAP_BLOCKSIZE-1)
- && oldlight != 0)
- {
- v3s16 p_map = p + posnodes;
- unlight_from[p_map] = oldlight;
- }
- }
- catch(InvalidPositionException &e)
- {
- /*
- This would happen when dealing with a
- dummy block.
+ v3s16 p(x,y,z);
+ bool is_valid_position;
+ MapNode n = block->getNode(p, &is_valid_position);
+ if (!is_valid_position) {
+ /* This would happen when dealing with a
+ dummy block.
*/
- //assert(0);
infostream<<"updateLighting(): InvalidPositionException"
<<std::endl;
+ continue;
+ }
+ u8 oldlight = n.getLight(bank, nodemgr);
+ n.setLight(bank, 0, nodemgr);
+ block->setNode(p, n);
+
+ // If node sources light, add to list
+ u8 source = nodemgr->get(n).light_source;
+ if(source != 0)
+ light_sources.insert(p + posnodes);
+
+ // Collect borders for unlighting
+ if((x==0 || x == MAP_BLOCKSIZE-1
+ || y==0 || y == MAP_BLOCKSIZE-1
+ || z==0 || z == MAP_BLOCKSIZE-1)
+ && oldlight != 0)
+ {
+ v3s16 p_map = p + posnodes;
+ unlight_from[p_map] = oldlight;
}
+
+
}
if(bank == LIGHTBANK_DAY)
Otherwise there probably is.
*/
- try{
- MapNode topnode = getNode(toppos);
- if(topnode.getLight(LIGHTBANK_DAY, ndef) != LIGHT_SUN)
- node_under_sunlight = false;
- }
- catch(InvalidPositionException &e)
- {
- }
+ bool is_valid_position;
+ MapNode topnode = getNodeNoEx(toppos, &is_valid_position);
+
+ if(is_valid_position && topnode.getLight(LIGHTBANK_DAY, ndef) != LIGHT_SUN)
+ node_under_sunlight = false;
/*
Remove all light that has come out of this node
{
enum LightBank bank = banks[i];
- u8 lightwas = getNode(p).getLight(bank, ndef);
+ u8 lightwas = getNodeNoEx(p).getLight(bank, ndef);
// Add the block of the added node to modified_blocks
v3s16 blockpos = getNodeBlockPos(p);
v3s16 n2pos(p.X, y, p.Z);
MapNode n2;
- try{
- n2 = getNode(n2pos);
- }
- catch(InvalidPositionException &e)
- {
+
+ n2 = getNodeNoEx(n2pos, &is_valid_position);
+ if (!is_valid_position)
break;
- }
if(n2.getLight(LIGHTBANK_DAY, ndef) == LIGHT_SUN)
{
};
for(u16 i=0; i<7; i++)
{
- try
- {
-
v3s16 p2 = p + dirs[i];
- MapNode n2 = getNode(p2);
- if(ndef->get(n2).isLiquid() || n2.getContent() == CONTENT_AIR)
+ MapNode n2 = getNodeNoEx(p2, &is_valid_position);
+ if(is_valid_position
+ && (ndef->get(n2).isLiquid() || n2.getContent() == CONTENT_AIR))
{
m_transforming_liquid.push_back(p2);
}
-
- }catch(InvalidPositionException &e)
- {
- }
}
}
If there is a node at top and it doesn't have sunlight,
there will be no sunlight going down.
*/
- try{
- MapNode topnode = getNode(toppos);
+ bool is_valid_position;
+ MapNode topnode = getNodeNoEx(toppos, &is_valid_position);
- if(topnode.getLight(LIGHTBANK_DAY, ndef) != LIGHT_SUN)
- node_under_sunlight = false;
- }
- catch(InvalidPositionException &e)
- {
- }
+ if(is_valid_position && topnode.getLight(LIGHTBANK_DAY, ndef) != LIGHT_SUN)
+ node_under_sunlight = false;
std::set<v3s16> light_sources;
Unlight neighbors (in case the node is a light source)
*/
unLightNeighbors(bank, p,
- getNode(p).getLight(bank, ndef),
+ getNodeNoEx(p).getLight(bank, ndef),
light_sources, modified_blocks);
}
{
// Set the lighting of this node to 0
// TODO: Is this needed? Lighting is cleared up there already.
- try{
- MapNode n = getNode(p);
+ MapNode n = getNodeNoEx(p, &is_valid_position);
+ if (is_valid_position) {
n.setLight(LIGHTBANK_DAY, 0, ndef);
setNode(p, n);
- }
- catch(InvalidPositionException &e)
- {
+ } else {
assert(0);
}
}
};
for(u16 i=0; i<7; i++)
{
- try
- {
-
v3s16 p2 = p + dirs[i];
- MapNode n2 = getNode(p2);
- if(ndef->get(n2).isLiquid() || n2.getContent() == CONTENT_AIR)
+ bool is_position_valid;
+ MapNode n2 = getNodeNoEx(p2, &is_position_valid);
+ if (is_position_valid
+ && (ndef->get(n2).isLiquid() || n2.getContent() == CONTENT_AIR))
{
m_transforming_liquid.push_back(p2);
}
-
- }catch(InvalidPositionException &e)
- {
- }
}
}
bool isValidPosition(v3s16 p);
- // throws InvalidPositionException if not found
- MapNode getNode(v3s16 p);
-
// throws InvalidPositionException if not found
void setNode(v3s16 p, MapNode & n);
// Returns a CONTENT_IGNORE node if not found
- MapNode getNodeNoEx(v3s16 p);
+ // If is_valid_position is not NULL then this will be set to true if the
+ // position is valid, otherwise false
+ MapNode getNodeNoEx(v3s16 p, bool *is_valid_position = NULL);
void unspreadLight(enum LightBank bank,
std::map<v3s16, u8> & from_nodes,
}
}
-MapNode MapBlock::getNodeParent(v3s16 p)
+MapNode MapBlock::getNodeParent(v3s16 p, bool *is_valid_position)
{
- if(isValidPosition(p) == false)
- {
- return m_parent->getNode(getPosRelative() + p);
- }
- else
- {
- if(data == NULL)
- throw InvalidPositionException();
- return data[p.Z*MAP_BLOCKSIZE*MAP_BLOCKSIZE + p.Y*MAP_BLOCKSIZE + p.X];
- }
-}
+ if (isValidPosition(p) == false)
+ return m_parent->getNodeNoEx(getPosRelative() + p, is_valid_position);
-void MapBlock::setNodeParent(v3s16 p, MapNode & n)
-{
- if(isValidPosition(p) == false)
- {
- m_parent->setNode(getPosRelative() + p, n);
- }
- else
- {
- if(data == NULL)
- throw InvalidPositionException();
- data[p.Z*MAP_BLOCKSIZE*MAP_BLOCKSIZE + p.Y*MAP_BLOCKSIZE + p.X] = n;
- }
-}
-
-MapNode MapBlock::getNodeParentNoEx(v3s16 p)
-{
- if(isValidPosition(p) == false)
- {
- try{
- return m_parent->getNode(getPosRelative() + p);
- }
- catch(InvalidPositionException &e)
- {
- return MapNode(CONTENT_IGNORE);
- }
- }
- else
- {
- if(data == NULL)
- {
- return MapNode(CONTENT_IGNORE);
- }
- return data[p.Z*MAP_BLOCKSIZE*MAP_BLOCKSIZE + p.Y*MAP_BLOCKSIZE + p.X];
+ if (data == NULL) {
+ if (is_valid_position)
+ *is_valid_position = false;
+ return MapNode(CONTENT_IGNORE);
}
+ if (is_valid_position)
+ *is_valid_position = true;
+ return data[p.Z*MAP_BLOCKSIZE*MAP_BLOCKSIZE + p.Y*MAP_BLOCKSIZE + p.X];
}
/*
#if 1
bool no_sunlight = false;
bool no_top_block = false;
+
// Check if node above block has sunlight
- try{
- MapNode n = getNodeParent(v3s16(x, MAP_BLOCKSIZE, z));
+
+ bool is_valid_position;
+ MapNode n = getNodeParent(v3s16(x, MAP_BLOCKSIZE, z),
+ &is_valid_position);
+ if (is_valid_position)
+ {
if(n.getContent() == CONTENT_IGNORE)
{
// Trust heuristics
no_sunlight = true;
}
}
- catch(InvalidPositionException &e)
+ else
{
no_top_block = true;
}
else
{
- MapNode n = getNode(v3s16(x, MAP_BLOCKSIZE-1, z));
+ MapNode n = getNodeNoEx(v3s16(x, MAP_BLOCKSIZE-1, z));
if(m_gamedef->ndef()->get(n).sunlight_propagates == false)
{
no_sunlight = true;
Ignore non-transparent nodes as they always have no light
*/
- try
- {
+
if(block_below_is_valid)
{
- MapNode n = getNodeParent(v3s16(x, -1, z));
- if(nodemgr->get(n).light_propagates)
+ MapNode n = getNodeParent(v3s16(x, -1, z), &is_valid_position);
+ if (is_valid_position) {
+ if(nodemgr->get(n).light_propagates)
+ {
+ if(n.getLight(LIGHTBANK_DAY, nodemgr) == LIGHT_SUN
+ && sunlight_should_go_down == false)
+ block_below_is_valid = false;
+ else if(n.getLight(LIGHTBANK_DAY, nodemgr) != LIGHT_SUN
+ && sunlight_should_go_down == true)
+ block_below_is_valid = false;
+ }
+ }
+ else
{
- if(n.getLight(LIGHTBANK_DAY, nodemgr) == LIGHT_SUN
- && sunlight_should_go_down == false)
- block_below_is_valid = false;
- else if(n.getLight(LIGHTBANK_DAY, nodemgr) != LIGHT_SUN
- && sunlight_should_go_down == true)
- block_below_is_valid = false;
+ /*std::cout<<"InvalidBlockException for bottom block node"
+ <<std::endl;*/
+ // Just no block below, no need to panic.
}
- }//if
- }//try
- catch(InvalidPositionException &e)
- {
- /*std::cout<<"InvalidBlockException for bottom block node"
- <<std::endl;*/
- // Just no block below, no need to panic.
}
}
}
for(s16 x0=0; x0<MAP_BLOCKSIZE; x0++)
{
v3s16 p(x0,y0,z0);
- MapNode n = block->getNode(p);
+ MapNode n = block->getNodeNoEx(p);
content_t c = n.getContent();
if(c == CONTENT_IGNORE)
some_ignore = true;
Regular MapNode get-setters
*/
+ bool isValidPosition(s16 x, s16 y, s16 z)
+ {
+ return data != NULL
+ && x >= 0 && x < MAP_BLOCKSIZE
+ && y >= 0 && y < MAP_BLOCKSIZE
+ && z >= 0 && z < MAP_BLOCKSIZE;
+ }
+
bool isValidPosition(v3s16 p)
{
- if(data == NULL)
- return false;
- return (p.X >= 0 && p.X < MAP_BLOCKSIZE
- && p.Y >= 0 && p.Y < MAP_BLOCKSIZE
- && p.Z >= 0 && p.Z < MAP_BLOCKSIZE);
+ return isValidPosition(p.X, p.Y, p.Z);
}
- MapNode getNode(s16 x, s16 y, s16 z)
+ MapNode getNode(s16 x, s16 y, s16 z, bool *valid_position)
{
- if(data == NULL)
- throw InvalidPositionException();
- if(x < 0 || x >= MAP_BLOCKSIZE) throw InvalidPositionException();
- if(y < 0 || y >= MAP_BLOCKSIZE) throw InvalidPositionException();
- if(z < 0 || z >= MAP_BLOCKSIZE) throw InvalidPositionException();
+ *valid_position = isValidPosition(x, y, z);
+
+ if (!*valid_position)
+ return MapNode(CONTENT_IGNORE);
+
return data[z*MAP_BLOCKSIZE*MAP_BLOCKSIZE + y*MAP_BLOCKSIZE + x];
}
- MapNode getNode(v3s16 p)
+ MapNode getNode(v3s16 p, bool *valid_position)
{
- return getNode(p.X, p.Y, p.Z);
+ return getNode(p.X, p.Y, p.Z, valid_position);
}
MapNode getNodeNoEx(v3s16 p)
{
- try{
- return getNode(p.X, p.Y, p.Z);
- }catch(InvalidPositionException &e){
- return MapNode(CONTENT_IGNORE);
- }
+ bool is_valid;
+ MapNode node = getNode(p.X, p.Y, p.Z, &is_valid);
+ return is_valid ? node : MapNode(CONTENT_IGNORE);
}
void setNode(s16 x, s16 y, s16 z, MapNode & n)
Non-checking variants of the above
*/
- MapNode getNodeNoCheck(s16 x, s16 y, s16 z)
+ MapNode getNodeNoCheck(s16 x, s16 y, s16 z, bool *valid_position)
{
- if(data == NULL)
- throw InvalidPositionException();
+ *valid_position = data != NULL;
+ if(!valid_position)
+ return MapNode(CONTENT_IGNORE);
+
return data[z*MAP_BLOCKSIZE*MAP_BLOCKSIZE + y*MAP_BLOCKSIZE + x];
}
- MapNode getNodeNoCheck(v3s16 p)
+ MapNode getNodeNoCheck(v3s16 p, bool *valid_position)
{
- return getNodeNoCheck(p.X, p.Y, p.Z);
+ return getNodeNoCheck(p.X, p.Y, p.Z, valid_position);
}
void setNodeNoCheck(s16 x, s16 y, s16 z, MapNode & n)
is not valid on this MapBlock.
*/
bool isValidPositionParent(v3s16 p);
- MapNode getNodeParent(v3s16 p);
+ MapNode getNodeParent(v3s16 p, bool *is_valid_position = NULL);
void setNodeParent(v3s16 p, MapNode & n);
- MapNode getNodeParentNoEx(v3s16 p);
void drawbox(s16 x0, s16 y0, s16 z0, s16 w, s16 h, s16 d, MapNode node)
{
void Particle::updateLight()
{
u8 light = 0;
- try{
- v3s16 p = v3s16(
- floor(m_pos.X+0.5),
- floor(m_pos.Y+0.5),
- floor(m_pos.Z+0.5)
- );
- MapNode n = m_env->getClientMap().getNode(p);
+ bool pos_ok;
+
+ v3s16 p = v3s16(
+ floor(m_pos.X+0.5),
+ floor(m_pos.Y+0.5),
+ floor(m_pos.Z+0.5)
+ );
+ MapNode n = m_env->getClientMap().getNodeNoEx(p, &pos_ok);
+ if (pos_ok)
light = n.getLightBlend(m_env->getDayNightRatio(), m_gamedef->ndef());
- }
- catch(InvalidPositionException &e){
+ else
light = blend_light(m_env->getDayNightRatio(), LIGHT_SUN, 0);
- }
+
m_light = decode_light(light);
}
// pos
v3s16 pos = read_v3s16(L, 1);
// Do it
- try{
- MapNode n = env->getMap().getNode(pos);
+ bool pos_ok;
+ MapNode n = env->getMap().getNodeNoEx(pos, &pos_ok);
+ if (pos_ok) {
// Return node
pushnode(L, n, env->getGameDef()->ndef());
- return 1;
- } catch(InvalidPositionException &e)
- {
+ } else {
lua_pushnil(L);
- return 1;
}
+ return 1;
}
// get_node_light(pos, timeofday)
time_of_day = 24000.0 * lua_tonumber(L, 2);
time_of_day %= 24000;
u32 dnr = time_to_daynight_ratio(time_of_day, true);
- try{
- MapNode n = env->getMap().getNode(pos);
+
+ bool is_position_ok;
+ MapNode n = env->getMap().getNodeNoEx(pos, &is_position_ok);
+ if (is_position_ok) {
INodeDefManager *ndef = env->getGameDef()->ndef();
lua_pushinteger(L, n.getLightBlend(dnr, ndef));
- return 1;
- } catch(InvalidPositionException &e)
- {
+ } else {
lua_pushnil(L);
- return 1;
}
+ return 1;
}
// place_node(pos, node)
somebody is cheating, by checking the timing.
*/
MapNode n(CONTENT_IGNORE);
- try
- {
- n = m_env->getMap().getNode(p_under);
- }
- catch(InvalidPositionException &e)
- {
+ bool pos_ok;
+ n = m_env->getMap().getNodeNoEx(p_under, &pos_ok);
+ if (pos_ok)
+ n = m_env->getMap().getNodeNoEx(p_under, &pos_ok);
+
+ if (!pos_ok) {
infostream<<"Server: Not punching: Node not found."
<<" Adding block to emerge queue."
<<std::endl;
m_emerge->enqueueBlockEmerge(peer_id, getNodeBlockPos(p_above), false);
}
+
if(n.getContent() != CONTENT_IGNORE)
m_script->node_on_punch(p_under, n, playersao, pointed);
// Cheat prevention
// Only digging of nodes
if(pointed.type == POINTEDTHING_NODE)
{
- MapNode n(CONTENT_IGNORE);
- try
- {
- n = m_env->getMap().getNode(p_under);
- }
- catch(InvalidPositionException &e)
- {
- infostream<<"Server: Not finishing digging: Node not found."
- <<" Adding block to emerge queue."
- <<std::endl;
+ bool pos_ok;
+ MapNode n = m_env->getMap().getNodeNoEx(p_under, &pos_ok);
+ if (!pos_ok) {
+ infostream << "Server: Not finishing digging: Node not found."
+ << " Adding block to emerge queue."
+ << std::endl;
m_emerge->enqueueBlockEmerge(peer_id, getNodeBlockPos(p_above), false);
}