aboutsummaryrefslogtreecommitdiff
path: root/src/features/dungeonMap2/index.js
blob: 026b09af6d642068abfb103b74acfaccaa16061b (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
/// <reference types="../../../../CTAutocomplete" />
/// <reference lib="es2015" />

import Feature from "../../featureClass/class";
import renderLibs from "../../../guimanager/renderLibs";
import DungeonMapData from "./DungeonMapData";
import DungeonRoomStaticData from "./DungeonRoomStaticData";
import ImageLocationSetting from "../settings/settingThings/imageLocation";
import ToggleSetting from "../settings/settingThings/toggle";
import { f, m } from "../../../mappings/mappings";

const DefaultVertexFormats = Java.type("net.minecraft.client.renderer.vertex.DefaultVertexFormats")
const MCTessellator = Java.type("net.minecraft.client.renderer.Tessellator")

class DungeonMap extends Feature {
    constructor() {
        super()
    }

    onEnable() {
        if (Player.getUUID().toString() !== "dc8c3964-7b29-4e03-ae9e-d13ebd65dd29") {
            new SettingBase("not Coming soontm", "maby", undefined, "coming_soontm", this)
            return
        }
        this.mapLocation = new ImageLocationSetting("Map Location", "Sets the location of the map on the hud", "dmap_location", this, [10, 10, 1], new Image(javax.imageio.ImageIO.read(new java.io.File("./config/ChatTriggers/modules/SoopyV2/features/dungeonMap/map.png"))), 150, 150)
        this.mapSecrets = new ToggleSetting("Show secret count instead of tick", "Syncs between soopyv2 users", true, "dmap_secrets", this)

        this.lastRoomId = undefined

        /**@type {DungeonMapData} */
        this.currentDungeon = undefined
        this.lastChange = 0

        this.roomXY = this.getRoomXYWorld().join(",")
        this.lastXY = undefined

        let registerActionBar = this.registerCustom("actionbar", (curr, max) => {

            let roomid = this.getCurrentRoomId()
            let roomWorldData = this.getRoomWorldData()

            let rotation = roomWorldData.width > roomWorldData.height ? 0 : 1

            if (this.getCurrentRoomData().shape === "L") rotation = roomWorldData.rotation
            if (this.getCurrentRoomData().type === "spawn") {
                roomWorldData.x = x + 1
                roomWorldData.y = y + 1
            }

            this.currentDungeon.roomSecrets(roomWorldData.x, roomWorldData.y, rotation, roomid, curr, max)
        })
        registerActionBar.trigger.setCriteria('&7${curr}/${max} Secrets').setParameter('contains');

        this.registerStep(true, 5, this.update)

        this.registerEvent("renderOverlay", this.renderOverlay)
        this.registerEvent("worldLoad", this.worldLoad)

    }

    update() {
        if (!this.isInDungeon()) {
            if (this.currentDungeon) {
                this.currentDungeon.destroy()
                this.lastRoomId = undefined
                this.currentDungeon = undefined
            }
            return
        }

        if (!this.currentDungeon) {
            this.currentDungeon = new DungeonMapData(this.FeatureManager.features["dataLoader"].class.dungeonFloor)
        }
        this.currentDungeon.setRenderTicks(!this.mapSecrets.getValue())

        this.currentDungeon.updatePlayers()
        this.currentDungeon.updateHotbarData()

        let roomid = this.getCurrentRoomId()
        if (!roomid.includes(",")) return
        if (this.roomXY !== this.getRoomXYWorld().join(",")) {
            this.roomXY = this.getRoomXYWorld().join(",")
            this.lastChange = Date.now()
        }

        let x = Math.floor((Player.getX() + 8) / 32) * 32 - 9
        let y = Math.floor((Player.getZ() + 8) / 32) * 32 - 9

        if (roomid !== this.lastRoomId && Date.now() - this.lastChange > 500) {
            this.lastRoomId = roomid

            let roomWorldData = this.getRoomWorldData()

            let rotation = roomWorldData.width > roomWorldData.height ? 0 : 1

            if (this.getCurrentRoomData().shape === "L") rotation = roomWorldData.rotation
            if (this.getCurrentRoomData().type === "spawn") {
                roomWorldData.x = x + 1
                roomWorldData.y = y + 1
            }

            this.currentDungeon.setRoom(roomWorldData.x, roomWorldData.y, rotation, roomid)
        }


        if (this.lastXY !== x + "," + y) {
            this.lastXY = x + "," + y
            if (this.getBlockAt(x + 16, 73, y) !== 0) {
                this.currentDungeon.setDoor(x + 16, y, -1, 0)
            }
            if (this.getBlockAt(x, 73, y + 16) !== 0) {
                this.currentDungeon.setDoor(x, y + 16, -1, 1)
            }
            if (this.getBlockAt(x + 16, 73, y + 32) !== 0) {
                this.currentDungeon.setDoor(x + 16, y + 32, -1, 0)
            }
            if (this.getBlockAt(x + 32, 73, y + 16) !== 0) {
                this.currentDungeon.setDoor(x + 32, y + 16, -1, 1)
            }
        }
    }

    renderOverlay() {
        if (this.currentDungeon) {
            this.currentDungeon.updatePlayersFast()

            let x = this.mapLocation.getValue()[0]
            let y = this.mapLocation.getValue()[1]
            let size = 150 * this.mapLocation.getValue()[2]
            Renderer.drawRect(Renderer.color(0, 0, 0, 100), x, y, size, size)

            this.currentDungeon.getImage().draw(x, y, size, size)

            Renderer.drawRect(Renderer.color(0, 0, 0), x, y, size, 2)
            Renderer.drawRect(Renderer.color(0, 0, 0), x, y, 2, size)
            Renderer.drawRect(Renderer.color(0, 0, 0), x + size - 2, y, 2, size)
            Renderer.drawRect(Renderer.color(0, 0, 0), x, y + size - 2, size, 2)

            for (let player of this.currentDungeon.getPlayers()) {
                let x2 = this.currentDungeon.toImageX(player.x) * size + x
                let y2 = this.currentDungeon.toImageY(player.y) * size + y
                let rx = -6
                let ry = -6
                let rw = 12
                let rh = 12

                Renderer.translate(x2, y2)
                Renderer.rotate(player.rotate)
                GlStateManager[m.enableBlend]()
                GlStateManager[m.scale](1, 1, 50)
                Client.getMinecraft()[m.getTextureManager]()[m.bindTexture.TextureManager](player.skin)
                GlStateManager[m.enableTexture2D]()

                let tessellator = MCTessellator[m.getInstance.Tessellator]()
                let worldRenderer = tessellator[m.getWorldRenderer]()
                worldRenderer[m.begin](7, DefaultVertexFormats[f.POSITION_TEX])

                worldRenderer[m.pos](rx, ry + rh, 0.0)[m.tex](8 / 64, 16 / 64)[m.endVertex]()
                worldRenderer[m.pos](rx + rw, ry + rh, 0.0)[m.tex](16 / 64, 16 / 64)[m.endVertex]()
                worldRenderer[m.pos](rx + rw, ry, 0.0)[m.tex](16 / 64, 8 / 64)[m.endVertex]()
                worldRenderer[m.pos](rx, ry, 0.0)[m.tex](8 / 64, 8 / 64)[m.endVertex]()
                tessellator[m.draw.Tessellator]()

                Tessellator.popMatrix()
                Tessellator.pushMatrix()
            }

            if (this.mapSecrets.getValue()) {
                Renderer.retainTransforms(true)
                Renderer.translate(x, y)
                this.currentDungeon.renderSecrets(size)
                Renderer.translate(-x, -y)
                Renderer.retainTransforms(false)
            }
        }
    }

    worldLoad() {
        if (this.currentDungeon) this.currentDungeon.destroy()
        this.lastRoomId = undefined
        this.currentDungeon = undefined
    }

    getCurrentRoomId() {
        if (Scoreboard.getLines().length === 0) return undefined
        let id = Scoreboard.getLineByIndex(Scoreboard.getLines().length - 1).getName().trim().split(" ").pop()

        return id
    }

    isInDungeon() {
        return this.FeatureManager.features["dataLoader"].class.isInDungeon
    }

    getRoomXYWorld() {
        let roomData = this.getRoomWorldData()
        if (roomData.rotation === 4) {
            return [roomData.x, roomData.y + 32]
        }

        return [roomData.x, roomData.y]
    }

    getCurrentRoomData() {
        return DungeonRoomStaticData.getDataFromId(this.getCurrentRoomId())
    }

    getRotation(x, y, width, height, roofY) {
        let currRoomData = this.getCurrentRoomData()
        if (!currRoomData) return -1

        if (currRoomData.shape !== "L") {
            if (this.getTopBlockAt(x, y, roofY) === 11) return 0
            if (this.getTopBlockAt(x + width, y, roofY) === 11) return 1
            if (this.getTopBlockAt(x + width, y + height, roofY) === 11) return 2
            if (this.getTopBlockAt(x, y + height, roofY) === 11) return 3
        } else {
            let one = this.getTopBlockAt2(x + width / 2 + 1, y + height / 2, roofY)
            let two = this.getTopBlockAt2(x + width / 2 - 1, y + height / 2, roofY)
            let three = this.getTopBlockAt2(x + width / 2, y + height / 2 + 1, roofY)
            let four = this.getTopBlockAt2(x + width / 2, y + height / 2 - 1, roofY)

            if (one === 0 && three === 0) return 0
            if (two === 0 && three === 0) return 1
            if (one === 0 && four === 0) return 3
            if (two === 0 && four === 0) return 2//3 IS SO TOXIK HGOLY HEL I HATE L SHAPE ROOMS WHY DO THIS TO ME
        }

        return -1
    }

    getRoomWorldData() {
        let x = Math.floor((Player.getX() + 8) / 32) * 32 - 8
        let y = Math.floor((Player.getZ() + 8) / 32) * 32 - 8
        let width = 30
        let height = 30

        let roofY = this.getRoofAt(x, y)

        while (World.getBlockStateAt(new BlockPos(x - 1, roofY, y)).getBlockId() !== 0) {
            x -= 32
            width += 32
        }
        while (World.getBlockStateAt(new BlockPos(x, roofY, y - 1)).getBlockId() !== 0) {
            y -= 32
            height += 32
        }
        while (World.getBlockStateAt(new BlockPos(x - 1, roofY, y)).getBlockId() !== 0) { //second iteration incase of L shape
            x -= 32
            width += 32
        }
        while (World.getBlockStateAt(new BlockPos(x + width + 1, roofY, y)).getBlockId() !== 0) {
            width += 32
        }
        while (World.getBlockStateAt(new BlockPos(x, roofY, y + height + 1)).getBlockId() !== 0) {
            height += 32
        }
        while (World.getBlockStateAt(new BlockPos(x + width, roofY, y + height + 1)).getBlockId() !== 0) { //second iteration incase of L shape
            height += 32
        }
        while (World.getBlockStateAt(new BlockPos(x + width + 1, roofY, y + height)).getBlockId() !== 0) { //second iteration incase of L shape
            width += 32
        }
        while (World.getBlockStateAt(new BlockPos(x + width, roofY, y - 1)).getBlockId() !== 0) {//second iteration incase of L shape
            y -= 32
            height += 32
        }
        while (World.getBlockStateAt(new BlockPos(x - 1, roofY, y + height)).getBlockId() !== 0) { //third iteration incase of L shape
            x -= 32
            width += 32
        }


        return {
            x,
            y,
            width,
            height,
            cx: x + width / 2,
            cy: y + height / 2,
            rotation: this.getRotation(x, y, width, height, roofY)
        }
    }

    getRoofAt(x, z) {
        let y = 255
        while (y > 0 && World.getBlockStateAt(new BlockPos(x, y, z)).getBlockId() === 0) y--

        return y
    }

    getTopBlockAt(x, z, y) {
        if (!y) y = this.getHeightAt(x, z)

        return World.getBlockStateAt(new BlockPos(x, y, z)).getMetadata()
    }
    getBlockAt(x, y, z) {
        return World.getBlockStateAt(new BlockPos(x, y, z)).getBlockId()
    }
    getTopBlockAt2(x, z, y) {
        if (!y) y = this.getHeightAt(x, z)

        return World.getBlockStateAt(new BlockPos(x, y, z)).getBlockId()
    }
    onDisable() {
    }
}

module.exports = {
    class: new DungeonMap()
}