Skip to content

Commit

Permalink
Some code style changes for climb_factor stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
Wuzzy2 committed Dec 28, 2024
1 parent e3aa419 commit 31adcec
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 19 deletions.
14 changes: 7 additions & 7 deletions doc/lua_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -9842,20 +9842,20 @@ 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
-- node isn't climbable.
-- 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,
Expand Down
13 changes: 5 additions & 8 deletions src/client/localplayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/nodedef.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions src/script/common/c_content.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 31adcec

Please sign in to comment.