aboutsummaryrefslogtreecommitdiff
path: root/src/game.cpp
diff options
context:
space:
mode:
authorCraig Robbins <kde.psych@gmail.com>2014-11-14 18:05:34 +1000
committerCraig Robbins <kde.psych@gmail.com>2014-11-14 18:05:34 +1000
commit5b8855e83c0d1cc7aef21492e7fe862b7d06917e (patch)
treeb05139dcea07222cfa3fab23064eeef0076c8019 /src/game.cpp
parent92815ad54b23fe92742ebca7263bb227149248c1 (diff)
downloadminetest-5b8855e83c0d1cc7aef21492e7fe862b7d06917e.tar.gz
minetest-5b8855e83c0d1cc7aef21492e7fe862b7d06917e.tar.bz2
minetest-5b8855e83c0d1cc7aef21492e7fe862b7d06917e.zip
Remove most exceptions from getNode() (and variants)
Diffstat (limited to 'src/game.cpp')
-rw-r--r--src/game.cpp44
1 files changed, 27 insertions, 17 deletions
diff --git a/src/game.cpp b/src/game.cpp
index 928c5b383..2c969b931 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -360,12 +360,11 @@ PointedThing getPointedThing(Client *client, v3f player_position,
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;
@@ -873,22 +872,31 @@ bool nodePlacementPrediction(Client &client,
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;
@@ -946,7 +954,7 @@ bool nodePlacementPrediction(Client &client,
else
pp = p + v3s16(0, -1, 0);
- if (!nodedef->get(map.getNode(pp)).walkable)
+ if (!nodedef->get(map.getNodeNoEx(pp)).walkable)
return false;
}
@@ -3431,7 +3439,7 @@ void Game::handlePointingAtNode(GameRunData *runData,
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: ";
@@ -3489,7 +3497,7 @@ void Game::handlePointingAtNode(GameRunData *runData,
}
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
}
}
@@ -3558,7 +3566,7 @@ void Game::handleDigging(GameRunData *runData,
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.
@@ -3623,8 +3631,10 @@ void Game::handleDigging(GameRunData *runData,
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 =