From 41d8202c478bba47103d050758faf7ae7cd8dca7 Mon Sep 17 00:00:00 2001 From: MathiewMay Date: Tue, 10 Mar 2026 18:20:33 -0400 Subject: [PATCH] applied changes requested by tropicaaal "i would prefer that these be cast to sized integer types int8_t for portability reasons." "The light layer changes are ultimately a hack over the broken renderer implementation and probably out of scope for this PR. There's an in-progress fix for the root cause of this, so this should be removed." "std::numeric_limits::max()" --- Minecraft.Client/Rendering/GameRenderer.cpp | 2 +- .../Network/Packets/MoveEntityPacket.cpp | 36 +++++++-------- .../Network/Packets/MoveEntityPacket.h | 8 ++-- .../Network/Packets/MoveEntityPacketSmall.cpp | 45 ++++++++++--------- .../Network/Packets/MoveEntityPacketSmall.h | 12 ++--- .../Network/Packets/SetEntityMotionPacket.cpp | 6 +-- .../Network/Packets/SetEntityMotionPacket.h | 2 +- .../Network/Packets/TeleportEntityPacket.cpp | 10 ++--- .../Network/Packets/TeleportEntityPacket.h | 8 ++-- 9 files changed, 65 insertions(+), 64 deletions(-) diff --git a/Minecraft.Client/Rendering/GameRenderer.cpp b/Minecraft.Client/Rendering/GameRenderer.cpp index 0b157937a..6a0fe0d4c 100644 --- a/Minecraft.Client/Rendering/GameRenderer.cpp +++ b/Minecraft.Client/Rendering/GameRenderer.cpp @@ -1402,7 +1402,7 @@ void GameRenderer::renderLevel(float a, __int64 until) #endif PIXEndNamedEvent(); PIXBeginNamedEvent(0,"Particle render"); - //turnOnLightLayer(a); // 4J - brought forward from 1.8.2 + turnOnLightLayer(a); // 4J - brought forward from 1.8.2 particleEngine->renderLit(cameraEntity, a); Lighting::turnOff(); setupFog(0, a); diff --git a/Minecraft.World/Network/Packets/MoveEntityPacket.cpp b/Minecraft.World/Network/Packets/MoveEntityPacket.cpp index b0f6298fc..6b5cc94c8 100644 --- a/Minecraft.World/Network/Packets/MoveEntityPacket.cpp +++ b/Minecraft.World/Network/Packets/MoveEntityPacket.cpp @@ -69,24 +69,24 @@ MoveEntityPacket::PosRot::PosRot() hasRot = true; } -MoveEntityPacket::PosRot::PosRot(int id, char xa, char ya, char za, char yRot, char xRot) : MoveEntityPacket( id ) +MoveEntityPacket::PosRot::PosRot(int id, int8_t xa, int8_t ya, int8_t za, int8_t yRot, int8_t xRot) : MoveEntityPacket( id ) { - this->xa = (int)(signed char)xa; - this->ya = (int)(signed char)ya; - this->za = (int)(signed char)za; - this->yRot = (int)(signed char)yRot; - this->xRot = (int)(signed char)xRot; + this->xa = (int)(int8_t)xa; + this->ya = (int)(int8_t)ya; + this->za = (int)(int8_t)za; + this->yRot = (int)(int8_t)yRot; + this->xRot = (int)(int8_t)xRot; hasRot = true; } void MoveEntityPacket::PosRot::read(DataInputStream *dis) //throws IOException { MoveEntityPacket::read(dis); - xa = (int)(signed char)dis->readByte(); - ya = (int)(signed char)dis->readByte(); - za = (int)(signed char)dis->readByte(); - yRot = (int)(signed char)dis->readByte(); - xRot = (int)(signed char)dis->readByte(); + xa = (int)(int8_t)dis->readByte(); + ya = (int)(int8_t)dis->readByte(); + za = (int)(int8_t)dis->readByte(); + yRot = (int)(int8_t)dis->readByte(); + xRot = (int)(int8_t)dis->readByte(); } void MoveEntityPacket::PosRot::write(DataOutputStream *dos) //throws IOException @@ -108,7 +108,7 @@ MoveEntityPacket::Pos::Pos() { } -MoveEntityPacket::Pos::Pos(int id, char xa, char ya, char za) : MoveEntityPacket(id) +MoveEntityPacket::Pos::Pos(int id, int8_t xa, int8_t ya, int8_t za) : MoveEntityPacket(id) { this->xa = xa; this->ya = ya; @@ -118,9 +118,9 @@ MoveEntityPacket::Pos::Pos(int id, char xa, char ya, char za) : MoveEntityPacket void MoveEntityPacket::Pos::read(DataInputStream *dis) //throws IOException { MoveEntityPacket::read(dis); - xa = (int)(signed char)dis->readByte(); - ya = (int)(signed char)dis->readByte(); - za = (int)(signed char)dis->readByte(); + xa = (int)(int8_t)dis->readByte(); + ya = (int)(int8_t)dis->readByte(); + za = (int)(int8_t)dis->readByte(); } void MoveEntityPacket::Pos::write(DataOutputStream *dos) //throws IOException @@ -141,7 +141,7 @@ MoveEntityPacket::Rot::Rot() hasRot = true; } -MoveEntityPacket::Rot::Rot(int id, char yRot, char xRot) : MoveEntityPacket(id) +MoveEntityPacket::Rot::Rot(int id, int8_t yRot, int8_t xRot) : MoveEntityPacket(id) { this->yRot = yRot; this->xRot = xRot; @@ -151,8 +151,8 @@ MoveEntityPacket::Rot::Rot(int id, char yRot, char xRot) : MoveEntityPacket(id) void MoveEntityPacket::Rot::read(DataInputStream *dis) //throws IOException { MoveEntityPacket::read(dis); - yRot = (int)(signed char)dis->readByte(); - xRot = (int)(signed char)dis->readByte(); + yRot = (int)(int8_t)dis->readByte(); + xRot = (int)(int8_t)dis->readByte(); } void MoveEntityPacket::Rot::write(DataOutputStream *dos) //throws IOException diff --git a/Minecraft.World/Network/Packets/MoveEntityPacket.h b/Minecraft.World/Network/Packets/MoveEntityPacket.h index 62560809f..8d2ac049c 100644 --- a/Minecraft.World/Network/Packets/MoveEntityPacket.h +++ b/Minecraft.World/Network/Packets/MoveEntityPacket.h @@ -13,7 +13,7 @@ public: class Rot; int id; - char xa, ya, za, yRot, xRot; + int8_t xa, ya, za, yRot, xRot; bool hasRot; MoveEntityPacket(); @@ -35,7 +35,7 @@ class MoveEntityPacket::PosRot : public MoveEntityPacket { public: PosRot(); - PosRot(int id, char xa, char ya, char za, char yRot, char xRot); + PosRot(int id, int8_t xa, int8_t ya, int8_t za, int8_t yRot, int8_t xRot); virtual void read(DataInputStream *dis); virtual void write(DataOutputStream *dos); @@ -50,7 +50,7 @@ class MoveEntityPacket::Pos : public MoveEntityPacket { public: Pos(); - Pos(int id, char xa, char ya, char za); + Pos(int id, int8_t xa, int8_t ya, int8_t za); virtual void read(DataInputStream *dis); virtual void write(DataOutputStream *dos); @@ -65,7 +65,7 @@ class MoveEntityPacket::Rot : public MoveEntityPacket { public: Rot(); - Rot(int id, char yRot, char xRot); + Rot(int id, int8_t yRot, int8_t xRot); virtual void read(DataInputStream *dis); virtual void write(DataOutputStream *dos); diff --git a/Minecraft.World/Network/Packets/MoveEntityPacketSmall.cpp b/Minecraft.World/Network/Packets/MoveEntityPacketSmall.cpp index 1c698f720..daf3eb8a9 100644 --- a/Minecraft.World/Network/Packets/MoveEntityPacketSmall.cpp +++ b/Minecraft.World/Network/Packets/MoveEntityPacketSmall.cpp @@ -1,5 +1,6 @@ #include "../../Platform/stdafx.h" #include +#include #include "../../IO/Streams/InputOutputStream.h" #include "PacketListener.h" #include "MoveEntityPacketSmall.h" @@ -31,7 +32,7 @@ void MoveEntityPacketSmall::read(DataInputStream *dis) //throws IOException void MoveEntityPacketSmall::write(DataOutputStream *dos) //throws IOException { - if(id < 0 || id > 32767 ) + if(id < 0 || id > std::numeric_limits::max() ) { // We shouln't be tracking an entity that doesn't have a short type of id __debugbreak(); @@ -65,7 +66,7 @@ MoveEntityPacketSmall::PosRot::PosRot() hasRot = true; } -MoveEntityPacketSmall::PosRot::PosRot(int id, char xa, char ya, char za, char yRot, char xRot) : MoveEntityPacketSmall( id ) +MoveEntityPacketSmall::PosRot::PosRot(int id, int8_t xa, int8_t ya, int8_t za, int8_t yRot, int8_t xRot) : MoveEntityPacketSmall( id ) { this->xa = xa; this->ya = ya; @@ -77,22 +78,22 @@ MoveEntityPacketSmall::PosRot::PosRot(int id, char xa, char ya, char za, char yR void MoveEntityPacketSmall::PosRot::read(DataInputStream *dis) //throws IOException { - MoveEntityPacketSmall::read(dis); - xa = (signed char)dis->readByte(); - ya = (signed char)dis->readByte(); - za = (signed char)dis->readByte(); - yRot = (signed char)dis->readByte(); - xRot = (signed char)dis->readByte(); + MoveEntityPacketSmall::read(dis); + xa = (int8_t)dis->readByte(); + ya = (int8_t)dis->readByte(); + za = (int8_t)dis->readByte(); + yRot = (int8_t)dis->readByte(); + xRot = (int8_t)dis->readByte(); } void MoveEntityPacketSmall::PosRot::write(DataOutputStream *dos) //throws IOException { - MoveEntityPacketSmall::write(dos); - dos->writeByte((uint8_t)(xa & 0xFF)); - dos->writeByte((uint8_t)(ya & 0xFF)); - dos->writeByte((uint8_t)(za & 0xFF)); - dos->writeByte((uint8_t)(yRot & 0xFF)); - dos->writeByte((uint8_t)(xRot & 0xFF)); + MoveEntityPacketSmall::write(dos); + dos->writeByte((uint8_t)(xa & 0xFF)); + dos->writeByte((uint8_t)(ya & 0xFF)); + dos->writeByte((uint8_t)(za & 0xFF)); + dos->writeByte((uint8_t)(yRot & 0xFF)); + dos->writeByte((uint8_t)(xRot & 0xFF)); } int MoveEntityPacketSmall::PosRot::getEstimatedSize() @@ -104,7 +105,7 @@ MoveEntityPacketSmall::Pos::Pos() { } -MoveEntityPacketSmall::Pos::Pos(int id, char xa, char ya, char za) : MoveEntityPacketSmall(id) +MoveEntityPacketSmall::Pos::Pos(int id, int8_t xa, int8_t ya, int8_t za) : MoveEntityPacketSmall(id) { this->xa = xa; this->ya = ya; @@ -113,10 +114,10 @@ MoveEntityPacketSmall::Pos::Pos(int id, char xa, char ya, char za) : MoveEntityP void MoveEntityPacketSmall::Pos::read(DataInputStream *dis) //throws IOException { - MoveEntityPacketSmall::read(dis); - xa = (signed char)dis->readByte(); - ya = (signed char)dis->readByte(); - za = (signed char)dis->readByte(); + MoveEntityPacketSmall::read(dis); + xa = (int8_t)dis->readByte(); + ya = (int8_t)dis->readByte(); + za = (int8_t)dis->readByte(); } void MoveEntityPacketSmall::Pos::write(DataOutputStream *dos) //throws IOException @@ -137,7 +138,7 @@ MoveEntityPacketSmall::Rot::Rot() hasRot = true; } -MoveEntityPacketSmall::Rot::Rot(int id, char yRot, char xRot) : MoveEntityPacketSmall(id) +MoveEntityPacketSmall::Rot::Rot(int id, int8_t yRot, int8_t xRot) : MoveEntityPacketSmall(id) { this->yRot = yRot; @@ -147,8 +148,8 @@ MoveEntityPacketSmall::Rot::Rot(int id, char yRot, char xRot) : MoveEntityPacket void MoveEntityPacketSmall::Rot::read(DataInputStream *dis) //throws IOException { - MoveEntityPacketSmall::read(dis); - yRot = (signed char)dis->readByte(); + MoveEntityPacketSmall::read(dis); + yRot = (int8_t)dis->readByte(); } void MoveEntityPacketSmall::Rot::write(DataOutputStream *dos) //throws IOException diff --git a/Minecraft.World/Network/Packets/MoveEntityPacketSmall.h b/Minecraft.World/Network/Packets/MoveEntityPacketSmall.h index fffdc7e56..a5cb220ac 100644 --- a/Minecraft.World/Network/Packets/MoveEntityPacketSmall.h +++ b/Minecraft.World/Network/Packets/MoveEntityPacketSmall.h @@ -13,8 +13,8 @@ public: class Rot; int id; - char xa, ya, za, yRot, xRot; - bool hasRot; + int8_t xa, ya, za, yRot, xRot; + bool hasRot; MoveEntityPacketSmall(); MoveEntityPacketSmall(int id); @@ -34,8 +34,8 @@ public: class MoveEntityPacketSmall::PosRot : public MoveEntityPacketSmall { public: - PosRot(); - PosRot(int id, char xa, char ya, char za, char yRot, char xRot); + PosRot(); + PosRot(int id, int8_t xa, int8_t ya, int8_t za, int8_t yRot, int8_t xRot); virtual void read(DataInputStream *dis); virtual void write(DataOutputStream *dos); @@ -50,7 +50,7 @@ class MoveEntityPacketSmall::Pos : public MoveEntityPacketSmall { public: Pos(); - Pos(int id, char xa, char ya, char za); + Pos(int id, int8_t xa, int8_t ya, int8_t za); virtual void read(DataInputStream *dis); virtual void write(DataOutputStream *dos); @@ -66,7 +66,7 @@ class MoveEntityPacketSmall::Rot : public MoveEntityPacketSmall { public: Rot(); - Rot(int id, char yRot, char xRot); + Rot(int id, int8_t yRot, int8_t xRot); virtual void read(DataInputStream *dis); virtual void write(DataOutputStream *dos); diff --git a/Minecraft.World/Network/Packets/SetEntityMotionPacket.cpp b/Minecraft.World/Network/Packets/SetEntityMotionPacket.cpp index 70ea64f92..72ee76ee7 100644 --- a/Minecraft.World/Network/Packets/SetEntityMotionPacket.cpp +++ b/Minecraft.World/Network/Packets/SetEntityMotionPacket.cpp @@ -17,9 +17,9 @@ void SetEntityMotionPacket::_init(int id, double xd, double yd, double zd) if (xd > m) xd = m; if (yd > m) yd = m; if (zd > m) zd = m; - xa = (int) (xd * 8000.0); - ya = (int) (yd * 8000.0); - za = (int) (zd * 8000.0); + xa = (int16_t) (xd * 8000.0); + ya = (int16_t) (yd * 8000.0); + za = (int16_t) (zd * 8000.0); useBytes = false; } diff --git a/Minecraft.World/Network/Packets/SetEntityMotionPacket.h b/Minecraft.World/Network/Packets/SetEntityMotionPacket.h index 537c5a4fd..5c3702577 100644 --- a/Minecraft.World/Network/Packets/SetEntityMotionPacket.h +++ b/Minecraft.World/Network/Packets/SetEntityMotionPacket.h @@ -7,7 +7,7 @@ class SetEntityMotionPacket : public Packet, public std::enable_shared_from_this { public: int id; - int xa, ya, za; + int16_t xa, ya, za; bool useBytes; // 4J added private: diff --git a/Minecraft.World/Network/Packets/TeleportEntityPacket.cpp b/Minecraft.World/Network/Packets/TeleportEntityPacket.cpp index 3a0c9927f..9dc2742ed 100644 --- a/Minecraft.World/Network/Packets/TeleportEntityPacket.cpp +++ b/Minecraft.World/Network/Packets/TeleportEntityPacket.cpp @@ -17,7 +17,7 @@ TeleportEntityPacket::TeleportEntityPacket() xRot = 0; } -TeleportEntityPacket::TeleportEntityPacket(std::shared_ptr e) +TeleportEntityPacket::TeleportEntityPacket(std::shared_ptr e) { id = e->entityId; x = Mth::floor(e->x * 32); @@ -27,7 +27,7 @@ TeleportEntityPacket::TeleportEntityPacket(std::shared_ptr e) xRot = (uint8_t) (e->xRot * 256 / 360); } -TeleportEntityPacket::TeleportEntityPacket(int id, int x, int y, int z, uint8_t yRot, uint8_t xRot) +TeleportEntityPacket::TeleportEntityPacket(int id, int32_t x, int32_t y, int32_t z, uint8_t yRot, uint8_t xRot) { this->id = id; this->x = x; @@ -53,7 +53,7 @@ void TeleportEntityPacket::read(DataInputStream *dis) //throws IOException xRot = (uint8_t) dis->read(); } -void TeleportEntityPacket::write(DataOutputStream *dos) //throws IOException +void TeleportEntityPacket::write(DataOutputStream *dos) //throws IOException { dos->writeShort((short)id); dos->writeInt(x); @@ -63,12 +63,12 @@ void TeleportEntityPacket::write(DataOutputStream *dos) //throws IOException dos->write(xRot); } -void TeleportEntityPacket::handle(PacketListener *listener) +void TeleportEntityPacket::handle(PacketListener *listener) { listener->handleTeleportEntity(shared_from_this()); } -int TeleportEntityPacket::getEstimatedSize() +int TeleportEntityPacket::getEstimatedSize() { return 2 + 2 + 2 + 2 + 1 + 1; } diff --git a/Minecraft.World/Network/Packets/TeleportEntityPacket.h b/Minecraft.World/Network/Packets/TeleportEntityPacket.h index 0b85a3b99..5ee91255d 100644 --- a/Minecraft.World/Network/Packets/TeleportEntityPacket.h +++ b/Minecraft.World/Network/Packets/TeleportEntityPacket.h @@ -7,19 +7,19 @@ class TeleportEntityPacket : public Packet, public std::enable_shared_from_this< { public: int id; - int x, y, z; - uint8_t yRot, xRot; + int32_t x, y, z; + uint8_t yRot, xRot; TeleportEntityPacket(); TeleportEntityPacket(std::shared_ptr e); - TeleportEntityPacket(int id, int x, int y, int z, uint8_t yRot, uint8_t xRot); + TeleportEntityPacket(int id, int32_t x, int32_t y, int32_t z, uint8_t yRot, uint8_t xRot); virtual void read(DataInputStream *dis); virtual void write(DataOutputStream *dos); virtual void handle(PacketListener *listener); virtual int getEstimatedSize(); virtual bool canBeInvalidated(); - virtual bool isInvalidatedBy(std::shared_ptr packet); + virtual bool isInvalidatedBy(std::shared_ptr packet); public: static std::shared_ptr create() { return std::shared_ptr(new TeleportEntityPacket()); }