From 28614b922fb77149a54da1a87bebfbc98736f296 Mon Sep 17 00:00:00 2001 From: ModMaker101 <119018978+ModMaker101@users.noreply.github.com> Date: Sun, 8 Mar 2026 19:08:36 -0400 Subject: Modernize project codebase (#906) * Fixed boats falling and a TP glitch #266 * Replaced every C-style cast with C++ ones * Replaced every C-style cast with C++ ones * Fixed boats falling and a TP glitch #266 * Updated NULL to nullptr and fixing some type issues * Modernized and fixed a few bugs - Replaced most instances of `NULL` with `nullptr`. - Replaced most `shared_ptr(new ...)` with `make_shared`. - Removed the `nullptr` macro as it was interfering with the actual nullptr keyword in some instances. * Fixing more conflicts * Replace int loops with size_t and start work on overrides * Add safety checks and fix a issue with vector going OOR --- Minecraft.World/MapItemSavedData.cpp | 86 ++++++++++++++++++------------------ 1 file changed, 43 insertions(+), 43 deletions(-) (limited to 'Minecraft.World/MapItemSavedData.cpp') diff --git a/Minecraft.World/MapItemSavedData.cpp b/Minecraft.World/MapItemSavedData.cpp index c06c3fac..0a5eb7c4 100644 --- a/Minecraft.World/MapItemSavedData.cpp +++ b/Minecraft.World/MapItemSavedData.cpp @@ -65,8 +65,8 @@ charArray MapItemSavedData::HoldingPlayer::nextUpdatePacket(shared_ptrdecorations.size(); - unsigned int nonPlayerDecorationsSize = (int)parent->nonPlayerDecorations.size(); + unsigned int playerDecorationsSize = static_cast(parent->decorations.size()); + unsigned int nonPlayerDecorationsSize = static_cast(parent->nonPlayerDecorations.size()); charArray data = charArray( (playerDecorationsSize + nonPlayerDecorationsSize ) * DEC_PACKET_BYTES + 1); data[0] = 1; for (unsigned int i = 0; i < parent->decorations.size(); i++) @@ -74,7 +74,7 @@ charArray MapItemSavedData::HoldingPlayer::nextUpdatePacket(shared_ptrdecorations.at(i); #ifdef _LARGE_WORLDS data[i * DEC_PACKET_BYTES + 1] = (char) (md->img); - data[i * DEC_PACKET_BYTES + 8] = (char) (md->rot & 0xF); + data[i * DEC_PACKET_BYTES + 8] = static_cast(md->rot & 0xF); #else data[i * DEC_PACKET_BYTES + 1] = (char) ((md->img << 4) | (md->rot & 0xF)); #endif @@ -92,7 +92,7 @@ charArray MapItemSavedData::HoldingPlayer::nextUpdatePacket(shared_ptrimg); - data[dataIndex * DEC_PACKET_BYTES + 8] = (char) (md->rot & 0xF); + data[dataIndex * DEC_PACKET_BYTES + 8] = static_cast(md->rot & 0xF); #else data[dataIndex * DEC_PACKET_BYTES + 1] = (char) ((md->img << 4) | (md->rot & 0xF)); #endif @@ -107,7 +107,7 @@ charArray MapItemSavedData::HoldingPlayer::nextUpdatePacket(shared_ptrisFramed(); - if (lastSentDecorations.data == NULL || lastSentDecorations.length != data.length) + if (lastSentDecorations.data == nullptr || lastSentDecorations.length != data.length) { thesame = false; } @@ -125,7 +125,7 @@ charArray MapItemSavedData::HoldingPlayer::nextUpdatePacket(shared_ptr(column); + data[2] = static_cast(min); for (unsigned int y = 0; y < data.length - 3; y++) { data[y + 3] = parent->colors[(y + min) * MapItem::IMAGE_WIDTH + column]; @@ -199,7 +199,7 @@ void MapItemSavedData::load(CompoundTag *tag) { byteArray newColors = tag->getByteArray(L"colors"); //4J - if(colors.data != NULL) + if(colors.data != nullptr) { delete[] colors.data; } @@ -236,7 +236,7 @@ void MapItemSavedData::tickCarriedBy(shared_ptr player, shared_ptr hp = shared_ptr( new HoldingPlayer(player, this ) ); + shared_ptr hp = std::make_shared(player, this); carriedByPlayers.insert( playerHoldingPlayerMapType::value_type(player, hp) ); carriedBy.push_back(hp); } @@ -303,17 +303,17 @@ void MapItemSavedData::tickCarriedBy(shared_ptr player, shared_ptr(xd * 2 + 0.5); + char y = static_cast(yd * 2 + 0.5); int size = MAP_SIZE - 1; #ifdef _LARGE_WORLDS if (xd < -size || yd < -size || xd > size || yd > size) { - if (xd <= -size) x = (byte) (size * 2 + 2.5); - if (yd <= -size) y = (byte) (size * 2 + 2.5); - if (xd >= size) x = (byte) (size * 2 + 1); - if (yd >= size) y = (byte) (size * 2 + 1); + if (xd <= -size) x = static_cast(size * 2 + 2.5); + if (yd <= -size) y = static_cast(size * 2 + 2.5); + if (xd >= size) x = static_cast(size * 2 + 1); + if (yd >= size) y = static_cast(size * 2 + 1); } #endif //decorations.push_back(new MapDecoration(4, x, y, 0)); @@ -332,25 +332,25 @@ void MapItemSavedData::tickCarriedBy(shared_ptr player, shared_ptrgetFrame()->entityId ) == nonPlayerDecorations.end() ) { - float xd = (float) ( item->getFrame()->xTile - x ) / (1 << scale); - float yd = (float) ( item->getFrame()->zTile - z ) / (1 << scale); - char x = (char) (xd * 2 + 0.5); - char y = (char) (yd * 2 + 0.5); + float xd = static_cast(item->getFrame()->xTile - x) / (1 << scale); + float yd = static_cast(item->getFrame()->zTile - z) / (1 << scale); + char x = static_cast(xd * 2 + 0.5); + char y = static_cast(yd * 2 + 0.5); int size = MAP_SIZE - 1; - char rot = (char) ( (item->getFrame()->dir * 90) * 16 / 360); + char rot = static_cast((item->getFrame()->dir * 90) * 16 / 360); if (dimension < 0) { - int s = (int) (playerLevel->getLevelData()->getDayTime() / 10); - rot = (char) ((s * s * 34187121 + s * 121) >> 15 & 15); + int s = static_cast(playerLevel->getLevelData()->getDayTime() / 10); + rot = static_cast((s * s * 34187121 + s * 121) >> 15 & 15); } #ifdef _LARGE_WORLDS if (xd < -size || yd < -size || xd > size || yd > size) { - if (xd <= -size) x = (byte) (size * 2 + 2.5); - if (yd <= -size) y = (byte) (size * 2 + 2.5); - if (xd >= size) x = (byte) (size * 2 + 1); - if (yd >= size) y = (byte) (size * 2 + 1); + if (xd <= -size) x = static_cast(size * 2 + 2.5); + if (yd <= -size) y = static_cast(size * 2 + 2.5); + if (xd >= size) x = static_cast(size * 2 + 1); + if (yd >= size) y = static_cast(size * 2 + 1); } #endif //decorations.push_back(new MapDecoration(7, x, y, 0)); @@ -399,12 +399,12 @@ void MapItemSavedData::tickCarriedBy(shared_ptr player, shared_ptrgetPlayerList(); for(auto& decorationPlayer : players->players) { - if(decorationPlayer!=NULL && decorationPlayer->dimension == this->dimension) + if(decorationPlayer!=nullptr && decorationPlayer->dimension == this->dimension) { - float xd = (float) (decorationPlayer->x - x) / (1 << scale); - float yd = (float) (decorationPlayer->z - z) / (1 << scale); - char x = (char) (xd * 2); - char y = (char) (yd * 2); + float xd = static_cast(decorationPlayer->x - x) / (1 << scale); + float yd = static_cast(decorationPlayer->z - z) / (1 << scale); + char x = static_cast(xd * 2); + char y = static_cast(yd * 2); int size = MAP_SIZE; // - 1; char rot; char imgIndex; @@ -414,16 +414,16 @@ void MapItemSavedData::tickCarriedBy(shared_ptr player, shared_ptryRot * 16 / 360 + 0.5); + rot = static_cast(decorationPlayer->yRot * 16 / 360 + 0.5); if (dimension < 0) { - int s = (int) (playerLevel->getLevelData()->getDayTime() / 10); - rot = (char) ((s * s * 34187121 + s * 121) >> 15 & 15); + int s = static_cast(playerLevel->getLevelData()->getDayTime() / 10); + rot = static_cast((s * s * 34187121 + s * 121) >> 15 & 15); } // 4J Stu - As we have added new icons for players on a new row below // other icons used in Java we need to move our index to the next row - imgIndex = (int)decorationPlayer->getPlayerIndex(); + imgIndex = static_cast(decorationPlayer->getPlayerIndex()); if(imgIndex>3) imgIndex += 4; } #ifdef _LARGE_WORLDS @@ -431,16 +431,16 @@ void MapItemSavedData::tickCarriedBy(shared_ptr player, shared_ptrgetPlayerIndex(); + imgIndex = static_cast(decorationPlayer->getPlayerIndex()); if(imgIndex>3) imgIndex += 4; imgIndex += 16; // Add 16 to indicate that it's on the next texture rot = 0; size--; // Added to match the old adjusted size - if (xd <= -size) x = (byte) (size * 2 + 2.5); - if (yd <= -size) y = (byte) (size * 2 + 2.5); - if (xd >= size) x = (byte) (size * 2 + 1); - if (yd >= size) y = (byte) (size * 2 + 1); + if (xd <= -size) x = static_cast(size * 2 + 2.5); + if (yd <= -size) y = static_cast(size * 2 + 2.5); + if (xd >= size) x = static_cast(size * 2 + 1); + if (yd >= size) y = static_cast(size * 2 + 1); } #endif @@ -527,7 +527,7 @@ void MapItemSavedData::handleComplexItemData(charArray &data) #endif char x = data[i * DEC_PACKET_BYTES + 2]; char y = data[i * DEC_PACKET_BYTES + 3]; - int entityId = (((int)data[i * DEC_PACKET_BYTES + 4])&0xFF) | ( (((int)data[i * DEC_PACKET_BYTES + 5])&0xFF)<<8) | ((((int)data[i * DEC_PACKET_BYTES + 6])&0xFF)<<16) | ((((int)data[i * DEC_PACKET_BYTES + 7])&0x7F)<<24); + int entityId = (static_cast(data[i * DEC_PACKET_BYTES + 4])&0xFF) | ( (static_cast(data[i * DEC_PACKET_BYTES + 5])&0xFF)<<8) | ((static_cast(data[i * DEC_PACKET_BYTES + 6])&0xFF)<<16) | ((static_cast(data[i * DEC_PACKET_BYTES + 7])&0x7F)<<24); bool visible = (data[i * DEC_PACKET_BYTES + 7] & 0x80) != 0; decorations.push_back(new MapDecoration(img, x, y, rot, entityId, visible)); } @@ -545,7 +545,7 @@ shared_ptr MapItemSavedData::getHoldingPlayer(s if (it == carriedByPlayers.end()) { - hp = shared_ptr( new HoldingPlayer(player, this) ); + hp = std::make_shared(player, this); carriedByPlayers[player] = hp; carriedBy.push_back(hp); } -- cgit v1.2.3