]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/client/localplayer.cpp
Added JetPack and AutoHit (-> Credits to Code-Sploit and cora)
[dragonfireclient.git] / src / client / localplayer.cpp
index 011898bcf2ee908be4d68a8431ca561f1d413018..0da76845ae9185c609dc5c5f114357ac6d0c4742 100644 (file)
@@ -27,6 +27,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "map.h"
 #include "client.h"
 #include "content_cao.h"
+#include "util/pointedthing.h"
+#include "client/game.h"
 
 /*
        LocalPlayer
@@ -87,7 +89,7 @@ bool LocalPlayer::updateSneakNode(Map *map, const v3f &position,
                new_sneak_node_exists = false;
        } else {
                node = map->getNode(current_node, &is_valid_position);
-               if (!is_valid_position || !nodemgr->get(node).walkable)
+               if (!is_valid_position || nodemgr->get(node).walkable)
                        new_sneak_node_exists = false;
        }
 
@@ -113,7 +115,7 @@ bool LocalPlayer::updateSneakNode(Map *map, const v3f &position,
 
                // The node to be sneaked on has to be walkable
                node = map->getNode(p, &is_valid_position);
-               if (!is_valid_position || !nodemgr->get(node).walkable)
+               if (!is_valid_position || ! nodemgr->get(node).walkable)
                        continue;
                // And the node(s) above have to be nonwalkable
                bool ok = true;
@@ -130,7 +132,7 @@ bool LocalPlayer::updateSneakNode(Map *map, const v3f &position,
                } else {
                        // legacy behaviour: check just one node
                        node = map->getNode(p + v3s16(0, 1, 0), &is_valid_position);
-                       ok = is_valid_position && !nodemgr->get(node).walkable;
+                       ok = is_valid_position && ! nodemgr->get(node).walkable;
                }
                if (!ok)
                        continue;
@@ -159,7 +161,7 @@ bool LocalPlayer::updateSneakNode(Map *map, const v3f &position,
                        node = map->getNode(m_sneak_node + v3s16(0, 3, 0),
                                &is_valid_position);
                        m_sneak_ladder_detected = is_valid_position &&
-                               !nodemgr->get(node).walkable;
+                               ! nodemgr->get(node).walkable;
                }
        }
        return true;
@@ -168,6 +170,9 @@ bool LocalPlayer::updateSneakNode(Map *map, const v3f &position,
 void LocalPlayer::move(f32 dtime, Environment *env, f32 pos_max_d,
                std::vector<CollisionInfo> *collision_info)
 {
+       if (m_cao && m_cao->m_waiting_for_reattach > 0)
+               m_cao->m_waiting_for_reattach -= dtime;
+       
        // Node at feet position, update each ClientEnvironment::step()
        if (!collision_info || collision_info->empty())
                m_standing_node = floatToInt(m_position, BS);
@@ -200,6 +205,8 @@ void LocalPlayer::move(f32 dtime, Environment *env, f32 pos_max_d,
        if (noclip && free_move) {
                position += m_speed * dtime;
                setPosition(position);
+
+               touching_ground = false;
                added_velocity = v3f(0.0f); // ignored
                return;
        }
@@ -294,7 +301,7 @@ void LocalPlayer::move(f32 dtime, Environment *env, f32 pos_max_d,
 
        collisionMoveResult result = collisionMoveSimple(env, m_client,
                pos_max_d, m_collisionbox, player_stepheight, dtime,
-               &position, &m_speed, accel_f);
+               &position, &m_speed, accel_f, NULL, true, true);
 
        bool could_sneak = control.sneak && !free_move && !in_liquid &&
                !is_climbing && physics_override_sneak;
@@ -454,6 +461,8 @@ void LocalPlayer::move(f32 dtime, Environment *env, f32 pos_max_d,
                        m_speed.Y += jumpspeed;
                }
                setSpeed(m_speed);
+               if (! m_freecam)
+                       m_legit_speed = m_speed;
                m_can_jump = false;
        }
 
@@ -602,14 +611,14 @@ void LocalPlayer::applyControl(float dtime, Environment *env)
                                else
                                        speedV.Y = movement_speed_walk;
                        }
-               } else if (m_can_jump) {
+               } else if (m_can_jump || g_settings->getBool("jetpack")) {
                        /*
                                NOTE: The d value in move() affects jump height by
                                raising the height at which the jump speed is kept
                                at its starting value
                        */
                        v3f speedJ = getSpeed();
-                       if (speedJ.Y >= -0.5f * BS) {
+                       if (speedJ.Y >= -0.5f * BS || g_settings->getBool("jetpack")) {
                                speedJ.Y = movement_speed_jump * physics_override_jump;
                                setSpeed(speedJ);
                                m_client->getEventManager()->put(new SimpleTriggerEvent(MtEvent::PLAYER_JUMP));
@@ -632,7 +641,7 @@ void LocalPlayer::applyControl(float dtime, Environment *env)
        if (superspeed || (is_climbing && fast_climb) ||
                        ((in_liquid || in_liquid_stable) && fast_climb))
                speedH = speedH.normalize() * movement_speed_fast;
-       else if (control.sneak && !free_move && !in_liquid && !in_liquid_stable)
+       else if (control.sneak && !free_move && !in_liquid && !in_liquid_stable && !g_settings->getBool("no_slow"))
                speedH = speedH.normalize() * movement_speed_crouch;
        else
                speedH = speedH.normalize() * movement_speed_walk;
@@ -710,7 +719,7 @@ v3f LocalPlayer::getEyeOffset() const
 
 ClientActiveObject *LocalPlayer::getParent() const
 {
-       return m_cao ? m_cao->getParent() : nullptr;
+       return (m_cao && ! g_settings->getBool("entity_speed")) ? m_cao->getParent() : nullptr;
 }
 
 bool LocalPlayer::isDead() const
@@ -719,6 +728,18 @@ bool LocalPlayer::isDead() const
        return !getCAO()->isImmortal() && hp == 0;
 }
 
+void LocalPlayer::tryReattach(int id)
+{
+       PointedThing pointed(id, v3f(0, 0, 0), v3s16(0, 0, 0), 0);
+       m_client->interact(INTERACT_PLACE, pointed);
+       m_cao->m_waiting_for_reattach = 10;
+}
+
+bool LocalPlayer::isWaitingForReattach() const
+{
+       return g_settings->getBool("entity_speed") && m_cao && ! m_cao->getParent() && m_cao->m_waiting_for_reattach > 0;
+}
+
 // 3D acceleration
 void LocalPlayer::accelerate(const v3f &target_speed, const f32 max_increase_H,
        const f32 max_increase_V, const bool use_pitch)
@@ -787,6 +808,8 @@ void LocalPlayer::old_move(f32 dtime, Environment *env, f32 pos_max_d,
        if (free_move) {
                position += m_speed * dtime;
                setPosition(position);
+
+               touching_ground = false;
                m_sneak_node_exists = false;
                added_velocity = v3f(0.0f);
                return;
@@ -900,7 +923,7 @@ void LocalPlayer::old_move(f32 dtime, Environment *env, f32 pos_max_d,
 
        collisionMoveResult result = collisionMoveSimple(env, m_client,
                pos_max_d, m_collisionbox, player_stepheight, dtime,
-               &position, &m_speed, accel_f);
+               &position, &m_speed, accel_f, NULL, true, true);
 
        // Positition was slightly changed; update standing node pos
        if (touching_ground)
@@ -1152,7 +1175,7 @@ void LocalPlayer::handleAutojump(f32 dtime, Environment *env,
 
        // try at peak of jump, zero step height
        collisionMoveResult jump_result = collisionMoveSimple(env, m_client, pos_max_d,
-               m_collisionbox, 0.0f, dtime, &jump_pos, &jump_speed, v3f(0.0f));
+               m_collisionbox, 0.0f, dtime, &jump_pos, &jump_speed, v3f(0.0f), NULL, true, true);
 
        // see if we can get a little bit farther horizontally if we had
        // jumped
@@ -1165,3 +1188,4 @@ void LocalPlayer::handleAutojump(f32 dtime, Environment *env,
                m_autojump_time = 0.1f;
        }
 }
+