Files
mcpe/source/client/renderer/entity/MobRenderer.cpp
Brent f12a3c1c61 Visual Studio Project Overhaul + Cleanup (#80)
* Visual Studio Project Overhaul + Cleanup
* SDL2 project for Windows
* Re-added game client icon to SDL2 code
* Renamed "AppPlatform_windows" to "AppPlatform_win32" (this is the name of the Windows API and is not representative of the architecture type)
* Renamed "LoggerWindows" to "LoggerWin32"
* Renamed "SoundSystemWindows to "SoundSystemDS" (DirectSound). This may be used for the 360, so it wouldn't really be Windows-specific then.
* Moved "ClientSideNetworkHandler" from "network" to "client/network". We don't need it being compiled for the server if the client's the only thing that needs it.
* I wonder if this still works on macOS...

* Bugfixes & Fixed for macOS

* Options::savePropertiesToFile Logging Bugfix

* Silence Winsock Deprecation Warnings in RakNet

* VS Project Improvements
- Replaced 50 billion relative paths with $(MC_ROOT)
- Added $(RAKNET_PATH) variable to override RakNet location
- Re-added gitignore for .vcxproj.user files
- Added debugging config to Directory.Builds.props
- Slimmed down project configurations for SDL2

* VS Project Config Bugfixes
- Fixed RakNet header path for additional includes

* RakNet Target for XCode

* XCode Project Config Fixes

* Packet logging

* Network VS Project Filter Fix

* Fix RakNet Packet ID Length
We previously didn't have consistency between old and new C++ regarding PacketType enum length. Now we do. This is required or else it completely breaks networking between the versions.

* Additional RakNet Error Handling

* Disable packet logging

* * Fix CMakeLists.txt

This reflects the relocation of ClientSideNetworkHandler.cpp.

* * Also add renderer/GL/GL.cpp to the CMakeLists.txt

* * Replace libpng with stb_image

* * Fix buggy water behavior.

* * Put the CMakeLists of the SDL project in debug mode

* Visual Studio 2010 Support

* * Change the SdlIoCallbacks from an array to a single member.

This fixes compilation of the sdl2 target on VS.

* * Fix missing _error label.

* Revert "* Fix missing _error label."

This reverts commit 99a057fc84049a16c864bd840fb439a008af5c74.

* Revert "* Replace libpng with stb_image"

* info_updateGame Tiles

---------

Co-authored-by: Brent Da Mage <BrentDaMage@users.noreply.github.com>
Co-authored-by: iProgramInCpp <iprogramincpp@gmail.com>
2023-10-22 10:08:59 +03:00

211 lines
5.2 KiB
C++

/********************************************************************
Minecraft: Pocket Edition - Decompilation Project
Copyright (C) 2023 iProgramInCpp
The following code is licensed under the BSD 1 clause license.
SPDX-License-Identifier: BSD-1-Clause
********************************************************************/
#include "MobRenderer.hpp"
#include "EntityRenderDispatcher.hpp"
#include "client/app/Minecraft.hpp"
MobRenderer::MobRenderer(Model* pModel, float f)
{
m_pArmorModel = nullptr;
m_pModel = pModel;
field_4 = f;
}
void MobRenderer::setArmor(Model* model)
{
m_pArmorModel = model;
}
int MobRenderer::prepareArmor(Mob* mob, int a, float b)
{
return 0;
}
void MobRenderer::additionalRendering(Mob* mob, float f)
{
}
float MobRenderer::getAttackAnim(Mob* mob, float f)
{
return mob->getAttackAnim(f);
}
float MobRenderer::getBob(Mob* mob, float f)
{
return float(mob->field_B4) + f;
}
float MobRenderer::getFlipDegrees(Mob* mob)
{
return 90.0f;
}
int MobRenderer::getOverlayColor(Mob* mob, float a, float b)
{
return 0;
}
void MobRenderer::scale(Mob*, float)
{
}
void MobRenderer::setupPosition(Entity* entity, float x, float y, float z)
{
glTranslatef(x, y, z);
}
void MobRenderer::setupRotations(Entity* entity, float x, float y, float z)
{
glRotatef(180.0f - y, 0.0f, 1.0f, 0.0f);
Mob* mob = (Mob*)entity;
if (mob->field_110 > 0)
{
float t = Mth::sqrt((float(mob->field_110) + z - 1.0f) / 20.0f * 1.6f);
if (t > 1.0f)
t = 1.0f;
glRotatef(getFlipDegrees(mob) * t, 0.0f, 0.0f, 1.0f);
}
}
void MobRenderer::render(Entity* entity, float x, float y, float z, float unused, float f)
{
Mob* pMob = (Mob*)entity;
glPushMatrix();
glDisable(GL_CULL_FACE);
m_pModel->field_4 = getAttackAnim(pMob, f);
m_pModel->field_8 = false;
if (m_pArmorModel)
m_pArmorModel->field_8 = m_pModel->field_8;
float aYaw = pMob->field_5C + (pMob->m_yaw - pMob->field_5C) * f;
float aPitch = pMob->field_60 + (pMob->m_pitch - pMob->field_60) * f;
float fBob = getBob(pMob, f);
float fSmth = pMob->field_EC + (pMob->field_E8 - pMob->field_EC) * f;
setupPosition(pMob, x, y - pMob->field_84, z);
setupRotations(pMob, fBob, fSmth, f);
glScalef(-1.0f, -1.0f, 1.0f);
scale(pMob, f);
glTranslatef(0.0f, -1.5078f, 0.0f);
float x1 = pMob->field_128 + (pMob->field_12C - pMob->field_128) * f;
if (x1 > 1.0f)
x1 = 1.0f;
float x2 = pMob->field_130 - pMob->field_12C * (1.0f - f);
bindTexture("mob/char.png");
glEnable(GL_ALPHA_TEST);
m_pModel->setBrightness(entity->getBrightness(1.0f));
m_pModel->prepareMobModel(pMob, x2, x1, f);
m_pModel->render(x2, x1, fBob, aYaw - fSmth, aPitch, 0.059375f);
additionalRendering(pMob, f);
float fBright = pMob->getBrightness(f);
int iOverlayColor = getOverlayColor(pMob, fBright, f);
if (GET_ALPHA(iOverlayColor) || pMob->field_104 > 0 || pMob->field_110 > 0)
{
glDisable(GL_TEXTURE_2D);
glDisable(GL_ALPHA_TEST);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glDepthFunc(GL_EQUAL);
if (pMob->field_104 > 0 || pMob->field_110 > 0)
{
glColor4f(fBright, 0.0f, 0.0f, 0.4f);
m_pModel->render(x2, x1, fBob, aYaw - fSmth, aPitch, 0.059375f); // was 0.0625f. Why?
}
if (GET_ALPHA(iOverlayColor))
{
glColor4f(
float(GET_RED(iOverlayColor)) / 255.0f,
float(GET_GREEN(iOverlayColor)) / 255.0f,
float(GET_BLUE(iOverlayColor)) / 255.0f,
float(GET_ALPHA(iOverlayColor)) / 255.0f);
m_pModel->render(x2, x1, fBob, aYaw - fSmth, aPitch, 0.059375f); // same here
}
glDepthFunc(GL_LEQUAL);
glDisable(GL_BLEND);
glEnable(GL_TEXTURE_2D);
glEnable(GL_ALPHA_TEST);
}
glEnable(GL_CULL_FACE);
glPopMatrix();
renderName(pMob, x, y, z);
}
void MobRenderer::renderName(Mob* mob, float x, float y, float z)
{
if (!mob->isPlayer())
return;
Player* player = (Player*)mob;
if (player == m_pDispatcher->m_pMinecraft->m_pLocalPlayer)
return;
// @TODO: don't know why but I have to add this correction. look into it and fix it!
renderNameTag(mob, player->m_name, x, y - 1.5f, z, mob->isSneaking() ? 32 : 64);
}
void MobRenderer::renderNameTag(Mob* mob, const std::string& str, float x, float y, float z, int a)
{
if (mob->distanceToSqr(m_pDispatcher->m_pMob) > float(a * a))
return;
Font* font = getFont();
glPushMatrix();
glTranslatef(x + 0.0f, y + 2.3f, z);
glNormal3f(0.0f, 1.0f, 0.0f);
// billboard the name towards the camera
glRotatef(-m_pDispatcher->m_yaw, 0.0f, 1.0f, 0.0f);
glRotatef(+m_pDispatcher->m_pitch, 1.0f, 0.0f, 0.0f);
glScalef(-0.026667f, -0.026667f, 0.026667f);
glDepthMask(false);
glDisable(GL_DEPTH_TEST);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glDisable(GL_TEXTURE_2D);
Tesselator& t = Tesselator::instance;
t.begin();
int width = font->width(str);
float widthHalf = float(width / 2);
t.color(0.0f, 0.0f, 0.0f, 0.25f);
t.vertex(-1.0f - widthHalf, -1.0f, 0.0f);
t.vertex(-1.0f - widthHalf, 8.0f, 0.0f);
t.vertex(widthHalf + 1.0f, 8.0f, 0.0f);
t.vertex(widthHalf + 1.0f, -1.0f, 0.0f);
t.draw();
glEnable(GL_TEXTURE_2D);
font->draw(str, -font->width(str) / 2, 0, 0x20FFFFFF);
glEnable(GL_DEPTH_TEST);
glDepthMask(true);
font->draw(str, -font->width(str) / 2, 0, 0xFFFFFFFF);
glDisable(GL_BLEND);
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
glPopMatrix();
}