aboutsummaryrefslogtreecommitdiff
path: root/Minecraft.Client/HorseRenderer.cpp
blob: 5bbf76616097343131fc0842c41b562ba73872c6 (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
#include "stdafx.h"
#include "HorseRenderer.h"
#include "MobRenderer.h"
#include "EntityRenderDispatcher.h"
#include "..\Minecraft.World\net.minecraft.world.entity.animal.h"

ResourceLocation HorseRenderer::HORSE_LOCATION = ResourceLocation(TN_MOB_HORSE_WHITE);
ResourceLocation HorseRenderer::HORSE_MULE_LOCATION = ResourceLocation(TN_MOB_MULE);
ResourceLocation HorseRenderer::HORSE_DONKEY_LOCATION = ResourceLocation(TN_MOB_DONKEY);
ResourceLocation HorseRenderer::HORSE_ZOMBIE_LOCATION = ResourceLocation(TN_MOB_HORSE_ZOMBIE);
ResourceLocation HorseRenderer::HORSE_SKELETON_LOCATION = ResourceLocation(TN_MOB_HORSE_SKELETON);

std::map<wstring, ResourceLocation *> HorseRenderer::LAYERED_LOCATION_CACHE;

HorseRenderer::HorseRenderer(Model *model, float f) : MobRenderer(model, f)
{
}

void HorseRenderer::adjustHeight(shared_ptr<PathfinderMob> mob, float FHeight)
{
    glTranslatef(0.0F, FHeight, 0.0F);
}

void HorseRenderer::scale(shared_ptr<LivingEntity> entityliving, float f)
{
    float sizeFactor = 1.0f;

	int type = dynamic_pointer_cast<EntityHorse>(entityliving)->getType();
    if (type == EntityHorse::TYPE_DONKEY)
	{
        sizeFactor *= 0.87F;
    }
	else if (type == EntityHorse::TYPE_MULE)
	{
        sizeFactor *= 0.92F;
    }
    glScalef(sizeFactor, sizeFactor, sizeFactor);
    MobRenderer::scale(entityliving, f);
}

void HorseRenderer::renderModel(shared_ptr<LivingEntity> mob, float wp, float ws, float bob, float headRotMinusBodyRot, float headRotx, float scale)
{
    if (mob->isInvisible())
	{
        model->setupAnim(wp, ws, bob, headRotMinusBodyRot, headRotx, scale, mob);
    }
	else
	{
        EntityRenderer::bindTexture(mob);
        model->render(mob, wp, ws, bob, headRotMinusBodyRot, headRotx, scale, true);
		// Ensure that any extra layers of texturing are disabled after rendering this horse
		RenderManager.TextureBind(-1);
    }
}

void HorseRenderer::bindTexture(ResourceLocation *location)
{
	if (location->getTextureCount() > 1)
	{
		// Set up multiple texture layers for the horse
		entityRenderDispatcher->textures->bindTextureLayers(location);
	}
	else
	{
		EntityRenderer::bindTexture(location);
	}
}

ResourceLocation *HorseRenderer::getTextureLocation(shared_ptr<Entity> entity)
{
	shared_ptr<EntityHorse> horse = dynamic_pointer_cast<EntityHorse>(entity);

    if (!horse->hasLayeredTextures())
	{
        switch (horse->getType())
		{
		default:
		case EntityHorse::TYPE_HORSE:		return &HORSE_LOCATION;
		case EntityHorse::TYPE_MULE:		return &HORSE_MULE_LOCATION;
		case EntityHorse::TYPE_DONKEY:		return &HORSE_DONKEY_LOCATION;
		case EntityHorse::TYPE_UNDEAD:		return &HORSE_ZOMBIE_LOCATION;
		case EntityHorse::TYPE_SKELETON:	return &HORSE_SKELETON_LOCATION;
		}
    }

    return getOrCreateLayeredTextureLocation(horse);
}

ResourceLocation *HorseRenderer::getOrCreateLayeredTextureLocation(shared_ptr<EntityHorse> horse)
{
    wstring textureName = horse->getLayeredTextureHashName();

    auto it = LAYERED_LOCATION_CACHE.find(textureName);

    ResourceLocation *location;
	if (it != LAYERED_LOCATION_CACHE.end())
	{
		location = it->second;
	}
	else
	{
		LAYERED_LOCATION_CACHE[textureName] = new ResourceLocation(horse->getLayeredTextureLayers());

		it = LAYERED_LOCATION_CACHE.find(textureName);
		location = it->second;
	}

    return location;
}