Skip to content

Commit

Permalink
Safe digging and placing (#6127)
Browse files Browse the repository at this point in the history
* Setting: Safe digging and placing

* New setting 'safe_dig_and_place' under Controls
* If set, digging and placing will not auto-repeat
* Releasing buttons unblocks the respective action again
* Useful for inexperienced users in creative mode where default
  repeat times may be too short

* Safe placing (right click repetition) does not need a guarding flag

* Added new setting to minetest.conf.example
  • Loading branch information
bendeutsch authored and nerzhul committed Aug 24, 2017
1 parent c7160cb commit 397a701
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 1 deletion.
4 changes: 4 additions & 0 deletions builtin/settingtypes.txt
Expand Up @@ -101,6 +101,10 @@ always_fly_fast (Always fly and fast) bool true
# The time in seconds it takes between repeated right clicks when holding the right mouse button.
repeat_rightclick_time (Rightclick repetition interval) float 0.25

# Prevent digging and placing from repeating when holding the mouse buttons.
# Enable this when you dig or place too often by accident.
safe_dig_and_place (Safe digging and placing) bool false

# Enable random user input (only used for testing).
random_input (Random input) bool false

Expand Down
5 changes: 5 additions & 0 deletions minetest.conf.example
Expand Up @@ -75,6 +75,11 @@
# type: float
# repeat_rightclick_time = 0.25

# Prevent digging and placing from repeating when holding the mouse buttons.
# Enable this when you dig or place too often by accident.
# type: bool
# safe_dig_and_place = false

# Enable random user input (only used for testing).
# type: bool
# random_input = false
Expand Down
1 change: 1 addition & 0 deletions src/defaultsettings.cpp
Expand Up @@ -240,6 +240,7 @@ void set_default_settings(Settings *settings)
settings->setDefault("invert_mouse", "false");
settings->setDefault("mouse_sensitivity", "0.2");
settings->setDefault("repeat_rightclick_time", "0.25");
settings->setDefault("safe_dig_and_place", "false");
settings->setDefault("random_input", "false");
settings->setDefault("aux1_descends", "false");
settings->setDefault("doubletap_jump", "false");
Expand Down
13 changes: 12 additions & 1 deletion src/game.cpp
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 397a701

Please sign in to comment.