From a9be52c41a02d207233199e98898fe7483d7e817 Mon Sep 17 00:00:00 2001 From: ModMaker101 <119018978+ModMaker101@users.noreply.github.com> Date: Sat, 7 Mar 2026 21:56:03 -0500 Subject: Project modernization (#630) * 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 --- Minecraft.World/MapItem.cpp | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'Minecraft.World/MapItem.cpp') diff --git a/Minecraft.World/MapItem.cpp b/Minecraft.World/MapItem.cpp index 03529c1a..61c203e3 100644 --- a/Minecraft.World/MapItem.cpp +++ b/Minecraft.World/MapItem.cpp @@ -24,7 +24,7 @@ shared_ptr MapItem::getSavedData(short idNum, Level *level) std::wstring id = wstring( L"map_" ) + std::to_wstring(idNum); shared_ptr mapItemSavedData = dynamic_pointer_cast(level->getSavedData(typeid(MapItemSavedData), id)); - if (mapItemSavedData == NULL) + if (mapItemSavedData == nullptr) { // 4J Stu - This call comes from ClientConnection, but i don't see why we should be trying to work out // the id again when it's passed as a param. In any case that won't work with the new map setup @@ -32,7 +32,7 @@ shared_ptr MapItem::getSavedData(short idNum, Level *level) int aux = idNum; id = wstring( L"map_" ) + std::to_wstring(aux); - mapItemSavedData = shared_ptr( new MapItemSavedData(id) ); + mapItemSavedData = std::make_shared(id); level->setSavedData(id, (shared_ptr ) mapItemSavedData); } @@ -48,14 +48,14 @@ shared_ptr MapItem::getSavedData(shared_ptr item shared_ptr mapItemSavedData = dynamic_pointer_cast( level->getSavedData(typeid(MapItemSavedData), id ) ); bool newData = false; - if (mapItemSavedData == NULL) + if (mapItemSavedData == nullptr) { // 4J Stu - I don't see why we should be trying to work out the id again when it's passed as a param. // In any case that won't work with the new map setup //itemInstance->setAuxValue(level->getFreeAuxValueFor(L"map")); id = wstring( L"map_" ) + std::to_wstring(itemInstance->getAuxValue() ); - mapItemSavedData = shared_ptr( new MapItemSavedData(id) ); + mapItemSavedData = std::make_shared(id); newData = true; } @@ -71,10 +71,10 @@ shared_ptr MapItem::getSavedData(shared_ptr item { #ifdef _LARGE_WORLDS int scale = MapItemSavedData::MAP_SIZE * 2 * (1 << mapItemSavedData->scale); - mapItemSavedData->x = Math::round((float) level->getLevelData()->getXSpawn() / scale) * scale; + mapItemSavedData->x = Math::round(static_cast(level->getLevelData()->getXSpawn()) / scale) * scale; mapItemSavedData->z = Math::round(level->getLevelData()->getZSpawn() / scale) * scale; #endif - mapItemSavedData->dimension = (byte) level->dimension->id; + mapItemSavedData->dimension = static_cast(level->dimension->id); mapItemSavedData->setDirty(); @@ -190,7 +190,7 @@ void MapItem::update(Level *level, shared_ptr player, shared_ptr 0 && below != 0 && Tile::tiles[below]->material->isLiquid()); } } - hh += yy / (double) (scale * scale); + hh += yy / static_cast(scale * scale); count[t]++; } @@ -237,7 +237,7 @@ void MapItem::update(Level *level, shared_ptr player, shared_ptrcolors[x + z * w]; - byte newColor = (byte) (col * 4 + br); + byte newColor = static_cast(col * 4 + br); if (oldColor != newColor) { if (yd0 > z) yd0 = z; @@ -295,9 +295,9 @@ shared_ptr MapItem::getUpdatePacket(shared_ptr itemInstanc { charArray data = MapItem::getSavedData(itemInstance, level)->getUpdatePacket(itemInstance, level, player); - if (data.data == NULL || data.length == 0) return nullptr; + if (data.data == nullptr || data.length == 0) return nullptr; - shared_ptr retval = shared_ptr(new ComplexItemDataPacket((short) Item::map->id, (short) itemInstance->getAuxValue(), data)); + shared_ptr retval = std::make_shared(static_cast(Item::map->id), static_cast(itemInstance->getAuxValue()), data); delete data.data; return retval; } @@ -309,8 +309,8 @@ void MapItem::onCraftedBy(shared_ptr itemInstance, Level *level, s int mapScale = 3; #ifdef _LARGE_WORLDS int scale = MapItemSavedData::MAP_SIZE * 2 * (1 << mapScale); - int centreXC = (int) (Math::round(player->x / scale) * scale); - int centreZC = (int) (Math::round(player->z / scale) * scale); + int centreXC = static_cast(Math::round(player->x / scale) * scale); + int centreZC = static_cast(Math::round(player->z / scale) * scale); #else // 4J-PB - for Xbox maps, we'll centre them on the origin of the world, since we can fit the whole world in our map int centreXC = 0; @@ -325,9 +325,9 @@ void MapItem::onCraftedBy(shared_ptr itemInstance, Level *level, s shared_ptr data = getSavedData(itemInstance->getAuxValue(), level); // 4J Stu - We only have one map per player per dimension, so don't reset the one that they have // when a new one is created - if( data == NULL ) + if( data == nullptr ) { - data = shared_ptr( new MapItemSavedData(id) ); + data = std::make_shared(id); } level->setSavedData(id, (shared_ptr ) data); @@ -335,7 +335,7 @@ void MapItem::onCraftedBy(shared_ptr itemInstance, Level *level, s // 4J-PB - for Xbox maps, we'll centre them on the origin of the world, since we can fit the whole world in our map data->x = centreXC; data->z = centreZC; - data->dimension = (byte) level->dimension->id; + data->dimension = static_cast(level->dimension->id); data->setDirty(); } -- cgit v1.2.3