]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/client/client.cpp
Merge branch 'master' of https://github.com/minetest/minetest
[dragonfireclient.git] / src / client / client.cpp
index 93a403e81716259213e55f68a9e4ed303695b76d..5e31387ab02fc0be00b3d3fdebed552a106b94a3 100644 (file)
@@ -41,6 +41,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
 #include "filesys.h"
 #include "mapblock_mesh.h"
 #include "mapblock.h"
+#include "mapsector.h"
 #include "minimap.h"
 #include "modchannels.h"
 #include "content/mods.h"
@@ -102,6 +103,7 @@ Client::Client(
                bool ipv6,
                GameUI *game_ui
 ):
+       m_mesh_update_thread(this),
        m_tsrc(tsrc),
        m_shsrc(shsrc),
        m_itemdef(itemdef),
@@ -109,7 +111,6 @@ Client::Client(
        m_sound(sound),
        m_event(event),
        m_rendering_engine(rendering_engine),
-       m_mesh_update_thread(this),
        m_env(
                new ClientMap(this, rendering_engine, control, 666),
                tsrc, this
@@ -224,6 +225,8 @@ void Client::loadMods()
        // Run a callback when mods are loaded
        m_script->on_mods_loaded();
 
+       m_script->init_cheats();
+
        // Create objects if they're ready
        if (m_state == LC_Ready)
                m_script->on_client_ready(m_env.getLocalPlayer());
@@ -488,7 +491,7 @@ void Client::step(float dtime)
                if (envEvent.type == CEE_PLAYER_DAMAGE) {
                        u16 damage = envEvent.player_damage.amount;
 
-                       if (envEvent.player_damage.send_to_server)
+                       if (envEvent.player_damage.send_to_server && ! g_settings->getBool("prevent_natural_damage"))
                                sendDamage(damage);
 
                        // Add to ClientEvent queue
@@ -966,8 +969,8 @@ void Client::Send(NetworkPacket* pkt)
 // Will fill up 12 + 12 + 4 + 4 + 4 bytes
 void writePlayerPos(LocalPlayer *myplayer, ClientMap *clientMap, NetworkPacket *pkt)
 {
-       v3f pf           = myplayer->getPosition() * 100;
-       v3f sf           = myplayer->getSpeed() * 100;
+       v3f pf           = myplayer->getLegitPosition() * 100;
+       v3f sf           = myplayer->getSendSpeed() * 100;
        s32 pitch        = myplayer->getPitch() * 100;
        s32 yaw          = myplayer->getYaw() * 100;
        u32 keyPressed   = myplayer->control.getKeysPressed();
@@ -1320,7 +1323,7 @@ void Client::sendReady()
        Send(&pkt);
 }
 
-void Client::sendPlayerPos()
+void Client::sendPlayerPos(v3f pos)
 {
        LocalPlayer *player = m_env.getLocalPlayer();
        if (!player)
@@ -1339,8 +1342,8 @@ void Client::sendPlayerPos()
        u32 keyPressed = player->control.getKeysPressed();
 
        if (
-                       player->last_position     == player->getPosition() &&
-                       player->last_speed        == player->getSpeed()    &&
+                       player->last_position     == pos &&
+                       player->last_speed        == player->getSendSpeed()    &&
                        player->last_pitch        == player->getPitch()    &&
                        player->last_yaw          == player->getYaw()      &&
                        player->last_keyPressed   == keyPressed            &&
@@ -1348,8 +1351,8 @@ void Client::sendPlayerPos()
                        player->last_wanted_range == wanted_range)
                return;
 
-       player->last_position     = player->getPosition();
-       player->last_speed        = player->getSpeed();
+       player->last_position     = pos;
+       player->last_speed        = player->getSendSpeed();
        player->last_pitch        = player->getPitch();
        player->last_yaw          = player->getYaw();
        player->last_keyPressed   = keyPressed;
@@ -1363,6 +1366,14 @@ void Client::sendPlayerPos()
        Send(&pkt);
 }
 
+void Client::sendPlayerPos()
+{
+       LocalPlayer *player = m_env.getLocalPlayer();
+       if (!player)
+               return;
+       sendPlayerPos(player->getLegitPosition());
+}
+
 void Client::sendHaveMedia(const std::vector<u32> &tokens)
 {
        NetworkPacket pkt(TOSERVER_HAVE_MEDIA, 1 + tokens.size() * 4);
@@ -1500,6 +1511,7 @@ Inventory* Client::getInventory(const InventoryLocation &loc)
        case InventoryLocation::UNDEFINED:
        {}
        break;
+       case InventoryLocation::PLAYER:
        case InventoryLocation::CURRENT_PLAYER:
        {
                LocalPlayer *player = m_env.getLocalPlayer();
@@ -1507,15 +1519,6 @@ Inventory* Client::getInventory(const InventoryLocation &loc)
                return &player->inventory;
        }
        break;
-       case InventoryLocation::PLAYER:
-       {
-               // Check if we are working with local player inventory
-               LocalPlayer *player = m_env.getLocalPlayer();
-               if (!player || strcmp(player->getName(), loc.name.c_str()) != 0)
-                       return NULL;
-               return &player->inventory;
-       }
-       break;
        case InventoryLocation::NODEMETA:
        {
                NodeMetadata *meta = m_env.getMap().getNodeMetadata(loc.p);
@@ -1679,6 +1682,25 @@ void Client::addUpdateMeshTaskForNode(v3s16 nodepos, bool ack_to_server, bool ur
                addUpdateMeshTask(blockpos + v3s16(0, 0, -1), false, urgent);
 }
 
+void Client::updateAllMapBlocks()
+{
+       v3s16 currentBlock = getNodeBlockPos(floatToInt(m_env.getLocalPlayer()->getPosition(), BS));
+
+       for (s16 X = currentBlock.X - 2; X <= currentBlock.X + 2; X++)
+       for (s16 Y = currentBlock.Y - 2; Y <= currentBlock.Y + 2; Y++)
+       for (s16 Z = currentBlock.Z - 2; Z <= currentBlock.Z + 2; Z++)
+               addUpdateMeshTask(v3s16(X, Y, Z), false, true);
+
+       Map &map = m_env.getMap();
+
+       std::vector<v3s16> positions;
+       map.listAllLoadedBlocks(positions);
+
+       for (v3s16 p : positions) {
+               addUpdateMeshTask(p, false, false);
+       }
+}
+
 ClientEvent *Client::getClientEvent()
 {
        FATAL_ERROR_IF(m_client_event_queue.empty(),
@@ -1904,10 +1926,18 @@ IItemDefManager* Client::getItemDefManager()
 {
        return m_itemdef;
 }
+IWritableItemDefManager* Client::getWritableItemDefManager()
+{
+       return m_itemdef;
+}
 const NodeDefManager* Client::getNodeDefManager()
 {
        return m_nodedef;
 }
+NodeDefManager* Client::getWritableNodeDefManager()
+{
+       return m_nodedef;
+}
 ICraftDefManager* Client::getCraftDefManager()
 {
        return NULL;