From e7d819bd00115f2d238d2b68d1aa909fed2623cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ana=C3=ABl?= <60509176+Bakoubak@users.noreply.github.com> Date: Sun, 25 Oct 2026 22:38:22 +0100 Subject: [PATCH] fix(render): fix item shadow caused by undefined behavior * Replace byte cast with int8_t in Tesselator::normal() * 4J calls this function with -1.0f as the first parameter sometimes, the previous cast caused it to become 0x00 and broke the shading in the inventory * It was done a similar way on Vita, i just kanged it and made it more C++ --- Minecraft.Client/Tesselator.cpp | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/Minecraft.Client/Tesselator.cpp b/Minecraft.Client/Tesselator.cpp index 7d60f864..443dc2ca 100644 --- a/Minecraft.Client/Tesselator.cpp +++ b/Minecraft.Client/Tesselator.cpp @@ -1030,20 +1030,16 @@ uint32_t _ConvertF32toX11Y11Z10N(float x, float y, float z) void Tesselator::normal(float x, float y, float z) { hasNormal = true; - #ifdef __PS3__ - _normal = _ConvertF32toX11Y11Z10N(x,y,z); -#elif __PSVITA__ - // AP - casting a negative value to 'byte' on Vita results in zero. changed to a signed 8 value - int8_t xx = (int8_t) (x * 127); - int8_t yy = (int8_t) (y * 127); - int8_t zz = (int8_t) (z * 127); - _normal = (xx & 0xff) | ((yy & 0xff) << 8) | ((zz & 0xff) << 16); + _normal = _ConvertF32toX11Y11Z10N(x, y, z); #else - byte xx = static_cast(x * 127); - byte yy = static_cast(y * 127); - byte zz = static_cast(z * 127); - _normal = (xx & 0xff) | ((yy & 0xff) << 8) | ((zz & 0xff) << 16); + int8_t xx = static_cast(x * 127.0f); + int8_t yy = static_cast(y * 127.0f); + int8_t zz = static_cast(z * 127.0f); + + _normal = (static_cast(xx) & 0xff) | + ((static_cast(yy) & 0xff) << 8) | + ((static_cast(zz) & 0xff) << 16); #endif }