Skip to content

Commit 81c8b40

Browse files
committedJun 19, 2013
Play placing sound only if place prediction was successful
1 parent 9b6f1d6 commit 81c8b40

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed
 

‎src/game.cpp

+13-7
Original file line numberDiff line numberDiff line change
@@ -834,7 +834,7 @@ class GameGlobalShaderConstantSetter : public IShaderConstantSetter
834834
}
835835
};
836836

837-
void nodePlacementPrediction(Client &client,
837+
bool nodePlacementPrediction(Client &client,
838838
const ItemDefinition &playeritem_def,
839839
v3s16 nodepos, v3s16 neighbourpos)
840840
{
@@ -854,7 +854,7 @@ void nodePlacementPrediction(Client &client,
854854
if(nodedef->get(n_under).buildable_to)
855855
p = nodepos;
856856
else if (!nodedef->get(map.getNode(p)).buildable_to)
857-
return;
857+
return false;
858858
}catch(InvalidPositionException &e){}
859859
// Find id of predicted node
860860
content_t id;
@@ -864,7 +864,7 @@ void nodePlacementPrediction(Client &client,
864864
<<playeritem_def.name<<" (places "
865865
<<prediction
866866
<<") - Name not known"<<std::endl;
867-
return;
867+
return false;
868868
}
869869
// Predict param2 for facedir and wallmounted nodes
870870
u8 param2 = 0;
@@ -903,20 +903,22 @@ void nodePlacementPrediction(Client &client,
903903
else
904904
pp = p + v3s16(0,-1,0);
905905
if(!nodedef->get(map.getNode(pp)).walkable)
906-
return;
906+
return false;
907907
}
908908
// Add node to client map
909909
MapNode n(id, 0, param2);
910910
try{
911911
// This triggers the required mesh update too
912912
client.addNode(p, n);
913+
return true;
913914
}catch(InvalidPositionException &e){
914915
errorstream<<"Node placement prediction failed for "
915916
<<playeritem_def.name<<" (places "
916917
<<prediction
917918
<<") - Position not loaded"<<std::endl;
918919
}
919920
}
921+
return false;
920922
}
921923

922924

@@ -2774,13 +2776,17 @@ void the_game(
27742776

27752777
// If the wielded item has node placement prediction,
27762778
// make that happen
2777-
nodePlacementPrediction(client,
2779+
bool placed = nodePlacementPrediction(client,
27782780
playeritem_def,
27792781
nodepos, neighbourpos);
27802782

27812783
// Read the sound
2782-
soundmaker.m_player_rightpunch_sound =
2783-
playeritem_def.sound_place;
2784+
if(placed)
2785+
soundmaker.m_player_rightpunch_sound =
2786+
playeritem_def.sound_place;
2787+
else
2788+
soundmaker.m_player_rightpunch_sound =
2789+
SimpleSoundSpec();
27842790
}
27852791
}
27862792
}

0 commit comments

Comments
 (0)
Please sign in to comment.