]> git.lizzy.rs Git - dragonfireclient.git/commitdiff
Added EntitySpeed
authorElias Fleckenstein <eliasfleckenstein@web.de>
Mon, 20 Jul 2020 14:43:11 +0000 (16:43 +0200)
committerElias Fleckenstein <eliasfleckenstein@web.de>
Mon, 20 Jul 2020 14:43:11 +0000 (16:43 +0200)
13 files changed:
builtin/client/util.lua
builtin/settingtypes.txt
clientmods/warp/init.lua
src/client/client.cpp
src/client/client.h
src/client/content_cao.cpp
src/client/content_cao.h
src/client/game.cpp
src/client/game.h
src/client/localplayer.cpp
src/client/localplayer.h
src/defaultsettings.cpp
src/network/clientpackethandler.cpp

index 8bcac23b50221084474b1f5ddaaa351d1a49ddb8..8956092885de844485a37a75968196134d450a65 100644 (file)
@@ -20,5 +20,3 @@ function core.parse_relative_pos(param)
        if success then pos = vector.round(vector.add(core.localplayer:get_pos(), pos)) end
        return success, pos
 end 
-
-core.anticheat_protection = minetest.settings:get_bool("anticheat_protection") ~= false
index db0b1aa24ec222db5a52b5d120e89ffc67a28c94..9c4c57f567f021b4716547bbe3a2e94a10290893 100644 (file)
@@ -2251,9 +2251,6 @@ hud_flags_bypass (HUDBypass) bool true
 
 antiknockback (AntiKnockback) bool false
 
-# Set to true if AntiCheat is enabled on server
-anticheat_protection (AnticheatProtection) bool true
-
 autorespawn (AutoRespawn) bool false
 
 show_cheat_hud (CheatHUD) bool true
index d74e023c323f5cea117c4779f9ccf8d2b1b4fc29..67f22a90123fb81727e45eece9ff6a58eb0c75e9 100644 (file)
@@ -45,25 +45,34 @@ minetest.register_chatcommand("deletewarp", {
        func = warp.delete,
 })
 
+local function do_warp(param)
+       if param == "" then return false, "Missing parameter." end
+       local success, pos = minetest.parse_pos(param)
+       if not success then
+               local msg
+               success, msg, pos = warp.get(param)
+               if not success then
+                       return false, msg
+               end
+       end
+       minetest.localplayer:set_pos(pos)
+       return true, "Warped to " .. minetest.pos_to_string(pos)
+end
+
 minetest.register_chatcommand("warp", {
        params = "<pos>|<warp>",
-       description = "Warp to a set warp or a position. " .. (core.anticheat_protection and "You have to be attached for this to work (sitting in a boat or similar) and you will be disconnected and have to rejoin." or ""),
+       description = "Warp to a set warp or a position.",
+       func = do_warp
+})
+
+minetest.register_chatcommand("warpandexit", {
+       params = "<pos>|<warp>",
+       description = "Warp to a set warp or a position and exit.",
        func = function(param)
-               if param == "" then return false, "Missing parameter." end
-               local success, pos = minetest.parse_pos(param)
-               if not success then
-                       local msg
-                       success, msg, pos = warp.get(param)
-                       if not success then
-                               return false, msg
-                       end
-               end
-               minetest.localplayer:set_pos(pos)
-               if core.anticheat_protection then
+               local s, m = do_warp(param)
+               if s then
                        minetest.disconnect()
                end
-               return true, "Warped to " .. minetest.pos_to_string(pos)
+               return s,m 
        end
 })
-
-
index e3a790a56a375cfa4f3e570495f36443d18895ed..d2330ecae05a0c71e26b242d4d71db946b96da8b 100644 (file)
@@ -1290,7 +1290,7 @@ void Client::sendReady()
        Send(&pkt);
 }
 
-void Client::sendPlayerPos()
+void Client::sendPlayerPos(v3f pos)
 {
        LocalPlayer *player = m_env.getLocalPlayer();
        if (!player)
@@ -1308,7 +1308,7 @@ void Client::sendPlayerPos()
        //      return;
 
        if (
-                       player->last_position     == player->getPosition() &&
+                       player->last_position     == pos &&
                        player->last_speed        == player->getSpeed()    &&
                        player->last_pitch        == player->getPitch()    &&
                        player->last_yaw          == player->getYaw()      &&
@@ -1317,7 +1317,7 @@ void Client::sendPlayerPos()
                        player->last_wanted_range == wanted_range)
                return;
 
-       player->last_position     = player->getPosition();
+       player->last_position     = pos;
        player->last_speed        = player->getSpeed();
        player->last_pitch        = player->getPitch();
        player->last_yaw          = player->getYaw();
@@ -1332,6 +1332,14 @@ void Client::sendPlayerPos()
        Send(&pkt);
 }
 
+void Client::sendPlayerPos()
+{
+       LocalPlayer *player = m_env.getLocalPlayer();
+       if (!player)
+               return;
+       sendPlayerPos(player->getPosition());
+}
+
 void Client::removeNode(v3s16 p)
 {
        std::map<v3s16, MapBlock*> modified_blocks;
index cdf5168861e9f02d57d44bcc09e7f2feb1f977c3..c7316fd91dbfff293b2c7e4dade9390b9c8d3eab 100644 (file)
@@ -437,6 +437,7 @@ class Client : public con::PeerHandler, public InventoryManager, public IGameDef
                return m_env.getLocalPlayer()->formspec_prepend;
        }
        
+       void sendPlayerPos(v3f pos);
        void sendPlayerPos();
        MeshUpdateThread m_mesh_update_thread;
        
index db78f7a65509edb744c6fd1fdd2f414c2dec52ed..5f60c33753b687e933f30764b64d2ad96262097a 100644 (file)
@@ -472,13 +472,14 @@ void GenericCAO::setAttachment(int parent_id, const std::string &bone, v3f posit
        ClientActiveObject *parent = m_env->getActiveObject(parent_id);
 
        if (parent_id != old_parent) {
+               if (old_parent)
+                       m_waiting_for_reattach = 10;
                if (auto *o = m_env->getActiveObject(old_parent))
                        o->removeAttachmentChild(m_id);
                if (parent)
                        parent->addAttachmentChild(m_id);
        }
-
-
+       
        updateAttachments();
 }
 
index 974ff9a1eecfd376f52d80639224024dec0468ae..88aa4870c008a527e9c4773dd0a5b0eeb05d0bef 100644 (file)
@@ -224,6 +224,7 @@ class GenericCAO : public ClientActiveObject
        void addAttachmentChild(int child_id);
        void removeAttachmentChild(int child_id);
        ClientActiveObject *getParent() const;
+       int getParentId() const { return m_attachment_parent_id; }
        const std::unordered_set<int> &getAttachmentChildIds() const
        { return m_attachment_child_ids; }
        void updateAttachments();
@@ -275,4 +276,6 @@ class GenericCAO : public ClientActiveObject
        {
                return m_prop.infotext;
        }
+       
+       float m_waiting_for_reattach;
 };
index 237d3539c8e733c6997f20a69331e3901d7a8f6e..f1ce4aa6029332a4e2f26da0bbf80647d9f059d9 100644 (file)
@@ -2417,27 +2417,9 @@ PointedThing Game::updatePointedThing(
        ClientMap &map = env.getClientMap();
        const NodeDefManager *nodedef = map.getNodeDefManager();
 
-       if (g_settings->getBool("killaura")) {
-               std::vector<DistanceSortedActiveObject> allObjects;
-               env.getActiveObjects(shootline.start, shootline.getLength() + 10.0f, allObjects);
-               const v3f line_vector = shootline.getVector();
-               for (const auto &allObject : allObjects) {
-                       ClientActiveObject *obj = allObject.obj;
-                       s16 id = obj->getId();
-                       v3f pos = obj->getPosition();
-                       v3f intersection;
-                       v3s16 normal;
-                       aabb3f selection_box;
-                       if (! obj->getSelectionBox(&selection_box))
-                               continue;
-                       aabb3f offsetted_box(selection_box.MinEdge + pos, selection_box.MaxEdge + pos);
-                       boxLineCollision(offsetted_box, shootline.start, line_vector, &intersection, &normal);
-                       PointedThing pointed(id, intersection, normal, (intersection - shootline.start).getLengthSQ());
-                       client->interact(INTERACT_START_DIGGING, pointed);
-                       break;
-               }
-       }
-       
+       if (g_settings->getBool("killaura"))
+               handleKillaura(shootline.start, shootline.getLength());
+               
        runData.selected_object = NULL;
        hud->pointing_at_object = false;
        RaycastState s(shootline, look_for_object, liquids_pointable);
@@ -2514,6 +2496,22 @@ PointedThing Game::updatePointedThing(
        return result;
 }
 
+void Game::handleKillaura(v3f origin, f32 max_d)
+{
+       ClientEnvironment &env = client->getEnv();
+       std::vector<DistanceSortedActiveObject> allObjects;
+       env.getActiveObjects(origin, max_d, allObjects);
+       for (const auto &allObject : allObjects) {
+               ClientActiveObject *obj = allObject.obj;
+               s16 id = obj->getId();
+               aabb3f selection_box;
+               if (! obj->getSelectionBox(&selection_box))
+                       continue;
+               PointedThing pointed(id, v3f(0,0,0), v3s16(0,0,0), 0);
+               client->interact(INTERACT_START_DIGGING, pointed);
+               break;
+       }
+}
 
 void Game::handlePointingAtNothing(const ItemStack &playerItem)
 {
index 042375f4d1dd34f7788eda491f8dd87c7c9d8b75..af34fb05621f7fad77a8de93d72b074fd404cc11 100644 (file)
@@ -771,6 +771,7 @@ class Game {
        PointedThing updatePointedThing(
                        const core::line3d<f32> &shootline, bool liquids_pointable,
                        bool look_for_object, const v3s16 &camera_offset);
+       void handleKillaura(v3f origin, f32 max_d);
        void handlePointingAtNothing(const ItemStack &playerItem);
        void handlePointingAtNode(const PointedThing &pointed,
                        const ItemStack &selected_item, const ItemStack &hand_item, f32 dtime);
index 1e7040d57d756de2d9269283e0cfb522bb99e6a2..d84238008bdffe073db8b46118fa444d56851092 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
@@ -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);
@@ -712,7 +717,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
@@ -721,6 +726,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)
index 345aec9d99e10321a3634a57899cedc50f792a79..dc3e7611889ac71414faa65b1dc873dd7d40bca0 100644 (file)
@@ -157,7 +157,11 @@ class LocalPlayer : public Player
        {
                added_velocity += vel;
        }
-
+       
+       void tryReattach(int id);
+       
+       bool isWaitingForReattach() const;
+       
 private:
        void accelerate(const v3f &target_speed, const f32 max_increase_H,
                const f32 max_increase_V, const bool use_pitch);
index d7399fdf66a32131c975e5c86607f5da478de64b..3909fefe8c9525ff8f8da5de6af0773f05ca4154 100644 (file)
@@ -76,6 +76,7 @@ void set_default_settings(Settings *settings)
        settings->setDefault("increase_tool_range", "true");
        settings->setDefault("hud_flags_bypass", "true");
        settings->setDefault("antiknockback", "false");
+       settings->setDefault("entity_speed", "false");
        
        // Keymap
        settings->setDefault("remote_port", "30000");
index 5ca481880ffd071558e14337a3e2df772ad965bf..9e0b35f5362f54ddf8f6cbf5450f8fd5b1eb0916 100644 (file)
@@ -33,6 +33,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "server.h"
 #include "util/strfnd.h"
 #include "client/clientevent.h"
+#include "client/content_cao.h"
 #include "client/sound.h"
 #include "network/clientopcodes.h"
 #include "network/connection.h"
@@ -448,7 +449,10 @@ void Client::handleCommand_ActiveObjectRemoveAdd(NetworkPacket* pkt)
                        string initialization data
                }
        */
-
+       
+       LocalPlayer *player = m_env.getLocalPlayer();
+       bool try_reattach = player && player->isWaitingForReattach();   
+       
        try {
                u8 type;
                u16 removed_count, added_count, id;
@@ -467,6 +471,8 @@ void Client::handleCommand_ActiveObjectRemoveAdd(NetworkPacket* pkt)
                for (u16 i = 0; i < added_count; i++) {
                        *pkt >> id >> type;
                        m_env.addActiveObject(id, type, pkt->readLongString());
+                       if (try_reattach)
+                               player->tryReattach(id);
                }
        } catch (PacketError &e) {
                infostream << "handleCommand_ActiveObjectRemoveAdd: " << e.what()
@@ -589,10 +595,13 @@ void Client::handleCommand_Breath(NetworkPacket* pkt)
 }
 
 void Client::handleCommand_MovePlayer(NetworkPacket* pkt)
-{
+{              
        LocalPlayer *player = m_env.getLocalPlayer();
        assert(player != NULL);
 
+       if ((player->getCAO() && player->getCAO()->getParentId()) || player->isWaitingForReattach())
+               return;
+       
        v3f pos;
        f32 pitch, yaw;