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/Packet.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'Minecraft.World/Packet.cpp') diff --git a/Minecraft.World/Packet.cpp b/Minecraft.World/Packet.cpp index bc2152b2..129024b7 100644 --- a/Minecraft.World/Packet.cpp +++ b/Minecraft.World/Packet.cpp @@ -357,7 +357,7 @@ shared_ptr Packet::readPacket(DataInputStream *dis, bool isServer) // th } packet = getPacket(id); - if (packet == NULL) assert(false);//throw new IOException(wstring(L"Bad packet id ") + std::to_wstring(id)); + if (packet == nullptr) assert(false);//throw new IOException(wstring(L"Bad packet id ") + std::to_wstring(id)); s_lastIds[s_lastIdPos] = id; s_lastIdPos = (s_lastIdPos + 1) % 8; @@ -369,7 +369,7 @@ shared_ptr Packet::readPacket(DataInputStream *dis, bool isServer) // th // { // // reached end of stream // OutputDebugString("Reached end of stream"); - // return NULL; + // return nullptr; // } // 4J - Don't bother tracking stats in a content package @@ -410,7 +410,7 @@ void Packet::writeUtf(const wstring& value, DataOutputStream *dos) // throws IOE } #endif - dos->writeShort((short)value.length()); + dos->writeShort(static_cast(value.length())); dos->writeChars(value); } @@ -467,7 +467,7 @@ double Packet::PacketStatistics::getAverageSize() { return 0; } - return (double) totalSize / count; + return static_cast(totalSize) / count; } int Packet::PacketStatistics::getTotalSize() @@ -536,7 +536,7 @@ shared_ptr Packet::readItem(DataInputStream *dis) int count = dis->readByte(); int damage = dis->readShort(); - item = shared_ptr( new ItemInstance(id, count, damage) ); + item = std::make_shared(id, count, damage); // 4J Stu - Always read/write the tag //if (Item.items[id].canBeDepleted() || Item.items[id].shouldOverrideMultiplayerNBT()) { @@ -549,7 +549,7 @@ shared_ptr Packet::readItem(DataInputStream *dis) void Packet::writeItem(shared_ptr item, DataOutputStream *dos) { - if (item == NULL) + if (item == nullptr) { dos->writeShort(-1); } @@ -569,7 +569,7 @@ void Packet::writeItem(shared_ptr item, DataOutputStream *dos) CompoundTag *Packet::readNbt(DataInputStream *dis) { int size = dis->readShort(); - if (size < 0) return NULL; + if (size < 0) return nullptr; byteArray buff(size); dis->readFully(buff); CompoundTag *result = (CompoundTag *) NbtIo::decompress(buff); @@ -579,14 +579,14 @@ CompoundTag *Packet::readNbt(DataInputStream *dis) void Packet::writeNbt(CompoundTag *tag, DataOutputStream *dos) { - if (tag == NULL) + if (tag == nullptr) { dos->writeShort(-1); } else { byteArray buff = NbtIo::compress(tag); - dos->writeShort((short) buff.length); + dos->writeShort(static_cast(buff.length)); dos->write(buff); delete [] buff.data; } -- cgit v1.2.3