aboutsummaryrefslogtreecommitdiff
path: root/Minecraft.Client/WitherBossRenderer.cpp
blob: 254a00bc783bdfd01e517d52d673543e4486bb88 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#include "stdafx.h"
#include "WitherBossRenderer.h"
#include "WitherBossModel.h"
#include "MobRenderer.h"
#include "../Minecraft.World/WitherBoss.h"
#include "../Minecraft.Client/BossMobGuiInfo.h"

ResourceLocation WitherBossRenderer::WITHER_ARMOR_LOCATION = ResourceLocation(TN_MOB_WITHER_ARMOR);
ResourceLocation WitherBossRenderer::WITHER_INVULERABLE_LOCATION = ResourceLocation(TN_MOB_WITHER_INVULNERABLE);
ResourceLocation WitherBossRenderer::WITHER_LOCATION = ResourceLocation(TN_MOB_WITHER);


WitherBossRenderer::WitherBossRenderer() : MobRenderer(new WitherBossModel(), 1.0f)
{
	modelVersion = dynamic_cast<WitherBossModel*>(model)->modelVersion();
}

void WitherBossRenderer::render(shared_ptr<Entity> entity, double x, double y, double z, float rot, float a)
{
	shared_ptr<WitherBoss> mob = dynamic_pointer_cast<WitherBoss>(entity);

	BossMobGuiInfo::setBossHealth(mob, true);

	int modelVersion = dynamic_cast<WitherBossModel*>(model)->modelVersion();
	if (modelVersion != this->modelVersion)
	{
		this->modelVersion = modelVersion;
		model = new WitherBossModel();
	}
	MobRenderer::render(entity, x, y, z, rot, a);
}

ResourceLocation *WitherBossRenderer::getTextureLocation(shared_ptr<Entity> entity)
{
	shared_ptr<WitherBoss> mob = dynamic_pointer_cast<WitherBoss>(entity);

	int invulnerableTicks = mob->getInvulnerableTicks();
	if (invulnerableTicks <= 0 || ( (invulnerableTicks <= (SharedConstants::TICKS_PER_SECOND * 4)) && (invulnerableTicks / 5) % 2 == 1) )
	{
		return &WITHER_LOCATION;
	}
	return &WITHER_INVULERABLE_LOCATION;
}

void WitherBossRenderer::scale(shared_ptr<LivingEntity> _mob, float a)
{
	shared_ptr<WitherBoss> mob = dynamic_pointer_cast<WitherBoss>(_mob);
	int inTicks = mob->getInvulnerableTicks();
	if (inTicks > 0)
	{
		float scale = 2.0f - (((float) inTicks - a) / (SharedConstants::TICKS_PER_SECOND * 11)) * .5f;
		glScalef(scale, scale, scale);
	}
	else
	{
		glScalef(2, 2, 2);
	}
}

int WitherBossRenderer::prepareArmor(shared_ptr<LivingEntity> entity, int layer, float a)
{
	shared_ptr<WitherBoss> mob = dynamic_pointer_cast<WitherBoss>(entity);

	if (mob->isPowered())
	{
		if (mob->isInvisible())
		{
			glDepthMask(false);
		}
		else
		{
			glDepthMask(true);
		}

		if (layer == 1)
		{
			float time = mob->tickCount + a;
			bindTexture(&WITHER_ARMOR_LOCATION);
			glMatrixMode(GL_TEXTURE);
			glLoadIdentity();
			float uo = cos(time * 0.02f) * 3;
			float vo = time * 0.01f;
			glTranslatef(uo, vo, 0);
			setArmor(model);
			glMatrixMode(GL_MODELVIEW);
			glEnable(GL_BLEND);
			float br = 0.5f;
			glColor4f(br, br, br, 1);
			glDisable(GL_LIGHTING);
			glBlendFunc(GL_ONE, GL_ONE);
			glTranslatef(0, -.01f, 0);
			glScalef(1.1f, 1.1f, 1.1f);
			return 1;
		}
		if (layer == 2)
		{
			glMatrixMode(GL_TEXTURE);
			glLoadIdentity();
			glMatrixMode(GL_MODELVIEW);
			glEnable(GL_LIGHTING);
			glDisable(GL_BLEND);
		}
	}
	return -1;
}

int WitherBossRenderer::prepareArmorOverlay(shared_ptr<LivingEntity> entity, int layer, float a)
{
	return -1;
}