diff options
Diffstat (limited to 'src/client/client.cpp')
-rw-r--r-- | src/client/client.cpp | 66 |
1 files changed, 48 insertions, 18 deletions
diff --git a/src/client/client.cpp b/src/client/client.cpp index d81ee434e..7337229fb 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -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" @@ -103,6 +104,7 @@ Client::Client( GameUI *game_ui, ELoginRegister allow_login_or_register ): + m_mesh_update_thread(this), m_tsrc(tsrc), m_shsrc(shsrc), m_itemdef(itemdef), @@ -110,7 +112,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 @@ -226,6 +227,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()); @@ -486,7 +489,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 @@ -964,8 +967,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(); @@ -1306,7 +1309,7 @@ void Client::sendReady() Send(&pkt); } -void Client::sendPlayerPos() +void Client::sendPlayerPos(v3f pos) { LocalPlayer *player = m_env.getLocalPlayer(); if (!player) @@ -1325,8 +1328,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 && @@ -1334,8 +1337,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; @@ -1349,6 +1352,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); @@ -1486,6 +1497,7 @@ Inventory* Client::getInventory(const InventoryLocation &loc) case InventoryLocation::UNDEFINED: {} break; + case InventoryLocation::PLAYER: case InventoryLocation::CURRENT_PLAYER: { LocalPlayer *player = m_env.getLocalPlayer(); @@ -1493,15 +1505,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); @@ -1665,6 +1668,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(), @@ -1890,10 +1912,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; |