aboutsummaryrefslogtreecommitdiff
path: root/Minecraft.Client/FishingHookRenderer.cpp
blob: d587ddb87e2c3123976031546c2ff085aa3191e4 (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
#include "stdafx.h"
#include "FishingHookRenderer.h"
#include "EntityRenderDispatcher.h"
#include "Options.h"
#include "..\Minecraft.World\net.minecraft.world.entity.projectile.h"
#include "..\Minecraft.World\net.minecraft.world.entity.player.h"
#include "..\Minecraft.World\Vec3.h"
#include "..\Minecraft.World\Mth.h"
#include "MultiPlayerLocalPlayer.h"

ResourceLocation FishingHookRenderer::PARTICLE_LOCATION = ResourceLocation(TN_PARTICLES);

void FishingHookRenderer::render(shared_ptr<Entity> _hook, double x, double y, double z, float rot, float a)
{
	// 4J - dynamic cast required because we aren't using templates/generics in our version
	shared_ptr<FishingHook> hook = dynamic_pointer_cast<FishingHook>(_hook);

    glPushMatrix();

    glTranslatef(static_cast<float>(x), static_cast<float>(y), static_cast<float>(z));
    glEnable(GL_RESCALE_NORMAL);
    glScalef(1 / 2.0f, 1 / 2.0f, 1 / 2.0f);
    int xi = 1;
    int yi = 2;
    bindTexture(hook);		// 4J was L"/particles.png"
    Tesselator *t = Tesselator::getInstance();

    float u0 = (xi * 8 + 0) / 128.0f;
    float u1 = (xi * 8 + 8) / 128.0f;
    float v0 = (yi * 8 + 0) / 128.0f;
    float v1 = (yi * 8 + 8) / 128.0f;


    float r = 1.0f;
    float xo = 0.5f;
    float yo = 0.5f;

    glRotatef(180 - entityRenderDispatcher->playerRotY, 0, 1, 0);
    glRotatef(-entityRenderDispatcher->playerRotX, 1, 0, 0);
    t->begin();
    t->normal(0, 1, 0);
    t->vertexUV((float)(0 - xo), (float)( 0 - yo), static_cast<float>(0), (float)( u0), (float)( v1));
    t->vertexUV((float)(r - xo), (float)( 0 - yo), static_cast<float>(0), (float)( u1), (float)( v1));
    t->vertexUV((float)(r - xo), (float)( 1 - yo), static_cast<float>(0), (float)( u1), (float)( v0));
    t->vertexUV((float)(0 - xo), (float)( 1 - yo), static_cast<float>(0), (float)( u0), (float)( v0));
    t->end();

    glDisable(GL_RESCALE_NORMAL);
    glPopMatrix();


    if (hook->owner != nullptr)
	{
        float swing = hook->owner->getAttackAnim(a);
        float swing2 = (float) Mth::sin(sqrt(swing) * PI);


        Vec3 *vv = Vec3::newTemp(-0.5, 0.03, 0.8);
        vv->xRot(-(hook->owner->xRotO + (hook->owner->xRot - hook->owner->xRotO) * a) * PI / 180);
        vv->yRot(-(hook->owner->yRotO + (hook->owner->yRot - hook->owner->yRotO) * a) * PI / 180);
        vv->yRot(swing2 * 0.5f);
        vv->xRot(-swing2 * 0.7f);

        double xp = hook->owner->xo + (hook->owner->x - hook->owner->xo) * a + vv->x;
        double yp = hook->owner->yo + (hook->owner->y - hook->owner->yo) * a + vv->y;
        double zp = hook->owner->zo + (hook->owner->z - hook->owner->zo) * a + vv->z;
		double yOffset = hook->owner == dynamic_pointer_cast<Player>(Minecraft::GetInstance()->player) ? 0 : hook->owner->getHeadHeight();

		// 4J-PB - changing this to be per player
		//if (this->entityRenderDispatcher->options->thirdPersonView)
		if (hook->owner->ThirdPersonView() > 0)
 		{
            float rr = (float) (hook->owner->yBodyRotO + (hook->owner->yBodyRot - hook->owner->yBodyRotO) * a) * PI / 180;
            double ss = Mth::sin((float) rr);
            double cc = Mth::cos((float) rr);
            xp = hook->owner->xo + (hook->owner->x - hook->owner->xo) * a - cc * 0.35 - ss * 0.85;
            yp = hook->owner->yo + yOffset + (hook->owner->y - hook->owner->yo) * a - 0.45;
            zp = hook->owner->zo + (hook->owner->z - hook->owner->zo) * a - ss * 0.35 + cc * 0.85;
        }

        double xh = hook->xo + (hook->x - hook->xo) * a;
        double yh = hook->yo + (hook->y - hook->yo) * a + 4 / 16.0f;
        double zh = hook->zo + (hook->z - hook->zo) * a;

        double xa = static_cast<float>(xp - xh);
        double ya = static_cast<float>(yp - yh);
        double za = static_cast<float>(zp - zh);

        glDisable(GL_TEXTURE_2D);
        glDisable(GL_LIGHTING);
        t->begin(GL_LINE_STRIP);
        t->color(0x000000);
        int steps = 16;
        for (int i = 0; i <= steps; i++)
		{
            float aa = i / static_cast<float>(steps);
            t->vertex(static_cast<float>(x + xa * aa), static_cast<float>(y + ya * (aa * aa + aa) * 0.5 + 4 / 16.0f), static_cast<float>(z + za * aa));
        }
        t->end();
        glEnable(GL_LIGHTING);
        glEnable(GL_TEXTURE_2D);
    }
}

ResourceLocation *FishingHookRenderer::getTextureLocation(shared_ptr<Entity> mob)
{
    return &PARTICLE_LOCATION;
}