aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gregtech/common/render/GT_CapeRenderer.java
blob: 274a914b67296ef3afedbee11da36f01ed9fca48 (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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
package gregtech.common.render;

import java.util.Collection;

import net.minecraft.client.entity.AbstractClientPlayer;
import net.minecraft.client.model.ModelBiped;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.client.renderer.entity.RenderPlayer;
import net.minecraft.potion.Potion;
import net.minecraft.util.MathHelper;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.event.RenderPlayerEvent;

import org.lwjgl.opengl.GL11;

import gregtech.api.enums.GT_Values;
import gregtech.api.util.GT_Log;
import gregtech.api.util.GT_Utility;

public class GT_CapeRenderer extends RenderPlayer {

    private final ResourceLocation[] mCapes = { new ResourceLocation("gregtech:textures/BrainTechCape.png"),
            new ResourceLocation("gregtech:textures/GregTechCape.png"),
            new ResourceLocation("gregtech:textures/MrBrainCape.png"),
            new ResourceLocation("gregtech:textures/GregoriusCape.png"),
            new ResourceLocation("gregtech:textures/DonorCape.png"),
            new ResourceLocation("gregtech:textures/DevCape.png"), new ResourceLocation("gregtech:textures/Steam.png"),
            new ResourceLocation("gregtech:textures/Titanium.png"),
            new ResourceLocation("gregtech:textures/Neutronium.png"),
            new ResourceLocation("gregtech:textures/Stargate.png") };
    private final Collection<String> mCapeList;

    public GT_CapeRenderer(Collection<String> aCapeList) {
        this.mCapeList = aCapeList;
        setRenderManager(RenderManager.instance);
    }

    public void receiveRenderSpecialsEvent(RenderPlayerEvent.Specials.Pre aEvent) {
        AbstractClientPlayer aPlayer = (AbstractClientPlayer) aEvent.entityPlayer;
        if (GT_Utility.getFullInvisibility(aPlayer)) {
            aEvent.setCanceled(true);
            return;
        }
        float aPartialTicks = aEvent.partialRenderTick;
        if (aPlayer.isInvisible()) {
            return;
        }
        if (GT_Utility.getPotion(aPlayer, Potion.invisibility.id)) {
            return;
        }
        try {
            ResourceLocation tResource = aPlayer.getLocationCape();
            if (aPlayer.getDisplayName().equalsIgnoreCase("Friedi4321")) {
                tResource = this.mCapes[0];
            }
            if (this.mCapeList.contains(aPlayer.getDisplayName().toLowerCase())) {
                tResource = this.mCapes[1];
            }
            if (aPlayer.getDisplayName().equalsIgnoreCase("Mr_Brain")) {
                tResource = this.mCapes[2];
            }
            if (aPlayer.getDisplayName().equalsIgnoreCase("GregoriusT")) {
                tResource = this.mCapes[3];
            }
            if (this.mCapeList.contains(aPlayer.getDisplayName().toLowerCase() + ":capedonor")) {
                tResource = this.mCapes[4];
            }
            if (this.mCapeList.contains(aPlayer.getDisplayName().toLowerCase() + ":capedev")) {
                tResource = this.mCapes[5];
            }
            if (this.mCapeList.contains(aPlayer.getDisplayName().toLowerCase() + ":cape_steam")) {
                tResource = this.mCapes[6];
            }
            if (this.mCapeList.contains(aPlayer.getDisplayName().toLowerCase() + ":cape_titanium")) {
                tResource = this.mCapes[7];
            }
            if (this.mCapeList.contains(aPlayer.getDisplayName().toLowerCase() + ":cape_neutronium")) {
                tResource = this.mCapes[8];
            }
            if (this.mCapeList.contains(aPlayer.getDisplayName().toLowerCase() + ":cape_stargate")) {
                tResource = this.mCapes[9];
            }

            if ((tResource != null) && (!aPlayer.getHideCape())) {
                bindTexture(tResource);
                GL11.glPushMatrix();
                GL11.glTranslatef(0.0F, 0.0F, 0.125F);
                double d0 = aPlayer.field_71091_bM + (aPlayer.field_71094_bP - aPlayer.field_71091_bM) * aPartialTicks
                        - (aPlayer.prevPosX + (aPlayer.posX - aPlayer.prevPosX) * aPartialTicks);
                double d1 = aPlayer.field_71096_bN + (aPlayer.field_71095_bQ - aPlayer.field_71096_bN) * aPartialTicks
                        - (aPlayer.prevPosY + (aPlayer.posY - aPlayer.prevPosY) * aPartialTicks);
                double d2 = aPlayer.field_71097_bO + (aPlayer.field_71085_bR - aPlayer.field_71097_bO) * aPartialTicks
                        - (aPlayer.prevPosZ + (aPlayer.posZ - aPlayer.prevPosZ) * aPartialTicks);
                float f6 = aPlayer.prevRenderYawOffset
                        + (aPlayer.renderYawOffset - aPlayer.prevRenderYawOffset) * aPartialTicks;
                double d3 = MathHelper.sin(f6 * (float) Math.PI / 180.0F);
                double d4 = -MathHelper.cos(f6 * (float) Math.PI / 180.0F);
                float f7 = (float) d1 * 10.0F;
                float f8 = (float) (d0 * d3 + d2 * d4) * 100.0F;
                float f9 = (float) (d0 * d4 - d2 * d3) * 100.0F;
                if (f7 < -6.0F) {
                    f7 = -6.0F;
                }
                if (f7 > 32.0F) {
                    f7 = 32.0F;
                }
                if (f8 < 0.0F) {
                    f8 = 0.0F;
                }
                float f10 = aPlayer.prevCameraYaw + (aPlayer.cameraYaw - aPlayer.prevCameraYaw) * aPartialTicks;
                f7 += MathHelper.sin(
                        (aPlayer.prevDistanceWalkedModified
                                + (aPlayer.distanceWalkedModified - aPlayer.prevDistanceWalkedModified) * aPartialTicks)
                                * 6.0F)
                        * 32.0F
                        * f10;
                if (aPlayer.isSneaking()) {
                    f7 += 25.0F;
                }
                GL11.glRotatef(6.0F + f8 / 2.0F + f7, 1.0F, 0.0F, 0.0F);
                GL11.glRotatef(f9 / 2.0F, 0.0F, 0.0F, 1.0F);
                GL11.glRotatef(-f9 / 2.0F, 0.0F, 1.0F, 0.0F);
                GL11.glRotatef(180.0F, 0.0F, 1.0F, 0.0F);
                ((ModelBiped) this.mainModel).renderCloak(0.0625F);
                GL11.glPopMatrix();
            }
        } catch (Throwable e) {
            if (GT_Values.D1) {
                e.printStackTrace(GT_Log.err);
            }
        }
    }
}