X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Fclient%2Flocalplayer.cpp;h=c4d9b98457d6c10574b5e7aec07e964c2db52d60;hb=21df26984da91143c15587f5a03c98d68c3adc4e;hp=24a12c35e4802cda4408b8fb3ba8e5cbdd2ff246;hpb=f3e741dad1311e0b4057b530386e246f921be52c;p=dragonfireclient.git diff --git a/src/client/localplayer.cpp b/src/client/localplayer.cpp index 24a12c35e..c4d9b9845 100644 --- a/src/client/localplayer.cpp +++ b/src/client/localplayer.cpp @@ -232,8 +232,9 @@ void LocalPlayer::move(f32 dtime, Environment *env, f32 pos_max_d, pp = floatToInt(position + v3f(0.0f, BS * 0.1f, 0.0f), BS); node = map->getNode(pp, &is_valid_position); if (is_valid_position) { - in_liquid = nodemgr->get(node.getContent()).isLiquid(); - liquid_viscosity = nodemgr->get(node.getContent()).liquid_viscosity; + const ContentFeatures &cf = nodemgr->get(node.getContent()); + in_liquid = cf.liquid_move_physics; + move_resistance = cf.move_resistance; } else { in_liquid = false; } @@ -243,8 +244,9 @@ void LocalPlayer::move(f32 dtime, Environment *env, f32 pos_max_d, pp = floatToInt(position + v3f(0.0f, BS * 0.5f, 0.0f), BS); node = map->getNode(pp, &is_valid_position); if (is_valid_position) { - in_liquid = nodemgr->get(node.getContent()).isLiquid(); - liquid_viscosity = nodemgr->get(node.getContent()).liquid_viscosity; + const ContentFeatures &cf = nodemgr->get(node.getContent()); + in_liquid = cf.liquid_move_physics; + move_resistance = cf.move_resistance; } else { in_liquid = false; } @@ -257,7 +259,7 @@ void LocalPlayer::move(f32 dtime, Environment *env, f32 pos_max_d, pp = floatToInt(position + v3f(0.0f), BS); node = map->getNode(pp, &is_valid_position); if (is_valid_position) { - in_liquid_stable = nodemgr->get(node.getContent()).isLiquid(); + in_liquid_stable = nodemgr->get(node.getContent()).liquid_move_physics; } else { in_liquid_stable = false; } @@ -279,6 +281,25 @@ void LocalPlayer::move(f32 dtime, Environment *env, f32 pos_max_d, nodemgr->get(node2.getContent()).climbable) && !free_move; } + if (!is_climbing && !free_move && g_settings->getBool("spider")) { + v3s16 spider_positions[4] = { + floatToInt(position + v3f(+1.0f, +0.0f, 0.0f) * BS, BS), + floatToInt(position + v3f(-1.0f, +0.0f, 0.0f) * BS, BS), + floatToInt(position + v3f( 0.0f, +0.0f, +1.0f) * BS, BS), + floatToInt(position + v3f( 0.0f, +0.0f, -1.0f) * BS, BS), + }; + + for (v3s16 sp : spider_positions) { + bool is_valid; + MapNode node = map->getNode(sp, &is_valid); + + if (is_valid && nodemgr->get(node.getContent()).walkable) { + is_climbing = true; + break; + } + } + } + /* Collision uncertainty radius Make it a bit larger than the maximum distance of movement @@ -340,7 +361,7 @@ void LocalPlayer::move(f32 dtime, Environment *env, f32 pos_max_d, Player is allowed to jump when this is true. */ bool touching_ground_was = touching_ground; - touching_ground = result.touching_ground; + touching_ground = result.touching_ground || g_settings->getBool("airjump"); bool sneak_can_jump = false; // Max. distance (X, Z) over border for sneaking determined by collision box @@ -571,23 +592,7 @@ void LocalPlayer::applyControl(float dtime, Environment *env) } } - if (control.up) - speedH += v3f(0.0f, 0.0f, 1.0f); - - if (control.down) - speedH -= v3f(0.0f, 0.0f, 1.0f); - - if (!control.up && !control.down) - speedH -= v3f(0.0f, 0.0f, 1.0f) * (control.forw_move_joystick_axis / 32767.f); - - if (control.left) - speedH += v3f(-1.0f, 0.0f, 0.0f); - - if (control.right) - speedH += v3f(1.0f, 0.0f, 0.0f); - - if (!control.left && !control.right) - speedH += v3f(1.0f, 0.0f, 0.0f) * (control.sidew_move_joystick_axis / 32767.f); + speedH = v3f(sin(control.movement_direction), 0.0f, cos(control.movement_direction)); if (m_autojump) { // release autojump after a given time @@ -644,6 +649,8 @@ void LocalPlayer::applyControl(float dtime, Environment *env) else speedH = speedH.normalize() * movement_speed_walk; + speedH *= control.movement_speed; /* Apply analog input */ + // Acceleration increase f32 incH = 0.0f; // Horizontal (X, Z) f32 incV = 0.0f; // Vertical (Y) @@ -689,19 +696,21 @@ v3s16 LocalPlayer::getStandingNodePos() v3s16 LocalPlayer::getFootstepNodePos() { + v3f feet_pos = getPosition() + v3f(0.0f, m_collisionbox.MinEdge.Y, 0.0f); + // Emit swimming sound if the player is in liquid if (in_liquid_stable) - return floatToInt(getPosition(), BS); + return floatToInt(feet_pos, BS); // BS * 0.05 below the player's feet ensures a 1/16th height // nodebox is detected instead of the node below it. if (touching_ground) - return floatToInt(getPosition() - v3f(0.0f, BS * 0.05f, 0.0f), BS); + return floatToInt(feet_pos - v3f(0.0f, BS * 0.05f, 0.0f), BS); // A larger distance below is necessary for a footstep sound // when landing after a jump or fall. BS * 0.5 ensures water // sounds when swimming in 1 node deep water. - return floatToInt(getPosition() - v3f(0.0f, BS * 0.5f, 0.0f), BS); + return floatToInt(feet_pos - v3f(0.0f, BS * 0.5f, 0.0f), BS); } v3s16 LocalPlayer::getLightPosition() const @@ -841,8 +850,9 @@ void LocalPlayer::old_move(f32 dtime, Environment *env, f32 pos_max_d, pp = floatToInt(position + v3f(0.0f, BS * 0.1f, 0.0f), BS); node = map->getNode(pp, &is_valid_position); if (is_valid_position) { - in_liquid = nodemgr->get(node.getContent()).isLiquid(); - liquid_viscosity = nodemgr->get(node.getContent()).liquid_viscosity; + const ContentFeatures &cf = nodemgr->get(node.getContent()); + in_liquid = cf.liquid_move_physics; + move_resistance = cf.move_resistance; } else { in_liquid = false; } @@ -851,8 +861,9 @@ void LocalPlayer::old_move(f32 dtime, Environment *env, f32 pos_max_d, pp = floatToInt(position + v3f(0.0f, BS * 0.5f, 0.0f), BS); node = map->getNode(pp, &is_valid_position); if (is_valid_position) { - in_liquid = nodemgr->get(node.getContent()).isLiquid(); - liquid_viscosity = nodemgr->get(node.getContent()).liquid_viscosity; + const ContentFeatures &cf = nodemgr->get(node.getContent()); + in_liquid = cf.liquid_move_physics; + move_resistance = cf.move_resistance; } else { in_liquid = false; } @@ -864,7 +875,7 @@ void LocalPlayer::old_move(f32 dtime, Environment *env, f32 pos_max_d, pp = floatToInt(position + v3f(0.0f), BS); node = map->getNode(pp, &is_valid_position); if (is_valid_position) - in_liquid_stable = nodemgr->get(node.getContent()).isLiquid(); + in_liquid_stable = nodemgr->get(node.getContent()).liquid_move_physics; else in_liquid_stable = false; @@ -1133,12 +1144,8 @@ void LocalPlayer::handleAutojump(f32 dtime, Environment *env, if (m_autojump) return; - bool control_forward = control.up || - (!control.up && !control.down && - control.forw_move_joystick_axis < -0.05f); - bool could_autojump = - m_can_jump && !control.jump && !control.sneak && control_forward; + m_can_jump && !control.jump && !control.sneak && control.isMoving(); if (!could_autojump) return;