aboutsummaryrefslogtreecommitdiff
path: root/utils/renderUtils.js
blob: 321e8217366f38fbc7bb51cc0b3b2557e91f0b44 (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
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
const { f, m } = require("../../mappings/mappings");

const { default: renderBeaconBeam2 } = require("../../BeaconBeam/index");
const numberUtils = require("./numberUtils");
const { default: RenderLib2D } = require("./renderLib2d");

if (!GlStateManager) {
    var GL11 = Java.type("org.lwjgl.opengl.GL11"); //using var so it goes to global scope
    var GlStateManager = Java.type("net.minecraft.client.renderer.GlStateManager");
}
let ret = {

    /* 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(GL11.GL_LINE_STRIP).colorize(r, g, b);

        Tessellator.pos(x, y, z);
        Tessellator.pos(x2, y2, z2);

        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 = 1) {

        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(GL11.GL_LINE_STRIP).colorize(r, g, b);

        Tessellator.pos(x, y, z);
        Tessellator.pos(x2, y2, z2);

        Tessellator.draw();


        GlStateManager.func_179121_F();
        GL11.glEnable(GL11.GL_TEXTURE_2D);
        GL11.glDepthMask(true);
        GL11.glDisable(GL11.GL_BLEND);
    },
    setupLineSmall: function (width) {
        GL11.glBlendFunc(770, 771);
        GL11.glEnable(GL11.GL_BLEND);
        GL11.glLineWidth(width);
        GL11.glDisable(GL11.GL_TEXTURE_2D);
        GL11.glDepthMask(false);
        GlStateManager.func_179094_E();
    },
    endLineSmall: function () {
        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(GL11.GL_LINE_STRIP).colorize(r, g, b);

        Tessellator.pos(x, y, z);
        Tessellator.pos(x2, y2, z2);

        Tessellator.draw();
    },
    drawLinePoints: function (locations, r, g, b, thickness = 1, phase = false) {
        GL11.glBlendFunc(770, 771);
        GL11.glEnable(GL11.GL_BLEND);
        GL11.glLineWidth(thickness);
        GL11.glDisable(GL11.GL_TEXTURE_2D);
        if (phase) GL11.glDisable(GL11.GL_DEPTH_TEST);
        GL11.glDepthMask(false);
        GlStateManager.func_179094_E();

        Tessellator.begin(GL11.GL_LINE_STRIP).colorize(r, g, b);

        locations.forEach(loc => {
            Tessellator.pos(...loc);
        });

        Tessellator.draw();


        GlStateManager.func_179121_F();
        GL11.glEnable(GL11.GL_TEXTURE_2D);
        GL11.glDepthMask(true);
        if (phase) GL11.glEnable(GL11.GL_DEPTH_TEST);
        GL11.glDisable(GL11.GL_BLEND);
    },
    drawBoxAtBlockNotVisThruWalls: function (x, y, z, colorR, colorG, colorB, w = 1, h = 1, a = 1) {
        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
        w += 0.01
        h += 0.01

        Tessellator.begin(GL11.GL_LINE_STRIP).colorize(colorR, colorG, colorB, a);

        Tessellator.pos(x + w, y + h, z + w);
        Tessellator.pos(x + w, y + h, z);
        Tessellator.pos(x, y + h, z);
        Tessellator.pos(x, y + h, z + w);
        Tessellator.pos(x + w, y + h, z + w);
        Tessellator.pos(x + w, y, z + w);
        Tessellator.pos(x + w, y, z);
        Tessellator.pos(x, y, z);
        Tessellator.pos(x, y, z + w);
        Tessellator.pos(x, y, z);
        Tessellator.pos(x, y + h, z);
        Tessellator.pos(x, y, z);
        Tessellator.pos(x + w, y, z);
        Tessellator.pos(x + w, y + h, z);
        Tessellator.pos(x + w, y, z);
        Tessellator.pos(x + w, y, z + w);
        Tessellator.pos(x, y, z + w);
        Tessellator.pos(x, y + h, z + w);
        Tessellator.pos(x + w, y + h, z + w);

        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, w = 1, h = 1, a = 1) {

        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[m.pushMatrix]()


        Tessellator.begin(GL11.GL_LINE_STRIP).colorize(colorR, colorG, colorB, a);

        Tessellator.pos(x + w, y + h, z + w);
        Tessellator.pos(x + w, y + h, z);
        Tessellator.pos(x, y + h, z);
        Tessellator.pos(x, y + h, z + w);
        Tessellator.pos(x + w, y + h, z + w);
        Tessellator.pos(x + w, y, z + w);
        Tessellator.pos(x + w, y, z);
        Tessellator.pos(x, y, z);
        Tessellator.pos(x, y, z + w);
        Tessellator.pos(x, y, z);
        Tessellator.pos(x, y + h, z);
        Tessellator.pos(x, y, z);
        Tessellator.pos(x + w, y, z);
        Tessellator.pos(x + w, y + h, z);
        Tessellator.pos(x + w, y, z);
        Tessellator.pos(x + w, y, z + w);
        Tessellator.pos(x, y, z + w);
        Tessellator.pos(x, y + h, z + w);
        Tessellator.pos(x + w, y + h, z + w);

        Tessellator.draw();

        GlStateManager[m.popMatrix]()
        GL11.glEnable(GL11.GL_TEXTURE_2D);
        GL11.glEnable(GL11.GL_DEPTH_TEST);
        GL11.glDepthMask(true);
        GL11.glDisable(GL11.GL_BLEND);
    },
    drawBoxAtBlock2: function (x, y, z, colorR, colorG, colorB, w = 1, h = 1, a = 1) {

        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[m.pushMatrix]()


        Tessellator.begin(GL11.GL_LINE_STRIP).colorize(colorR, colorG, colorB, a);

        x -= w / 2
        z -= w / 2

        Tessellator.pos(x + w, y + h, z + w);
        Tessellator.pos(x + w, y + h, z);
        Tessellator.pos(x, y + h, z);
        Tessellator.pos(x, y + h, z + w);
        Tessellator.pos(x + w, y + h, z + w);
        Tessellator.pos(x + w, y, z + w);
        Tessellator.pos(x + w, y, z);
        Tessellator.pos(x, y, z);
        Tessellator.pos(x, y, z + w);
        Tessellator.pos(x, y, z);
        Tessellator.pos(x, y + h, z);
        Tessellator.pos(x, y, z);
        Tessellator.pos(x + w, y, z);
        Tessellator.pos(x + w, y + h, z);
        Tessellator.pos(x + w, y, z);
        Tessellator.pos(x + w, y, z + w);
        Tessellator.pos(x, y, z + w);
        Tessellator.pos(x, y + h, z + w);
        Tessellator.pos(x + w, y + h, z + w);

        Tessellator.draw();

        GlStateManager[m.popMatrix]()
        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(GL11.GL_LINE_STRIP).colorize(colorR, colorG, colorB, 1);

        Tessellator.pos(x + width, y + height, z + width);
        Tessellator.pos(x + width, y + height, z - width);
        Tessellator.pos(x - width, y + height, z - width);
        Tessellator.pos(x - width, y + height, z + width);
        Tessellator.pos(x + width, y + height, z + width);
        Tessellator.pos(x + width, y, z + width);
        Tessellator.pos(x + width, y, z - width);
        Tessellator.pos(x - width, y, z - width);
        Tessellator.pos(x - width, y, z + width);
        Tessellator.pos(x - width, y, z - width);
        Tessellator.pos(x - width, y + height, z - width);
        Tessellator.pos(x - width, y, z - width);
        Tessellator.pos(x + width, y, z - width);
        Tessellator.pos(x + width, y + height, z - width);
        Tessellator.pos(x + width, y, z - width);
        Tessellator.pos(x + width, y, z + width);
        Tessellator.pos(x - width, y, z + width);
        Tessellator.pos(x - width, y + height, z + width);
        Tessellator.pos(x + width, y + height, z + width);

        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);
        }
    },
    renderBeaconBeam(x, y, z, r, g, b, alpha, phase) {
        renderBeaconBeam2(x, y, z, r, g, b, alpha, !phase)
    },
    drawCoolWaypoint(x, y, z, r, g, b, { name = "", showDist = !!name, phase = false }) {
        let distToPlayerSq = (x - Player.getRenderX()) ** 2 + (y - (Player.getRenderY() + Player.getPlayer()[m.getEyeHeight]())) ** 2 + (z - Player.getRenderZ()) ** 2

        let alpha = Math.min(1, Math.max(0, 1 - (distToPlayerSq - 10000) / 12500))

        ret[phase ? "drawBoxAtBlock" : "drawBoxAtBlockNotVisThruWalls"](x - 0.005, y - 0.005, z - 0.005, r, g, b, 1.01, 1.01, alpha)
        ret.drawFilledBox(x + 0.5, y, z + 0.5, 1.02, 1.01, r, g, b, 0.25 * alpha, phase)
        renderBeaconBeam2(x, y + 1, z, r, g, b, Math.min(1, Math.max(0, (distToPlayerSq - 25) / 100)) * alpha, !phase)

        if (name || showDist) {
            let distToPlayer = Math.sqrt(distToPlayerSq)

            let distRender = Math.min(distToPlayer, 50)

            let loc5 = [Player.getRenderX() + (x + 0.5 - Player.getRenderX()) / (distToPlayer / distRender), (Player.getRenderY() + Player.getPlayer()[m.getEyeHeight]()) + (y + 2 + 20 * distToPlayer / 300 - (Player.getRenderY() + Player.getPlayer()[m.getEyeHeight]())) / (distToPlayer / distRender), Player.getRenderZ() + (z + 0.5 - Player.getRenderZ()) / (distToPlayer / distRender)]
            let loc6 = [Player.getRenderX() + (x + 0.5 - Player.getRenderX()) / (distToPlayer / distRender), (Player.getRenderY() + Player.getPlayer()[m.getEyeHeight]()) + (y + 2 + 20 * distToPlayer / 300 - 10 * distToPlayer / 300 - (Player.getRenderY() + Player.getPlayer()[m.getEyeHeight]())) / (distToPlayer / distRender), Player.getRenderZ() + (z + 0.5 - Player.getRenderZ()) / (distToPlayer / distRender)]

            if (name) Tessellator.drawString("§a" + name, loc5[0], loc5[1], loc5[2], 0, true, distRender / 300, false)
            if (showDist) Tessellator.drawString("§b(" + numberUtils.numberWithCommas(Math.round(distToPlayer)) + "m)", (name ? loc6[0] : loc5[0]), (name ? loc6[1] : loc5[1]), (name ? loc6[2] : loc5[2]), 0, false, distRender / 300, false)
        }
    }
}

module.exports = ret