From a76bfcc6ace88d31567e10bb34d632953454a0ac Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Mon, 23 Dec 2024 14:20:22 +0100 Subject: [PATCH 1/6] Add per-node climb speed modifier --- doc/lua_api.md | 7 ++++ games/devtest/mods/testnodes/properties.lua | 41 ++++++++++++++++++++- src/client/localplayer.cpp | 11 ++++-- src/client/localplayer.h | 1 + src/nodedef.cpp | 9 ++++- src/nodedef.h | 2 + src/script/common/c_content.cpp | 4 ++ 7 files changed, 68 insertions(+), 7 deletions(-) diff --git a/doc/lua_api.md b/doc/lua_api.md index 91d8f314a..52583a592 100644 --- a/doc/lua_api.md +++ b/doc/lua_api.md @@ -9849,6 +9849,13 @@ Used by `core.register_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 is multiplied + -- with this number. Must not be negative. No effect if node isn't + -- climbable. + -- Note: To set the base climbing speed in your game, + -- change the setting "movement_speed_climb". + buildable_to = false, -- If true, placed nodes can replace this node floodable = false, diff --git a/games/devtest/mods/testnodes/properties.lua b/games/devtest/mods/testnodes/properties.lua index 29dc14a25..9ffd75510 100644 --- a/games/devtest/mods/testnodes/properties.lua +++ b/games/devtest/mods/testnodes/properties.lua @@ -209,6 +209,41 @@ core.register_node("testnodes:climbable", { groups = {dig_immediate=3}, }) +minetest.register_node("testnodes:climbable_fast", { + description = S("Fast Climbable Node").."\n".. + S("You can climb up and down, faster than usual"), + climbable = true, + climb_factor = 2.0, + walkable = false, + + + paramtype = "light", + sunlight_propagates = true, + is_ground_content = false, + tiles = {"testnodes_climbable_top.png^[colorize:#FFFFFF:140","testnodes_climbable_top.png^[colorize:#FFFFFF:140","testnodes_climbable_side.png^[colorize:#FFFFFF:140"}, + use_texture_alpha = "clip", + drawtype = "nodebox", + node_box = climbable_nodebox, + groups = {dig_immediate=3}, +}) +minetest.register_node("testnodes:climbable_slow", { + description = S("Slow Climbable Node").."\n".. + S("You can climb up and down, slower than usual"), + climbable = true, + climb_factor = 0.5, + walkable = false, + + + paramtype = "light", + sunlight_propagates = true, + is_ground_content = false, + tiles = {"testnodes_climbable_top.png^[colorize:#000000:140","testnodes_climbable_top.png^[colorize:#000000:140","testnodes_climbable_side.png^[colorize:#000000:140"}, + use_texture_alpha = "clip", + drawtype = "nodebox", + node_box = climbable_nodebox, + groups = {dig_immediate=3}, +}) + -- Climbable only downwards with sneak key core.register_node("testnodes:climbable_nojump", { description = S("Downwards-climbable Node").."\n".. @@ -227,7 +262,8 @@ core.register_node("testnodes:climbable_nojump", { core.register_node("testnodes:climbable_nodescend", { - description = S("Upwards-climbable Node"), + description = S("Upwards-climbable Node").."\n".. + S("You can climb only upwards"), climbable = true, walkable = false, @@ -241,7 +277,8 @@ core.register_node("testnodes:climbable_nodescend", { }) core.register_node("testnodes:climbable_nodescend_nojump", { - description = S("Horizontal-only Climbable Node"), + description = S("Horizontal-only Climbable Node").."\n".. + S("You hold on to this node but can't climb vertically"), climbable = true, walkable = false, diff --git a/src/client/localplayer.cpp b/src/client/localplayer.cpp index 53a9db810..38e3f0a8b 100644 --- a/src/client/localplayer.cpp +++ b/src/client/localplayer.cpp @@ -318,6 +318,9 @@ void LocalPlayer::move(f32 dtime, Environment *env, } else { is_climbing = (nodemgr->get(node.getContent()).climbable || nodemgr->get(node2.getContent()).climbable) && !free_move; + if (is_climbing) { + node_climb_factor = nodemgr->get(node.getContent()).climb_factor; + } } // Player object property step height is multiplied by BS in @@ -584,7 +587,7 @@ void LocalPlayer::applyControl(float dtime, Environment *env) speedV.Y = -speed_walk; swimming_vertical = true; } else if (is_climbing && !m_disable_descend) { - speedV.Y = -movement_speed_climb * physics_override.speed_climb; + speedV.Y = -movement_speed_climb * physics_override.speed_climb * node_climb_factor; } else { // If not free movement but fast is allowed, aux1 is // "Turbo button" @@ -620,9 +623,9 @@ void LocalPlayer::applyControl(float dtime, Environment *env) swimming_vertical = true; } else if (is_climbing && !m_disable_descend) { if (fast_climb) - speedV.Y = -speed_fast; + speedV.Y = -speed_fast * node_climb_factor; else - speedV.Y = -movement_speed_climb * physics_override.speed_climb; + speedV.Y = -movement_speed_climb * physics_override.speed_climb * node_climb_factor; } } } @@ -675,7 +678,7 @@ void LocalPlayer::applyControl(float dtime, Environment *env) if (fast_climb) speedV.Y = speed_fast; else - speedV.Y = movement_speed_climb * physics_override.speed_climb; + speedV.Y = movement_speed_climb * physics_override.speed_climb * node_climb_factor; } } diff --git a/src/client/localplayer.h b/src/client/localplayer.h index 93b768ceb..dd8b11352 100644 --- a/src/client/localplayer.h +++ b/src/client/localplayer.h @@ -64,6 +64,7 @@ public: // Slows down the player when moving through u8 move_resistance = 0; bool is_climbing = false; + f32 node_climb_factor = 1.0f; bool swimming_vertical = false; bool swimming_pitch = false; diff --git a/src/nodedef.cpp b/src/nodedef.cpp index 2f0307d11..f60f8fbfb 100644 --- a/src/nodedef.cpp +++ b/src/nodedef.cpp @@ -406,6 +406,7 @@ void ContentFeatures::reset() move_resistance = 0; liquid_move_physics = false; post_effect_color_shaded = false; + climb_factor = 1.0; } void ContentFeatures::setAlphaFromLegacy(u8 legacy_alpha) @@ -533,6 +534,7 @@ void ContentFeatures::serialize(std::ostream &os, u16 protocol_version) const writeU8(os, move_resistance); writeU8(os, liquid_move_physics); writeU8(os, post_effect_color_shaded); + writeF32(os, climb_factor); } void ContentFeatures::deSerialize(std::istream &is, u16 protocol_version) @@ -663,7 +665,12 @@ void ContentFeatures::deSerialize(std::istream &is, u16 protocol_version) if (is.eof()) throw SerializationError(""); post_effect_color_shaded = tmp; - } catch (SerializationError &e) {}; + + f32 ftmp = readF32(is); + if (is.eof()) + throw SerializationError(""); + climb_factor = ftmp; + } catch(SerializationError &e) {}; } #if CHECK_CLIENT_BUILD() diff --git a/src/nodedef.h b/src/nodedef.h index ab3362872..844acb719 100644 --- a/src/nodedef.h +++ b/src/nodedef.h @@ -387,6 +387,8 @@ struct ContentFeatures bool diggable; // Player can climb these bool climbable; + // Climb speed factor + f32 climb_factor; // Player can build on these bool buildable_to; // Player cannot build to these (placement prediction disabled) diff --git a/src/script/common/c_content.cpp b/src/script/common/c_content.cpp index 5f000acd8..283908a89 100644 --- a/src/script/common/c_content.cpp +++ b/src/script/common/c_content.cpp @@ -951,6 +951,8 @@ 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) @@ -1084,6 +1086,8 @@ void push_content_features(lua_State *L, const ContentFeatures &c) lua_setfield(L, -2, "move_resistance"); lua_pushboolean(L, c.liquid_move_physics); lua_setfield(L, -2, "liquid_move_physics"); + lua_pushnumber(L, c.climb_factor); + lua_setfield(L, -2, "climb_factor"); } /******************************************************************************/ From 7b69c8e3a3df57c1413d506bccba64994d18a77f Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Sun, 18 Aug 2024 11:29:38 +0200 Subject: [PATCH 2/6] Shorten line length in properties.lua --- games/devtest/mods/testnodes/properties.lua | 30 +++++++++++++++++---- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/games/devtest/mods/testnodes/properties.lua b/games/devtest/mods/testnodes/properties.lua index 9ffd75510..b578e1857 100644 --- a/games/devtest/mods/testnodes/properties.lua +++ b/games/devtest/mods/testnodes/properties.lua @@ -220,7 +220,11 @@ minetest.register_node("testnodes:climbable_fast", { paramtype = "light", sunlight_propagates = true, is_ground_content = false, - tiles = {"testnodes_climbable_top.png^[colorize:#FFFFFF:140","testnodes_climbable_top.png^[colorize:#FFFFFF:140","testnodes_climbable_side.png^[colorize:#FFFFFF:140"}, + tiles = { + "testnodes_climbable_top.png^[colorize:#FFFFFF:140", + "testnodes_climbable_top.png^[colorize:#FFFFFF:140", + "testnodes_climbable_side.png^[colorize:#FFFFFF:140" + }, use_texture_alpha = "clip", drawtype = "nodebox", node_box = climbable_nodebox, @@ -237,7 +241,11 @@ minetest.register_node("testnodes:climbable_slow", { paramtype = "light", sunlight_propagates = true, is_ground_content = false, - tiles = {"testnodes_climbable_top.png^[colorize:#000000:140","testnodes_climbable_top.png^[colorize:#000000:140","testnodes_climbable_side.png^[colorize:#000000:140"}, + tiles = { + "testnodes_climbable_top.png^[colorize:#000000:140", + "testnodes_climbable_top.png^[colorize:#000000:140", + "testnodes_climbable_side.png^[colorize:#000000:140" + }, use_texture_alpha = "clip", drawtype = "nodebox", node_box = climbable_nodebox, @@ -254,7 +262,11 @@ core.register_node("testnodes:climbable_nojump", { groups = {disable_jump=1, dig_immediate=3}, drawtype = "nodebox", node_box = climbable_nodebox, - tiles = {"testnodes_climbable_nojump_top.png","testnodes_climbable_nojump_top.png","testnodes_climbable_nojump_side.png"}, + tiles = { + "testnodes_climbable_nojump_top.png", + "testnodes_climbable_nojump_top.png", + "testnodes_climbable_nojump_side.png" + }, use_texture_alpha = "clip", paramtype = "light", sunlight_propagates = true, @@ -270,7 +282,11 @@ core.register_node("testnodes:climbable_nodescend", { groups = {disable_descend=1, dig_immediate=3}, drawtype = "nodebox", node_box = climbable_nodebox, - tiles = {"testnodes_climbable_nodescend_top.png","testnodes_climbable_nodescend_top.png","testnodes_climbable_nodescend_side.png"}, + tiles = { + "testnodes_climbable_nodescend_top.png", + "testnodes_climbable_nodescend_top.png", + "testnodes_climbable_nodescend_side.png" + }, use_texture_alpha = "clip", paramtype = "light", sunlight_propagates = true, @@ -285,7 +301,11 @@ core.register_node("testnodes:climbable_nodescend_nojump", { groups = {disable_jump=1, disable_descend=1, dig_immediate=3}, drawtype = "nodebox", node_box = climbable_nodebox, - tiles = {"testnodes_climbable_noclimb_top.png","testnodes_climbable_noclimb_top.png","testnodes_climbable_noclimb_side.png"}, + tiles = { + "testnodes_climbable_noclimb_top.png", + "testnodes_climbable_noclimb_top.png", + "testnodes_climbable_noclimb_side.png" + }, use_texture_alpha = "clip", paramtype = "light", sunlight_propagates = true, From 1a72e156f36072a54fed81602476e79b5af90160 Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Sun, 18 Aug 2024 11:30:00 +0200 Subject: [PATCH 3/6] Don't suggest to change climb setting in lua_api --- doc/lua_api.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/lua_api.md b/doc/lua_api.md index 52583a592..8f4309783 100644 --- a/doc/lua_api.md +++ b/doc/lua_api.md @@ -9853,8 +9853,8 @@ Used by `core.register_node`. -- The speed at which a climbable node can be climbed is multiplied -- with this number. Must not be negative. No effect if node isn't -- climbable. - -- Note: To set the base climbing speed in your game, - -- change the setting "movement_speed_climb". + -- Note: The base climbing speed is controlled by the setting + -- `movement_speed_climb`. buildable_to = false, -- If true, placed nodes can replace this node From 45b8a3bf45cc380eb1451785c2f81956908bf0a2 Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Sat, 26 Oct 2024 18:29:44 +0200 Subject: [PATCH 4/6] A bit climb factor cleanup --- doc/lua_api.md | 8 ++++---- src/nodedef.cpp | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/doc/lua_api.md b/doc/lua_api.md index 8f4309783..fd8f6fb8b 100644 --- a/doc/lua_api.md +++ b/doc/lua_api.md @@ -9850,11 +9850,11 @@ Used by `core.register_node`. -- affected by the `movement_liquid_*` settings. climb_factor = 1.0, - -- The speed at which a climbable node can be climbed is multiplied - -- with this number. Must not be negative. No effect if node isn't - -- climbable. + -- 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 + -- node isn't climbable. -- Note: The base climbing speed is controlled by the setting - -- `movement_speed_climb`. + -- `movement_speed_climb` multiplied by the physics override `speed_climb`. buildable_to = false, -- If true, placed nodes can replace this node diff --git a/src/nodedef.cpp b/src/nodedef.cpp index f60f8fbfb..9fbfd663e 100644 --- a/src/nodedef.cpp +++ b/src/nodedef.cpp @@ -406,7 +406,7 @@ void ContentFeatures::reset() move_resistance = 0; liquid_move_physics = false; post_effect_color_shaded = false; - climb_factor = 1.0; + climb_factor = 1.0f; } void ContentFeatures::setAlphaFromLegacy(u8 legacy_alpha) From e3aa419695f293d4620a3ccda5cb0eb52e7faccd Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Sun, 27 Oct 2024 12:13:18 +0100 Subject: [PATCH 5/6] Consider up to 2 nodes to apply climb_factor --- src/client/localplayer.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/client/localplayer.cpp b/src/client/localplayer.cpp index 38e3f0a8b..de28387e8 100644 --- a/src/client/localplayer.cpp +++ b/src/client/localplayer.cpp @@ -316,10 +316,15 @@ void LocalPlayer::move(f32 dtime, Environment *env, if (!(is_valid_position && is_valid_position2)) { is_climbing = false; } else { - is_climbing = (nodemgr->get(node.getContent()).climbable || - nodemgr->get(node2.getContent()).climbable) && !free_move; + bool climbable_upper = nodemgr->get(node.getContent()).climbable; + bool climbable_lower = nodemgr->get(node2.getContent()).climbable; + is_climbing = (climbable_upper || climbable_lower) && !free_move; if (is_climbing) { - node_climb_factor = nodemgr->get(node.getContent()).climb_factor; + if (climbable_lower) { + node_climb_factor = nodemgr->get(node2.getContent()).climb_factor; + } else { + node_climb_factor = nodemgr->get(node.getContent()).climb_factor; + } } } From 31adcec585c4b594b175062e051077d2799e88d8 Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Sat, 28 Dec 2024 14:36:19 +0100 Subject: [PATCH 6/6] 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 fd8f6fb8b..73fa9c2ab 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 de28387e8..6a0dee480 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 9fbfd663e..5b809c14d 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 283908a89..078a1eac0 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)