aboutsummaryrefslogtreecommitdiff
path: root/utils/renderUtils.js
blob: 1c91b6a306d4709ce1d8eee7ad918492526fcab8 (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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
const GlStateManager = Java.type("net.minecraft.client.renderer.GlStateManager");
const GL11 = Java.type("org.lwjgl.opengl.GL11");

module.exports = {

    /* accepts parameters
     * h  Object = {h:x, s:y, v:z}
     * OR
     * h, s, v
    */
    HSVtoRGB:function (h, s, v) {
        var r, g, b, i, f, p, q, t;
        if (arguments.length === 1) {
            s = h.s, v = h.v, h = h.h;
        }
        i = Math.floor(h * 6);
        f = h * 6 - i;
        p = v * (1 - s);
        q = v * (1 - f * s);
        t = v * (1 - (1 - f) * s);
        switch (i % 6) {
            case 0: r = v, g = t, b = p; break;
            case 1: r = q, g = v, b = p; break;
            case 2: r = p, g = v, b = t; break;
            case 3: r = p, g = q, b = v; break;
            case 4: r = t, g = p, b = v; break;
            case 5: r = v, g = p, b = q; break;
        }
        return {
            r: r * 255,
            g: g * 255,
            b: b * 255
        };
    },
    drawLine:function (x, y, z, x2, y2, z2, r, g, b, thickness=1) {
    
        GL11.glBlendFunc(770, 771);
        GL11.glEnable(GL11.GL_BLEND);
        GL11.glLineWidth(thickness);
        GL11.glDisable(GL11.GL_TEXTURE_2D);
        GL11.glDisable(GL11.GL_DEPTH_TEST);
        GL11.glDepthMask(false);
        GlStateManager.func_179094_E();
    
        Tessellator.begin(3).colorize(r, g, b);
    
        Tessellator.pos(x, y, z).tex(0, 0);
        Tessellator.pos(x2, y2, z2).tex(0, 0);
    
        Tessellator.draw();
    
    
        GlStateManager.func_179121_F();
        GL11.glEnable(GL11.GL_TEXTURE_2D);
        GL11.glEnable(GL11.GL_DEPTH_TEST);
        GL11.glDepthMask(true);
        GL11.glDisable(GL11.GL_BLEND);
    },
    drawLineWithDepth:function (x, y, z, x2, y2, z2, r, g, b,t) {
    
        GL11.glBlendFunc(770, 771);
        GL11.glEnable(GL11.GL_BLEND);
        GL11.glLineWidth(t);
        GL11.glDisable(GL11.GL_TEXTURE_2D);
        GL11.glDepthMask(false);
        GlStateManager.func_179094_E();
    
        Tessellator.begin(3).colorize(r, g, b);
    
        Tessellator.pos(x, y, z).tex(0, 0);
        Tessellator.pos(x2, y2, z2).tex(0, 0);
    
        Tessellator.draw();
    
    
        GlStateManager.func_179121_F();
        GL11.glEnable(GL11.GL_TEXTURE_2D);
        GL11.glDepthMask(true);
        GL11.glDisable(GL11.GL_BLEND);
    },
    drawLineSmall:function (x, y, z, x2, y2, z2, r, g, b) {
    
        Tessellator.begin(3).colorize(r, g, b);
    
        Tessellator.pos(x, y, z).tex(0, 0);
        Tessellator.pos(x2, y2, z2).tex(0, 0);
    
        Tessellator.draw();
    },
    drawBoxAtBlockNotVisThruWalls:function (x, y, z, colorR, colorG, colorB){
        GL11.glBlendFunc(770, 771);
        GL11.glEnable(GL11.GL_BLEND);
        GL11.glLineWidth(3);
        GL11.glDisable(GL11.GL_TEXTURE_2D);
        GlStateManager.func_179094_E();
    
        x -= 0.005
        y -= 0.005
        z -= 0.005
        
        Tessellator.begin(3).colorize(colorR, colorG, colorB);
            
        Tessellator.pos(x+1.01,y+1.01,z+1.01).tex(0, 0);
        Tessellator.pos(x+1.01,y+1.01,z).tex(0, 0);
        Tessellator.pos(x,y+1.01,z).tex(0, 0);
        Tessellator.pos(x,y+1.01,z+1.01).tex(0, 0);
        Tessellator.pos(x+1.01,y+1.01,z+1.01).tex(0, 0);
        Tessellator.pos(x+1.01,y,z+1.01).tex(0, 0);
        Tessellator.pos(x+1.01,y,z).tex(0, 0);
        Tessellator.pos(x,y,z).tex(0, 0);
        Tessellator.pos(x,y,z+1.01).tex(0, 0);
        Tessellator.pos(x,y,z).tex(0, 0);
        Tessellator.pos(x,y+1.01,z).tex(0, 0);
        Tessellator.pos(x,y,z).tex(0, 0);
        Tessellator.pos(x+1.01,y,z).tex(0, 0);
        Tessellator.pos(x+1.01,y+1.01,z).tex(0, 0);
        Tessellator.pos(x+1.01,y,z).tex(0, 0);
        Tessellator.pos(x+1.01,y,z+1.01).tex(0, 0);
        Tessellator.pos(x,y,z+1.01).tex(0, 0);
        Tessellator.pos(x,y+1.01,z+1.01).tex(0, 0);
        Tessellator.pos(x+1.01,y+1.01,z+1.01).tex(0, 0);
    
        Tessellator.draw();
    
        GlStateManager.func_179121_F();
        GL11.glEnable(GL11.GL_TEXTURE_2D);
        GL11.glDisable(GL11.GL_BLEND);
    },
    drawBoxAtBlock:function (x, y, z, colorR, colorG, colorB){
    
        GL11.glBlendFunc(770, 771);
        GL11.glEnable(GL11.GL_BLEND);
        GL11.glLineWidth(3);
        GL11.glDisable(GL11.GL_TEXTURE_2D);
        GL11.glDisable(GL11.GL_DEPTH_TEST);
        GL11.glDepthMask(false);
        GlStateManager.func_179094_E();
    
        
        Tessellator.begin(3).colorize(colorR, colorG, colorB);
            
        Tessellator.pos(x+1,y+1,z+1).tex(0, 0);
        Tessellator.pos(x+1,y+1,z).tex(0, 0);
        Tessellator.pos(x,y+1,z).tex(0, 0);
        Tessellator.pos(x,y+1,z+1).tex(0, 0);
        Tessellator.pos(x+1,y+1,z+1).tex(0, 0);
        Tessellator.pos(x+1,y,z+1).tex(0, 0);
        Tessellator.pos(x+1,y,z).tex(0, 0);
        Tessellator.pos(x,y,z).tex(0, 0);
        Tessellator.pos(x,y,z+1).tex(0, 0);
        Tessellator.pos(x,y,z).tex(0, 0);
        Tessellator.pos(x,y+1,z).tex(0, 0);
        Tessellator.pos(x,y,z).tex(0, 0);
        Tessellator.pos(x+1,y,z).tex(0, 0);
        Tessellator.pos(x+1,y+1,z).tex(0, 0);
        Tessellator.pos(x+1,y,z).tex(0, 0);
        Tessellator.pos(x+1,y,z+1).tex(0, 0);
        Tessellator.pos(x,y,z+1).tex(0, 0);
        Tessellator.pos(x,y+1,z+1).tex(0, 0);
        Tessellator.pos(x+1,y+1,z+1).tex(0, 0);
    
        Tessellator.draw();
    
        GlStateManager.func_179121_F();
        GL11.glEnable(GL11.GL_TEXTURE_2D);
        GL11.glEnable(GL11.GL_DEPTH_TEST);
        GL11.glDepthMask(true);
        GL11.glDisable(GL11.GL_BLEND);
    },
    drawBoxAtEntity:function (entity, colorR, colorG, colorB, width, height, partialTicks, lineWidth=2, phase=false){
        let x = entity.getX() + ((entity.getX()-entity.getLastX())*partialTicks)
        let y = entity.getY() + ((entity.getY()-entity.getLastY())*partialTicks)
        let z = entity.getZ() + ((entity.getZ()-entity.getLastZ())*partialTicks)
        
        if(width === null){
            width = entity.getWidth()/2
            height = entity.getHeight()
        }else{
            width = width/2
        }
        
    
        GL11.glBlendFunc(770, 771);
        GL11.glEnable(GL11.GL_BLEND);
        GL11.glLineWidth(lineWidth);
        if(phase) GL11.glDisable(GL11.GL_DEPTH_TEST);
        GL11.glDisable(GL11.GL_TEXTURE_2D);
        GlStateManager.func_179094_E();
    
        
        Tessellator.begin(3).colorize(colorR, colorG, colorB);
            
        Tessellator.pos(x+width,y+height,z+width).tex(0, 0);
        Tessellator.pos(x+width,y+height,z-width).tex(0, 0);
        Tessellator.pos(x-width,y+height,z-width).tex(0, 0);
        Tessellator.pos(x-width,y+height,z+width).tex(0, 0);
        Tessellator.pos(x+width,y+height,z+width).tex(0, 0);
        Tessellator.pos(x+width,y,z+width).tex(0, 0);
        Tessellator.pos(x+width,y,z-width).tex(0, 0);
        Tessellator.pos(x-width,y,z-width).tex(0, 0);
        Tessellator.pos(x-width,y,z+width).tex(0, 0);
        Tessellator.pos(x-width,y,z-width).tex(0, 0);
        Tessellator.pos(x-width,y+height,z-width).tex(0, 0);
        Tessellator.pos(x-width,y,z-width).tex(0, 0);
        Tessellator.pos(x+width,y,z-width).tex(0, 0);
        Tessellator.pos(x+width,y+height,z-width).tex(0, 0);
        Tessellator.pos(x+width,y,z-width).tex(0, 0);
        Tessellator.pos(x+width,y,z+width).tex(0, 0);
        Tessellator.pos(x-width,y,z+width).tex(0, 0);
        Tessellator.pos(x-width,y+height,z+width).tex(0, 0);
        Tessellator.pos(x+width,y+height,z+width).tex(0, 0);
    
        Tessellator.draw();
    
        GlStateManager.func_179121_F();
        GL11.glEnable(GL11.GL_TEXTURE_2D);
        if(phase) GL11.glEnable(GL11.GL_DEPTH_TEST);
        GL11.glDisable(GL11.GL_BLEND);
    },
    drawFilledBox: function(x, y, z, w, h, red, green, blue, alpha, phase) { //FROM RENDERUTILS
        GL11.glDisable(GL11.GL_CULL_FACE);
        if (phase) {
            GL11.glBlendFunc(770, 771);
            GL11.glEnable(GL11.GL_BLEND);
            GL11.glLineWidth(2.0);
            GL11.glDisable(GL11.GL_TEXTURE_2D);
            GL11.glDisable(GL11.GL_DEPTH_TEST);
            GL11.glDepthMask(false);
            GlStateManager.func_179094_E();
        } else {
            GL11.glDisable(GL11.GL_TEXTURE_2D);
            GL11.glBlendFunc(770, 771);
            GL11.glEnable(GL11.GL_BLEND);
            GL11.glLineWidth(2.0);
            GL11.glDepthMask(false);
            GlStateManager.func_179094_E();
        }

        w /= 2;

        Tessellator.begin(GL11.GL_QUADS, false);
        Tessellator.colorize(red, green, blue, alpha);

        Tessellator.translate(x, y, z)
            .pos(w, 0, w)
            .pos(w, 0, -w)
            .pos(-w, 0, -w)
            .pos(-w, 0, w)

            .pos(w, h, w)
            .pos(w, h, -w)
            .pos(-w, h, -w)
            .pos(-w, h, w)

            .pos(-w, h, w)
            .pos(-w, h, -w)
            .pos(-w, 0, -w)
            .pos(-w, 0, w)

            .pos(w, h, w)
            .pos(w, h, -w)
            .pos(w, 0, -w)
            .pos(w, 0, w)

            .pos(w, h, -w)
            .pos(-w, h, -w)
            .pos(-w, 0, -w)
            .pos(w, 0, -w)

            .pos(-w, h, w)
            .pos(w, h, w)
            .pos(w, 0, w)
            .pos(-w, 0, w)
            .draw();

        GL11.glEnable(GL11.GL_CULL_FACE);
        if (phase) {
            GlStateManager.func_179121_F();
            GL11.glEnable(GL11.GL_TEXTURE_2D);
            GL11.glEnable(GL11.GL_DEPTH_TEST);
            GL11.glDepthMask(true);
            GL11.glDisable(GL11.GL_BLEND);
        } else {
            GL11.glEnable(GL11.GL_TEXTURE_2D);
            GlStateManager.func_179121_F();
            GL11.glDepthMask(true);
            GL11.glDisable(GL11.GL_BLEND);
        }
    }
}