aboutsummaryrefslogtreecommitdiff
path: root/utils/renderJavaUtils.js
blob: b9a3f83e7c704f43d78beca8b2e72f3ff873e766 (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
let SoopyV2Forge = Java.type("me.soopyboo32.soopyv2forge.SoopyV2Forge").INSTANCE

let LASTEST_SOOPYFORGE_VER = "1.0"

let ArrayList = Java.type("java.util.ArrayList")

let Vec3 = Java.type("net.minecraft.util.Vec3")
let Vector2f = Java.type("javax.vecmath.Vector2f")
let RenderPointsC = Java.type("me.soopyboo32.soopyv2forge.RenderTypes.Points")
let RenderWorldTextC = Java.type("me.soopyboo32.soopyv2forge.RenderTypes.WorldText")
let RenderBeaconC = Java.type("me.soopyboo32.soopyv2forge.RenderTypes.Beacon")
let HudPointsC = Java.type("me.soopyboo32.soopyv2forge.RenderTypes.HudPoints")
let HudTextC = Java.type("me.soopyboo32.soopyv2forge.RenderTypes.HudText")

let RenderWorldThings = new Set()
let RenderHudThings = new Set()

class RenderWorldAble {
    startRender() {
        RenderWorldThings.add(this.javaObj)
        SoopyV2Forge.setRenderWorldList(new ArrayList([...RenderWorldThings]))
        return this
    }
    stopRender() {
        RenderWorldThings.delete(this.javaObj)
        SoopyV2Forge.setRenderWorldList(new ArrayList([...RenderWorldThings]))
        return this
    }
}
class RenderHudAble {
    startRender() {
        RenderHudThings.add(this.javaObj)
        SoopyV2Forge.setRenderHudList(new ArrayList([...RenderHudThings]))
        return this
    }
    stopRender() {
        RenderHudThings.delete(this.javaObj)
        SoopyV2Forge.setRenderHudList(new ArrayList([...RenderHudThings]))
        return this
    }
}

export class Points extends RenderWorldAble {
    constructor(points, r, g, b, a, thickness, depth) {
        this.javaObj = new RenderPointsC(new ArrayList(points.map(a => new Vec3(...a))), r, g, b, a, thickness, depth)
    }

    setPoints(points) {
        this.javaObj.points = new ArrayList(points.map(a => new Vec3(...a)))
        return this
    }
    setRGBA(r, g, b, a) {
        this.javaObj.red = r
        this.javaObj.green = g
        this.javaObj.blue = b
        this.javaObj.alpha = a
        return this
    }
    setThickness(thickness) {
        this.javaObj.thickness = thickness
        return this
    }
    setDepth(depth) {
        this.javaObj.depthtest = depth
        return this
    }
    setDisableCullFace(disable) {
        this.javaObj.disableCullFace = disable
        return this
    }
    setGLMode(glMode) {
        this.javaObj.glmode = glMode
        return this
    }
}
export class FilledPoints extends Points {
    constructor(points, r, g, b, a, thickness, depth) {
        super(points, r, g, b, a, thickness, depth)

        this.setGLMode(GL11.GL_QUADS)
        this.setDisableCullFace(true)
    }
}
export class Box extends Points {
    constructor(location, size, r, g, b, a, thickness, depth) {
        super(Box.getPointsFromLocationSize(location, size), r, g, b, a, thickness, depth)
    }

    setLocationSize(location, size) {
        this.setPoints(Box.getPointsFromLocationSize(location, size))
        return this
    }

    static getPointsFromLocationSize(location, size) {
        let [x, y, z] = location
        let [width, height, width2] = size

        return [[x + width, y + height, z + width2],
        [x + width, y + height, z],
        [x, y + height, z],
        [x, y + height, z + width2],
        [x + width, y + height, z + width2],
        [x + width, y, z + width2],
        [x + width, y, z],
        [x, y, z],
        [x, y, z + width2],
        [x, y, z],
        [x, y + height, z],
        [x, y, z],
        [x + width, y, z],
        [x + width, y + height, z],
        [x + width, y, z],
        [x + width, y, z + width2],
        [x, y, z + width2],
        [x, y + height, z + width2],
        [x + width, y + height, z + width2]]
    }
}
export class FilledBox extends FilledPoints {
    constructor(location, size, r, g, b, a, thickness, depth) {
        super(FilledBox.getPointsFromLocationSize(location, size), r, g, b, a, thickness, depth)
    }

    setLocationSize(location, size) {
        this.setPoints(FilledBox.getPointsFromLocationSize(location, size))
        return this
    }

    static getPointsFromLocationSize(location, size) {
        let [x, y, z] = location
        let [w, h, w2] = size

        return [
            [x + w, y + 0, z + w2],
            [x + w, y + 0, z],
            [x, y + 0, z],
            [x, y + 0, z + w2],

            [x + w, y + h, z + w2],
            [x + w, y + h, z],
            [x, y + h, z],
            [x, y + h, z + w2],

            [x, y + h, z + w2],
            [x, y + h, z],
            [x, y + 0, z],
            [x, y + 0, z + w2],

            [x + w, y + h, z + w2],
            [x + w, y + h, z],
            [x + w, y + 0, z],
            [x + w, y + 0, z + w2],

            [x + w, y + h, z],
            [x, y + h, z],
            [x, y + 0, z],
            [x + w, y + 0, z],

            [x, y + h, z + w2],
            [x + w, y + h, z + w2],
            [x + w, y + 0, z + w2],
            [x, y + 0, z + w2]
        ]
    }
}
export class WorldText extends RenderWorldAble {
    constructor(location, text, depth, scale) {
        this.javaObj = new RenderWorldTextC(new Vec3(...location), text, depth, scale)
    }

    setLocation(location) {
        this.javaObj.location = location
        return this
    }
    setText(text) {
        this.javaObj.text = text
        return this
    }
    setDepthtest(depthtest) {
        this.javaObj.depthtest = depthtest
        return this
    }
    setScale(scale) {
        this.javaObj.scale = scale
        return this
    }
    setShadow(shadow) {
        this.javaObj.shadow = shadow
        return this
    }
}

export class Beacon extends RenderWorldAble {
    constructor(location, r, g, b, a, depth) {
        this.javaObj = new RenderBeaconC(new Vec3(...location), r, g, b, a, depth)
    }

    setLocation(location) {
        this.javaObj.location = location
        return this
    }
    setRGBA(r, g, b, a) {
        this.javaObj.red = r
        this.javaObj.green = g
        this.javaObj.blue = b
        this.javaObj.alpha = a
        return this
    }
    setDepthtest(depthtest) {
        this.javaObj.depthtest = depthtest
        return this
    }

}
export class HudPoints extends RenderHudAble {
    constructor(points, r, g, b, a, thickness) {
        this.javaObj = new HudPointsC(new ArrayList(points.map(a => new Vector2f(...a))), r, g, b, a, thickness)
    }

    setPoints(points) {
        this.javaObj.points = new ArrayList(points.map(a => new Vec3(...a)))
        return this
    }
    setRGBA(r, g, b, a) {
        this.javaObj.colorR = r
        this.javaObj.colorG = g
        this.javaObj.colorB = b
        this.javaObj.colorA = a
        return this
    }
    setThickness(thickness) {
        this.javaObj.thickness = thickness
        return this
    }
    setGlmode(glmode) {
        this.javaObj.glmode = glmode
        return this
    }
}
export class HudText extends RenderHudAble {
    constructor(text, x, y, shadow) {
        this.javaObj = new HudTextC(text, x, y, shadow)
    }

    setText(text) {
        this.javaObj.textLines = text
        return this
    }
    setX(x) {
        this.javaObj.x = x
        return this
    }
    setY(y) {
        this.javaObj.y = y
        return this
    }
    setScale(scale) {
        this.javaObj.scale = scale
        return this
    }
    setShadow(shadow) {
        this.javaObj.shadow = shadow
        return this
    }
}

new Box([128, 72, 58], [1, 1, 1], 1, 0, 0, 1, 1, true).startRender()
new FilledBox([128, 72, 58], [1, 1, 1], 1, 0, 0, 0.25, 1, true).startRender()

// let data = []

// data.push(createPoints([[108, 70, 63], [108, 71, 63], [108, 70, 67], [108, 70, 63]], 1, 0, 0, 1, 2, true))
// data.push(createWorldText([115, 73, 63], "Text §dWOW §6YEP", true, 1))
// data.push(createBeacon([115, 75, 63], 0, 1, 0, 1, true))

// SoopyV2Forge.setRenderWorldList(new ArrayList(data))

// let data2 = []

// data2.push(createHudPoints([[10, 10], [50, 10], [50, 20], [10, 10]], 0, 0, 1, 1, 5))
// data2[data2.length - 1].glmode = 5
// data2.push(createHudText("Text §dWOW §6YEP", 10, 30, true))

// SoopyV2Forge.setRenderHudList(new ArrayList(data2))

register("worldLoad", () => {
    if (!net.minecraftforge.fml.common.Loader.isModLoaded("soopyv2forge")) {
        ChatLib.chat("&1" + ChatLib.getChatBreak("-").trim())
        ChatLib.chat("§cWARNING: You dont have the forge mod for soopyv2 installed")
        ChatLib.chat("§cWARNING: If you have the mod installed it will take over rendering")
        ChatLib.chat("§cWARNING: And improve performance quite a bit")
        new TextComponent(" &e[CLICK] &7- Download").setHover("show_text", "&2Download").setClick("open_url", "https://github.com/Soopyboo32/SoopyV2Forge/releases").chat()
        ChatLib.chat("&1" + ChatLib.getChatBreak("-").trim())
    }
    if (SoopyV2Forge.getVersion() !== LASTEST_SOOPYFORGE_VER) {
        ChatLib.chat("&1" + ChatLib.getChatBreak("-").trim())
        ChatLib.chat("§cWARNING: Your forge version of soopyv2 is outdated")
        ChatLib.chat("§cWARNING: Chattriggers will take over rendering")
        ChatLib.chat("§cWARNING: This will hurt performance quite a bit")
        new TextComponent(" &e[CLICK] &7- Download").setHover("show_text", "&2Download update").setClick("open_url", "https://github.com/Soopyboo32/SoopyV2Forge/releases").chat()
        ChatLib.chat("&1" + ChatLib.getChatBreak("-").trim())
    }
})

let renderWorldList
let renderHudList

let shouldUseForgeRendering = net.minecraftforge.fml.common.Loader.isModLoaded("soopyv2forge") && SoopyV2Forge.getVersion() === LASTEST_SOOPYFORGE_VER

if (!shouldUseForgeRendering) {
    renderWorldList = []
    renderHudList = []
    register("renderOverlay", (ticks) => {

    })
    register("renderWorld", (ticks) => {

    })
}