Skip to content

Commit

Permalink
[Config] Added option for max block reach distance.
Browse files Browse the repository at this point in the history
  • Loading branch information
Unarelith committed Jul 11, 2020
1 parent 2d56b94 commit dc0517b
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 1 deletion.
3 changes: 3 additions & 0 deletions source/client/core/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions source/client/core/Config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ namespace Config {
// Gameplay
extern bool isFlyModeEnabled;
extern bool isNoClipEnabled;
extern u16 maxBlockReach;

// Interface
extern bool isBlockInfoWidgetEnabled;
Expand Down
2 changes: 1 addition & 1 deletion source/client/hud/BlockCursor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
5 changes: 5 additions & 0 deletions source/client/states/SettingsMenuState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down

0 comments on commit dc0517b

Please sign in to comment.