Skip to content

Commit 1b4908b

Browse files
committedJan 15, 2014
Prevent placing node when player would be inside new node
1 parent 4896d4b commit 1b4908b

File tree

1 file changed

+31
-15
lines changed

1 file changed

+31
-15
lines changed
 

‎src/game.cpp

+31-15
Original file line numberDiff line numberDiff line change
@@ -905,9 +905,20 @@ bool nodePlacementPrediction(Client &client,
905905
// Add node to client map
906906
MapNode n(id, 0, param2);
907907
try{
908-
// This triggers the required mesh update too
909-
client.addNode(p, n);
910-
return true;
908+
LocalPlayer* player = client.getEnv().getLocalPlayer();
909+
910+
// Dont place node when player would be inside new node
911+
// NOTE: This is to be eventually implemented by a mod as client-side Lua
912+
if (!nodedef->get(n).walkable ||
913+
(client.checkPrivilege("noclip") && g_settings->getBool("noclip")) ||
914+
(nodedef->get(n).walkable &&
915+
neighbourpos != player->getStandingNodePos() + v3s16(0,1,0) &&
916+
neighbourpos != player->getStandingNodePos() + v3s16(0,2,0))) {
917+
918+
// This triggers the required mesh update too
919+
client.addNode(p, n);
920+
return true;
921+
}
911922
}catch(InvalidPositionException &e){
912923
errorstream<<"Node placement prediction failed for "
913924
<<playeritem_def.name<<" (places "
@@ -2798,23 +2809,28 @@ void the_game(
27982809
// Otherwise report right click to server
27992810
else
28002811
{
2801-
// Report to server
2802-
client.interact(3, pointed);
2803-
camera.setDigging(1); // right click animation
2804-
2812+
camera.setDigging(1); // right click animation (always shown for feedback)
2813+
28052814
// If the wielded item has node placement prediction,
28062815
// make that happen
28072816
bool placed = nodePlacementPrediction(client,
2808-
playeritem_def,
2809-
nodepos, neighbourpos);
2810-
2811-
// Read the sound
2812-
if(placed)
2817+
playeritem_def,
2818+
nodepos, neighbourpos);
2819+
2820+
if(placed) {
2821+
// Report to server
2822+
client.interact(3, pointed);
2823+
// Read the sound
28132824
soundmaker.m_player_rightpunch_sound =
2814-
playeritem_def.sound_place;
2815-
else
2825+
playeritem_def.sound_place;
2826+
} else {
28162827
soundmaker.m_player_rightpunch_sound =
2817-
SimpleSoundSpec();
2828+
SimpleSoundSpec();
2829+
}
2830+
2831+
if (playeritem_def.node_placement_prediction == "" ||
2832+
nodedef->get(map.getNode(nodepos)).rightclickable)
2833+
client.interact(3, pointed); // Report to server
28182834
}
28192835
}
28202836
}

0 commit comments

Comments
 (0)