diff --git a/Minecraft.Client/AchievementScreen.h b/Minecraft.Client/AchievementScreen.h index 3c4412e3..bc7e658e 100644 --- a/Minecraft.Client/AchievementScreen.h +++ b/Minecraft.Client/AchievementScreen.h @@ -6,22 +6,22 @@ class StatsCounter; class AchievementScreen : public Screen { private: - static const int BIGMAP_X = 16; - static const int BIGMAP_Y = 17; - static const int BIGMAP_WIDTH = 224; - static const int BIGMAP_HEIGHT = 155; + static constexpr int BIGMAP_X = 16; + static constexpr int BIGMAP_Y = 17; + static constexpr int BIGMAP_WIDTH = 224; + static constexpr int BIGMAP_HEIGHT = 155; // number of pixels per achievement - static const int ACHIEVEMENT_COORD_SCALE = 24; - static const int EDGE_VALUE_X = Achievements::ACHIEVEMENT_WIDTH_POSITION * ACHIEVEMENT_COORD_SCALE; - static const int EDGE_VALUE_Y = Achievements::ACHIEVEMENT_HEIGHT_POSITION * ACHIEVEMENT_COORD_SCALE; + static constexpr int ACHIEVEMENT_COORD_SCALE = 24; + static constexpr int EDGE_VALUE_X = Achievements::ACHIEVEMENT_WIDTH_POSITION * ACHIEVEMENT_COORD_SCALE; + static constexpr int EDGE_VALUE_Y = Achievements::ACHIEVEMENT_HEIGHT_POSITION * ACHIEVEMENT_COORD_SCALE; int xMin; int yMin; int xMax; int yMax; - static const int MAX_BG_TILE_Y = (EDGE_VALUE_Y * 2 - 1) / 16; + static constexpr int MAX_BG_TILE_Y = (EDGE_VALUE_Y * 2 - 1) / 16; protected: int imageWidth; diff --git a/Minecraft.Client/ClientConnection.cpp b/Minecraft.Client/ClientConnection.cpp index b837087b..3edc52ed 100644 --- a/Minecraft.Client/ClientConnection.cpp +++ b/Minecraft.Client/ClientConnection.cpp @@ -795,7 +795,7 @@ void ClientConnection::handleSetEntityMotion(shared_ptr p { if (!shouldProcessForEntity(packet->id)) { - if (minecraft->localplayers[m_userIndex] == NULL || + if (minecraft->localplayers[m_userIndex] == nullptr || packet->id != minecraft->localplayers[m_userIndex]->entityId) return; } @@ -1186,7 +1186,7 @@ void ClientConnection::handleMovePlayer(shared_ptr packet) // 4J Added void ClientConnection::handleChunkVisibilityArea(shared_ptr packet) { - if (level == NULL) return; + if (level == nullptr) return; for(int z = packet->m_minZ; z <= packet->m_maxZ; ++z) { for(int x = packet->m_minX; x <= packet->m_maxX; ++x) @@ -1199,7 +1199,7 @@ void ClientConnection::handleChunkVisibilityArea(shared_ptr packet) { - if (level == NULL) return; + if (level == nullptr) return; if (packet->visible) { m_visibleChunks.insert(chunkKey(packet->x, packet->z)); @@ -2996,7 +2996,7 @@ void ClientConnection::handleExplosion(shared_ptr packet) // Per-player knockback — each connection applies to its own local player //app.DebugPrintf("Adding knockback (%f,%f,%f) for player %d\n", packet->getKnockbackX(), packet->getKnockbackY(), packet->getKnockbackZ(), m_userIndex); - if (minecraft->localplayers[m_userIndex] == NULL) + if (minecraft->localplayers[m_userIndex] == nullptr) return; minecraft->localplayers[m_userIndex]->xd += packet->getKnockbackX(); minecraft->localplayers[m_userIndex]->yd += packet->getKnockbackY(); @@ -3007,7 +3007,7 @@ void ClientConnection::handleContainerOpen(shared_ptr packe { bool failed = false; shared_ptr player = minecraft->localplayers[m_userIndex]; - if (player == NULL) + if (player == nullptr) return; switch(packet->type) { diff --git a/Minecraft.Client/Common/C4JMemoryPool.h b/Minecraft.Client/Common/C4JMemoryPool.h index e1e795ec..9e9b4db9 100644 --- a/Minecraft.Client/Common/C4JMemoryPool.h +++ b/Minecraft.Client/Common/C4JMemoryPool.h @@ -36,8 +36,8 @@ public: m_sizeOfEachBlock = 0; m_numFreeBlocks = 0; m_numInitialized = 0; - m_memStart = NULL; - m_memEnd = NULL; + m_memStart = nullptr; + m_memEnd = nullptr; m_next = 0; } @@ -65,7 +65,7 @@ public: void DestroyPool() { delete[] m_memStart; - m_memStart = NULL; + m_memStart = nullptr; } uchar* AddrFromIndex(uint i) const @@ -89,7 +89,7 @@ public: *p = m_numInitialized + 1; m_numInitialized++; } - void* ret = NULL; + void* ret = nullptr; if ( m_numFreeBlocks > 0 ) { ret = (void*)m_next; @@ -100,7 +100,7 @@ public: } else { - m_next = NULL; + m_next = nullptr; } } // LeaveCriticalSection(&m_CS); @@ -115,7 +115,7 @@ public: return; } // EnterCriticalSection(&m_CS); - if (m_next != NULL) + if (m_next != nullptr) { (*(uint*)ptr) = IndexFromAddr( m_next ); m_next = (uchar*)ptr; diff --git a/Minecraft.Client/CreativeMode.cpp b/Minecraft.Client/CreativeMode.cpp index 48342ebc..cf09cba9 100644 --- a/Minecraft.Client/CreativeMode.cpp +++ b/Minecraft.Client/CreativeMode.cpp @@ -41,7 +41,7 @@ void CreativeMode::adjustPlayer(shared_ptr player) for (int i = 0; i < 9; i++) { - if (player->inventory->items[i] == NULL) + if (player->inventory->items[i] == nullptr) { player->inventory->items[i] = shared_ptr( new ItemInstance(User::allowedTiles[i]) ); } @@ -68,7 +68,7 @@ bool CreativeMode::useItemOn(shared_ptr player, Level *level, shared_ptr { if (Tile::tiles[t]->use(level, x, y, z, player)) return true; } - if (item == NULL) return false; + if (item == nullptr) return false; int aux = item->getAuxValue(); int count = item->count; bool success = item->useOn(player, level, x, y, z, face); diff --git a/Minecraft.Client/CreativeMode.h b/Minecraft.Client/CreativeMode.h index 10b27a53..87c04b7e 100644 --- a/Minecraft.Client/CreativeMode.h +++ b/Minecraft.Client/CreativeMode.h @@ -13,7 +13,7 @@ public: static void disableCreativeForPlayer(shared_ptr player); virtual void adjustPlayer(shared_ptr player); static void creativeDestroyBlock(Minecraft *minecraft, GameMode *gameMode, int x, int y, int z, int face); - virtual bool useItemOn(shared_ptr player, Level *level, shared_ptr item, int x, int y, int z, int face, bool bTestUseOnOnly=false, bool *pbUsedItem = NULL); + virtual bool useItemOn(shared_ptr player, Level *level, shared_ptr item, int x, int y, int z, int face, bool bTestUseOnOnly=false, bool *pbUsedItem = nullptr); virtual void startDestroyBlock(int x, int y, int z, int face); virtual void continueDestroyBlock(int x, int y, int z, int face); virtual void stopDestroyBlock(); diff --git a/Minecraft.Client/GameMode.cpp b/Minecraft.Client/GameMode.cpp index a11d6c07..7650c2e6 100644 --- a/Minecraft.Client/GameMode.cpp +++ b/Minecraft.Client/GameMode.cpp @@ -24,7 +24,7 @@ bool GameMode::destroyBlock(int x, int y, int z, int face) { Level *level = minecraft->level; Tile *oldTile = Tile::tiles[level->getTile(x, y, z)]; - if (oldTile == NULL) return false; + if (oldTile == nullptr) return false; // 4J - Let the rendering side of thing know we are about to destroy the tile, so we can synchronise collision with async render data upates. minecraft->levelRenderer->destroyedTileManager->destroyingTileAt(level, x, y, z); @@ -35,7 +35,7 @@ bool GameMode::destroyBlock(int x, int y, int z, int face) level->getChunkAt(x,z)->recalcHeightmapOnly(); bool changed = level->setTile(x, y, z, 0); - if (oldTile != NULL && changed) + if (oldTile != nullptr && changed) { oldTile->destroy(level, x, y, z, data); } @@ -95,7 +95,7 @@ void GameMode::adjustPlayer(shared_ptr player) // } // } // -// if (item == NULL) return false; +// if (item == nullptr) return false; // return item->useOn(player, level, x, y, z, face, bTestUseOnOnly); //} diff --git a/Minecraft.Client/GameMode.h b/Minecraft.Client/GameMode.h index ab9ec9d1..6a120f02 100644 --- a/Minecraft.Client/GameMode.h +++ b/Minecraft.Client/GameMode.h @@ -30,7 +30,7 @@ public: virtual bool canHurtPlayer() = 0; virtual void adjustPlayer(shared_ptr player); virtual bool useItem(shared_ptr player, Level *level, shared_ptr item, bool bTestUseOnly=false); - virtual bool useItemOn(shared_ptr player, Level *level, shared_ptr item, int x, int y, int z, int face, bool bTestUseOnOnly=false, bool *pbUsedItem = NULL) = 0; + virtual bool useItemOn(shared_ptr player, Level *level, shared_ptr item, int x, int y, int z, int face, bool bTestUseOnOnly=false, bool *pbUsedItem = nullptr) = 0; virtual shared_ptr createPlayer(Level *level); virtual bool interact(shared_ptr player, shared_ptr entity); @@ -55,5 +55,5 @@ public: // 4J Stu - Added for tutorial checks virtual bool isInputAllowed(int mapping) { return true; } virtual bool isTutorial() { return false; } - virtual Tutorial *getTutorial() { return NULL; } + virtual Tutorial *getTutorial() { return nullptr; } }; diff --git a/Minecraft.Client/LevelRenderer.h b/Minecraft.Client/LevelRenderer.h index 37e0b813..e3a796eb 100644 --- a/Minecraft.Client/LevelRenderer.h +++ b/Minecraft.Client/LevelRenderer.h @@ -45,23 +45,23 @@ private: static ResourceLocation END_SKY_LOCATION; public: - static const int CHUNK_XZSIZE = 16; + static constexpr int CHUNK_XZSIZE = 16; #ifdef _LARGE_WORLDS - static const int CHUNK_SIZE = 16; + static constexpr int CHUNK_SIZE = 16; #else - static const int CHUNK_SIZE = 16; + static constexpr int CHUNK_SIZE = 16; #endif - static const int CHUNK_Y_COUNT = Level::maxBuildHeight / CHUNK_SIZE; + static constexpr int CHUNK_Y_COUNT = Level::maxBuildHeight / CHUNK_SIZE; #if defined _WINDOWS64 - static const int MAX_COMMANDBUFFER_ALLOCATIONS = 2047 * 1024 * 1024; // Changed to 2047. 4J had set to 512. + static constexpr int MAX_COMMANDBUFFER_ALLOCATIONS = 2047 * 1024 * 1024; // Changed to 2047. 4J had set to 512. #elif defined _XBOX_ONE - static const int MAX_COMMANDBUFFER_ALLOCATIONS = 512 * 1024 * 1024; // 4J - added + static constexpr int MAX_COMMANDBUFFER_ALLOCATIONS = 512 * 1024 * 1024; // 4J - added #elif defined __ORBIS__ - static const int MAX_COMMANDBUFFER_ALLOCATIONS = 448 * 1024 * 1024; // 4J - added - hard limit is 512 so giving a lot of headroom here for fragmentation (have seen 16MB lost to fragmentation in multiplayer crash dump before) + static constexpr int MAX_COMMANDBUFFER_ALLOCATIONS = 448 * 1024 * 1024; // 4J - added - hard limit is 512 so giving a lot of headroom here for fragmentation (have seen 16MB lost to fragmentation in multiplayer crash dump before) #elif defined __PS3__ - static const int MAX_COMMANDBUFFER_ALLOCATIONS = 110 * 1024 * 1024; // 4J - added + static constexpr int MAX_COMMANDBUFFER_ALLOCATIONS = 110 * 1024 * 1024; // 4J - added #else - static const int MAX_COMMANDBUFFER_ALLOCATIONS = 55 * 1024 * 1024; // 4J - added + static constexpr int MAX_COMMANDBUFFER_ALLOCATIONS = 55 * 1024 * 1024; // 4J - added #endif public: LevelRenderer(Minecraft *mc, Textures *textures); @@ -221,10 +221,10 @@ public: // This is the TOTAL area of columns of chunks to be allocated for render round the players. So for one player, it would be a region of // sqrt(PLAYER_RENDER_AREA) x sqrt(PLAYER_RENDER_AREA) #ifdef _LARGE_WORLDS - static const int PLAYER_VIEW_DISTANCE = 18; // Straight line distance from centre to extent of visible world - static const int PLAYER_RENDER_AREA = (PLAYER_VIEW_DISTANCE * PLAYER_VIEW_DISTANCE * 4); + static constexpr int PLAYER_VIEW_DISTANCE = 18; // Straight line distance from centre to extent of visible world + static constexpr int PLAYER_RENDER_AREA = (PLAYER_VIEW_DISTANCE * PLAYER_VIEW_DISTANCE * 4); #else - static const int PLAYER_RENDER_AREA = 400; + static constexpr int PLAYER_RENDER_AREA = 400; #endif static int getDimensionIndexFromId(int id); @@ -275,8 +275,8 @@ public: static const int FORCE_DIRTY_CHUNK_CHECK_PERIOD_MS = 125; // decreased from 250 to 125 - updated by detectiveren #ifdef _LARGE_WORLDS - static const int MAX_CONCURRENT_CHUNK_REBUILDS = 8; // increased from 4 to 8 - updated by detectiveren - static const int MAX_CHUNK_REBUILD_THREADS = MAX_CONCURRENT_CHUNK_REBUILDS - 1; + static constexpr int MAX_CONCURRENT_CHUNK_REBUILDS = 8; // increased from 4 to 8 - updated by detectiveren + static constexpr int MAX_CHUNK_REBUILD_THREADS = MAX_CONCURRENT_CHUNK_REBUILDS - 1; static Chunk permaChunk[MAX_CONCURRENT_CHUNK_REBUILDS]; static C4JThread *rebuildThreads[MAX_CHUNK_REBUILD_THREADS]; static C4JThread::EventArray *s_rebuildCompleteEvents; diff --git a/Minecraft.Client/LocalPlayer.h b/Minecraft.Client/LocalPlayer.h index 2198c489..442e7ebd 100644 --- a/Minecraft.Client/LocalPlayer.h +++ b/Minecraft.Client/LocalPlayer.h @@ -21,7 +21,7 @@ using namespace std; class LocalPlayer : public Player { public: - static const int SPRINT_DURATION = 20 * 30; + static constexpr int SPRINT_DURATION = 20 * 30; eINSTANCEOF GetType() { return eTYPE_LOCALPLAYER; } diff --git a/Minecraft.Client/Minecraft.cpp b/Minecraft.Client/Minecraft.cpp index 064ba858..0261af52 100644 --- a/Minecraft.Client/Minecraft.cpp +++ b/Minecraft.Client/Minecraft.cpp @@ -4723,7 +4723,7 @@ void Minecraft::startAndConnectTo(const wstring& name, const wstring& sid, const */ Minecraft *minecraft; - // 4J - was new Minecraft(frame, canvas, NULL, 854, 480, fullScreen); + // 4J - was new Minecraft(frame, canvas, nullptr, 854, 480, fullScreen); // Logical width is proportional to the real screen aspect ratio so that // the ortho projection and HUD layout match the viewport without stretching. extern int g_iScreenWidth; diff --git a/Minecraft.Client/MinecraftServer.cpp b/Minecraft.Client/MinecraftServer.cpp index abbbd7c1..96e9b539 100644 --- a/Minecraft.Client/MinecraftServer.cpp +++ b/Minecraft.Client/MinecraftServer.cpp @@ -2393,7 +2393,7 @@ bool MinecraftServer::chunkPacketManagement_CanSendTo(INetworkPlayer *player) if( currentPlayerCount == 0 ) return false; int index = s_slowQueuePlayerIndex % (int)currentPlayerCount; INetworkPlayer *queuePlayer = g_NetworkManager.GetPlayerByIndex( index ); - if( queuePlayer != NULL && (player == queuePlayer || player->IsSameSystem(queuePlayer)) && (time - s_slowQueueLastTime) > MINECRAFT_SERVER_SLOW_QUEUE_DELAY ) + if( queuePlayer != nullptr && (player == queuePlayer || player->IsSameSystem(queuePlayer)) && (time - s_slowQueueLastTime) > MINECRAFT_SERVER_SLOW_QUEUE_DELAY ) { return true; } diff --git a/Minecraft.Client/MinecraftServer.h b/Minecraft.Client/MinecraftServer.h index 1ed5db9d..cf9c7bec 100644 --- a/Minecraft.Client/MinecraftServer.h +++ b/Minecraft.Client/MinecraftServer.h @@ -72,14 +72,14 @@ class MinecraftServer : public ConsoleInputSource { public: static const wstring VERSION; - static const int TICK_STATS_SPAN = SharedConstants::TICKS_PER_SECOND * 5; + static constexpr int TICK_STATS_SPAN = SharedConstants::TICKS_PER_SECOND * 5; // static Logger logger = Logger.getLogger("Minecraft"); static unordered_map ironTimers; private: static const int DEFAULT_MINECRAFT_PORT = 25565; - static const int MS_PER_TICK = 1000 / SharedConstants::TICKS_PER_SECOND; + static constexpr int MS_PER_TICK = 1000 / SharedConstants::TICKS_PER_SECOND; // 4J Stu - Added 1.0.1, Not needed //wstring localIp; diff --git a/Minecraft.Client/MultiPlayerLevel.h b/Minecraft.Client/MultiPlayerLevel.h index b7f1640a..460f67b5 100644 --- a/Minecraft.Client/MultiPlayerLevel.h +++ b/Minecraft.Client/MultiPlayerLevel.h @@ -14,7 +14,7 @@ class MultiPlayerLevel : public Level { friend class ClientConnection; private: - static const int TICKS_BEFORE_RESET = 20 * 4; + static constexpr int TICKS_BEFORE_RESET = 20 * 4; class ResetInfo { diff --git a/Minecraft.Client/PendingConnection.h b/Minecraft.Client/PendingConnection.h index e8a493b0..2eb604d8 100644 --- a/Minecraft.Client/PendingConnection.h +++ b/Minecraft.Client/PendingConnection.h @@ -11,7 +11,7 @@ class PendingConnection : public PacketListener { private: static const int FAKE_LAG = 0; - static const int MAX_TICKS_BEFORE_LOGIN = 20 * 30; + static constexpr int MAX_TICKS_BEFORE_LOGIN = 20 * 30; // public static Logger logger = Logger.getLogger("Minecraft"); static Random *random; diff --git a/Minecraft.Client/PlayerConnection.cpp b/Minecraft.Client/PlayerConnection.cpp index 186555dc..c6912f0c 100644 --- a/Minecraft.Client/PlayerConnection.cpp +++ b/Minecraft.Client/PlayerConnection.cpp @@ -86,7 +86,7 @@ PlayerConnection::PlayerConnection(MinecraftServer *server, Connection *connecti m_logSmallId = 0; // Cache the first valid transport smallId because disconnect teardown can clear it before the server logger runs. - if (this->connection != NULL && this->connection->getSocket() != NULL) + if (this->connection != nullptr && this->connection->getSocket() != nullptr) { m_logSmallId = this->connection->getSocket()->getSmallId(); } @@ -103,7 +103,7 @@ PlayerConnection::~PlayerConnection() unsigned char PlayerConnection::getLogSmallId() { // Fall back to the live socket only while the cached value is still empty. - if (m_logSmallId == 0 && connection != NULL && connection->getSocket() != NULL) + if (m_logSmallId == 0 && connection != nullptr && connection->getSocket() != nullptr) { m_logSmallId = connection->getSocket()->getSmallId(); } @@ -156,7 +156,7 @@ void PlayerConnection::disconnect(DisconnectPacket::eDisconnectReason reason) #if defined(_WINDOWS64) && defined(MINECRAFT_SERVER_BUILD) ServerRuntime::ServerLogManager::OnPlayerDisconnected( getLogSmallId(), - (player != NULL) ? player->name : std::wstring(), + (player != nullptr) ? player->name : std::wstring(), reason, true); #endif @@ -591,7 +591,7 @@ void PlayerConnection::onDisconnect(DisconnectPacket::eDisconnectReason reason, #if defined(_WINDOWS64) && defined(MINECRAFT_SERVER_BUILD) ServerRuntime::ServerLogManager::OnPlayerDisconnected( getLogSmallId(), - (player != NULL) ? player->name : std::wstring(), + (player != nullptr) ? player->name : std::wstring(), reason, false); #endif diff --git a/Minecraft.Client/PlayerList.h b/Minecraft.Client/PlayerList.h index a4ae9c5d..74fee1e4 100644 --- a/Minecraft.Client/PlayerList.h +++ b/Minecraft.Client/PlayerList.h @@ -20,7 +20,7 @@ using namespace std; class PlayerList { private: - static const int SEND_PLAYER_INFO_INTERVAL = 20 * 10; // 4J - brought forward from 1.2.3 + static constexpr int SEND_PLAYER_INFO_INTERVAL = 20 * 10; // 4J - brought forward from 1.2.3 // public static Logger logger = Logger.getLogger("Minecraft"); public: vector > players; diff --git a/Minecraft.Client/ServerConnection.cpp b/Minecraft.Client/ServerConnection.cpp index 0f96e032..26257e19 100644 --- a/Minecraft.Client/ServerConnection.cpp +++ b/Minecraft.Client/ServerConnection.cpp @@ -54,7 +54,7 @@ void ServerConnection::stop() for (unsigned int i = 0; i < pendingSnapshot.size(); i++) { shared_ptr uc = pendingSnapshot[i]; - if (uc != NULL && !uc->done) + if (uc != nullptr && !uc->done) { uc->disconnect(DisconnectPacket::eDisconnect_Closed); } @@ -65,7 +65,7 @@ void ServerConnection::stop() for (unsigned int i = 0; i < playerSnapshot.size(); i++) { shared_ptr player = playerSnapshot[i]; - if (player != NULL && !player->done) + if (player != nullptr && !player->done) { player->disconnect(DisconnectPacket::eDisconnect_Quitting); } diff --git a/Minecraft.Client/StatsSyncher.h b/Minecraft.Client/StatsSyncher.h index 843505bf..8dca93ac 100644 --- a/Minecraft.Client/StatsSyncher.h +++ b/Minecraft.Client/StatsSyncher.h @@ -9,8 +9,8 @@ using namespace std; class StatsSyncher { private: - static const int SAVE_INTERVAL = 20 * 5; - static const int SEND_INTERVAL = 20 * 60; + static constexpr int SAVE_INTERVAL = 20 * 5; + static constexpr int SEND_INTERVAL = 20 * 60; volatile bool busy; diff --git a/Minecraft.Client/SurvivalMode.cpp b/Minecraft.Client/SurvivalMode.cpp index 27a992df..465bef88 100644 --- a/Minecraft.Client/SurvivalMode.cpp +++ b/Minecraft.Client/SurvivalMode.cpp @@ -22,7 +22,7 @@ SurvivalMode::SurvivalMode(Minecraft *minecraft) : GameMode(minecraft) if (ClientConstants::IS_DEMO_VERSION) { - if( dynamic_cast(this) == NULL ) + if( dynamic_cast(this) == nullptr ) { assert(false); // throw new IllegalStateException("Invalid game mode"); // 4J - removed @@ -65,7 +65,7 @@ bool SurvivalMode::destroyBlock(int x, int y, int z, int face) shared_ptr item = minecraft->player->getSelectedItem(); bool couldDestroy = minecraft->player->canDestroy(Tile::tiles[t]); - if (item != NULL) + if (item != nullptr) { item->mineBlock(t, x, y, z, minecraft->player); if (item->count == 0) @@ -117,7 +117,7 @@ void SurvivalMode::continueDestroyBlock(int x, int y, int z, int face) if (destroyTicks % 4 == 0) { - if (tile != NULL) + if (tile != nullptr) { minecraft->soundEngine->play(tile->soundType->getStepSound(), x + 0.5f, y + 0.5f, z + 0.5f, (tile->soundType->getVolume() + 1) / 8, tile->soundType->getPitch() * 0.5f); } @@ -196,7 +196,7 @@ bool SurvivalMode::useItemOn(shared_ptr player, Level *level, shared_ptr { if (Tile::tiles[t]->use(level, x, y, z, player)) return true; } - if (item == NULL) return false; + if (item == nullptr) return false; return item->useOn(player, level, x, y, z, face); } diff --git a/Minecraft.Client/SurvivalMode.h b/Minecraft.Client/SurvivalMode.h index b4ce5e6d..7f6aec15 100644 --- a/Minecraft.Client/SurvivalMode.h +++ b/Minecraft.Client/SurvivalMode.h @@ -27,6 +27,6 @@ public: virtual void initLevel(Level *level); virtual shared_ptr createPlayer(Level *level); virtual void tick(); - virtual bool useItemOn(shared_ptr player, Level *level, shared_ptr item, int x, int y, int z, int face, bool bTestUseOnOnly=false, bool *pbUsedItem=NULL); + virtual bool useItemOn(shared_ptr player, Level *level, shared_ptr item, int x, int y, int z, int face, bool bTestUseOnOnly=false, bool *pbUsedItem=nullptr); virtual bool hasExperience(); }; \ No newline at end of file diff --git a/Minecraft.Client/Tesselator.h b/Minecraft.Client/Tesselator.h index 4166727a..4ee8a420 100644 --- a/Minecraft.Client/Tesselator.h +++ b/Minecraft.Client/Tesselator.h @@ -9,8 +9,8 @@ private: static bool TRIANGLE_MODE; static bool USE_VBO; - static const int MAX_MEMORY_USE = 16 * 1024 * 1024; - static const int MAX_FLOATS = MAX_MEMORY_USE / 4 / 2; + static constexpr int MAX_MEMORY_USE = 16 * 1024 * 1024; + static constexpr int MAX_FLOATS = MAX_MEMORY_USE / 4 / 2; intArray *_array; diff --git a/Minecraft.Client/TexturePackRepository.h b/Minecraft.Client/TexturePackRepository.h index 2b66df43..fb5014d4 100644 --- a/Minecraft.Client/TexturePackRepository.h +++ b/Minecraft.Client/TexturePackRepository.h @@ -26,7 +26,7 @@ private: TexturePack *selected; TexturePack *lastSelected; bool usingWeb; - static const int MAX_WEB_FILESIZE = 10 * 1000 * 1000; // 10 Megabytes + static constexpr int MAX_WEB_FILESIZE = 10 * 1000 * 1000; // 10 Megabytes public: TexturePackRepository(File workingDirectory, Minecraft *minecraft); diff --git a/Minecraft.Client/TileRenderer.cpp b/Minecraft.Client/TileRenderer.cpp index 8dd5c3df..231f627e 100644 --- a/Minecraft.Client/TileRenderer.cpp +++ b/Minecraft.Client/TileRenderer.cpp @@ -15,7 +15,7 @@ bool TileRenderer::fancy = true; -const float smallUV = ( 1.0f / 16.0f ); +constexpr float smallUV = ( 1.0f / 16.0f ); void TileRenderer::_init() { @@ -831,7 +831,7 @@ bool TileRenderer::tesselateCauldronInWorld(CauldronTile *tt, int x, int y, int // render inside Icon *insideTex = tt->getTexture(Facing::NORTH); - const float cWidth = ( 2.0f / 16.0f ) - ( 1.0f / 128.0f ); // 4J - Moved by 1/128th (smallest movement possible with our vertex storage) to remove gap at edge of cauldron + constexpr float cWidth = ( 2.0f / 16.0f ) - ( 1.0f / 128.0f ); // 4J - Moved by 1/128th (smallest movement possible with our vertex storage) to remove gap at edge of cauldron renderEast(tt, x - 1.0f + cWidth, y, z, insideTex); renderWest(tt, x + 1.0f - cWidth, y, z, insideTex); renderSouth(tt, x, y, z - 1.0f + cWidth, insideTex); @@ -1461,7 +1461,7 @@ bool TileRenderer::tesselatePistonBaseInWorld( Tile* tt, int x, int y, int z, bo bool extended = forceExtended || ( data & PistonBaseTile::EXTENDED_BIT ) != 0; int facing = PistonBaseTile::getFacing( data ); - const float thickness = PistonBaseTile::PLATFORM_THICKNESS / 16.0f; + constexpr float thickness = PistonBaseTile::PLATFORM_THICKNESS / 16.0f; if ( extended ) { @@ -1643,9 +1643,9 @@ bool TileRenderer::tesselatePistonExtensionInWorld( Tile* tt, int x, int y, int int data = ( forceData == -1 ) ? level->getData( x, y, z ) : forceData; int facing = PistonExtensionTile::getFacing( data ); - const float thickness = PistonBaseTile::PLATFORM_THICKNESS / 16.0f; - const float leftEdge = ( 8.0f - ( PistonBaseTile::PLATFORM_THICKNESS / 2.0f ) ) / 16.0f; - const float rightEdge = ( 8.0f + ( PistonBaseTile::PLATFORM_THICKNESS / 2.0f ) ) / 16.0f; + constexpr float thickness = PistonBaseTile::PLATFORM_THICKNESS / 16.0f; + constexpr float leftEdge = (8.0f - (PistonBaseTile::PLATFORM_THICKNESS / 2.0f)) / 16.0f; + constexpr float rightEdge = (8.0f + (PistonBaseTile::PLATFORM_THICKNESS / 2.0f)) / 16.0f; const float br = tt->getBrightness( level, x, y, z ); const float armLength = fullArm ? 1.0f : 0.5f; const float armLengthPixels = fullArm ? 16.0f : 8.0f; @@ -2793,8 +2793,8 @@ bool TileRenderer::tesselateDustInWorld( Tile* tt, int x, int y, int z ) { t->color( br * red, br * green, br * blue ); } - const float dustOffset = 0.25f / 16.0f; - const float overlayOffset = 0.25f / 16.0f; + constexpr float dustOffset = 0.25f / 16.0f; + constexpr float overlayOffset = 0.25f / 16.0f; bool w = RedStoneDustTile::shouldConnectTo( level, x - 1, y, z, Direction::WEST ) || ( !level->isSolidBlockingTile( x - 1, y, z ) && RedStoneDustTile::shouldConnectTo( level, x - 1, y - 1, z, @@ -2889,7 +2889,7 @@ bool TileRenderer::tesselateDustInWorld( Tile* tt, int x, int y, int z ) if ( !level->isSolidBlockingTile( x, y + 1, z ) ) { - const float yStretch = .35f / 16.0f; + constexpr float yStretch = .35f / 16.0f; if ( level->isSolidBlockingTile( x - 1, y, z ) && level->getTile( x - 1, y + 1, z ) == Tile::redStoneDust_Id ) { @@ -3713,8 +3713,8 @@ bool TileRenderer::tesselateThinFenceInWorld( ThinFenceTile* tt, int x, int y, i bool up = tt->shouldRenderFace( level, x, y + 1, z, Facing::UP ); bool down = tt->shouldRenderFace( level, x, y - 1, z, Facing::DOWN ); - const float noZFightingOffset = 0.01f; - const float noZFightingOffsetB = 0.005; + constexpr float noZFightingOffset = 0.01f; + constexpr float noZFightingOffsetB = 0.005; if ( ( w && e ) || ( !w && !e && !n && !s ) ) { @@ -4576,9 +4576,7 @@ bool TileRenderer::tesselateWaterInWorld(Tile* tt, int x, int y, int z) dirs[3] = tt->shouldRenderFace( level, x + 1, y, z, 5 ); if (!up && !down && !dirs[0] && !dirs[1] && !dirs[2] && !dirs[3]) - { return false; - } bool changed = false; Material* m = tt->material; @@ -4614,9 +4612,7 @@ bool TileRenderer::tesselateWaterInWorld(Tile* tt, int x, int y, int z) float angle = static_cast(LiquidTile::getSlopeAngle(level, x, y, z, m)); if (angle > -999.0f) - { tex = getTexture(tt, 2, data); - } h0 -= offs; h1 -= offs; h2 -= offs; h3 -= offs; @@ -4624,7 +4620,7 @@ bool TileRenderer::tesselateWaterInWorld(Tile* tt, int x, int y, int z) if (angle >= -999.0f) { - float cc = 8.0f; + constexpr float cc = SharedConstants::WORLD_RESOLUTION * 0.5f; float fsin = Mth::sin(angle) * 0.25f; float fcos = Mth::cos(angle) * 0.25f; u0 = tex->getU(cc + (-fcos - fsin) * SharedConstants::WORLD_RESOLUTION); @@ -4819,7 +4815,7 @@ bool TileRenderer::tesselateWaterInWorldAO(Tile* tt, int x, int y, int z) if (angle >= -999.0f) { - float cc = 8.0f; + constexpr float cc = SharedConstants::WORLD_RESOLUTION * 0.5f; float fsin = Mth::sin(angle) * 0.25f; float fcos = Mth::cos(angle) * 0.25f; u0 = tex->getU(cc + (-fcos - fsin) * SharedConstants::WORLD_RESOLUTION); @@ -6827,14 +6823,14 @@ bool TileRenderer::tesselateFenceGateInWorld(FenceGateTile *tt, int x, int y, in if (direction == Direction::EAST) { - const float z00 = 0 / 16.0f; - const float z01 = 2 / 16.0f; - const float z10 = 14 / 16.0f; - const float z11 = 16 / 16.0f; + constexpr float z00 = 0 / 16.0f; + constexpr float z01 = 2 / 16.0f; + constexpr float z10 = 14 / 16.0f; + constexpr float z11 = 16 / 16.0f; - const float x0 = 9 / 16.0f; - const float x1 = 13 / 16.0f; - const float x2 = 15 / 16.0f; + constexpr float x0 = 9 / 16.0f; + constexpr float x1 = 13 / 16.0f; + constexpr float x2 = 15 / 16.0f; setShape(x1, h00, z00, x2, h11, z01); tesselateBlockInWorld(tt, x, y, z); @@ -6853,14 +6849,14 @@ bool TileRenderer::tesselateFenceGateInWorld(FenceGateTile *tt, int x, int y, in } else if (direction == Direction::WEST) { - const float z00 = 0 / 16.0f; - const float z01 = 2 / 16.0f; - const float z10 = 14 / 16.0f; - const float z11 = 16 / 16.0f; + constexpr float z00 = 0 / 16.0f; + constexpr float z01 = 2 / 16.0f; + constexpr float z10 = 14 / 16.0f; + constexpr float z11 = 16 / 16.0f; - const float x0 = 1 / 16.0f; - const float x1 = 3 / 16.0f; - const float x2 = 7 / 16.0f; + constexpr float x0 = 1 / 16.0f; + constexpr float x1 = 3 / 16.0f; + constexpr float x2 = 7 / 16.0f; setShape(x0, h00, z00, x1, h11, z01); tesselateBlockInWorld(tt, x, y, z); @@ -6880,14 +6876,14 @@ bool TileRenderer::tesselateFenceGateInWorld(FenceGateTile *tt, int x, int y, in else if (direction == Direction::SOUTH) { - const float x00 = 0 / 16.0f; - const float x01 = 2 / 16.0f; - const float x10 = 14 / 16.0f; - const float x11 = 16 / 16.0f; + constexpr float x00 = 0 / 16.0f; + constexpr float x01 = 2 / 16.0f; + constexpr float x10 = 14 / 16.0f; + constexpr float x11 = 16 / 16.0f; - const float z0 = 9 / 16.0f; - const float z1 = 13 / 16.0f; - const float z2 = 15 / 16.0f; + constexpr float z0 = 9 / 16.0f; + constexpr float z1 = 13 / 16.0f; + constexpr float z2 = 15 / 16.0f; setShape(x00, h00, z1, x01, h11, z2); tesselateBlockInWorld(tt, x, y, z); @@ -6906,14 +6902,14 @@ bool TileRenderer::tesselateFenceGateInWorld(FenceGateTile *tt, int x, int y, in } else if (direction == Direction::NORTH) { - const float x00 = 0 / 16.0f; - const float x01 = 2 / 16.0f; - const float x10 = 14 / 16.0f; - const float x11 = 16 / 16.0f; + constexpr float x00 = 0 / 16.0f; + constexpr float x01 = 2 / 16.0f; + constexpr float x10 = 14 / 16.0f; + constexpr float x11 = 16 / 16.0f; - const float z0 = 1 / 16.0f; - const float z1 = 3 / 16.0f; - const float z2 = 7 / 16.0f; + constexpr float z0 = 1 / 16.0f; + constexpr float z1 = 3 / 16.0f; + constexpr float z2 = 7 / 16.0f; setShape(x00, h00, z0, x01, h11, z1); tesselateBlockInWorld(tt, x, y, z); diff --git a/Minecraft.Server/Common/StringUtils.cpp b/Minecraft.Server/Common/StringUtils.cpp index 40881ae7..b88d420c 100644 --- a/Minecraft.Server/Common/StringUtils.cpp +++ b/Minecraft.Server/Common/StringUtils.cpp @@ -18,7 +18,7 @@ namespace ServerRuntime return std::string(); } - int charCount = WideCharToMultiByte(CP_UTF8, 0, value.c_str(), (int)value.length(), NULL, 0, NULL, NULL); + int charCount = WideCharToMultiByte(CP_UTF8, 0, value.c_str(), (int)value.length(), nullptr, 0, nullptr, nullptr); if (charCount <= 0) { return std::string(); @@ -26,22 +26,22 @@ namespace ServerRuntime std::string utf8; utf8.resize(charCount); - WideCharToMultiByte(CP_UTF8, 0, value.c_str(), (int)value.length(), &utf8[0], charCount, NULL, NULL); + WideCharToMultiByte(CP_UTF8, 0, value.c_str(), (int)value.length(), &utf8[0], charCount, nullptr, nullptr); return utf8; } std::wstring Utf8ToWide(const char *value) { - if (value == NULL || value[0] == 0) + if (value == nullptr || value[0] == 0) { return std::wstring(); } - int wideCount = MultiByteToWideChar(CP_UTF8, 0, value, -1, NULL, 0); + int wideCount = MultiByteToWideChar(CP_UTF8, 0, value, -1, nullptr, 0); if (wideCount <= 0) { // Fall back to the current ANSI code page so legacy non-UTF-8 inputs remain readable. - wideCount = MultiByteToWideChar(CP_ACP, 0, value, -1, NULL, 0); + wideCount = MultiByteToWideChar(CP_ACP, 0, value, -1, nullptr, 0); if (wideCount <= 0) { return std::wstring(); diff --git a/Minecraft.Server/Console/commands/list/CliCommandList.cpp b/Minecraft.Server/Console/commands/list/CliCommandList.cpp index a9c5a212..dcace876 100644 --- a/Minecraft.Server/Console/commands/list/CliCommandList.cpp +++ b/Minecraft.Server/Console/commands/list/CliCommandList.cpp @@ -28,7 +28,7 @@ namespace ServerRuntime { (void)line; MinecraftServer *server = MinecraftServer::getInstance(); - if (server == NULL || server->getPlayers() == NULL) + if (server == nullptr || server->getPlayers() == nullptr) { engine->LogWarn("Player list is not available."); return false; diff --git a/Minecraft.Server/ServerLogger.cpp b/Minecraft.Server/ServerLogger.cpp index 0c7c567f..14aa7e1a 100644 --- a/Minecraft.Server/ServerLogger.cpp +++ b/Minecraft.Server/ServerLogger.cpp @@ -14,7 +14,7 @@ static volatile LONG g_minLogLevel = (LONG)eServerLogLevel_Info; static const char *NormalizeCategory(const char *category) { - if (category == NULL || category[0] == 0) + if (category == nullptr || category[0] == 0) { return "server"; } @@ -56,7 +56,7 @@ static WORD LogLevelToColor(EServerLogLevel level) static void BuildTimestamp(char *buffer, size_t bufferSize) { - if (buffer == NULL || bufferSize == 0) + if (buffer == nullptr || bufferSize == 0) { return; } @@ -91,7 +91,7 @@ static void WriteLogLine(EServerLogLevel level, const char *category, const char linenoiseExternalWriteBegin(); const char *safeCategory = NormalizeCategory(category); - const char *safeMessage = (message != NULL) ? message : ""; + const char *safeMessage = (message != nullptr) ? message : ""; char timestamp[32] = {}; BuildTimestamp(timestamp, sizeof(timestamp)); @@ -99,7 +99,7 @@ static void WriteLogLine(EServerLogLevel level, const char *category, const char HANDLE stdoutHandle = GetStdHandle(STD_OUTPUT_HANDLE); CONSOLE_SCREEN_BUFFER_INFO originalInfo; bool hasColorConsole = false; - if (stdoutHandle != INVALID_HANDLE_VALUE && stdoutHandle != NULL) + if (stdoutHandle != INVALID_HANDLE_VALUE && stdoutHandle != nullptr) { if (GetConsoleScreenBufferInfo(stdoutHandle, &originalInfo)) { @@ -127,7 +127,7 @@ static void WriteLogLine(EServerLogLevel level, const char *category, const char static void WriteLogLineV(EServerLogLevel level, const char *category, const char *format, va_list args) { char messageBuffer[2048] = {}; - if (format == NULL) + if (format == nullptr) { WriteLogLine(level, category, ""); return; @@ -139,7 +139,7 @@ static void WriteLogLineV(EServerLogLevel level, const char *category, const cha bool TryParseServerLogLevel(const char *value, EServerLogLevel *outLevel) { - if (value == NULL || outLevel == NULL) + if (value == nullptr || outLevel == nullptr) { return false; } @@ -252,7 +252,7 @@ void LogWorldIO(const char *message) void LogWorldName(const char *prefix, const std::wstring &name) { std::string utf8 = StringUtils::WideToUtf8(name); - LogInfof("world-io", "%s: %s", (prefix != NULL) ? prefix : "name", utf8.c_str()); + LogInfof("world-io", "%s: %s", (prefix != nullptr) ? prefix : "name", utf8.c_str()); } } diff --git a/Minecraft.Server/WorldManager.h b/Minecraft.Server/WorldManager.h index a4a8e77b..579b05c9 100644 --- a/Minecraft.Server/WorldManager.h +++ b/Minecraft.Server/WorldManager.h @@ -41,14 +41,14 @@ namespace ServerRuntime { /** Bootstrap status */ EWorldBootstrapStatus status; - /** Save data used for server initialization, `NULL` when creating a new world */ + /** Save data used for server initialization, `nullptr` when creating a new world */ LoadSaveDataThreadParam *saveData; /** Save ID that was actually selected */ std::string resolvedSaveId; WorldBootstrapResult() : status(eWorldBootstrap_Failed) - , saveData(NULL) + , saveData(nullptr) { } }; diff --git a/Minecraft.World/AnvilMenu.h b/Minecraft.World/AnvilMenu.h index a70145dd..228e91d4 100644 --- a/Minecraft.World/AnvilMenu.h +++ b/Minecraft.World/AnvilMenu.h @@ -6,20 +6,20 @@ class AnvilMenu : public AbstractContainerMenu { friend class RepairResultSlot; private: - static const bool DEBUG_COST = false; + static constexpr bool DEBUG_COST = false; public: - static const int INPUT_SLOT = 0; - static const int ADDITIONAL_SLOT = 1; - static const int RESULT_SLOT = 2; + static constexpr int INPUT_SLOT = 0; + static constexpr int ADDITIONAL_SLOT = 1; + static constexpr int RESULT_SLOT = 2; - static const int INV_SLOT_START = RESULT_SLOT + 1; - static const int INV_SLOT_END = INV_SLOT_START + 9 * 3; - static const int USE_ROW_SLOT_START = INV_SLOT_END; - static const int USE_ROW_SLOT_END = USE_ROW_SLOT_START + 9; + static constexpr int INV_SLOT_START = RESULT_SLOT + 1; + static constexpr int INV_SLOT_END = INV_SLOT_START + 9 * 3; + static constexpr int USE_ROW_SLOT_START = INV_SLOT_END; + static constexpr int USE_ROW_SLOT_END = USE_ROW_SLOT_START + 9; public: - static const int DATA_TOTAL_COST = 0; + static constexpr int DATA_TOTAL_COST = 0; private: shared_ptr resultSlots; diff --git a/Minecraft.World/ArrowAttackGoal.cpp b/Minecraft.World/ArrowAttackGoal.cpp index 23a2d2ac..f04615e1 100644 --- a/Minecraft.World/ArrowAttackGoal.cpp +++ b/Minecraft.World/ArrowAttackGoal.cpp @@ -27,14 +27,14 @@ ArrowAttackGoal::ArrowAttackGoal(Mob *mob, float speed, int projectileType, int bool ArrowAttackGoal::canUse() { shared_ptr bestTarget = mob->getTarget(); - if (bestTarget == NULL) return false; + if (bestTarget == nullptr) return false; target = weak_ptr(bestTarget); return true; } bool ArrowAttackGoal::canContinueToUse() { - return target.lock() != NULL && (canUse() || !mob->getNavigation()->isDone()); + return target.lock() != nullptr && (canUse() || !mob->getNavigation()->isDone()); } void ArrowAttackGoal::stop() diff --git a/Minecraft.World/ByteArrayInputStream.cpp b/Minecraft.World/ByteArrayInputStream.cpp index 29f6fc26..c1a24926 100644 --- a/Minecraft.World/ByteArrayInputStream.cpp +++ b/Minecraft.World/ByteArrayInputStream.cpp @@ -135,7 +135,7 @@ __int64 ByteArrayInputStream::skip(__int64 n) ByteArrayInputStream::~ByteArrayInputStream() { - if (buf.data != NULL) + if (buf.data != nullptr) { delete[] buf.data; } diff --git a/Minecraft.World/ByteArrayOutputStream.cpp b/Minecraft.World/ByteArrayOutputStream.cpp index 9173941f..933b5cdd 100644 --- a/Minecraft.World/ByteArrayOutputStream.cpp +++ b/Minecraft.World/ByteArrayOutputStream.cpp @@ -20,7 +20,7 @@ ByteArrayOutputStream::ByteArrayOutputStream(unsigned int size) ByteArrayOutputStream::~ByteArrayOutputStream() { - if (buf.data != NULL) + if (buf.data != nullptr) { delete[] buf.data; } diff --git a/Minecraft.World/ClothTile.cpp b/Minecraft.World/ClothTile.cpp index 8c18b01c..301fbb7d 100644 --- a/Minecraft.World/ClothTile.cpp +++ b/Minecraft.World/ClothTile.cpp @@ -4,7 +4,7 @@ ClothTile::ClothTile() : Tile(35, Material::cloth) { - icons = NULL; + icons = nullptr; } Icon *ClothTile::getTexture(int face, int data) diff --git a/Minecraft.World/CraftingMenu.h b/Minecraft.World/CraftingMenu.h index 9786f32f..8cfbccaa 100644 --- a/Minecraft.World/CraftingMenu.h +++ b/Minecraft.World/CraftingMenu.h @@ -9,13 +9,13 @@ class CraftingMenu : public AbstractContainerMenu { // 4J Stu Made these public for UI menus, perhaps should make friend class? public: - static const int RESULT_SLOT = 0; - static const int CRAFT_SLOT_START = 1; - static const int CRAFT_SLOT_END = CRAFT_SLOT_START + 9; - static const int INV_SLOT_START = CRAFT_SLOT_END; - static const int INV_SLOT_END = INV_SLOT_START + (9*3); - static const int USE_ROW_SLOT_START = INV_SLOT_END; - static const int USE_ROW_SLOT_END = USE_ROW_SLOT_START + 9; + static constexpr int RESULT_SLOT = 0; + static constexpr int CRAFT_SLOT_START = 1; + static constexpr int CRAFT_SLOT_END = CRAFT_SLOT_START + 9; + static constexpr int INV_SLOT_START = CRAFT_SLOT_END; + static constexpr int INV_SLOT_END = INV_SLOT_START + (9*3); + static constexpr int USE_ROW_SLOT_START = INV_SLOT_END; + static constexpr int USE_ROW_SLOT_END = USE_ROW_SLOT_START + 9; public: shared_ptr craftSlots; diff --git a/Minecraft.World/EnchantmentMenu.h b/Minecraft.World/EnchantmentMenu.h index 62408f1d..675965b6 100644 --- a/Minecraft.World/EnchantmentMenu.h +++ b/Minecraft.World/EnchantmentMenu.h @@ -6,11 +6,11 @@ class EnchantmentMenu : public AbstractContainerMenu { // 4J Stu Made these public for UI menus, perhaps should make friend class? public: - static const int INGREDIENT_SLOT = 0; - static const int INV_SLOT_START = EnchantmentMenu::INGREDIENT_SLOT + 1; - static const int INV_SLOT_END = EnchantmentMenu::INV_SLOT_START + 9 * 3; - static const int USE_ROW_SLOT_START = EnchantmentMenu::INV_SLOT_END; - static const int USE_ROW_SLOT_END = EnchantmentMenu::USE_ROW_SLOT_START + 9; + static constexpr int INGREDIENT_SLOT = 0; + static constexpr int INV_SLOT_START = EnchantmentMenu::INGREDIENT_SLOT + 1; + static constexpr int INV_SLOT_END = EnchantmentMenu::INV_SLOT_START + (9*3); + static constexpr int USE_ROW_SLOT_START = EnchantmentMenu::INV_SLOT_END; + static constexpr int USE_ROW_SLOT_END = EnchantmentMenu::USE_ROW_SLOT_START + 9; public: shared_ptr enchantSlots; diff --git a/Minecraft.World/Entity.h b/Minecraft.World/Entity.h index 5e5c7162..49608fc4 100644 --- a/Minecraft.World/Entity.h +++ b/Minecraft.World/Entity.h @@ -377,8 +377,8 @@ private: // Things also added here to be able to manage the concept of a number of extra "wandering" entities - normally path finding entities aren't allowed to // randomly wander about once they are a certain distance away from any player, but we want to be able to (in a controlled fashion) allow some to be able // to move so that we can determine whether they have been enclosed in some kind of farm, and so be able to better determine what shouldn't or shouldn't be despawned. - static const int EXTRA_WANDER_MAX = 3; // Number of entities that can simultaneously wander (in addition to the ones that would be wandering in java) - static const int EXTRA_WANDER_TICKS = 20 * 30; // Number of ticks each extra entity will be allowed to wander for. This should be enough for it to realistically be able to walk further than the biggest enclosure we want to consider + static constexpr int EXTRA_WANDER_MAX = 3; // Number of entities that can simultaneously wander (in addition to the ones that would be wandering in java) + static constexpr int EXTRA_WANDER_TICKS = 20 * 30; // Number of ticks each extra entity will be allowed to wander for. This should be enough for it to realistically be able to walk further than the biggest enclosure we want to consider int getSmallId(); void freeSmallId(int index); diff --git a/Minecraft.World/EntityTile.cpp b/Minecraft.World/EntityTile.cpp index 8dd68ff2..edf869fb 100644 --- a/Minecraft.World/EntityTile.cpp +++ b/Minecraft.World/EntityTile.cpp @@ -25,7 +25,7 @@ void EntityTile::triggerEvent(Level *level, int x, int y, int z, int b0, int b1) { Tile::triggerEvent(level, x, y, z, b0, b1); shared_ptr te = level->getTileEntity(x, y, z); - if (te != NULL) + if (te != nullptr) { te->triggerEvent(b0, b1); } diff --git a/Minecraft.World/FireworksMenu.h b/Minecraft.World/FireworksMenu.h index 97621261..daef7902 100644 --- a/Minecraft.World/FireworksMenu.h +++ b/Minecraft.World/FireworksMenu.h @@ -9,13 +9,13 @@ class FireworksMenu : public AbstractContainerMenu { // 4J Stu Made these public for UI menus, perhaps should make friend class? public: - static const int RESULT_SLOT = 0; - static const int CRAFT_SLOT_START = 1; - static const int CRAFT_SLOT_END = CRAFT_SLOT_START + 9; - static const int INV_SLOT_START = CRAFT_SLOT_END; - static const int INV_SLOT_END = INV_SLOT_START + (9*3); - static const int USE_ROW_SLOT_START = INV_SLOT_END; - static const int USE_ROW_SLOT_END = USE_ROW_SLOT_START + 9; + static constexpr int RESULT_SLOT = 0; + static constexpr int CRAFT_SLOT_START = 1; + static constexpr int CRAFT_SLOT_END = CRAFT_SLOT_START + 9; + static constexpr int INV_SLOT_START = CRAFT_SLOT_END; + static constexpr int INV_SLOT_END = INV_SLOT_START + (9*3); + static constexpr int USE_ROW_SLOT_START = INV_SLOT_END; + static constexpr int USE_ROW_SLOT_END = USE_ROW_SLOT_START + 9; public: shared_ptr craftSlots; diff --git a/Minecraft.World/FlatLevelSource.cpp b/Minecraft.World/FlatLevelSource.cpp index 9ea1ed36..0a9fb6b9 100644 --- a/Minecraft.World/FlatLevelSource.cpp +++ b/Minecraft.World/FlatLevelSource.cpp @@ -140,7 +140,7 @@ wstring FlatLevelSource::gatherStats() vector *FlatLevelSource::getMobsAt(MobCategory *mobCategory, int x, int y, int z) { Biome *biome = level->getBiome(x, z); - if (biome == NULL) + if (biome == nullptr) { return nullptr; } diff --git a/Minecraft.World/FurnaceMenu.h b/Minecraft.World/FurnaceMenu.h index 6eaf98e6..d7a9f6d3 100644 --- a/Minecraft.World/FurnaceMenu.h +++ b/Minecraft.World/FurnaceMenu.h @@ -8,13 +8,13 @@ class FurnaceMenu : public AbstractContainerMenu { // 4J Stu Made these public for UI menus, perhaps should make friend class? public: - static const int INGREDIENT_SLOT = 0; - static const int FUEL_SLOT = 1; - static const int RESULT_SLOT = 2; - static const int INV_SLOT_START = FurnaceMenu::RESULT_SLOT + 1; - static const int INV_SLOT_END = FurnaceMenu::INV_SLOT_START + 9 * 3; - static const int USE_ROW_SLOT_START = FurnaceMenu::INV_SLOT_END; - static const int USE_ROW_SLOT_END = FurnaceMenu::USE_ROW_SLOT_START + 9; + static constexpr int INGREDIENT_SLOT = 0; + static constexpr int FUEL_SLOT = 1; + static constexpr int RESULT_SLOT = 2; + static constexpr int INV_SLOT_START = FurnaceMenu::RESULT_SLOT + 1; + static constexpr int INV_SLOT_END = FurnaceMenu::INV_SLOT_START + (9*3); + static constexpr int USE_ROW_SLOT_START = FurnaceMenu::INV_SLOT_END; + static constexpr int USE_ROW_SLOT_END = FurnaceMenu::USE_ROW_SLOT_START + 9; private: shared_ptr furnace; diff --git a/Minecraft.World/HopperMenu.h b/Minecraft.World/HopperMenu.h index ee0c4b93..89347b52 100644 --- a/Minecraft.World/HopperMenu.h +++ b/Minecraft.World/HopperMenu.h @@ -8,11 +8,11 @@ private: shared_ptr hopper; public: - static const int CONTENTS_SLOT_START = 0; - static const int INV_SLOT_START = CONTENTS_SLOT_START + 5; - static const int INV_SLOT_END = INV_SLOT_START + 9 * 3; - static const int USE_ROW_SLOT_START = INV_SLOT_END; - static const int USE_ROW_SLOT_END = USE_ROW_SLOT_START + 9; + static constexpr int CONTENTS_SLOT_START = 0; + static constexpr int INV_SLOT_START = CONTENTS_SLOT_START + 5; + static constexpr int INV_SLOT_END = INV_SLOT_START + (9*3); + static constexpr int USE_ROW_SLOT_START = INV_SLOT_END; + static constexpr int USE_ROW_SLOT_END = USE_ROW_SLOT_START + 9; public: HopperMenu(shared_ptr inventory, shared_ptr hopper); diff --git a/Minecraft.World/InventoryMenu.cpp b/Minecraft.World/InventoryMenu.cpp index 9c6c661f..027d8457 100644 --- a/Minecraft.World/InventoryMenu.cpp +++ b/Minecraft.World/InventoryMenu.cpp @@ -10,16 +10,6 @@ #include "Tile.h" #include "GenericStats.h" -const int InventoryMenu::RESULT_SLOT = 0; -const int InventoryMenu::CRAFT_SLOT_START = 1; -const int InventoryMenu::CRAFT_SLOT_END = InventoryMenu::CRAFT_SLOT_START + 4; -const int InventoryMenu::ARMOR_SLOT_START = InventoryMenu::CRAFT_SLOT_END; -const int InventoryMenu::ARMOR_SLOT_END = InventoryMenu::ARMOR_SLOT_START + 4; -const int InventoryMenu::INV_SLOT_START = InventoryMenu::ARMOR_SLOT_END; -const int InventoryMenu::INV_SLOT_END = InventoryMenu::INV_SLOT_START + 9 * 3; -const int InventoryMenu::USE_ROW_SLOT_START = InventoryMenu::INV_SLOT_END; -const int InventoryMenu::USE_ROW_SLOT_END = InventoryMenu::USE_ROW_SLOT_START + 9; - InventoryMenu::InventoryMenu(shared_ptr inventory, bool active, Player *player) : AbstractContainerMenu() { owner = player; diff --git a/Minecraft.World/InventoryMenu.h b/Minecraft.World/InventoryMenu.h index 1795eaef..a527eb11 100644 --- a/Minecraft.World/InventoryMenu.h +++ b/Minecraft.World/InventoryMenu.h @@ -12,15 +12,15 @@ private: // 4J Stu Made these public for UI menus, perhaps should make friend class? public: - static const int RESULT_SLOT; - static const int CRAFT_SLOT_START; - static const int CRAFT_SLOT_END; - static const int ARMOR_SLOT_START; - static const int ARMOR_SLOT_END; - static const int INV_SLOT_START; - static const int INV_SLOT_END; - static const int USE_ROW_SLOT_START; - static const int USE_ROW_SLOT_END; + static constexpr int RESULT_SLOT = 0; + static constexpr int CRAFT_SLOT_START = 1; + static constexpr int CRAFT_SLOT_END = CRAFT_SLOT_START + 4; + static constexpr int ARMOR_SLOT_START = CRAFT_SLOT_END; + static constexpr int ARMOR_SLOT_END = ARMOR_SLOT_START + 4; + static constexpr int INV_SLOT_START = ARMOR_SLOT_END; + static constexpr int INV_SLOT_END = INV_SLOT_START + (9*3); + static constexpr int USE_ROW_SLOT_START = INV_SLOT_END; + static constexpr int USE_ROW_SLOT_END = USE_ROW_SLOT_START + 9; public: shared_ptr craftSlots; diff --git a/Minecraft.World/Level.h b/Minecraft.World/Level.h index b56aebf6..1f5cdadb 100644 --- a/Minecraft.World/Level.h +++ b/Minecraft.World/Level.h @@ -71,18 +71,18 @@ public: static const int MAX_LEVEL_SIZE = 30000000; static const int maxMovementHeight = 512; // 4J added - static const int minBuildHeight = 0; // 4J - brought forward from 1.2.3 - static const int maxBuildHeight = 256; // 4J - brought forward from 1.2.3 - static const int genDepthBits = 7; - static const int genDepthBitsPlusFour = genDepthBits + 4; - static const int genDepth = 1 << genDepthBits; - static const int genDepthMinusOne = genDepth - 1; - static const int constSeaLevel = genDepth / 2 - 1; + static constexpr int minBuildHeight = 0; // 4J - brought forward from 1.2.3 + static constexpr int maxBuildHeight = 256; // 4J - brought forward from 1.2.3 + static constexpr int genDepthBits = 7; + static constexpr int genDepthBitsPlusFour = genDepthBits + 4; + static constexpr int genDepth = 1 << genDepthBits; + static constexpr int genDepthMinusOne = genDepth - 1; + static constexpr int constSeaLevel = genDepth / 2 - 1; - static const int CHUNK_TILE_COUNT = maxBuildHeight * 16 * 16; - static const int HALF_CHUNK_TILE_COUNT = CHUNK_TILE_COUNT/2; - static const int COMPRESSED_CHUNK_SECTION_HEIGHT = 128; - static const int COMPRESSED_CHUNK_SECTION_TILES = COMPRESSED_CHUNK_SECTION_HEIGHT * 16 * 16; // 4J Stu - Fixed size + static constexpr int CHUNK_TILE_COUNT = maxBuildHeight * 16 * 16; + static constexpr int HALF_CHUNK_TILE_COUNT = CHUNK_TILE_COUNT/2; + static constexpr int COMPRESSED_CHUNK_SECTION_HEIGHT = 128; + static constexpr int COMPRESSED_CHUNK_SECTION_TILES = COMPRESSED_CHUNK_SECTION_HEIGHT * 16 * 16; // 4J Stu - Fixed size int seaLevel; @@ -96,8 +96,8 @@ public: static void setInstaTick(bool enable); // bool instaTick; // 4J - removed - static const int MAX_BRIGHTNESS = 15; - static const int TICKS_PER_DAY = 20 * 60 * 20; // ORG:20*60*20 + static constexpr int MAX_BRIGHTNESS = 15; + static constexpr int TICKS_PER_DAY = 20 * 60 * 20; // ORG:20*60*20 public: CRITICAL_SECTION m_entitiesCS; // 4J added @@ -402,9 +402,9 @@ protected: private: int delayUntilNextMoodSound; - static const int CHUNK_POLL_RANGE = 9; - static const int CHUNK_TILE_TICK_COUNT = 80; - static const int CHUNK_SECTION_TILE_TICK_COUNT = (CHUNK_TILE_TICK_COUNT / 8) + 1; + static constexpr int CHUNK_POLL_RANGE = 9; + static constexpr int CHUNK_TILE_TICK_COUNT = 80; + static constexpr int CHUNK_SECTION_TILE_TICK_COUNT = (CHUNK_TILE_TICK_COUNT / 8) + 1; protected: virtual void buildAndPrepareChunksToPoll(); diff --git a/Minecraft.World/LevelChunk.cpp b/Minecraft.World/LevelChunk.cpp index 584e3df1..f68c5896 100644 --- a/Minecraft.World/LevelChunk.cpp +++ b/Minecraft.World/LevelChunk.cpp @@ -1228,11 +1228,11 @@ void LevelChunk::addRidingEntities(shared_ptr rider, CompoundTag *riderT CompoundTag *mountTag = riderTag; shared_ptr ridingEntity = rider; - while (mountTag != NULL && mountTag->contains(Entity::RIDING_TAG)) + while (mountTag != nullptr && mountTag->contains(Entity::RIDING_TAG)) { CompoundTag *nextMountTag = mountTag->getCompound(Entity::RIDING_TAG); shared_ptr mount = EntityIO::loadStatic(nextMountTag, level); - if (mount == NULL) + if (mount == nullptr) { break; } diff --git a/Minecraft.World/LevelData.cpp b/Minecraft.World/LevelData.cpp index fbc10ddb..a64b8ab7 100644 --- a/Minecraft.World/LevelData.cpp +++ b/Minecraft.World/LevelData.cpp @@ -193,7 +193,7 @@ LevelData::LevelData(CompoundTag *tag) this->loadedPlayerTag = nullptr; ======= { - this->loadedPlayerTag = NULL; + this->loadedPlayerTag = nullptr; >>>>>>> origin/main } */ diff --git a/Minecraft.World/LivingEntity.h b/Minecraft.World/LivingEntity.h index ecc819df..9fed322e 100644 --- a/Minecraft.World/LivingEntity.h +++ b/Minecraft.World/LivingEntity.h @@ -39,7 +39,7 @@ public: static const int SLOT_HELM = 4; static const int SWING_DURATION = 6; - static const int PLAYER_HURT_EXPERIENCE_TIME = SharedConstants::TICKS_PER_SECOND * 5; + static constexpr int PLAYER_HURT_EXPERIENCE_TIME = SharedConstants::TICKS_PER_SECOND * 5; private: static const double MIN_MOVEMENT_DISTANCE; diff --git a/Minecraft.World/MonsterPlacerItem.cpp b/Minecraft.World/MonsterPlacerItem.cpp index e5a84122..3b4cffa0 100644 --- a/Minecraft.World/MonsterPlacerItem.cpp +++ b/Minecraft.World/MonsterPlacerItem.cpp @@ -15,7 +15,7 @@ MonsterPlacerItem::MonsterPlacerItem(int id) : Item(id) { setMaxStackSize(16); // 4J-PB brought forward. It is 64 on PC, but we'll never be able to place that many setStackedByData(true); - overlay = NULL; + overlay = nullptr; } wstring MonsterPlacerItem::getHoverName(shared_ptr itemInstance) @@ -68,7 +68,7 @@ Icon *MonsterPlacerItem::getLayerIcon(int auxValue, int spriteLayer) shared_ptr MonsterPlacerItem::canSpawn(int iAuxVal, Level *level, int *piResult) { shared_ptr newEntity = EntityIO::newById(iAuxVal, level); - if (newEntity != NULL) + if (newEntity != nullptr) { bool canSpawn = false; @@ -182,7 +182,7 @@ bool MonsterPlacerItem::useOn(shared_ptr itemInstance, shared_ptr< level->setTile(x,y,z,0); level->setTile(x,y,z,Tile::mobSpawner_Id); shared_ptr mste = dynamic_pointer_cast( level->getTileEntity(x,y,z) ); - if(mste != NULL) + if(mste != nullptr) { mste->setEntityId( EntityIO::getEncodeId(itemInstance->getAuxValue()) ); return true; @@ -203,7 +203,7 @@ bool MonsterPlacerItem::useOn(shared_ptr itemInstance, shared_ptr< } int iResult=0; - bool spawned = spawnMobAt(level, itemInstance->getAuxValue(), x + .5, y + yOff, z + .5, &iResult) != NULL; + bool spawned = spawnMobAt(level, itemInstance->getAuxValue(), x + .5, y + yOff, z + .5, &iResult) != nullptr; if(bTestUseOnOnly) { diff --git a/Minecraft.World/MusicTile.cpp b/Minecraft.World/MusicTile.cpp index ebdb9680..b8290c5e 100644 --- a/Minecraft.World/MusicTile.cpp +++ b/Minecraft.World/MusicTile.cpp @@ -14,7 +14,7 @@ void MusicTile::neighborChanged(Level *level, int x, int y, int z, int type) bool signal = level->hasNeighborSignal(x, y, z); shared_ptr mte = dynamic_pointer_cast( level->getTileEntity(x, y, z) ); app.DebugPrintf("-------- Signal is %s, tile is currently %s\n",signal?"TRUE":"FALSE", mte->on?"ON":"OFF"); - if (mte != NULL && mte->on != signal) + if (mte != nullptr && mte->on != signal) { if (signal) { @@ -35,7 +35,7 @@ bool MusicTile::use(Level *level, int x, int y, int z, shared_ptr player if (soundOnly) return false; if (level->isClientSide) return true; shared_ptr mte = dynamic_pointer_cast( level->getTileEntity(x, y, z) ); - if (mte != NULL ) + if (mte != nullptr ) { mte->tune(); mte->playNote(level, x, y, z); @@ -47,7 +47,7 @@ void MusicTile::attack(Level *level, int x, int y, int z, shared_ptr pla { if (level->isClientSide) return; shared_ptr mte = dynamic_pointer_cast( level->getTileEntity(x, y, z) ); - if( mte != NULL ) mte->playNote(level, x, y, z); + if( mte != nullptr ) mte->playNote(level, x, y, z); } shared_ptr MusicTile::newTileEntity(Level *level) diff --git a/Minecraft.World/NetherStalkTile.cpp b/Minecraft.World/NetherStalkTile.cpp index eadf9646..adc9e26d 100644 --- a/Minecraft.World/NetherStalkTile.cpp +++ b/Minecraft.World/NetherStalkTile.cpp @@ -12,7 +12,7 @@ NetherStalkTile::NetherStalkTile(int id) : Bush(id) setTicking(true); updateDefaultShape(); - icons = NULL; + icons = nullptr; } // 4J Added override @@ -39,7 +39,7 @@ void NetherStalkTile::tick(Level *level, int x, int y, int z, Random *random) if (age < MAX_AGE) { //Biome *biome = biomeSource->getBiome(x, z); - //if (dynamic_cast(biome) != NULL) + //if (dynamic_cast(biome) != nullptr) //{ if (random->nextInt(10) == 0) { diff --git a/Minecraft.World/Ozelot.cpp b/Minecraft.World/Ozelot.cpp index 3c05f357..f4a011a2 100644 --- a/Minecraft.World/Ozelot.cpp +++ b/Minecraft.World/Ozelot.cpp @@ -214,7 +214,7 @@ bool Ozelot::interact(shared_ptr player) } else { - if (temptGoal->isRunning() && item != NULL && item->id == Item::fish_raw_Id && player->distanceToSqr(shared_from_this()) < 3 * 3) + if (temptGoal->isRunning() && item != nullptr && item->id == Item::fish_raw_Id && player->distanceToSqr(shared_from_this()) < 3 * 3) { // 4J-PB - don't lose the fish in creative mode if (!player->abilities.instabuild) item->count--; @@ -272,7 +272,7 @@ shared_ptr Ozelot::getBreedOffspring(shared_ptr target) bool Ozelot::isFood(shared_ptr itemInstance) { - return itemInstance != NULL && itemInstance->id == Item::fish_raw_Id; + return itemInstance != nullptr && itemInstance->id == Item::fish_raw_Id; } bool Ozelot::canMate(shared_ptr animal) @@ -281,7 +281,7 @@ bool Ozelot::canMate(shared_ptr animal) if (!isTame()) return false; shared_ptr partner = dynamic_pointer_cast(animal); - if (partner == NULL) return false; + if (partner == nullptr) return false; if (!partner->isTame()) return false; return isInLove() && partner->isInLove(); diff --git a/Minecraft.World/OzelotAttackGoal.cpp b/Minecraft.World/OzelotAttackGoal.cpp index 27ca2b5c..ab3336ec 100644 --- a/Minecraft.World/OzelotAttackGoal.cpp +++ b/Minecraft.World/OzelotAttackGoal.cpp @@ -21,14 +21,14 @@ OzelotAttackGoal::OzelotAttackGoal(Mob *mob) bool OzelotAttackGoal::canUse() { shared_ptr bestTarget = mob->getTarget(); - if (bestTarget == NULL) return false; + if (bestTarget == nullptr) return false; target = weak_ptr(bestTarget); return true; } bool OzelotAttackGoal::canContinueToUse() { - if (target.lock() == NULL || !target.lock()->isAlive()) return false; + if (target.lock() == nullptr || !target.lock()->isAlive()) return false; if (mob->distanceToSqr(target.lock()) > 15 * 15) return false; return !mob->getNavigation()->isDone() || canUse(); } diff --git a/Minecraft.World/PistonBaseTile.cpp b/Minecraft.World/PistonBaseTile.cpp index 204b7e39..26c83b94 100644 --- a/Minecraft.World/PistonBaseTile.cpp +++ b/Minecraft.World/PistonBaseTile.cpp @@ -17,8 +17,6 @@ const wstring PistonBaseTile::PLATFORM_STICKY_TEX = L"piston_top_sticky"; const wstring PistonBaseTile::BACK_TEX = L"piston_bottom"; const wstring PistonBaseTile::INSIDE_TEX = L"piston_inner_top"; -const float PistonBaseTile::PLATFORM_THICKNESS = 4.0f; - DWORD PistonBaseTile::tlsIdx = TlsAlloc(); // TU25 Note: IgnoreUpdate is removed. I need to find what they did. @@ -354,7 +352,7 @@ void PistonBaseTile::updateShape(LevelSource *level, int x, int y, int z, int fo if (isExtended(data)) { - const float thickness = PLATFORM_THICKNESS / 16.0f; + constexpr float thickness = PLATFORM_THICKNESS / 16.0f; switch (getFacing(data)) { case Facing::DOWN: diff --git a/Minecraft.World/PistonBaseTile.h b/Minecraft.World/PistonBaseTile.h index 59c2e833..9f322ee7 100644 --- a/Minecraft.World/PistonBaseTile.h +++ b/Minecraft.World/PistonBaseTile.h @@ -7,7 +7,7 @@ public: static const int EXTENDED_BIT = 8; static const int UNDEFINED_FACING = 7; - static const float PLATFORM_THICKNESS; + static const int PLATFORM_THICKNESS = 4; static const int MAX_PUSH_DEPTH = 12; static const int TRIGGER_EXTEND = 0; static const int TRIGGER_CONTRACT = 1; diff --git a/Minecraft.World/PistonExtensionTile.cpp b/Minecraft.World/PistonExtensionTile.cpp index bf5e6e60..a1ad1aee 100644 --- a/Minecraft.World/PistonExtensionTile.cpp +++ b/Minecraft.World/PistonExtensionTile.cpp @@ -121,11 +121,11 @@ void PistonExtensionTile::addAABBs(Level *level, int x, int y, int z, AABB *box, { int data = level->getData(x, y, z); - const float thickness = PistonBaseTile::PLATFORM_THICKNESS / 16.0f; - const float smallEdge1 = (8.0f - (PistonBaseTile::PLATFORM_THICKNESS / 2.0f)) / 16.0f; - const float smallEdge2 = (8.0f + (PistonBaseTile::PLATFORM_THICKNESS / 2.0f)) / 16.0f; - const float largeEdge1 = (8.0f - PistonBaseTile::PLATFORM_THICKNESS) / 16.0f; - const float largeEdge2 = (8.0f + PistonBaseTile::PLATFORM_THICKNESS) / 16.0f; + constexpr float thickness = PistonBaseTile::PLATFORM_THICKNESS / 16.0f; + constexpr float smallEdge1 = (8.0f - (PistonBaseTile::PLATFORM_THICKNESS / 2.0f)) / 16.0f; + constexpr float smallEdge2 = (8.0f + (PistonBaseTile::PLATFORM_THICKNESS / 2.0f)) / 16.0f; + constexpr float largeEdge1 = (8.0f - PistonBaseTile::PLATFORM_THICKNESS) / 16.0f; + constexpr float largeEdge2 = (8.0f + PistonBaseTile::PLATFORM_THICKNESS) / 16.0f; switch (getFacing(data)) { diff --git a/Minecraft.World/RecordPlayerTile.cpp b/Minecraft.World/RecordPlayerTile.cpp index de5f7386..4e7dba49 100644 --- a/Minecraft.World/RecordPlayerTile.cpp +++ b/Minecraft.World/RecordPlayerTile.cpp @@ -10,7 +10,7 @@ RecordPlayerTile::RecordPlayerTile(int id) : EntityTile(id, Material::wood) { - iconTop = NULL; + iconTop = nullptr; } Icon *RecordPlayerTile::getTexture(int face, int data) @@ -54,7 +54,7 @@ void RecordPlayerTile::dropRecording(Level *level, int x, int y, int z) if (level->isClientSide) return; shared_ptr rte = dynamic_pointer_cast( level->getTileEntity(x, y, z) ); - if( rte == NULL ) return; + if( rte == nullptr ) return; int oldRecord = rte->record; if (oldRecord == 0) return; diff --git a/Minecraft.World/RepairMenu.cpp b/Minecraft.World/RepairMenu.cpp index a4c48edf..7b0078b9 100644 --- a/Minecraft.World/RepairMenu.cpp +++ b/Minecraft.World/RepairMenu.cpp @@ -55,7 +55,7 @@ void RepairMenu::createResult() if (DEBUG_COST) app.DebugPrintf("----"); - if (input == NULL) + if (input == nullptr) { resultSlots->setItem(0, nullptr); cost = 0; @@ -68,15 +68,15 @@ void RepairMenu::createResult() unordered_map *enchantments = EnchantmentHelper::getEnchantments(result); bool usingBook = false; - tax += input->getBaseRepairCost() + (addition == NULL ? 0 : addition->getBaseRepairCost()); + tax += input->getBaseRepairCost() + (addition == nullptr ? 0 : addition->getBaseRepairCost()); if (DEBUG_COST) { - app.DebugPrintf("Starting with base repair tax of %d (%d + %d)\n", tax, input->getBaseRepairCost(), (addition == NULL ? 0 : addition->getBaseRepairCost())); + app.DebugPrintf("Starting with base repair tax of %d (%d + %d)\n", tax, input->getBaseRepairCost(), (addition == nullptr ? 0 : addition->getBaseRepairCost())); } repairItemCountCost = 0; - if (addition != NULL) + if (addition != nullptr) { usingBook = addition->id == Item::enchantedBook_Id && Item::enchantedBook->getEnchantments(addition)->size() > 0; @@ -273,10 +273,10 @@ void RepairMenu::createResult() result = nullptr; } - if (result != NULL) + if (result != nullptr) { int baseCost = result->getBaseRepairCost(); - if (addition != NULL && baseCost < addition->getBaseRepairCost()) baseCost = addition->getBaseRepairCost(); + if (addition != nullptr && baseCost < addition->getBaseRepairCost()) baseCost = addition->getBaseRepairCost(); if (result->hasCustomHoverName()) baseCost -= 9; if (baseCost < 0) baseCost = 0; baseCost += 2; @@ -327,7 +327,7 @@ void RepairMenu::removed(shared_ptr player) for (int i = 0; i < repairSlots->getContainerSize(); i++) { shared_ptr item = repairSlots->removeItemNoUpdate(i); - if (item != NULL) + if (item != nullptr) { player->drop(item); } @@ -345,7 +345,7 @@ shared_ptr RepairMenu::quickMoveStack(shared_ptr player, i { shared_ptr clicked = nullptr; Slot *slot = slots->at(slotIndex); - if (slot != NULL && slot->hasItem()) + if (slot != nullptr && slot->hasItem()) { shared_ptr stack = slot->getItem(); clicked = stack->copy(); diff --git a/Minecraft.World/RepairMenu.h b/Minecraft.World/RepairMenu.h index e0c90267..4c7ab461 100644 --- a/Minecraft.World/RepairMenu.h +++ b/Minecraft.World/RepairMenu.h @@ -6,20 +6,20 @@ class RepairMenu : public AbstractContainerMenu { friend class RepairResultSlot; private: - static const bool DEBUG_COST = false; + static constexpr bool DEBUG_COST = false; public: - static const int INPUT_SLOT = 0; - static const int ADDITIONAL_SLOT = 1; - static const int RESULT_SLOT = 2; + static constexpr int INPUT_SLOT = 0; + static constexpr int ADDITIONAL_SLOT = 1; + static constexpr int RESULT_SLOT = 2; - static const int INV_SLOT_START = RESULT_SLOT + 1; - static const int INV_SLOT_END = INV_SLOT_START + 9 * 3; - static const int USE_ROW_SLOT_START = INV_SLOT_END; - static const int USE_ROW_SLOT_END = USE_ROW_SLOT_START + 9; + static constexpr int INV_SLOT_START = RESULT_SLOT + 1; + static constexpr int INV_SLOT_END = INV_SLOT_START + 9 * 3; + static constexpr int USE_ROW_SLOT_START = INV_SLOT_END; + static constexpr int USE_ROW_SLOT_END = USE_ROW_SLOT_START + 9; public: - static const int DATA_TOTAL_COST = 0; + static constexpr int DATA_TOTAL_COST = 0; private: shared_ptr resultSlots; diff --git a/Minecraft.World/SetRidingPacket.cpp b/Minecraft.World/SetRidingPacket.cpp index 454da047..32dc0dbe 100644 --- a/Minecraft.World/SetRidingPacket.cpp +++ b/Minecraft.World/SetRidingPacket.cpp @@ -16,7 +16,7 @@ SetRidingPacket::SetRidingPacket() SetRidingPacket::SetRidingPacket(shared_ptr rider, shared_ptr riding) { this->riderId = rider->entityId; - this->riddenId = riding != NULL ? riding->entityId : -1; + this->riddenId = riding != nullptr ? riding->entityId : -1; } int SetRidingPacket::getEstimatedSize() diff --git a/Minecraft.World/ZoneFile.h b/Minecraft.World/ZoneFile.h index 5adb60ee..eff8b1ce 100644 --- a/Minecraft.World/ZoneFile.h +++ b/Minecraft.World/ZoneFile.h @@ -6,7 +6,7 @@ class ZoneFile { public: - static const int FILE_HEADER_SIZE = 1024 * 4; + static constexpr int FILE_HEADER_SIZE = 1024 * 4; private: static const int MAGIC_NUMBER = 0x13737000;