mirror of
https://github.com/celisej567/mcpe.git
synced 2026-09-23 20:09:46 +03:00
migrate ALMOST everything from source tree into client
This commit is contained in:
133
source/client/renderer/entity/EntityRenderDispatcher.cpp
Normal file
133
source/client/renderer/entity/EntityRenderDispatcher.cpp
Normal file
@@ -0,0 +1,133 @@
|
||||
/********************************************************************
|
||||
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 "EntityRenderDispatcher.hpp"
|
||||
#include "ItemInHandRenderer.hpp"
|
||||
#include "Minecraft.hpp"
|
||||
|
||||
EntityRenderDispatcher* EntityRenderDispatcher::instance;
|
||||
float EntityRenderDispatcher::xOff, EntityRenderDispatcher::yOff, EntityRenderDispatcher::zOff;
|
||||
|
||||
EntityRenderDispatcher::EntityRenderDispatcher() :
|
||||
m_HumanoidMobRenderer(new HumanoidModel(0.0f, 0.0f), 0.0f)
|
||||
{
|
||||
m_HumanoidMobRenderer.init(this);
|
||||
m_TntRenderer.init(this);
|
||||
m_CameraRenderer.init(this);
|
||||
|
||||
#ifndef ORIGINAL_CODE
|
||||
// @BUG: Not initializing the item renderer would cause crashes if item7
|
||||
// entities exist, because it references the dispatcher
|
||||
m_ItemRenderer.init(this);
|
||||
#endif
|
||||
|
||||
#ifdef ENH_ALLOW_SAND_GRAVITY
|
||||
m_FallingTileRenderer.init(this);
|
||||
#endif
|
||||
}
|
||||
|
||||
float EntityRenderDispatcher::distanceToSqr(float x, float y, float z)
|
||||
{
|
||||
float dX = x - m_pos.x;
|
||||
float dY = y - m_pos.y;
|
||||
float dZ = z - m_pos.z;
|
||||
|
||||
return dX * dX + dY * dY + dZ * dZ;
|
||||
}
|
||||
|
||||
Font* EntityRenderDispatcher::getFont()
|
||||
{
|
||||
return m_pFont;
|
||||
}
|
||||
|
||||
EntityRenderDispatcher* EntityRenderDispatcher::getInstance()
|
||||
{
|
||||
if(!instance)
|
||||
instance = new EntityRenderDispatcher;
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
EntityRenderer* EntityRenderDispatcher::getRenderer(Entity* pEnt)
|
||||
{
|
||||
switch (pEnt->field_C8)
|
||||
{
|
||||
case RENDER_TNT:
|
||||
return &m_TntRenderer;
|
||||
case RENDER_ITEM:
|
||||
return &m_ItemRenderer;
|
||||
case RENDER_CAMERA:
|
||||
return &m_CameraRenderer;
|
||||
case RENDER_HUMANOID:
|
||||
return &m_HumanoidMobRenderer;
|
||||
#ifdef ENH_ALLOW_SAND_GRAVITY
|
||||
case RENDER_FALLING_TILE:
|
||||
return &m_FallingTileRenderer;
|
||||
#endif
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void EntityRenderDispatcher::onGraphicsReset()
|
||||
{
|
||||
m_HumanoidMobRenderer.onGraphicsReset();
|
||||
}
|
||||
|
||||
void EntityRenderDispatcher::prepare(Level* level, Textures* textures, Font* font, Mob* mob, Options* options, float f)
|
||||
{
|
||||
m_pLevel = level;
|
||||
m_pTextures = textures;
|
||||
m_pMob = mob;
|
||||
m_pFont = font;
|
||||
m_pOptions = options;
|
||||
m_yaw = mob->field_5C + f * (mob->m_yaw - mob->field_5C);
|
||||
m_pitch = mob->field_60 + f * (mob->m_pitch - mob->field_60);
|
||||
m_pos.x = mob->field_98.x + f * (mob->m_pos.x - mob->field_98.x);
|
||||
m_pos.y = mob->field_98.y + f * (mob->m_pos.x - mob->field_98.y);
|
||||
m_pos.z = mob->field_98.z + f * (mob->m_pos.x - mob->field_98.z);
|
||||
}
|
||||
|
||||
void EntityRenderDispatcher::render(Entity* entity, float f)
|
||||
{
|
||||
float x = entity->field_98.x + f * (entity->m_pos.x - entity->field_98.x);
|
||||
float y = entity->field_98.y + f * (entity->m_pos.y - entity->field_98.y);
|
||||
float z = entity->field_98.z + f * (entity->m_pos.z - entity->field_98.z);
|
||||
float yaw = entity->field_5C + f * (entity->m_yaw - entity->field_5C);
|
||||
|
||||
float bright = entity->getBrightness(1.0f);
|
||||
glColor4f(bright, bright, bright, 1.0f);
|
||||
|
||||
render(entity, x - xOff, y - yOff, z - zOff, yaw, f);
|
||||
}
|
||||
|
||||
void EntityRenderDispatcher::render(Entity* entity, float a, float b, float c, float d, float e)
|
||||
{
|
||||
EntityRenderer* pRenderer = getRenderer(entity);
|
||||
if (pRenderer)
|
||||
{
|
||||
#ifndef ORIGINAL_CODE
|
||||
if (pRenderer == &m_HumanoidMobRenderer)
|
||||
m_HumanoidMobRenderer.m_pHumanoidModel->field_10BE = entity->isSneaking();
|
||||
else
|
||||
m_HumanoidMobRenderer.m_pHumanoidModel->field_10BE = false;
|
||||
#endif
|
||||
|
||||
pRenderer->render(entity, a, b, c, d, e);
|
||||
}
|
||||
}
|
||||
|
||||
void EntityRenderDispatcher::setLevel(Level* level)
|
||||
{
|
||||
m_pLevel = level;
|
||||
}
|
||||
|
||||
void EntityRenderDispatcher::setMinecraft(Minecraft* mc)
|
||||
{
|
||||
m_pMinecraft = mc;
|
||||
}
|
||||
64
source/client/renderer/entity/EntityRenderDispatcher.hpp
Normal file
64
source/client/renderer/entity/EntityRenderDispatcher.hpp
Normal file
@@ -0,0 +1,64 @@
|
||||
/********************************************************************
|
||||
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
|
||||
********************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "EntityRenderer.hpp"
|
||||
#include "HumanoidMobRenderer.hpp"
|
||||
#include "TripodCameraRenderer.hpp"
|
||||
#include "TntRenderer.hpp"
|
||||
#include "ItemRenderer.hpp"
|
||||
#include "FallingTileRenderer.hpp"
|
||||
|
||||
class Minecraft;
|
||||
class Font;
|
||||
class Level;
|
||||
class Entity;
|
||||
class Textures;
|
||||
class ItemInHandRenderer;
|
||||
|
||||
class EntityRenderDispatcher
|
||||
{
|
||||
public:
|
||||
EntityRenderDispatcher();
|
||||
float distanceToSqr(float x, float y, float z);
|
||||
Font* getFont();
|
||||
EntityRenderer* getRenderer(Entity* pEnt);
|
||||
void onGraphicsReset();
|
||||
void prepare(Level*, Textures*, Font*, Mob*, Options*, float);
|
||||
void render(Entity*, float);
|
||||
void render(Entity*, float, float, float, float, float);
|
||||
void setLevel(Level*);
|
||||
void setMinecraft(Minecraft*);
|
||||
|
||||
static EntityRenderDispatcher* getInstance();
|
||||
|
||||
public:
|
||||
ItemInHandRenderer* m_pItemInHandRenderer = nullptr;
|
||||
HumanoidMobRenderer m_HumanoidMobRenderer;
|
||||
TntRenderer m_TntRenderer;
|
||||
ItemRenderer m_ItemRenderer;
|
||||
TripodCameraRenderer m_CameraRenderer;
|
||||
Textures* m_pTextures = nullptr;
|
||||
Level* m_pLevel = nullptr;
|
||||
Minecraft* m_pMinecraft = nullptr;
|
||||
Mob* m_pMob = nullptr;
|
||||
float m_yaw = 0.0f;
|
||||
float m_pitch = 0.0f;
|
||||
Options* m_pOptions = nullptr;
|
||||
Vec3 m_pos;
|
||||
Font* m_pFont = nullptr;
|
||||
|
||||
#if defined(ENH_ALLOW_SAND_GRAVITY)
|
||||
FallingTileRenderer m_FallingTileRenderer;
|
||||
#endif
|
||||
|
||||
static EntityRenderDispatcher* instance;
|
||||
static float xOff, yOff, zOff;
|
||||
};
|
||||
|
||||
104
source/client/renderer/entity/EntityRenderer.cpp
Normal file
104
source/client/renderer/entity/EntityRenderer.cpp
Normal file
@@ -0,0 +1,104 @@
|
||||
/********************************************************************
|
||||
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 "EntityRenderer.hpp"
|
||||
#include "EntityRenderDispatcher.hpp"
|
||||
|
||||
EntityRenderer::EntityRenderer() : m_model(0.0f, 0.0f)
|
||||
{
|
||||
}
|
||||
|
||||
void EntityRenderer::bindTexture(const std::string& file)
|
||||
{
|
||||
m_pDispatcher->m_pTextures->loadAndBindTexture(file);
|
||||
}
|
||||
|
||||
Font* EntityRenderer::getFont()
|
||||
{
|
||||
return m_pDispatcher->m_pFont;
|
||||
}
|
||||
|
||||
void EntityRenderer::init(EntityRenderDispatcher* d)
|
||||
{
|
||||
m_pDispatcher = d;
|
||||
}
|
||||
|
||||
void EntityRenderer::onGraphicsReset()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void EntityRenderer::render(const AABB& aabb, float offX, float offY, float offZ)
|
||||
{
|
||||
Tesselator& t = Tesselator::instance;
|
||||
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
t.begin();
|
||||
t.vertex(offX, offY, offZ);
|
||||
t.vertex(aabb.min.x, aabb.max.y, aabb.min.z);
|
||||
t.vertex(aabb.max.x, aabb.max.y, aabb.min.z);
|
||||
t.vertex(aabb.max.x, aabb.min.y, aabb.min.z);
|
||||
t.vertex(aabb.min.x, aabb.min.y, aabb.min.z);
|
||||
t.vertex(aabb.min.x, aabb.min.y, aabb.max.z);
|
||||
t.vertex(aabb.max.x, aabb.min.y, aabb.max.z);
|
||||
t.vertex(aabb.max.x, aabb.max.y, aabb.max.z);
|
||||
t.vertex(aabb.min.x, aabb.max.y, aabb.max.z);
|
||||
t.vertex(aabb.min.x, aabb.min.y, aabb.min.z);
|
||||
t.vertex(aabb.max.x, aabb.min.y, aabb.min.z);
|
||||
t.vertex(aabb.max.x, aabb.min.y, aabb.max.z);
|
||||
t.vertex(aabb.min.x, aabb.min.y, aabb.max.z);
|
||||
t.vertex(aabb.min.x, aabb.max.y, aabb.max.z);
|
||||
t.vertex(aabb.max.x, aabb.max.y, aabb.max.z);
|
||||
t.vertex(aabb.max.x, aabb.max.y, aabb.min.z);
|
||||
t.vertex(aabb.min.x, aabb.max.y, aabb.min.z);
|
||||
t.vertex(aabb.min.x, aabb.min.y, aabb.max.z);
|
||||
t.vertex(aabb.min.x, aabb.max.y, aabb.max.z);
|
||||
t.vertex(aabb.min.x, aabb.max.y, aabb.min.z);
|
||||
t.vertex(aabb.min.x, aabb.min.y, aabb.min.z);
|
||||
t.vertex(aabb.max.x, aabb.min.y, aabb.min.z);
|
||||
t.vertex(aabb.max.x, aabb.max.y, aabb.min.z);
|
||||
t.vertex(aabb.max.x, aabb.max.y, aabb.max.z);
|
||||
t.vertex(aabb.max.x, aabb.min.y, aabb.max.z);
|
||||
t.offset(0.0f, 0.0f, 0.0f);
|
||||
t.draw();
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
}
|
||||
|
||||
void EntityRenderer::renderFlat(const AABB& aabb)
|
||||
{
|
||||
Tesselator& t = Tesselator::instance;
|
||||
|
||||
t.begin();
|
||||
t.vertex(aabb.min.x, aabb.max.y, aabb.min.z);
|
||||
t.vertex(aabb.max.x, aabb.max.y, aabb.min.z);
|
||||
t.vertex(aabb.max.x, aabb.min.y, aabb.min.z);
|
||||
t.vertex(aabb.min.x, aabb.min.y, aabb.min.z);
|
||||
t.vertex(aabb.min.x, aabb.min.y, aabb.max.z);
|
||||
t.vertex(aabb.max.x, aabb.min.y, aabb.max.z);
|
||||
t.vertex(aabb.max.x, aabb.max.y, aabb.max.z);
|
||||
t.vertex(aabb.min.x, aabb.max.y, aabb.max.z);
|
||||
t.vertex(aabb.min.x, aabb.min.y, aabb.min.z);
|
||||
t.vertex(aabb.max.x, aabb.min.y, aabb.min.z);
|
||||
t.vertex(aabb.max.x, aabb.min.y, aabb.max.z);
|
||||
t.vertex(aabb.min.x, aabb.min.y, aabb.max.z);
|
||||
t.vertex(aabb.min.x, aabb.max.y, aabb.max.z);
|
||||
t.vertex(aabb.max.x, aabb.max.y, aabb.max.z);
|
||||
t.vertex(aabb.max.x, aabb.max.y, aabb.min.z);
|
||||
t.vertex(aabb.min.x, aabb.max.y, aabb.min.z);
|
||||
t.vertex(aabb.min.x, aabb.min.y, aabb.max.z);
|
||||
t.vertex(aabb.min.x, aabb.max.y, aabb.max.z);
|
||||
t.vertex(aabb.min.x, aabb.max.y, aabb.min.z);
|
||||
t.vertex(aabb.min.x, aabb.min.y, aabb.min.z);
|
||||
t.vertex(aabb.max.x, aabb.min.y, aabb.min.z);
|
||||
t.vertex(aabb.max.x, aabb.max.y, aabb.min.z);
|
||||
t.vertex(aabb.max.x, aabb.max.y, aabb.max.z);
|
||||
t.vertex(aabb.max.x, aabb.min.y, aabb.max.z);
|
||||
t.draw();
|
||||
}
|
||||
|
||||
37
source/client/renderer/entity/EntityRenderer.hpp
Normal file
37
source/client/renderer/entity/EntityRenderer.hpp
Normal file
@@ -0,0 +1,37 @@
|
||||
/********************************************************************
|
||||
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
|
||||
********************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "HumanoidModel.hpp"
|
||||
#include "Font.hpp"
|
||||
|
||||
class EntityRenderDispatcher;
|
||||
|
||||
class EntityRenderer
|
||||
{
|
||||
public:
|
||||
EntityRenderer();
|
||||
void bindTexture(const std::string& file);
|
||||
Font* getFont();
|
||||
void init(EntityRenderDispatcher* d);
|
||||
static void render(const AABB&, float, float, float);
|
||||
static void renderFlat(const AABB&);
|
||||
|
||||
virtual void render(Entity*, float, float, float, float, float) = 0;
|
||||
virtual void onGraphicsReset();
|
||||
|
||||
public:
|
||||
float field_4 = 0.0f;
|
||||
float field_8 = 1.0f;
|
||||
EntityRenderDispatcher* m_pDispatcher = nullptr;
|
||||
|
||||
// @HUH: Why is there a HumanoidModel here? There's another
|
||||
// in HumanoidMobRenderer...
|
||||
HumanoidModel m_model;
|
||||
};
|
||||
71
source/client/renderer/entity/HumanoidMobRenderer.cpp
Normal file
71
source/client/renderer/entity/HumanoidMobRenderer.cpp
Normal file
@@ -0,0 +1,71 @@
|
||||
/********************************************************************
|
||||
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 "HumanoidMobRenderer.hpp"
|
||||
#include "EntityRenderDispatcher.hpp"
|
||||
#include "ItemInHandRenderer.hpp"
|
||||
#include "ItemInstance.hpp"
|
||||
#include "TileRenderer.hpp"
|
||||
#include "Player.hpp"
|
||||
|
||||
HumanoidMobRenderer::HumanoidMobRenderer(HumanoidModel* pModel, float f) : MobRenderer(pModel, f)
|
||||
{
|
||||
m_pHumanoidModel = pModel;
|
||||
}
|
||||
|
||||
void HumanoidMobRenderer::additionalRendering(Mob* mob, float f)
|
||||
{
|
||||
if (!mob->isPlayer()) return;
|
||||
Player* player = (Player*)mob;
|
||||
|
||||
int itemID = player->m_pInventory->getSelectedItemId();
|
||||
if (itemID < 0)
|
||||
return;
|
||||
|
||||
ItemInstance inst(itemID, 1, 0);
|
||||
glPushMatrix();
|
||||
m_pHumanoidModel->m_armL.translateTo(0.0625f);
|
||||
glTranslatef(-0.0625f, 0.4375f, 0.0625f);
|
||||
if (itemID <= C_MAX_TILES && TileRenderer::canRender(Tile::tiles[itemID]->getRenderShape()))
|
||||
{
|
||||
glTranslatef(0.0f, 0.1875f, -0.3125f);
|
||||
glRotatef(20.0f, 1.0f, 0.0f, 0.0f);
|
||||
glRotatef(45.0f, 0.0f, 1.0f, 0.0f);
|
||||
glScalef(0.375f, -0.375f, 0.375f);
|
||||
}
|
||||
else if (Item::items[itemID]->isHandEquipped())
|
||||
{
|
||||
glTranslatef(0.0f, 0.1875f, 0.0f);
|
||||
glScalef(0.625f, -0.625f, 0.625f);
|
||||
glRotatef(-100.0f, 1.0f, 0.0f, 0.0f);
|
||||
glRotatef(45.0f, 0.0f, 1.0f, 0.0f);
|
||||
}
|
||||
else
|
||||
{
|
||||
glTranslatef(0.25f, 0.1875f, -0.1875f);
|
||||
glScalef(0.375f, 0.375f, 0.375f);
|
||||
glRotatef(60.0f, 0.0f, 0.0f, 1.0f);
|
||||
glRotatef(-90.0f, 1.0f, 0.0f, 0.0f);
|
||||
glRotatef(20.0f, 0.0f, 0.0f, 1.0f);
|
||||
}
|
||||
|
||||
m_pDispatcher->m_pItemInHandRenderer->renderItem(&inst);
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
void HumanoidMobRenderer::onGraphicsReset()
|
||||
{
|
||||
m_pHumanoidModel->onGraphicsReset();
|
||||
}
|
||||
|
||||
void HumanoidMobRenderer::renderHand()
|
||||
{
|
||||
m_pHumanoidModel->field_4 = 0;
|
||||
m_pHumanoidModel->setupAnim(0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0625f);
|
||||
m_pHumanoidModel->m_armL.render(0.0625f);
|
||||
}
|
||||
25
source/client/renderer/entity/HumanoidMobRenderer.hpp
Normal file
25
source/client/renderer/entity/HumanoidMobRenderer.hpp
Normal file
@@ -0,0 +1,25 @@
|
||||
/********************************************************************
|
||||
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
|
||||
********************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "MobRenderer.hpp"
|
||||
|
||||
class HumanoidMobRenderer : public MobRenderer
|
||||
{
|
||||
public:
|
||||
HumanoidMobRenderer(HumanoidModel*, float);
|
||||
virtual void additionalRendering(Mob*, float) override;
|
||||
virtual void onGraphicsReset() override;
|
||||
|
||||
void renderHand();
|
||||
|
||||
public:
|
||||
HumanoidModel* m_pHumanoidModel;
|
||||
};
|
||||
|
||||
268
source/client/renderer/entity/ItemRenderer.cpp
Normal file
268
source/client/renderer/entity/ItemRenderer.cpp
Normal file
@@ -0,0 +1,268 @@
|
||||
/********************************************************************
|
||||
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 <sstream>
|
||||
#include "ItemRenderer.hpp"
|
||||
#include "TileRenderer.hpp"
|
||||
#include "ItemEntity.hpp"
|
||||
#include "EntityRenderDispatcher.hpp"
|
||||
|
||||
// @TODO: ItemSpriteRenderer. Unused relative
|
||||
TileRenderer* ItemRenderer::tileRenderer = new TileRenderer;
|
||||
|
||||
const uint8_t g_ItemFrames[C_MAX_TILES] =
|
||||
{
|
||||
0, 1, 2, 3, 4, 5, 0, 6, 0, 0, 0, 0, 7, 8, 9, 10,
|
||||
11, 12, 13, 0, 14, 15, 0, 0, 16, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 17, 0, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 0,
|
||||
0, 28, 29, 0, 0, 30, 0, 0, 31, 32, 0, 0, 33, 0, 0, 0,
|
||||
34, 35, 0, 36, 0, 0, 0, 37, 0, 38, 39, 0, 0, 0, 40, 41,
|
||||
0, 0, 42, 43, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54,
|
||||
55, 56, 57, 58, 0
|
||||
};
|
||||
|
||||
ItemRenderer::ItemRenderer()
|
||||
{
|
||||
field_4 = 0.15f;
|
||||
field_8 = 0.75f;
|
||||
}
|
||||
|
||||
void ItemRenderer::render(Entity* pEntity, float x, float y, float z, float a, float b)
|
||||
{
|
||||
m_random.init_genrand(187);
|
||||
ItemEntity* pItemEntity = (ItemEntity*)pEntity;
|
||||
|
||||
glPushMatrix();
|
||||
float yOffset = Mth::sin((float(pItemEntity->field_E0) + b) / 10.0f + pItemEntity->field_E8);
|
||||
ItemInstance* pItemInstance = pItemEntity->m_pItemInstance;
|
||||
|
||||
int itemsToRender = 1;
|
||||
if (pItemInstance->m_amount > 1)
|
||||
itemsToRender = 2;
|
||||
if (pItemInstance->m_amount > 5)
|
||||
itemsToRender = 3;
|
||||
if (pItemInstance->m_amount > 20)
|
||||
itemsToRender = 4;
|
||||
|
||||
glTranslatef(x, y + 0.1f + yOffset * 0.1f, z);
|
||||
glEnable(GL_RESCALE_NORMAL);
|
||||
|
||||
int itemID = pItemInstance->m_itemID;
|
||||
if (itemID < C_MAX_TILES && TileRenderer::canRender(Tile::tiles[itemID]->getRenderShape()))
|
||||
{
|
||||
glRotatef(((float(pItemEntity->field_E0) + b) / 20.0f + pItemEntity->field_E8) * 57.296f, 0.0f, 1.0f, 0.0f);
|
||||
bindTexture(C_TERRAIN_NAME);
|
||||
|
||||
float scale = 0.5f;
|
||||
|
||||
// @BUG: If cacti existed and were able to be dropped, they would be 2x the size of a regular tile.
|
||||
// This bug has been in the main game until Java Edition Beta 1.8.
|
||||
if (Tile::tiles[itemID]->isCubeShaped() || pItemInstance->m_itemID == Tile::stoneSlabHalf->m_ID)
|
||||
scale = 0.25f;
|
||||
|
||||
glScalef(scale, scale, scale);
|
||||
|
||||
for (int i = 0; i < itemsToRender; i++)
|
||||
{
|
||||
glPushMatrix();
|
||||
if (i != 0)
|
||||
{
|
||||
glTranslatef(
|
||||
0.2f * (m_random.nextFloat() * 2.0f - 1.0f) / scale,
|
||||
0.2f * (m_random.nextFloat() * 2.0f - 1.0f) / scale,
|
||||
0.2f * (m_random.nextFloat() * 2.0f - 1.0f) / scale);
|
||||
}
|
||||
|
||||
#ifdef ENH_SHADE_HELD_TILES
|
||||
# define PARM_HACK , pItemEntity->getBrightness(1.0f)
|
||||
#else
|
||||
# define PARM_HACK
|
||||
#endif
|
||||
tileRenderer->renderTile(Tile::tiles[itemID], pItemInstance->m_auxValue PARM_HACK);
|
||||
#undef PARM_HACK
|
||||
glPopMatrix();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
glScalef(0.5f, 0.5f, 0.5f);
|
||||
int icon = pItemInstance->getIcon();
|
||||
|
||||
bindTexture(pItemInstance->m_itemID < C_MAX_TILES ? C_TERRAIN_NAME : C_ITEMS_NAME);
|
||||
|
||||
for (int i = 0; i < itemsToRender; i++)
|
||||
{
|
||||
glPushMatrix();
|
||||
if (i != 0)
|
||||
{
|
||||
glTranslatef(
|
||||
0.2f * (m_random.nextFloat() * 2.0f - 1.0f) * 0.3f,
|
||||
0.2f * (m_random.nextFloat() * 2.0f - 1.0f) * 0.3f,
|
||||
0.2f * (m_random.nextFloat() * 2.0f - 1.0f) * 0.3f);
|
||||
}
|
||||
|
||||
glRotatef(180.0f - m_pDispatcher->m_yaw, 0.0f, 1.0f, 0.0f);
|
||||
|
||||
Tesselator& t = Tesselator::instance;
|
||||
t.begin();
|
||||
|
||||
#ifdef ENH_SHADE_HELD_TILES
|
||||
float bright = pItemEntity->getBrightness(1.0f);
|
||||
t.color(bright, bright, bright);
|
||||
#endif
|
||||
t.vertexUV(-0.5f, -0.25f, 0.0f, float(16 * (icon % 16)) / 256.0f, float(16 * (icon / 16 + 1)) / 256.0f);
|
||||
t.vertexUV(+0.5f, -0.25f, 0.0f, float(16 * (icon % 16 + 1)) / 256.0f, float(16 * (icon / 16 + 1)) / 256.0f);
|
||||
t.vertexUV(+0.5f, +0.75f, 0.0f, float(16 * (icon % 16 + 1)) / 256.0f, float(16 * (icon / 16)) / 256.0f);
|
||||
t.vertexUV(-0.5f, +0.75f, 0.0f, float(16 * (icon % 16)) / 256.0f, float(16 * (icon / 16)) / 256.0f);
|
||||
|
||||
t.draw();
|
||||
|
||||
glPopMatrix();
|
||||
}
|
||||
}
|
||||
|
||||
glDisable(GL_RESCALE_NORMAL);
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
void ItemRenderer::blitRect(Tesselator& t, int x, int y, int w, int h, int color)
|
||||
{
|
||||
t.begin();
|
||||
t.color(color);
|
||||
t.vertex(float(x), float(y), 0.0f);
|
||||
t.vertex(float(x), float(y + h), 0.0f);
|
||||
t.vertex(float(x + w), float(y + h), 0.0f);
|
||||
t.vertex(float(x + w), float(y), 0.0f);
|
||||
t.draw();
|
||||
}
|
||||
|
||||
void ItemRenderer::blit(int dx, int dy, int sx, int sy, int tw, int th)
|
||||
{
|
||||
auto& t = Tesselator::instance;
|
||||
|
||||
float ex = float(dx), ey = float(dy);
|
||||
float uw = float(tw), uh = float(th);
|
||||
float vx = float(sx), vy = float(sy);
|
||||
|
||||
t.begin();
|
||||
t.vertexUV(ex, ey + uh, 0.0f, float(vx) / 256.0f, float(vy + uh) / 256.0f);
|
||||
t.vertexUV(ex + uw, ey + uh, 0.0f, float(vx + uw) / 256.0f, float(vy + uh) / 256.0f);
|
||||
t.vertexUV(ex + uw, ey, 0.0f, float(vx + uw) / 256.0f, float(vy) / 256.0f);
|
||||
t.vertexUV(ex, ey, 0.0f, float(vx) / 256.0f, float(vy) / 256.0f);
|
||||
t.draw();
|
||||
}
|
||||
|
||||
void ItemRenderer::renderGuiItemOverlay(Font* font, Textures* textures, ItemInstance* instance, int x, int y)
|
||||
{
|
||||
if (!instance)
|
||||
return;
|
||||
|
||||
if (instance->m_amount == 1)
|
||||
return;
|
||||
|
||||
std::stringstream ss;
|
||||
ss << instance->m_amount;
|
||||
std::string amtstr = ss.str();
|
||||
|
||||
int width = font->width(amtstr), height = font->height(amtstr) + 8;
|
||||
|
||||
font->drawShadow(amtstr, x + 17 - width, y + 17 - height, 0xFFFFFF);
|
||||
}
|
||||
|
||||
void ItemRenderer::renderGuiItem(Font* font, Textures* textures, ItemInstance* instance, int x, int y, bool b)
|
||||
{
|
||||
// @NOTE: Font unused but would presumably be used to draw the item amount.
|
||||
// As if that actually works due to us blocking t.begin() and t.draw() calls...
|
||||
if (!instance)
|
||||
return;
|
||||
|
||||
int itemID = instance->m_itemID;
|
||||
if (!b)
|
||||
return;
|
||||
|
||||
// @BUG: This is one of the reasons you can't actually hold items in early Minecraft.
|
||||
// There's an attempt to index `Tile::tiles` out of bounds, which of course fails, and likely crashes the game. :(
|
||||
// If only they'd placed the g_ItemFrames[itemID] check before the TileRenderer::canRender check...
|
||||
#ifdef ORIGINAL_CODE
|
||||
#define COND_PRE
|
||||
#else
|
||||
#define COND_PRE (0 <= itemID && itemID < C_MAX_TILES) &&
|
||||
#endif
|
||||
|
||||
bool bCanRenderAsIs = false;
|
||||
|
||||
#ifdef ENH_3D_INVENTORY_TILES
|
||||
// We don't need to care about g_ItemFrames at all since blocks will get 3D rendered and 2D props will use the terrain.png as the texture.
|
||||
if (COND_PRE(TileRenderer::canRender(Tile::tiles[itemID]->getRenderShape())))
|
||||
{
|
||||
bCanRenderAsIs = true;
|
||||
}
|
||||
#else
|
||||
if (COND_PRE(TileRenderer::canRender(Tile::tiles[itemID]->getRenderShape()) || g_ItemFrames[itemID] != 0))
|
||||
{
|
||||
bCanRenderAsIs = true;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (itemID < C_MAX_TILES && bCanRenderAsIs)
|
||||
{
|
||||
#ifndef ENH_3D_INVENTORY_TILES
|
||||
textures->loadAndBindTexture(C_BLOCKS_NAME);
|
||||
|
||||
float texU = float(g_ItemFrames[instance->m_itemID] % 10) * 48.0f;
|
||||
float texV = float(g_ItemFrames[instance->m_itemID] / 10) * 48.0f;
|
||||
|
||||
Tesselator& t = Tesselator::instance;
|
||||
// @NOTE: These do nothing, due to a previous t.voidBeginAndEndCalls call.
|
||||
t.begin();
|
||||
t.vertexUV(float(x + 0), float(y + 16), 0.0f, texU / 512.0f, (texV + 48.0f) / 512.0f);
|
||||
t.vertexUV(float(x + 16), float(y + 16), 0.0f, (texU + 48.0f) / 512.0f, (texV + 48.0f) / 512.0f);
|
||||
t.vertexUV(float(x + 16), float(y + 0), 0.0f, (texU + 48.0f) / 512.0f, texV / 512.0f);
|
||||
t.vertexUV(float(x + 0), float(y + 0), 0.0f, texU / 512.0f, texV / 512.0f);
|
||||
t.draw();
|
||||
#else
|
||||
textures->loadAndBindTexture(C_TERRAIN_NAME);
|
||||
|
||||
//glDisable(GL_BLEND);
|
||||
//glEnable(GL_DEPTH_TEST);
|
||||
|
||||
glPushMatrix();
|
||||
|
||||
// scale, rotate, and translate the tile onto the correct screen coordinate
|
||||
glTranslatef((GLfloat)x + 8, (GLfloat)y + 8, -8);
|
||||
glScalef(10, 10, 10);
|
||||
glRotatef(210.0f, 1.0f, 0.0f, 0.0f);
|
||||
glRotatef(45.0f, 0.0f, 1.0f, 0.0f);
|
||||
|
||||
#ifdef ENH_SHADE_HELD_TILES
|
||||
# define PARM_HACK , 1
|
||||
#else
|
||||
# define PARM_HACK
|
||||
#endif
|
||||
tileRenderer->renderTile(Tile::tiles[itemID], instance->m_auxValue PARM_HACK);
|
||||
#undef PARM_HACK
|
||||
|
||||
glPopMatrix();
|
||||
|
||||
//glDisable(GL_DEPTH_TEST);
|
||||
//glEnable(GL_BLEND);
|
||||
#endif
|
||||
}
|
||||
else if (instance->getIcon() >= 0)
|
||||
{
|
||||
// @BUG: The last bound texture will be the texture that ALL items will take. This is because begin and end calls
|
||||
// have been void'ed by a t.voidBeginAndEndCalls call in Gui::render.
|
||||
if (instance->m_itemID <= 255)
|
||||
textures->loadAndBindTexture(C_TERRAIN_NAME);
|
||||
else
|
||||
textures->loadAndBindTexture(C_ITEMS_NAME);
|
||||
|
||||
blit(x, y, 16 * (instance->getIcon() % 16), 16 * (instance->getIcon() / 16), 16, 16);
|
||||
}
|
||||
}
|
||||
31
source/client/renderer/entity/ItemRenderer.hpp
Normal file
31
source/client/renderer/entity/ItemRenderer.hpp
Normal file
@@ -0,0 +1,31 @@
|
||||
/********************************************************************
|
||||
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
|
||||
********************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "EntityRenderer.hpp"
|
||||
#include "ItemInstance.hpp"
|
||||
#include "TileRenderer.hpp"
|
||||
|
||||
class ItemRenderer : public EntityRenderer
|
||||
{
|
||||
public:
|
||||
ItemRenderer();
|
||||
|
||||
void render(Entity*, float, float, float, float, float) override;
|
||||
void blitRect(Tesselator&, int, int, int, int, int);
|
||||
|
||||
static void blit(int, int, int, int, int, int);
|
||||
static void renderGuiItem(Font*, Textures*, ItemInstance*, int, int, bool);
|
||||
static void renderGuiItemOverlay(Font*, Textures*, ItemInstance*, int, int);
|
||||
|
||||
public:
|
||||
Random m_random;
|
||||
static TileRenderer* tileRenderer;
|
||||
};
|
||||
|
||||
36
source/client/renderer/entity/ItemSpriteRenderer.cpp
Normal file
36
source/client/renderer/entity/ItemSpriteRenderer.cpp
Normal file
@@ -0,0 +1,36 @@
|
||||
#include "ItemSpriteRenderer.hpp"
|
||||
#include "EntityRenderDispatcher.hpp"
|
||||
|
||||
ItemSpriteRenderer::ItemSpriteRenderer(int sprite)
|
||||
{
|
||||
m_sprite = sprite;
|
||||
}
|
||||
|
||||
void ItemSpriteRenderer::render(Entity* pEntity, float x, float y, float z, float a, float b)
|
||||
{
|
||||
glPushMatrix();
|
||||
glTranslatef(x, y, z);
|
||||
glEnable(GL_RESCALE_NORMAL);
|
||||
glScalef(0.5f, 0.5f, 0.5f);
|
||||
bindTexture(C_ITEMS_NAME);
|
||||
|
||||
float texU_1 = float(16 * (m_sprite % 16)) / 256.0f;
|
||||
float texU_2 = float(16 * (m_sprite % 16 + 1)) / 256.0f;
|
||||
float texV_1 = float(16 * (m_sprite / 16)) / 256.0f;
|
||||
float texV_2 = float(16 * (m_sprite / 16 + 1)) / 256.0f;
|
||||
|
||||
glRotatef(180.0f - m_pDispatcher->m_yaw, 0.0f, 1.0f, 0.0f);
|
||||
glRotatef(-m_pDispatcher->m_pitch, 1.0f, 0.0f, 0.0f);
|
||||
|
||||
Tesselator& t = Tesselator::instance;
|
||||
t.begin();
|
||||
t.color(1.0f, 1.0f, 1.0f);
|
||||
t.vertexUV(-0.5f, -0.25f, 0.0f, float(16 * (m_sprite % 16)) / 256.0f, float(16 * (m_sprite / 16 + 1)) / 256.0f);
|
||||
t.vertexUV(+0.5f, -0.25f, 0.0f, float(16 * (m_sprite % 16 + 1)) / 256.0f, float(16 * (m_sprite / 16 + 1)) / 256.0f);
|
||||
t.vertexUV(+0.5f, +0.75f, 0.0f, float(16 * (m_sprite % 16 + 1)) / 256.0f, float(16 * (m_sprite / 16)) / 256.0f);
|
||||
t.vertexUV(-0.5f, +0.75f, 0.0f, float(16 * (m_sprite % 16)) / 256.0f, float(16 * (m_sprite / 16)) / 256.0f);
|
||||
t.draw();
|
||||
|
||||
glDisable(GL_RESCALE_NORMAL);
|
||||
glPopMatrix();
|
||||
}
|
||||
14
source/client/renderer/entity/ItemSpriteRenderer.hpp
Normal file
14
source/client/renderer/entity/ItemSpriteRenderer.hpp
Normal file
@@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#include "EntityRenderer.hpp"
|
||||
|
||||
class ItemSpriteRenderer : public EntityRenderer
|
||||
{
|
||||
public:
|
||||
ItemSpriteRenderer(int sprite);
|
||||
void render(Entity*, float x, float y, float z, float a, float b) override;
|
||||
|
||||
public:
|
||||
int m_sprite;
|
||||
};
|
||||
|
||||
189
source/client/renderer/entity/MobRenderer.cpp
Normal file
189
source/client/renderer/entity/MobRenderer.cpp
Normal file
@@ -0,0 +1,189 @@
|
||||
/********************************************************************
|
||||
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"
|
||||
|
||||
MobRenderer::MobRenderer(Model* pModel, float f)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
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->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.0625f);
|
||||
}
|
||||
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.0625f);
|
||||
}
|
||||
|
||||
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*, float, float, float)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
36
source/client/renderer/entity/MobRenderer.hpp
Normal file
36
source/client/renderer/entity/MobRenderer.hpp
Normal file
@@ -0,0 +1,36 @@
|
||||
/********************************************************************
|
||||
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
|
||||
********************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "EntityRenderer.hpp"
|
||||
|
||||
class MobRenderer : public EntityRenderer
|
||||
{
|
||||
public:
|
||||
MobRenderer(Model*, float);
|
||||
void setArmor(Model*);
|
||||
|
||||
virtual void render(Entity*, float, float, float, float, float) override;
|
||||
virtual int prepareArmor(Mob*, int, float);
|
||||
virtual void setupPosition(Entity*, float, float, float);
|
||||
virtual void setupRotations(Entity*, float, float, float);
|
||||
virtual float getAttackAnim(Mob*, float);
|
||||
virtual float getBob(Mob*, float);
|
||||
virtual float getFlipDegrees(Mob*);
|
||||
virtual int getOverlayColor(Mob*, float, float);
|
||||
virtual void scale(Mob*, float);
|
||||
virtual void renderName(Mob*, float, float, float);
|
||||
virtual void renderNameTag(Mob*, const std::string&, float, float, float, int);
|
||||
virtual void additionalRendering(Mob*, float);
|
||||
|
||||
public:
|
||||
Model* m_pModel;
|
||||
Model* m_pArmorModel = nullptr;
|
||||
};
|
||||
|
||||
69
source/client/renderer/entity/TntRenderer.cpp
Normal file
69
source/client/renderer/entity/TntRenderer.cpp
Normal file
@@ -0,0 +1,69 @@
|
||||
/********************************************************************
|
||||
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 "TntRenderer.hpp"
|
||||
#include "PrimedTnt.hpp"
|
||||
|
||||
TntRenderer::TntRenderer()
|
||||
{
|
||||
field_4 = 0.5f;
|
||||
}
|
||||
|
||||
void TntRenderer::render(Entity* entity, float x, float y, float z, float a6, float a7)
|
||||
{
|
||||
PrimedTnt* tnt = (PrimedTnt*)entity;
|
||||
|
||||
glPushMatrix();
|
||||
glTranslatef(x, y, z);
|
||||
|
||||
float m = 1.0f + float(tnt->m_fuseTimer) - a7;
|
||||
if (m < 10.0f)
|
||||
{
|
||||
float n = (m / -10.0f) + 1.0f;
|
||||
if (n < 0.0f)
|
||||
n = 0.0f;
|
||||
if (n > 1.0f)
|
||||
n = 1.0f;
|
||||
|
||||
float scale = 1.0f + 0.3f * n * n * n * n;
|
||||
glScalef(scale, scale, scale);
|
||||
}
|
||||
|
||||
bindTexture(C_TERRAIN_NAME);
|
||||
|
||||
// @NOTE: Useless assignment. Already being done by the renderTile function
|
||||
Tesselator::instance.color(1.0f, 1.0f, 1.0f);
|
||||
|
||||
// Render the base
|
||||
#ifdef ENH_SHADE_HELD_TILES
|
||||
#define ARGPATCH , 1.0f
|
||||
#else
|
||||
#define ARGPATCH
|
||||
#endif
|
||||
|
||||
m_tileRenderer.renderTile(Tile::tnt, 0 ARGPATCH);
|
||||
|
||||
// @NOTE: Converting to a uint8 for whatever reason
|
||||
if (((uint8_t(tnt->m_fuseTimer) / 5) & 1) == 0)
|
||||
{
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_DST_ALPHA);
|
||||
glColor4f(1.0f, 1.0f, 1.0f, (((float(tnt->m_fuseTimer) - a7) + 1.0f) / -100.0f + 1.0f) * 0.8f);
|
||||
m_tileRenderer.renderTile(Tile::tnt, 0 ARGPATCH);
|
||||
glColor4f(1.0f, 1.0, 1.0f, 1.0f);
|
||||
glDisable(GL_BLEND);
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
}
|
||||
|
||||
glPopMatrix();
|
||||
|
||||
#ifdef ARGPATCH
|
||||
#undef ARGPATCH
|
||||
#endif
|
||||
}
|
||||
24
source/client/renderer/entity/TntRenderer.hpp
Normal file
24
source/client/renderer/entity/TntRenderer.hpp
Normal file
@@ -0,0 +1,24 @@
|
||||
/********************************************************************
|
||||
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
|
||||
********************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "EntityRenderer.hpp"
|
||||
#include "TileRenderer.hpp"
|
||||
|
||||
class TntRenderer : public EntityRenderer
|
||||
{
|
||||
public:
|
||||
TntRenderer();
|
||||
|
||||
void render(Entity*, float, float, float, float, float) override;
|
||||
|
||||
public:
|
||||
TileRenderer m_tileRenderer;
|
||||
};
|
||||
|
||||
70
source/client/renderer/entity/TripodCameraRenderer.cpp
Normal file
70
source/client/renderer/entity/TripodCameraRenderer.cpp
Normal file
@@ -0,0 +1,70 @@
|
||||
/********************************************************************
|
||||
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 "TripodCameraRenderer.hpp"
|
||||
#include "Minecraft.hpp"
|
||||
|
||||
TripodCameraRenderer::TripodCameraRenderer() :
|
||||
m_tile(0, 243, Material::plant),
|
||||
m_cube(0, 0)
|
||||
{
|
||||
m_cube.addBox(-4.0f, -4.0f, -6.0f, 8, 8, 10);
|
||||
m_cube.m_posY = 11.0f;
|
||||
field_4 = 0.5f;
|
||||
}
|
||||
|
||||
float TripodCameraRenderer::getFlashTime(TripodCamera* camera, float f)
|
||||
{
|
||||
if (camera->field_B90 > 7 || camera->field_B90 < 0)
|
||||
return -1.0f;
|
||||
|
||||
return 0.125f * (float(camera->field_B90) - f);
|
||||
}
|
||||
|
||||
void TripodCameraRenderer::render(Entity* entity, float x, float y, float z, float a, float b)
|
||||
{
|
||||
glPushMatrix();
|
||||
glTranslatef(x, y, z);
|
||||
m_cube.field_C = 0.017453f * (180.0f + 0.5f * entity->m_pitch);
|
||||
m_cube.field_10 = -0.017453f * entity->m_yaw;
|
||||
|
||||
Tesselator& t = Tesselator::instance;
|
||||
t.color(1.0f, 1.0f, 1.0f);
|
||||
|
||||
bindTexture("gui/items.png");
|
||||
t.begin();
|
||||
m_renderer.tesselateCrossTexture(&m_tile, 0, -0.5f, -0.5f, -0.5f);
|
||||
t.draw();
|
||||
|
||||
bindTexture("item/camera.png");
|
||||
m_cube.render(0.0625f);
|
||||
|
||||
Entity* pHREntity = m_pDispatcher->m_pMinecraft->m_hitResult.m_pEnt;
|
||||
|
||||
float time = getFlashTime((TripodCamera*)entity, b);
|
||||
if (time >= 0.0f)
|
||||
{
|
||||
glColor4f(1.0f, 1.0f, 1.0f, sinf(float(M_PI) * 2.0f * time));
|
||||
glColor4f(1.0f, 1.0f, 1.0f, 1.0f); // @BUG: overwriting the sinf result with 1.0f
|
||||
}
|
||||
|
||||
if (entity == pHREntity)
|
||||
{
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
// @TODO FIX: With ENH_ENTITY_SHADING on, the cube is fully opaque.
|
||||
glColor4f(0.5f, 0.5f, 0.5f, 0.5f);
|
||||
m_cube.renderHorrible(0.0625f);
|
||||
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
glDisable(GL_BLEND);
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
}
|
||||
|
||||
glPopMatrix();
|
||||
}
|
||||
30
source/client/renderer/entity/TripodCameraRenderer.hpp
Normal file
30
source/client/renderer/entity/TripodCameraRenderer.hpp
Normal file
@@ -0,0 +1,30 @@
|
||||
/********************************************************************
|
||||
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
|
||||
********************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "EntityRenderer.hpp"
|
||||
#include "Tile.hpp"
|
||||
#include "TileRenderer.hpp"
|
||||
#include "TripodCamera.hpp"
|
||||
|
||||
class TripodCameraRenderer : public EntityRenderer
|
||||
{
|
||||
public:
|
||||
TripodCameraRenderer();
|
||||
|
||||
void render(Entity*, float, float, float, float, float) override;
|
||||
|
||||
static float getFlashTime(TripodCamera*, float f);
|
||||
|
||||
public:
|
||||
TileRenderer m_renderer;
|
||||
Tile m_tile;
|
||||
Cube m_cube;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user