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
This commit is contained in:
Sally Knight 2026-03-11 07:13:48 +03:00
parent d9dbb5c39c
commit c42f71ba22
9 changed files with 80 additions and 17 deletions

View file

@ -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();
}

View file

@ -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);

View file

@ -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;

View file

@ -0,0 +1,5 @@
#include "../../../../Minecraft.World/Platform/stdafx.h"
#include "LinuxLeaderboardManager.h"
LeaderboardManager *LeaderboardManager::m_instance = new LinuxLeaderboardManager(); //Singleton instance of the LeaderboardManager

View file

@ -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; }
};

View file

@ -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;

View file

@ -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);

View file

@ -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<std::shared_ptr<Entity> > 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<Mob> 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();

View file

@ -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;