From c42f71ba22f297d99510ac5880e7f6eb355cc865 Mon Sep 17 00:00:00 2001 From: Sally Knight Date: Wed, 11 Mar 2026 07:13:48 +0300 Subject: [PATCH] fix: restore and fix entity, block and hand lighting Block and entity light layers are done differently for now due to some caveats with light map transformation --- 4J.Render/4J_Render.cpp | 15 +++++++- 4J.Render/4J_Render.h | 2 +- .../Leaderboards/LeaderboardManager.cpp | 2 -- .../Leaderboards/LinuxLeaderboardManager.cpp | 5 +++ .../Leaderboards/LinuxLeaderboardManager.h | 36 +++++++++++++++++++ Minecraft.Client/Rendering/GameRenderer.cpp | 19 ++++++---- Minecraft.Client/Rendering/GameRenderer.h | 2 +- Minecraft.Client/Rendering/LevelRenderer.cpp | 8 ++--- Minecraft.Client/Rendering/Tesselator.cpp | 8 ++++- 9 files changed, 80 insertions(+), 17 deletions(-) create mode 100644 Minecraft.Client/Platform/Linux/Leaderboards/LinuxLeaderboardManager.cpp create mode 100644 Minecraft.Client/Platform/Linux/Leaderboards/LinuxLeaderboardManager.h diff --git a/4J.Render/4J_Render.cpp b/4J.Render/4J_Render.cpp index c16920e82..3ac57d9a6 100644 --- a/4J.Render/4J_Render.cpp +++ b/4J.Render/4J_Render.cpp @@ -560,7 +560,7 @@ void C4JRender::TextureBind(int idx) } } -void C4JRender::TextureBindVertex(int idx) +void C4JRender::TextureBindVertex(int idx, bool scaleLight) { // Unit 1 used for lightmapping in fixed-function or standard shaders ::glActiveTexture(GL_TEXTURE1); @@ -574,7 +574,20 @@ void C4JRender::TextureBindVertex(int idx) ::glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); ::glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); ::glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); + + // 4jcraft: jank workaround for entities + // referenced from the disabled code in GameRenderer::turnOnLightLayer + if (scaleLight) + { + ::glMatrixMode(GL_TEXTURE); + ::glLoadIdentity(); + float s = 1 / 16.0f / 15.0f * 15 / 16; + ::glScalef(s, s, s); + ::glTranslatef(8.0f, 8.0f, 8.0f); + ::glMatrixMode(GL_MODELVIEW); + } } + ::glActiveTexture(GL_TEXTURE0); ::glFlush(); } diff --git a/4J.Render/4J_Render.h b/4J.Render/4J_Render.h index 738ab91eb..aa69717bc 100644 --- a/4J.Render/4J_Render.h +++ b/4J.Render/4J_Render.h @@ -155,7 +155,7 @@ public: int TextureCreate(); void TextureFree(int idx); void TextureBind(int idx); - void TextureBindVertex(int idx); + void TextureBindVertex(int idx, bool scaleLight = false); void TextureSetTextureLevels(int levels); int TextureGetTextureLevels(); void TextureData(int width, int height, void *data, int level, eTextureFormat format = TEXTURE_FORMAT_RxGyBzAw); diff --git a/Minecraft.Client/Platform/Common/Leaderboards/LeaderboardManager.cpp b/Minecraft.Client/Platform/Common/Leaderboards/LeaderboardManager.cpp index 996a678f1..6afee4421 100644 --- a/Minecraft.Client/Platform/Common/Leaderboards/LeaderboardManager.cpp +++ b/Minecraft.Client/Platform/Common/Leaderboards/LeaderboardManager.cpp @@ -9,8 +9,6 @@ const std::wstring LeaderboardManager::filterNames[eNumFilterModes] = L"Friends", L"MyScore", L"TopRank" }; -LeaderboardManager *LeaderboardManager::m_instance = NULL; - void LeaderboardManager::DeleteInstance() { delete m_instance; diff --git a/Minecraft.Client/Platform/Linux/Leaderboards/LinuxLeaderboardManager.cpp b/Minecraft.Client/Platform/Linux/Leaderboards/LinuxLeaderboardManager.cpp new file mode 100644 index 000000000..ebb870584 --- /dev/null +++ b/Minecraft.Client/Platform/Linux/Leaderboards/LinuxLeaderboardManager.cpp @@ -0,0 +1,5 @@ +#include "../../../../Minecraft.World/Platform/stdafx.h" + +#include "LinuxLeaderboardManager.h" + +LeaderboardManager *LeaderboardManager::m_instance = new LinuxLeaderboardManager(); //Singleton instance of the LeaderboardManager \ No newline at end of file diff --git a/Minecraft.Client/Platform/Linux/Leaderboards/LinuxLeaderboardManager.h b/Minecraft.Client/Platform/Linux/Leaderboards/LinuxLeaderboardManager.h new file mode 100644 index 000000000..50696c37d --- /dev/null +++ b/Minecraft.Client/Platform/Linux/Leaderboards/LinuxLeaderboardManager.h @@ -0,0 +1,36 @@ +#pragma once + +#include "../../Common/Leaderboards/LeaderboardManager.h" + +class LinuxLeaderboardManager : public LeaderboardManager +{ +public: + virtual void Tick() {} + + //Open a session + virtual bool OpenSession() { return true; } + + //Close a session + virtual void CloseSession() {} + + //Delete a session + virtual void DeleteSession() {} + + //Write the given stats + //This is called synchronously and will not free any memory allocated for views when it is done + + virtual bool WriteStats(unsigned int viewCount, ViewIn views) { return false; } + + virtual bool ReadStats_Friends(LeaderboardReadListener *callback, int difficulty, EStatsType type, PlayerUID myUID) { return false; } + virtual bool ReadStats_MyScore(LeaderboardReadListener *callback, int difficulty, EStatsType type, PlayerUID myUID, unsigned int readCount) { return false; } + virtual bool ReadStats_TopRank(LeaderboardReadListener *callback, int difficulty, EStatsType type, unsigned int startIndex, unsigned int readCount) { return false; } + + //Perform a flush of the stats + virtual void FlushStats() {} + + //Cancel the current operation + virtual void CancelOperation() {} + + //Is the leaderboard manager idle. + virtual bool isIdle() { return true; } +}; diff --git a/Minecraft.Client/Rendering/GameRenderer.cpp b/Minecraft.Client/Rendering/GameRenderer.cpp index 9335fee5b..46bb4ea86 100644 --- a/Minecraft.Client/Rendering/GameRenderer.cpp +++ b/Minecraft.Client/Rendering/GameRenderer.cpp @@ -777,14 +777,14 @@ void GameRenderer::renderItemInHand(float a, int eye) { if (!mc->options->hideGui && !mc->gameMode->isCutScene()) { - //turnOnLightLayer(a); // 4jcraft: disable light layer on handrenderer similarly to how it was done on the chunk render (this makes the hand look proper) + turnOnLightLayer(a, true); PIXBeginNamedEvent(0,"Item in hand render"); // 4jcraft: add null pointer check to itemInHandRenderer to prevent a occasional seg fault if (itemInHandRenderer != nullptr) { itemInHandRenderer->render(a); } PIXEndNamedEvent(); - //turnOffLightLayer(a); // 4jcraft: disable light layer on handrenderer similarly to how it was done on the chunk render (this makes the hand look proper) + turnOffLightLayer(a); } } glPopMatrix(); @@ -806,21 +806,26 @@ void GameRenderer::renderItemInHand(float a, int eye) // 4J - change brought forward from 1.8.2 void GameRenderer::turnOffLightLayer(double alpha) { // 4J - TODO -#if 0 + // 4jcraft: manually handle this in order to ensure that the light layer is turned off correctly +#if 1 if (SharedConstants::TEXTURE_LIGHTING) { glClientActiveTexture(GL_TEXTURE1); glActiveTexture(GL_TEXTURE1); + glMatrixMode(GL_TEXTURE); + glLoadIdentity(); + glMatrixMode(GL_MODELVIEW); glDisable(GL_TEXTURE_2D); + glBindTexture(GL_TEXTURE_2D, 0); glClientActiveTexture(GL_TEXTURE0); glActiveTexture(GL_TEXTURE0); } #endif - RenderManager.TextureBindVertex(-1); + //RenderManager.TextureBindVertex(-1); } // 4J - change brought forward from 1.8.2 -void GameRenderer::turnOnLightLayer(double alpha) +void GameRenderer::turnOnLightLayer(double alpha, bool scaleLight) { // 4J - TODO #if 0 if (SharedConstants::TEXTURE_LIGHTING) @@ -851,7 +856,7 @@ void GameRenderer::turnOnLightLayer(double alpha) #endif // update light texture // todo: check implementation of getLightTexture. - RenderManager.TextureBindVertex(getLightTexture(mc->player->GetXboxPad(), mc->level)); + RenderManager.TextureBindVertex(getLightTexture(mc->player->GetXboxPad(), mc->level), scaleLight); #if 0 glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); @@ -971,7 +976,7 @@ void GameRenderer::updateLightTexture(float a) int g = (int) (_g * 255); int b = (int) (_b * 255); -#if ( defined _DURANGO || defined _WIN64 || __PSVITA__ ) +#if ( defined _DURANGO || defined _WIN64 || __PSVITA__ || __linux__ ) lightPixels[j][i] = a << 24 | b << 16 | g << 8 | r; #elif ( defined _XBOX || defined __ORBIS__ ) lightPixels[j][i] = a << 24 | r << 16 | g << 8 | b; diff --git a/Minecraft.Client/Rendering/GameRenderer.h b/Minecraft.Client/Rendering/GameRenderer.h index 5026704bb..f5cdedecc 100644 --- a/Minecraft.Client/Rendering/GameRenderer.h +++ b/Minecraft.Client/Rendering/GameRenderer.h @@ -104,7 +104,7 @@ public: float blg; float blgt; void turnOffLightLayer(double alpha); - void turnOnLightLayer(double alpha); + void turnOnLightLayer(double alpha, bool scaleLight = false); private: void tickLightTexture(); void updateLightTexture(float a); diff --git a/Minecraft.Client/Rendering/LevelRenderer.cpp b/Minecraft.Client/Rendering/LevelRenderer.cpp index 538529ac4..01d97cf09 100644 --- a/Minecraft.Client/Rendering/LevelRenderer.cpp +++ b/Minecraft.Client/Rendering/LevelRenderer.cpp @@ -518,7 +518,7 @@ void LevelRenderer::renderEntities(Vec3 *cam, Culler *culler, float a) TileEntityRenderDispatcher::yOff = (player->yOld + (player->y - player->yOld) * a); TileEntityRenderDispatcher::zOff = (player->zOld + (player->z - player->zOld) * a); - // mc->gameRenderer->turnOnLightLayer(a); // 4J - brought forward from 1.8.2 + mc->gameRenderer->turnOnLightLayer(a, true); // 4J - brought forward from 1.8.2 std::vector > entities = level[playerIndex]->getAllEntities(); totalEntities = (int)entities.size(); @@ -600,7 +600,7 @@ void LevelRenderer::renderEntities(Vec3 *cam, Culler *culler, float a) LeaveCriticalSection(&m_csRenderableTileEntities); - // mc->gameRenderer->turnOffLightLayer(a); // 4J - brought forward from 1.8.2 + mc->gameRenderer->turnOffLightLayer(a); // 4J - brought forward from 1.8.2 } std::wstring LevelRenderer::gatherStats1() @@ -742,7 +742,7 @@ int LevelRenderer::renderChunks(int from, int to, int layer, double alpha) #if 1 // 4J - cut down version, we're not using offsetted render lists, or a sorted chunk list, anymore - // mc->gameRenderer->turnOnLightLayer(alpha); // 4J - brought forward from 1.8.2 + mc->gameRenderer->turnOnLightLayer(alpha); // 4J - brought forward from 1.8.2 shared_ptr player = mc->cameraTargetPlayer; double xOff = player->xOld + (player->x - player->xOld) * alpha; double yOff = player->yOld + (player->y - player->yOld) * alpha; @@ -838,7 +838,7 @@ int LevelRenderer::renderChunks(int from, int to, int layer, double alpha) #endif // __PS3__ glPopMatrix(); - // mc->gameRenderer->turnOffLightLayer(alpha); // 4J - brought forward from 1.8.2 + mc->gameRenderer->turnOffLightLayer(alpha); // 4J - brought forward from 1.8.2 #else _renderChunks.clear(); diff --git a/Minecraft.Client/Rendering/Tesselator.cpp b/Minecraft.Client/Rendering/Tesselator.cpp index e1c7373b3..821ec037b 100644 --- a/Minecraft.Client/Rendering/Tesselator.cpp +++ b/Minecraft.Client/Rendering/Tesselator.cpp @@ -942,9 +942,15 @@ void Tesselator::vertex(float x, float y, float z) #ifdef _XBOX _array->data[p + 7] = ( ( _tex2 >> 16 ) & 0xffff ) | ( _tex2 << 16 ); #else - #ifdef __PS3__ + // 4jcraft: we will be lighting the blocks right in here + #if defined(__PS3__) || defined (__linux__) + #ifdef __PS3__ int16_t tex2U = ((int16_t*)&_tex2)[1] + 8; int16_t tex2V = ((int16_t*)&_tex2)[0] + 8; + #else + int16_t tex2U = ((int16_t*)&_tex2)[0] + 8; + int16_t tex2V = ((int16_t*)&_tex2)[1] + 8; + #endif int16_t* pShortArray = (int16_t*)&_array->data[p + 7]; pShortArray[0] = tex2U; pShortArray[1] = tex2V;