Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Play placing sound only if place prediction was successful
  • Loading branch information
PilzAdam committed Jun 19, 2013
1 parent 9b6f1d6 commit 81c8b40
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/game.cpp
Expand Up @@ -834,7 +834,7 @@ class GameGlobalShaderConstantSetter : public IShaderConstantSetter
}
};

void nodePlacementPrediction(Client &client,
bool nodePlacementPrediction(Client &client,
const ItemDefinition &playeritem_def,
v3s16 nodepos, v3s16 neighbourpos)
{
Expand All @@ -854,7 +854,7 @@ void nodePlacementPrediction(Client &client,
if(nodedef->get(n_under).buildable_to)
p = nodepos;
else if (!nodedef->get(map.getNode(p)).buildable_to)
return;
return false;
}catch(InvalidPositionException &e){}
// Find id of predicted node
content_t id;
Expand All @@ -864,7 +864,7 @@ void nodePlacementPrediction(Client &client,
<<playeritem_def.name<<" (places "
<<prediction
<<") - Name not known"<<std::endl;
return;
return false;
}
// Predict param2 for facedir and wallmounted nodes
u8 param2 = 0;
Expand Down Expand Up @@ -903,20 +903,22 @@ void nodePlacementPrediction(Client &client,
else
pp = p + v3s16(0,-1,0);
if(!nodedef->get(map.getNode(pp)).walkable)
return;
return false;
}
// Add node to client map
MapNode n(id, 0, param2);
try{
// This triggers the required mesh update too
client.addNode(p, n);
return true;
}catch(InvalidPositionException &e){
errorstream<<"Node placement prediction failed for "
<<playeritem_def.name<<" (places "
<<prediction
<<") - Position not loaded"<<std::endl;
}
}
return false;
}


Expand Down Expand Up @@ -2774,13 +2776,17 @@ void the_game(

// If the wielded item has node placement prediction,
// make that happen
nodePlacementPrediction(client,
bool placed = nodePlacementPrediction(client,
playeritem_def,
nodepos, neighbourpos);

// Read the sound
soundmaker.m_player_rightpunch_sound =
playeritem_def.sound_place;
if(placed)
soundmaker.m_player_rightpunch_sound =
playeritem_def.sound_place;
else
soundmaker.m_player_rightpunch_sound =
SimpleSoundSpec();
}
}
}
Expand Down

0 comments on commit 81c8b40

Please sign in to comment.