From dc0517bff999b34c4373eecec2c9194d2de84969 Mon Sep 17 00:00:00 2001 From: Quentin Bazin Date: Sat, 11 Jul 2020 15:17:56 +0200 Subject: [PATCH] [Config] Added option for max block reach distance. --- source/client/core/Config.cpp | 3 +++ source/client/core/Config.hpp | 1 + source/client/hud/BlockCursor.cpp | 2 +- source/client/states/SettingsMenuState.cpp | 5 +++++ 4 files changed, 10 insertions(+), 1 deletion(-) diff --git a/source/client/core/Config.cpp b/source/client/core/Config.cpp index bf0e2f26e..cc22b77d1 100644 --- a/source/client/core/Config.cpp +++ b/source/client/core/Config.cpp @@ -40,6 +40,7 @@ namespace fs = ghc::filesystem; // Gameplay bool Config::isFlyModeEnabled = false; bool Config::isNoClipEnabled = false; +u16 Config::maxBlockReach = 7; // Interface bool Config::isBlockInfoWidgetEnabled = true; @@ -81,6 +82,7 @@ void Config::loadConfigFromFile(const char *filename) { isFlyModeEnabled = lua["isFlyModeEnabled"].get_or(isFlyModeEnabled); isNoClipEnabled = lua["isNoClipEnabled"].get_or(isNoClipEnabled); + maxBlockReach = lua["maxBlockReach"].get_or(maxBlockReach); isBlockInfoWidgetEnabled = lua["isBlockInfoWidgetEnabled"].get_or(isBlockInfoWidgetEnabled); isFpsCounterEnabled = lua["isFpsCounterEnabled"].get_or(isFpsCounterEnabled); @@ -116,6 +118,7 @@ void Config::saveConfigToFile(const char *filename) { std::ofstream file{filename, std::ofstream::out | std::ofstream::trunc}; file << "isFlyModeEnabled = " << (isFlyModeEnabled ? "true" : "false") << std::endl; file << "isNoClipEnabled = " << (isNoClipEnabled ? "true" : "false") << std::endl; + file << "maxBlockReach = " << maxBlockReach << std::endl; file << std::endl; file << "isBlockInfoWidgetEnabled = " << (isBlockInfoWidgetEnabled ? "true" : "false") << std::endl; file << "isFpsCounterEnabled = " << (isFpsCounterEnabled ? "true" : "false") << std::endl; diff --git a/source/client/core/Config.hpp b/source/client/core/Config.hpp index fecb59d63..84764ea82 100644 --- a/source/client/core/Config.hpp +++ b/source/client/core/Config.hpp @@ -35,6 +35,7 @@ namespace Config { // Gameplay extern bool isFlyModeEnabled; extern bool isNoClipEnabled; + extern u16 maxBlockReach; // Interface extern bool isBlockInfoWidgetEnabled; diff --git a/source/client/hud/BlockCursor.cpp b/source/client/hud/BlockCursor.cpp index fddc01e25..6f23c3a97 100644 --- a/source/client/hud/BlockCursor.cpp +++ b/source/client/hud/BlockCursor.cpp @@ -334,7 +334,7 @@ glm::ivec4 BlockCursor::findSelectedBlock() const { glm::dvec3 lookAt{m_player.dirTargetedX(), m_player.dirTargetedY(), m_player.dirTargetedZ()}; // Ray casting algorithm to find out which block we are looking at - const double maxReach = 10.; + const double maxReach = Config::maxBlockReach; double bestDepth; s8f bestFace = -1; diff --git a/source/client/states/SettingsMenuState.cpp b/source/client/states/SettingsMenuState.cpp index c798258ba..8048a2006 100644 --- a/source/client/states/SettingsMenuState.cpp +++ b/source/client/states/SettingsMenuState.cpp @@ -176,6 +176,11 @@ void SettingsMenuState::addGameplayButtons() { addToggleButton("Fly Mode", Config::isFlyModeEnabled, false); addToggleButton("No Clip", Config::isNoClipEnabled, false); + m_menuWidget.addSlider("Max Block Reach: " + std::to_string(Config::maxBlockReach), [] (SliderWidget &slider, u32) { + Config::maxBlockReach = slider.getCurrentValue(); + slider.setText("Max Block Reach: " + std::to_string(Config::maxBlockReach)); + }, 1, 15, Config::maxBlockReach); + updateWidgetPosition(); }