Files
neoLegacy/Minecraft.Client/BoatRenderer.cpp
T

72 lines
2.2 KiB
C++

#include "stdafx.h"
#include "BoatRenderer.h"
#include "BoatModel.h"
#include "../Minecraft.World/net.minecraft.world.entity.item.h"
#include "../Minecraft.World/Mth.h"
ResourceLocation BoatRenderer::BOAT_LOCATIONS[6] =
{
ResourceLocation(TN_ITEM_BOAT_OAK),
ResourceLocation(TN_ITEM_BOAT_SPRUCE),
ResourceLocation(TN_ITEM_BOAT_BIRCH),
ResourceLocation(TN_ITEM_BOAT_JUNGLE),
ResourceLocation(TN_ITEM_BOAT_ACACIA),
ResourceLocation(TN_ITEM_BOAT_DARKOAK),
};
bool BoatRenderer::s_secondPass = false;
BoatRenderer::BoatRenderer() : EntityRenderer()
{
this->shadowRadius = 0.5f;
model = new BoatModel();
}
void BoatRenderer::render(shared_ptr<Entity> _boat, double x, double y, double z, float rot, float a)
{
// 4J - original version used generics and thus had an input parameter of type Boat rather than shared_ptr<Entity> we have here -
// do some casting around instead
shared_ptr<Boat> boat = dynamic_pointer_cast<Boat>(_boat);
const float hullOffset = 0.375f - boat->heightOffset;
if (s_secondPass)
{
glPushMatrix();
glTranslatef(static_cast<float>(x), static_cast<float>(y) + hullOffset, static_cast<float>(z));
glRotatef(180-rot, 0, 1, 0);
glScalef(-1, -1, 1);
static_cast<BoatModel *>(model)->renderWaterPatch(1 / 16.0f, true);
glPopMatrix();
return;
}
glPushMatrix();
glTranslatef(static_cast<float>(x), static_cast<float>(y) + hullOffset, static_cast<float>(z));
glRotatef(180-rot, 0, 1, 0);
float hurt = boat->getHurtTime() - a;
float dmg = boat->getDamage() - a;
if (dmg<0) dmg = 0;
if (hurt>0)
{
glRotatef(Mth::sin(hurt)*hurt*dmg/10*boat->getHurtDir(), 1, 0, 0);
}
bindTexture(boat);
glScalef(-1, -1, 1);
model->render(boat, a, 0, -0.1f, 0, 0, 1 / 16.0f, true);
glPopMatrix();
}
ResourceLocation *BoatRenderer::getTextureLocation(shared_ptr<Entity> mob)
{
shared_ptr<Boat> boat = dynamic_pointer_cast<Boat>(mob);
return &BOAT_LOCATIONS[boat != nullptr ? boat->getType() : 0];
}
void BoatRenderer::postRender(shared_ptr<Entity> entity, double x, double y, double z, float rot, float a, bool bRenderPlayerShadow)
{
if (s_secondPass) return;
EntityRenderer::postRender(entity, x, y, z, rot, a, bRenderPlayerShadow);
}