Merge branch 'tu19-take-2' of https://github.com/4jcraft/4jcraft into tu19-take-2

This commit is contained in:
Tropical 2026-03-24 14:27:14 -05:00
commit ca533de1c3
2 changed files with 157 additions and 97 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.2 KiB

After

Width:  |  Height:  |  Size: 9.4 KiB

View file

@ -28,6 +28,8 @@
#include "../../Minecraft.World/Headers/net.minecraft.world.h" #include "../../Minecraft.World/Headers/net.minecraft.world.h"
#include "../../Minecraft.World/Level/LevelChunk.h" #include "../../Minecraft.World/Level/LevelChunk.h"
#include "../../Minecraft.World/WorldGen/Biomes/Biome.h" #include "../../Minecraft.World/WorldGen/Biomes/Biome.h"
#include "../../Minecraft.World/Entities/Mobs/SharedMonsterAttributes.h"
#include "../../Minecraft.World/AI/Attributes/AttributeInstance.h"
ResourceLocation Gui::PUMPKIN_BLUR_LOCATION = ResourceLocation Gui::PUMPKIN_BLUR_LOCATION =
ResourceLocation(TN__BLUR__MISC_PUMPKINBLUR); ResourceLocation(TN__BLUR__MISC_PUMPKINBLUR);
@ -40,11 +42,6 @@ ResourceLocation Gui::GUI_ICONS_LOCATION = ResourceLocation(TN_GUI_ICONS);
#define RENDER_HUD 0 #define RENDER_HUD 0
#endif #endif
// #ifndef _XBOX
// #undef RENDER_HUD
// #define RENDER_HUD 1
// #endif
float Gui::currentGuiBlendFactor = 1.0f; // 4J added float Gui::currentGuiBlendFactor = 1.0f; // 4J added
float Gui::currentGuiScaleFactor = 1.0f; // 4J added float Gui::currentGuiScaleFactor = 1.0f; // 4J added
ItemRenderer* Gui::itemRenderer = new ItemRenderer(); ItemRenderer* Gui::itemRenderer = new ItemRenderer();
@ -93,7 +90,7 @@ void Gui::render(float a, bool mouseFree, int xMouse, int yMouse) {
minecraft->height, guiScale); minecraft->height, guiScale);
int screenWidth = ssc.getWidth(); int screenWidth = ssc.getWidth();
int screenHeight = ssc.getHeight(); int screenHeight = ssc.getHeight();
int iSafezoneXHalf = 0, iSafezoneYHalf = 0; int iSafezoneXHalf = 0, iSafezoneYHalf = 0, iSafezoneTopYHalf = 0;
int iTooltipsYOffset = 0; int iTooltipsYOffset = 0;
int quickSelectWidth = 182; int quickSelectWidth = 182;
int quickSelectHeight = 22; int quickSelectHeight = 22;
@ -122,6 +119,7 @@ void Gui::render(float a, bool mouseFree, int xMouse, int yMouse) {
// single player // single player
iSafezoneXHalf = screenWidth / 20; // 5% iSafezoneXHalf = screenWidth / 20; // 5%
iSafezoneYHalf = screenHeight / 20; // 5% iSafezoneYHalf = screenHeight / 20; // 5%
iSafezoneTopYHalf = iSafezoneYHalf;
iTooltipsYOffset = 40 + splitYOffset; iTooltipsYOffset = 40 + splitYOffset;
break; break;
case C4JRender::VIEWPORT_TYPE_SPLIT_TOP: case C4JRender::VIEWPORT_TYPE_SPLIT_TOP:
@ -129,6 +127,7 @@ void Gui::render(float a, bool mouseFree, int xMouse, int yMouse) {
screenWidth / screenWidth /
10; // 5% (need to treat the whole screen is 2x this screen) 10; // 5% (need to treat the whole screen is 2x this screen)
iSafezoneYHalf = splitYOffset; iSafezoneYHalf = splitYOffset;
iSafezoneTopYHalf = screenHeight / 10;
fScaleFactorWidth = 0.5f; fScaleFactorWidth = 0.5f;
iWidthOffset = iWidthOffset =
(int)((float)screenWidth * (1.0f - fScaleFactorWidth)); (int)((float)screenWidth * (1.0f - fScaleFactorWidth));
@ -143,6 +142,7 @@ void Gui::render(float a, bool mouseFree, int xMouse, int yMouse) {
iSafezoneYHalf = splitYOffset + iSafezoneYHalf = splitYOffset +
screenHeight / 10; // 5% (need to treat the whole screenHeight / 10; // 5% (need to treat the whole
// screen is 2x this screen) // screen is 2x this screen)
iSafezoneTopYHalf = 0;
fScaleFactorWidth = 0.5f; fScaleFactorWidth = 0.5f;
iWidthOffset = iWidthOffset =
(int)((float)screenWidth * (1.0f - fScaleFactorWidth)); (int)((float)screenWidth * (1.0f - fScaleFactorWidth));
@ -156,6 +156,7 @@ void Gui::render(float a, bool mouseFree, int xMouse, int yMouse) {
iSafezoneYHalf = splitYOffset + iSafezoneYHalf = splitYOffset +
screenHeight / 10; // 5% (need to treat the whole screenHeight / 10; // 5% (need to treat the whole
// screen is 2x this screen) // screen is 2x this screen)
iSafezoneTopYHalf = screenHeight / 10;
fScaleFactorHeight = 0.5f; fScaleFactorHeight = 0.5f;
iHeightOffset = screenHeight; iHeightOffset = screenHeight;
iTooltipsYOffset = 44; iTooltipsYOffset = 44;
@ -167,6 +168,7 @@ void Gui::render(float a, bool mouseFree, int xMouse, int yMouse) {
iSafezoneYHalf = splitYOffset + iSafezoneYHalf = splitYOffset +
screenHeight / 10; // 5% (need to treat the whole screenHeight / 10; // 5% (need to treat the whole
// screen is 2x this screen) // screen is 2x this screen)
iSafezoneTopYHalf = splitYOffset + screenHeight / 10;
fScaleFactorHeight = 0.5f; fScaleFactorHeight = 0.5f;
iHeightOffset = screenHeight; iHeightOffset = screenHeight;
iTooltipsYOffset = 44; iTooltipsYOffset = 44;
@ -177,12 +179,14 @@ void Gui::render(float a, bool mouseFree, int xMouse, int yMouse) {
iSafezoneXHalf = iSafezoneXHalf =
screenWidth / 10; // 5% (the whole screen is 2x this screen) screenWidth / 10; // 5% (the whole screen is 2x this screen)
iSafezoneYHalf = splitYOffset; iSafezoneYHalf = splitYOffset;
iSafezoneTopYHalf = screenHeight / 10;
iTooltipsYOffset = 44; iTooltipsYOffset = 44;
currentGuiScaleFactor *= 0.5f; currentGuiScaleFactor *= 0.5f;
break; break;
case C4JRender::VIEWPORT_TYPE_QUADRANT_TOP_RIGHT: case C4JRender::VIEWPORT_TYPE_QUADRANT_TOP_RIGHT:
iSafezoneXHalf = 0; iSafezoneXHalf = 0;
iSafezoneYHalf = splitYOffset; // 5% iSafezoneYHalf = splitYOffset; // 5%
iSafezoneTopYHalf = screenHeight / 10;
iTooltipsYOffset = 44; iTooltipsYOffset = 44;
currentGuiScaleFactor *= 0.5f; currentGuiScaleFactor *= 0.5f;
break; break;
@ -192,6 +196,7 @@ void Gui::render(float a, bool mouseFree, int xMouse, int yMouse) {
iSafezoneYHalf = iSafezoneYHalf =
splitYOffset + splitYOffset +
screenHeight / 10; // 5% (the whole screen is 2x this screen) screenHeight / 10; // 5% (the whole screen is 2x this screen)
iSafezoneTopYHalf = 0;
iTooltipsYOffset = 44; iTooltipsYOffset = 44;
currentGuiScaleFactor *= 0.5f; currentGuiScaleFactor *= 0.5f;
break; break;
@ -200,6 +205,7 @@ void Gui::render(float a, bool mouseFree, int xMouse, int yMouse) {
iSafezoneYHalf = iSafezoneYHalf =
splitYOffset + splitYOffset +
screenHeight / 10; // 5% (the whole screen is 2x this screen) screenHeight / 10; // 5% (the whole screen is 2x this screen)
iSafezoneTopYHalf = 0;
iTooltipsYOffset = 44; iTooltipsYOffset = 44;
currentGuiScaleFactor *= 0.5f; currentGuiScaleFactor *= 0.5f;
break; break;
@ -468,93 +474,173 @@ void Gui::render(float a, bool mouseFree, int xMouse, int yMouse) {
yLine2 = yLine1 - 10; yLine2 = yLine1 - 10;
} }
double maxHealth =
minecraft->localplayers[iPad]
->getAttribute(SharedMonsterAttributes::MAX_HEALTH)
->getValue(); // 4jcraft: use getValue() to get the
// actual double value
double currentHealth =
ceil(minecraft->localplayers[iPad]
->getHealth()); // 4jcraft: missing definition
double totalAbsorption =
minecraft->localplayers[iPad]->getAbsorptionAmount();
int NUM_HEARTS_PER_ROW = 10; // 4jcraft: missing definition
int numHealthRows = Mth::ceil((maxHealth + totalAbsorption) /
2 / (float)NUM_HEARTS_PER_ROW);
int healthRowHeight = max(10 - (numHealthRows - 2), 3);
yLine2 = yLine1 - (numHealthRows - 1) * healthRowHeight - 10;
double absorption = totalAbsorption;
int armor = minecraft->player->getArmorValue(); int armor = minecraft->player->getArmorValue();
int heartOffsetIndex = -1; int heartOffsetIndex = -1;
if (minecraft->player->hasEffect(MobEffect::regeneration)) { if (minecraft->player->hasEffect(MobEffect::regeneration)) {
heartOffsetIndex = tickCount % 25; heartOffsetIndex = tickCount % (int)ceil(maxHealth + 5);
} }
// render health and armor // render health and armor
// minecraft.profiler.push("armor");
for (int i = 0; i < Player::MAX_HEALTH / 2; i++) { for (int i = 0; i < Player::MAX_HEALTH / 2; i++) {
if (armor > 0) { if (armor > 0) {
int xo = xLeft + i * 8; int xo = xLeft + i * 8;
// HEALTH
if (i * 2 + 1 < armor) if (i * 2 + 1 < armor)
blit(xo, yLine2, 16 + 2 * 9, 9 * 1, 9, 9); blit(xo, yLine2, 16 + 2 * 9, 9, 9, 9);
if (i * 2 + 1 == armor) if (i * 2 + 1 == armor)
blit(xo, yLine2, 16 + 1 * 9, 9 * 1, 9, 9); blit(xo, yLine2, 16 + 1 * 9, 9, 9, 9);
if (i * 2 + 1 > armor) if (i * 2 + 1 > armor)
blit(xo, yLine2, 16 + 0 * 9, 9 * 1, 9, 9); blit(xo, yLine2, 16 + 0 * 9, 9, 9, 9);
} }
}
// minecraft.profiler.popPush("health");
for (int i = Mth::ceil((maxHealth + totalAbsorption) / 2) - 1;
i >= 0; i--) {
int healthTexBaseX = 16; int healthTexBaseX = 16;
if (minecraft->player->hasEffect(MobEffect::poison)) { if (minecraft->player->hasEffect(MobEffect::poison)) {
healthTexBaseX += 4 * 9; healthTexBaseX += 4 * 9;
} else if (minecraft->player->hasEffect(
MobEffect::wither)) {
healthTexBaseX += 8 * 9;
} }
int bg = 0; int bg = 0;
if (blink) bg = 1; if (blink) bg = 1;
int xo = xLeft + i * 8; int rowIndex =
int yo = yLine1; Mth::ceil((i + 1) / (float)NUM_HEARTS_PER_ROW) - 1;
int xo = xLeft + (i % NUM_HEARTS_PER_ROW) * 8;
if (iHealth <= 4) { int yo = yLine1 - rowIndex * healthRowHeight;
if (currentHealth <= 4) {
yo += random->nextInt(2); yo += random->nextInt(2);
} }
if (i == heartOffsetIndex) { if (i == heartOffsetIndex) {
yo -= 2; yo -= 2;
} }
int y0 = 0; int y0 = 0;
// 4J-PB - no hardcore in xbox
// if // No hardcore on console
// (minecraft.level.getLevelData().isHardcore()) { /*if (minecraft->level.getLevelData().isHardcore())
// y0 = 5; {
// } y0 = 5;
blit(xo, yo, 16 + bg * 9, 9 * 0, 9, 9); }*/
double oldHealth =
ceil(minecraft->localplayers[iPad]
->lastHealth); // 4jcraft: missing definition
blit(xo, yo, 16 + bg * 9, 9 * y0, 9, 9);
if (blink) { if (blink) {
if (i * 2 + 1 < iLastHealth) if (i * 2 + 1 < oldHealth)
blit(xo, yo, healthTexBaseX + 6 * 9, 9 * y0, 9, 9); blit(xo, yo, healthTexBaseX + 6 * 9, 9 * y0, 9, 9);
if (i * 2 + 1 == iLastHealth) if (i * 2 + 1 == oldHealth)
blit(xo, yo, healthTexBaseX + 7 * 9, 9 * y0, 9, 9); blit(xo, yo, healthTexBaseX + 7 * 9, 9 * y0, 9, 9);
} }
if (i * 2 + 1 < iHealth)
blit(xo, yo, healthTexBaseX + 4 * 9, 9 * y0, 9, 9); if (absorption > 0) {
if (i * 2 + 1 == iHealth) if (absorption == totalAbsorption &&
blit(xo, yo, healthTexBaseX + 5 * 9, 9 * y0, 9, 9); fmodf(totalAbsorption, 2) == 1) {
blit(xo, yo, healthTexBaseX + 17 * 9, 9 * y0, 9, 9);
} else {
blit(xo, yo, healthTexBaseX + 16 * 9, 9 * y0, 9, 9);
}
absorption -= 2;
} else {
if (i * 2 + 1 < currentHealth)
blit(xo, yo, healthTexBaseX + 4 * 9, 9 * y0, 9, 9);
if (i * 2 + 1 == currentHealth)
blit(xo, yo, healthTexBaseX + 5 * 9, 9 * y0, 9, 9);
}
} }
// render food std::shared_ptr<Entity> riding =
for (int i = 0; i < FoodConstants::MAX_FOOD / 2; i++) { minecraft->localplayers[iPad].get()->riding;
int yo = yLine1; std::shared_ptr<LivingEntity> living =
dynamic_pointer_cast<LivingEntity>(riding);
if (riding == NULL) {
// render food
for (int i = 0; i < FoodConstants::MAX_FOOD / 2; i++) {
int yo = yLine1;
int texBaseX = 16; int texBaseX = 16;
int bg = 0; int bg = 0;
if (minecraft->player->hasEffect(MobEffect::hunger)) { if (minecraft->player->hasEffect(MobEffect::hunger)) {
texBaseX += 4 * 9; texBaseX += 4 * 9;
bg = 13; bg = 13;
}
if (minecraft->player->getFoodData()
->getSaturationLevel() <= 0) {
if ((tickCount % (food * 3 + 1)) == 0) {
yo += random->nextInt(3) - 1;
} }
if (minecraft->player->getFoodData()
->getSaturationLevel() <= 0) {
if ((tickCount % (food * 3 + 1)) == 0) {
yo += random->nextInt(3) - 1;
}
}
if (foodBlink) bg = 1;
int xo = xRight - i * 8 - 9;
blit(xo, yo, 16 + bg * 9, 9 * 3, 9, 9);
if (foodBlink) {
if (i * 2 + 1 < oldFood)
blit(xo, yo, texBaseX + 6 * 9, 9 * 3, 9, 9);
if (i * 2 + 1 == oldFood)
blit(xo, yo, texBaseX + 7 * 9, 9 * 3, 9, 9);
}
if (i * 2 + 1 < food)
blit(xo, yo, texBaseX + 4 * 9, 9 * 3, 9, 9);
if (i * 2 + 1 == food)
blit(xo, yo, texBaseX + 5 * 9, 9 * 3, 9, 9);
}
} else if (living != nullptr) {
// Render mount health
int riderCurrentHealth =
(int)ceil(living.get()->getHealth());
float maxRiderHealth = living->getMaxHealth();
int hearts = (int)(maxRiderHealth + .5f) / 2;
if (hearts > 30) {
hearts = 30;
} }
if (foodBlink) bg = 1; int yo = yLine1;
int xo = xRight - i * 8 - 9; int baseHealth = 0;
blit(xo, yo, 16 + bg * 9, 9 * 3, 9, 9);
if (foodBlink) { while (hearts > 0) {
if (i * 2 + 1 < oldFood) int rowHearts = min(hearts, 10);
blit(xo, yo, texBaseX + 6 * 9, 9 * 3, 9, 9); hearts -= rowHearts;
if (i * 2 + 1 == oldFood)
blit(xo, yo, texBaseX + 7 * 9, 9 * 3, 9, 9); for (int i = 0; i < rowHearts; i++) {
int texBaseX = 52;
int bg = 0;
if (foodBlink) bg = 1;
int xo = xRight - i * 8 - 9;
blit(xo, yo, texBaseX + bg * 9, 9 * 1, 9, 9);
if (i * 2 + 1 + baseHealth < riderCurrentHealth)
blit(xo, yo, texBaseX + 4 * 9, 9 * 1, 9, 9);
if (i * 2 + 1 + baseHealth == riderCurrentHealth)
blit(xo, yo, texBaseX + 5 * 9, 9 * 1, 9, 9);
}
yo -= 10;
baseHealth += 20;
} }
if (i * 2 + 1 < food)
blit(xo, yo, texBaseX + 4 * 9, 9 * 3, 9, 9);
if (i * 2 + 1 == food)
blit(xo, yo, texBaseX + 5 * 9, 9 * 3, 9, 9);
} }
// render air bubbles // render air bubbles
@ -647,49 +733,20 @@ void Gui::render(float a, bool mouseFree, int xMouse, int yMouse) {
glEnable(GL_RESCALE_NORMAL); glEnable(GL_RESCALE_NORMAL);
glEnable(GL_COLOR_MATERIAL); glEnable(GL_COLOR_MATERIAL);
int xo = 0; // 4J - TomK now using safe zone values directly instead of the
int yo = 0; // magic number calculation that lived here before (which only
switch (minecraft->player->m_iScreenSection) { // worked for medium scale, the other two were off!)
case C4JRender::VIEWPORT_TYPE_FULLSCREEN: int xo = iSafezoneXHalf + 10;
default: int yo = iSafezoneTopYHalf + 10;
if (RenderManager.IsHiDef()) xo = -22;
yo = -36; #ifdef __PSVITA__
break; // align directly with corners, there are no safe zones on vita
case C4JRender::VIEWPORT_TYPE_SPLIT_TOP: xo = 10;
xo = 0; yo = 10;
yo = -25; #endif
break;
case C4JRender::VIEWPORT_TYPE_SPLIT_BOTTOM:
xo = 0;
yo = -48;
break;
case C4JRender::VIEWPORT_TYPE_SPLIT_LEFT:
xo = 0;
yo = -25;
break;
case C4JRender::VIEWPORT_TYPE_SPLIT_RIGHT:
xo = -43;
yo = -25;
break;
case C4JRender::VIEWPORT_TYPE_QUADRANT_TOP_LEFT:
xo = 0;
yo = -25;
break;
case C4JRender::VIEWPORT_TYPE_QUADRANT_TOP_RIGHT:
xo = -43;
yo = -25;
break;
case C4JRender::VIEWPORT_TYPE_QUADRANT_BOTTOM_LEFT:
xo = 0;
yo = -48;
break;
case C4JRender::VIEWPORT_TYPE_QUADRANT_BOTTOM_RIGHT:
xo = -43;
yo = -48;
break;
}
glPushMatrix(); glPushMatrix();
glTranslatef((float)xo + 51, (float)yo + 75, 50); glTranslatef((float)xo, (float)yo, 50);
float ss = 12; float ss = 12;
glScalef(-ss, ss, ss); glScalef(-ss, ss, ss);
glRotatef(180, 0, 0, 1); glRotatef(180, 0, 0, 1);
@ -735,7 +792,10 @@ void Gui::render(float a, bool mouseFree, int xMouse, int yMouse) {
minecraft->player->onFire = 0; minecraft->player->onFire = 0;
minecraft->player->setSharedFlag(Entity::FLAG_ONFIRE, false); minecraft->player->setSharedFlag(Entity::FLAG_ONFIRE, false);
glTranslatef(0, minecraft->player->heightOffset, 0); // 4J - TomK don't offset the player. it's easier to align it
// with the safe zones that way!
// glTranslatef(0, minecraft->player->heightOffset, 0);
glTranslatef(0, 0, 0);
EntityRenderDispatcher::instance->playerRotY = 180; EntityRenderDispatcher::instance->playerRotY = 180;
EntityRenderDispatcher::instance->isGuiRender = true; EntityRenderDispatcher::instance->isGuiRender = true;
EntityRenderDispatcher::instance->render(minecraft->player, 0, EntityRenderDispatcher::instance->render(minecraft->player, 0,