]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/game.cpp
Safe digging and placing (#6127)
[dragonfireclient.git] / src / game.cpp
index 0f82277492cb1c63b0764afa9cbc815a14f73550..c3d8446344237ea17ea95d27cc8d5330653bb3e4 100644 (file)
@@ -1142,6 +1142,7 @@ struct GameRunData {
        bool digging;
        bool ldown_for_dig;
        bool dig_instantly;
+       bool digging_blocked;
        bool left_punch;
        bool update_wielded_item_trigger;
        bool reset_jump_timer;
@@ -3559,6 +3560,11 @@ void Game::processPlayerInteraction(f32 dtime, bool show_hud, bool show_debug)
                hud->updateSelectionMesh(camera_offset);
        }
 
+       if (runData.digging_blocked && !isLeftPressed()) {
+               // allow digging again if button is not pressed
+               runData.digging_blocked = false;
+       }
+
        /*
                Stop digging when
                - releasing left mouse button
@@ -3603,7 +3609,8 @@ void Game::processPlayerInteraction(f32 dtime, bool show_hud, bool show_debug)
 
        soundmaker->m_player_leftpunch_sound.name = "";
 
-       if (isRightPressed())
+       // Prepare for repeating, unless we're not supposed to
+       if (isRightPressed() && !g_settings->getBool("safe_dig_and_place"))
                runData.repeat_rightclick_timer += dtime;
        else
                runData.repeat_rightclick_timer = 0;
@@ -3762,6 +3769,7 @@ void Game::handlePointingAtNode(const PointedThing &pointed,
        ClientMap &map = client->getEnv().getClientMap();
 
        if (runData.nodig_delay_timer <= 0.0 && isLeftPressed()
+                       && !runData.digging_blocked
                        && client->checkPrivilege("interact")) {
                handleDigging(pointed, nodepos, playeritem_toolcap, dtime);
        }
@@ -3985,6 +3993,9 @@ void Game::handleDigging(const PointedThing &pointed, const v3s16 &nodepos,
 
                runData.dig_time = 0;
                runData.digging = false;
+               // we successfully dug, now block it from repeating if we want to be safe
+               if (g_settings->getBool("safe_dig_and_place"))
+                       runData.digging_blocked = true;
 
                runData.nodig_delay_timer =
                                runData.dig_time_complete / (float)crack_animation_length;