From 31adcec585c4b594b175062e051077d2799e88d8 Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Sat, 28 Dec 2024 14:36:19 +0100 Subject: [PATCH] Some code style changes for climb_factor stuff --- doc/lua_api.md | 14 +++++++------- src/client/localplayer.cpp | 13 +++++-------- src/nodedef.cpp | 4 ++-- src/script/common/c_content.cpp | 4 ++-- 4 files changed, 16 insertions(+), 19 deletions(-) diff --git a/doc/lua_api.md b/doc/lua_api.md index fd8f6fb8bb9b1..73fa9c2ab746a 100644 --- a/doc/lua_api.md +++ b/doc/lua_api.md @@ -9842,13 +9842,6 @@ Used by `core.register_node`. climbable = false, -- If true, can be climbed on like a ladder - move_resistance = 0, - -- Slows down movement of players through this node (max. 7). - -- If this is nil, it will be equal to liquid_viscosity. - -- Note: If liquid movement physics apply to the node - -- (see `liquid_move_physics`), the movement speed will also be - -- affected by the `movement_liquid_*` settings. - climb_factor = 1.0, -- The speed at which a climbable node can be climbed up and down -- is multiplied by this number. Must not be negative. No effect if @@ -9856,6 +9849,13 @@ Used by `core.register_node`. -- Note: The base climbing speed is controlled by the setting -- `movement_speed_climb` multiplied by the physics override `speed_climb`. + move_resistance = 0, + -- Slows down movement of players through this node (max. 7). + -- If this is nil, it will be equal to liquid_viscosity. + -- Note: If liquid movement physics apply to the node + -- (see `liquid_move_physics`), the movement speed will also be + -- affected by the `movement_liquid_*` settings. + buildable_to = false, -- If true, placed nodes can replace this node floodable = false, diff --git a/src/client/localplayer.cpp b/src/client/localplayer.cpp index de28387e8eaeb..6a0dee4808ea7 100644 --- a/src/client/localplayer.cpp +++ b/src/client/localplayer.cpp @@ -316,15 +316,12 @@ void LocalPlayer::move(f32 dtime, Environment *env, if (!(is_valid_position && is_valid_position2)) { is_climbing = false; } else { - bool climbable_upper = nodemgr->get(node.getContent()).climbable; - bool climbable_lower = nodemgr->get(node2.getContent()).climbable; - is_climbing = (climbable_upper || climbable_lower) && !free_move; + const ContentFeatures &cf_upper = nodemgr->get(node.getContent()); + const ContentFeatures &cf_lower = nodemgr->get(node2.getContent()); + is_climbing = (cf_upper.climbable || cf_lower.climbable) && !free_move; if (is_climbing) { - if (climbable_lower) { - node_climb_factor = nodemgr->get(node2.getContent()).climb_factor; - } else { - node_climb_factor = nodemgr->get(node.getContent()).climb_factor; - } + node_climb_factor = cf_lower.climbable + ? cf_lower.climb_factor : cf_upper.climb_factor; } } diff --git a/src/nodedef.cpp b/src/nodedef.cpp index 9fbfd663eea37..5b809c14d734e 100644 --- a/src/nodedef.cpp +++ b/src/nodedef.cpp @@ -371,6 +371,7 @@ void ContentFeatures::reset() pointable = PointabilityType::POINTABLE; diggable = true; climbable = false; + climb_factor = 1.0f; buildable_to = false; floodable = false; rightclickable = true; @@ -406,7 +407,6 @@ void ContentFeatures::reset() move_resistance = 0; liquid_move_physics = false; post_effect_color_shaded = false; - climb_factor = 1.0f; } void ContentFeatures::setAlphaFromLegacy(u8 legacy_alpha) @@ -670,7 +670,7 @@ void ContentFeatures::deSerialize(std::istream &is, u16 protocol_version) if (is.eof()) throw SerializationError(""); climb_factor = ftmp; - } catch(SerializationError &e) {}; + } catch (SerializationError &e) {}; } #if CHECK_CLIENT_BUILD() diff --git a/src/script/common/c_content.cpp b/src/script/common/c_content.cpp index 283908a8926db..078a1eac0e578 100644 --- a/src/script/common/c_content.cpp +++ b/src/script/common/c_content.cpp @@ -812,6 +812,8 @@ void read_content_features(lua_State *L, ContentFeatures &f, int index) getboolfield(L, index, "diggable", f.diggable); // Player can climb these getboolfield(L, index, "climbable", f.climbable); + // Multiplies climb speed on climbable node + getfloatfield(L, index, "climb_factor", f.climb_factor); // Player can build on these getboolfield(L, index, "buildable_to", f.buildable_to); // Liquids flow into and replace node @@ -951,8 +953,6 @@ void read_content_features(lua_State *L, ContentFeatures &f, int index) errorstream << "Field \"liquid_move_physics\": Invalid type!" << std::endl; } lua_pop(L, 1); - - getfloatfield(L, index, "climb_factor", f.climb_factor); } void push_content_features(lua_State *L, const ContentFeatures &c)