Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New jumping behavior controlled by physics override #9980

Closed
wants to merge 11 commits into from
3 changes: 3 additions & 0 deletions doc/lua_api.txt
Expand Up @@ -6092,6 +6092,9 @@ object you are working with still exists.
(default: `false`)
* `new_move`: use new move/sneak code. When `false` the exact old code
is used for the specific old sneak behaviour (default: `true`)
* `new_jump`: use the new jump/bouncy jump code. When `false` the exact

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

jump/bouncy jump? I don't think this was intended?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was, you can now continuously jump on bouncy nodes

old code is used for jumping and bouncy jumping behavior.
(default: `true`)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this be false by default?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this rather be a float for jump "floatiness"?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That sounds like too much configurability that most people won't need.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm actually kinda weirded out why such a thing would be optional, that's one of the first annoying things I found about Minetest and it's the way jumping works.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated to make it false by default

* `get_physics_override()`: returns the table given to `set_physics_override`
* `hud_add(hud definition)`: add a HUD element described by HUD def, returns ID
number on success
Expand Down
2 changes: 2 additions & 0 deletions src/client/content_cao.cpp
Expand Up @@ -1593,6 +1593,7 @@ void GenericCAO::processMessage(const std::string &data)
bool sneak = !readU8(is);
bool sneak_glitch = !readU8(is);
bool new_move = !readU8(is);
bool new_jump = !readU8(is);
sfan5 marked this conversation as resolved.
Show resolved Hide resolved


if(m_is_local_player)
Expand All @@ -1604,6 +1605,7 @@ void GenericCAO::processMessage(const std::string &data)
player->physics_override_sneak = sneak;
player->physics_override_sneak_glitch = sneak_glitch;
player->physics_override_new_move = new_move;
player->physics_override_new_jump = new_jump;
}
} else if (cmd == AO_CMD_SET_ANIMATION) {
// TODO: change frames send as v2s32 value
Expand Down
8 changes: 5 additions & 3 deletions src/client/localplayer.cpp
Expand Up @@ -444,8 +444,9 @@ void LocalPlayer::move(f32 dtime, Environment *env, f32 pos_max_d,
m_can_jump = ((touching_ground && !is_climbing) || sneak_can_jump) && !m_disable_jump;

// Jump key pressed while jumping off from a bouncy block
if (m_can_jump && control.jump && itemgroup_get(f.groups, "bouncy") &&
m_speed.Y >= -0.5f * BS) {
if ((!physics_override_new_jump && m_can_jump && control.jump && itemgroup_get(f.groups, "bouncy") && m_speed.Y >= -0.5f * BS)||
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The options common to both new & old jump should be moved into a variable for readability.

(physics_override_new_jump && control.jump && itemgroup_get(f.groups, "bouncy") &&
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed m_can_jump is missing here, which probably breaks some feature. Is this intentional?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh it's very intentional, it's because m_can_jump is broken with bouncy nodes, and this creates a sane way to calculate if the player can jump based on their Y speed

m_speed.Y >= -0.5f * BS && m_speed.Y <= itemgroup_get(f.groups, "bouncy"))) {
float jumpspeed = movement_speed_jump * physics_override_jump;
if (m_speed.Y > 1.0f) {
// Reduce boost when speed already is high
Expand Down Expand Up @@ -609,7 +610,8 @@ void LocalPlayer::applyControl(float dtime, Environment *env)
at its starting value
*/
v3f speedJ = getSpeed();
if (speedJ.Y >= -0.5f * BS) {
if ((!physics_override_new_jump && speedJ.Y >= -0.5f * BS) ||
(physics_override_new_jump && touching_ground && speedJ.Y >= -0.5f * BS && speedJ.Y <= 0.5f * BS)) {
sfan5 marked this conversation as resolved.
Show resolved Hide resolved
speedJ.Y = movement_speed_jump * physics_override_jump;
setSpeed(speedJ);
m_client->getEventManager()->put(new SimpleTriggerEvent(MtEvent::PLAYER_JUMP));
Expand Down
1 change: 1 addition & 0 deletions src/client/localplayer.h
Expand Up @@ -66,6 +66,7 @@ class LocalPlayer : public Player
float physics_override_gravity = 1.0f;
bool physics_override_sneak = true;
bool physics_override_sneak_glitch = false;
bool physics_override_new_jump = false;
// Temporary option for old move code
bool physics_override_new_move = true;

Expand Down
3 changes: 3 additions & 0 deletions src/script/lua_api/l_localplayer.cpp
Expand Up @@ -176,6 +176,9 @@ int LuaLocalPlayer::l_get_physics_override(lua_State *L)
lua_pushboolean(L, player->physics_override_new_move);
lua_setfield(L, -2, "new_move");

lua_pushboolean(L, player->physics_override_new_move);
oilboi marked this conversation as resolved.
Show resolved Hide resolved
lua_setfield(L, -2, "new_jump");

return 1;
}

Expand Down
6 changes: 5 additions & 1 deletion src/script/lua_api/l_object.cpp
Expand Up @@ -386,7 +386,7 @@ int ObjectRef::l_get_armor_groups(lua_State *L)
}

// set_physics_override(self, physics_override_speed, physics_override_jump,
// physics_override_gravity, sneak, sneak_glitch, new_move)
// physics_override_gravity, sneak, sneak_glitch, new_move, new_jump)
int ObjectRef::l_set_physics_override(lua_State *L)
{
NO_MAP_LOCK_REQUIRED;
Expand All @@ -407,6 +407,8 @@ int ObjectRef::l_set_physics_override(lua_State *L)
L, 2, "sneak_glitch", co->m_physics_override_sneak_glitch);
co->m_physics_override_new_move = getboolfield_default(
L, 2, "new_move", co->m_physics_override_new_move);
co->m_physics_override_new_jump = getboolfield_default(
L, 2, "new_jump", co->m_physics_override_new_jump);
co->m_physics_override_sent = false;
} else {
// old, non-table format
Expand Down Expand Up @@ -448,6 +450,8 @@ int ObjectRef::l_get_physics_override(lua_State *L)
lua_setfield(L, -2, "sneak_glitch");
lua_pushboolean(L, co->m_physics_override_new_move);
lua_setfield(L, -2, "new_move");
lua_pushboolean(L, co->m_physics_override_new_jump);
lua_setfield(L, -2, "new_jump");
return 1;
}

Expand Down
2 changes: 1 addition & 1 deletion src/script/lua_api/l_object.h
Expand Up @@ -116,7 +116,7 @@ class ObjectRef : public ModApiBase {
static int l_get_armor_groups(lua_State *L);

// set_physics_override(self, physics_override_speed, physics_override_jump,
// physics_override_gravity, sneak, sneak_glitch, new_move)
// physics_override_gravity, sneak, sneak_glitch, new_move, new_jump)
static int l_set_physics_override(lua_State *L);

// get_physics_override(self)
Expand Down
1 change: 1 addition & 0 deletions src/server/player_sao.cpp
Expand Up @@ -339,6 +339,7 @@ std::string PlayerSAO::generateUpdatePhysicsOverrideCommand() const
writeU8(os, !m_physics_override_sneak);
writeU8(os, !m_physics_override_sneak_glitch);
writeU8(os, !m_physics_override_new_move);
writeU8(os, !m_physics_override_new_jump);
return os.str();
}

Expand Down
1 change: 1 addition & 0 deletions src/server/player_sao.h
Expand Up @@ -223,6 +223,7 @@ class PlayerSAO : public UnitSAO
bool m_physics_override_sneak = true;
bool m_physics_override_sneak_glitch = false;
bool m_physics_override_new_move = true;
bool m_physics_override_new_jump = false;
bool m_physics_override_sent = false;
};

Expand Down