diff options
Diffstat (limited to 'src/features/dungeonMap2')
-rw-r--r-- | src/features/dungeonMap2/DungeonMapData.js | 513 | ||||
-rw-r--r-- | src/features/dungeonMap2/DungeonMapRoom.js | 256 | ||||
-rw-r--r-- | src/features/dungeonMap2/DungeonRoomStaticData.js | 19 | ||||
-rw-r--r-- | src/features/dungeonMap2/index.js | 312 | ||||
-rw-r--r-- | src/features/dungeonMap2/metadata.json | 8 |
5 files changed, 1108 insertions, 0 deletions
diff --git a/src/features/dungeonMap2/DungeonMapData.js b/src/features/dungeonMap2/DungeonMapData.js new file mode 100644 index 0000000..1b50c67 --- /dev/null +++ b/src/features/dungeonMap2/DungeonMapData.js @@ -0,0 +1,513 @@ +import { f, m } from "../../../mappings/mappings" +import DungeonMapRoom from "./DungeonMapRoom" +import DungeonRoomStaticData from "./DungeonRoomStaticData" + +const Color = Java.type("java.awt.Color") +const BufferedImage = Java.type("java.awt.image.BufferedImage") + +let DEFAULT_DOOR_COLOR = new Color(Renderer.color(114, 67, 27, 255)) +let PUZZLE_DOOR_COLOR = new Color(Renderer.color(178, 76, 216, 255)) +let MINIBOSS_DOOR_COLOR = new Color(Renderer.color(229, 229, 51, 255)) +let BLOOD_DOOR_COLOR = new Color(Renderer.color(255, 0, 0, 255)) +let TRAP_DOOR_COLOR = new Color(Renderer.color(216, 127, 51, 255)) +let WITHER_DOOR_COLOR = new Color(Renderer.color(0, 0, 0, 255)) + +let mapDataScale = { + "E": 22, + "1": 22, + "2": 22, + "3": 22, + "4": 20, + "5": 20, + "6": 20, + "7": 20 +} + +// let TabOverlayListField = Java.type("net.minecraft.client.gui.GuiPlayerTabOverlay").class.getDeclaredField("field_175252_a") +// TabOverlayListField.setAccessible(true) +// let TabOverlayList = TabOverlayListField.get(null) +let PlayerComparator = Java.type("net.minecraft.client.gui.GuiPlayerTabOverlay").PlayerComparator +let c = PlayerComparator.class.getDeclaredConstructor() +c.setAccessible(true); +let sorter = c.newInstance() +let nethandlerplayclient = Player.getPlayer()[f.sendQueue.EntityPlayerSP] + +class DungeonMapData { + constructor(floor) { + this.floor = floor + + this.roomScaleMap = mapDataScale[floor[floor.length - 1]] //how many pixels on the map is 32 blocks + this.roomOffsetMap = [0, 0] //How offset is the map + + /** + * @type {Map<String,DungeonMapRoom>} + */ + this.rooms = new Map() + /** + * @type {Map<String,Number>} + */ + this.doors = new Map() + + this.greenRoomCoords = undefined + + this.image = undefined + this.oldImage = undefined + + this.renderTicks = false + + this.players = [] + this.playersNameToId = {} + } + + updatePlayers() { + let pl = nethandlerplayclient[m.getPlayerInfoMap]().sort((a, b) => sorter.compare(a, b)) + let i = 0 + for (let p of pl) { + if (!p[m.getDisplayName.NetworkPlayerInfo]()) continue + let line = p[m.getDisplayName.NetworkPlayerInfo]()[m.getUnformattedText]().trim().replace("♲ ", "") //TODO: Remove bingo symbol + if (line.endsWith(")") && line.includes(" (") && line.split(" (").length === 2 && line.split(" (")[0].split(" ").length === 1 && line.split(" (")[1].length > 5) { + let name = line.split(" ")[0] + + if (!this.players[i]) { + this.players[i] = { + name: "", + x: 0, + y: 0, + rotate: 0, + skin: undefined + } + } + this.players[i].name = name + this.players[i].skin = p[m.getLocationSkin.NetworkPlayerInfo]() + this.playersNameToId[name] = i + + i++ + } + } + } + + updatePlayersFast() { + World.getAllPlayers().forEach(player => { + let p = this.players[this.playersNameToId[ChatLib.removeFormatting(player.getName()).trim()]] + if (!p) return + + p.x = player.getX() + p.y = player.getZ() + p.rotate = player.getYaw() + 180 + }) + } + + loadPlayersFromDecoration(deco) { + + let i = 0 + deco.forEach((icon, vec4b) => { + + if (!this.players[i]) return + + let x = vec4b.func_176112_b() + let y = vec4b.func_176113_c() + let rot = vec4b.func_176111_d() + x = x / 2 + this.roomScaleMap + y = y / 2 + this.roomScaleMap + rot = rot * 360 / 16 + 180 + + this.players[i].rotate = rot + this.players[i].x = (x) / this.roomScaleMap * 32 - this.roomOffsetMap[0] + this.players[i].y = (y) / this.roomScaleMap * 32 - this.roomOffsetMap[1] + + i++ + }); + } + + updateHotbarData() { + let mapData + try { + let item = Player.getInventory().getStackInSlot(8) + mapData = item.getItem()[m.getMapData](item.getItemStack(), World.getWorld()); // ItemStack.getItem().getMapData() + } catch (error) { + } + if (mapData) { + this.loadPlayersFromDecoration(mapData[f.mapDecorations]) + + let bytes = mapData[f.colors.MapData] + if (!this.greenRoomCoords) return + //30 = green + //0 = transparent + //66 = puzzle + //34 = white + + let rx = 0 + let ry = 0 + for (let x = 0; x < 128; x += 5) { + for (let y = 0; y < 128; y += 5) { + if (bytes[x + y * 128] === 30 + && bytes[x + 1 + y * 128] === 30 + && bytes[x + 2 + y * 128] === 30 + && bytes[x + 3 + y * 128] === 30) { + rx = x + ry = y + while (bytes[(rx - 1) + ry * 128] === 30) { + rx-- + } + while (bytes[(rx) + (ry - 1) * 128] === 30) { + ry-- + } + break; + } + } + if (rx) break; + } + rx += (this.roomScaleMap / 4 * 5) / 2 - this.roomScaleMap + ry += (this.roomScaleMap / 4 * 5) / 2 - this.roomScaleMap + this.roomOffsetMap[0] = -((this.greenRoomCoords[0]) / 32 * this.roomScaleMap + 2 * this.roomScaleMap - rx) / this.roomScaleMap * 32 + this.roomOffsetMap[1] = -((this.greenRoomCoords[1]) / 32 * this.roomScaleMap + 2 * this.roomScaleMap - ry) / this.roomScaleMap * 32 + + console.log(this.roomOffsetMap.join(",")) + + + let toMap = (x2, y2) => { + return Math.round(((x2 + this.roomOffsetMap[0]) / 32 * this.roomScaleMap + 2 * this.roomScaleMap)) + Math.round(((y2 + this.roomOffsetMap[1]) / 32 * this.roomScaleMap + 2 * this.roomScaleMap)) * 128 + } + + console.log(bytes[toMap(Player.getX(), Player.getZ())]) + + let loadRoomAt = (x, y) => { + x = Math.floor((x + 8) / 32) * 32 - 8 + y = Math.floor((y + 8) / 32) * 32 - 8 + + if (bytes[toMap(x + 16, y + 16)] === 30) { + this.setRoomFull(x, y, 0, DungeonMapRoom.TYPE_SPAWN, DungeonMapRoom.SHAPE_1X1, 0) + } + if (bytes[toMap(x + 16, y + 16)] === 66) { + this.setRoomFull(x, y, 0, DungeonMapRoom.TYPE_PUZZLE, DungeonMapRoom.SHAPE_1X1, 0) + } + if (bytes[toMap(x + 16, y + 16)] === 82) { + this.setRoomFull(x, y, 0, DungeonMapRoom.TYPE_FAIRY, DungeonMapRoom.SHAPE_1X1, 0) + } + if (bytes[toMap(x + 16, y + 16)] === 18) { + this.setRoomFull(x, y, 0, DungeonMapRoom.TYPE_BLOOD, DungeonMapRoom.SHAPE_1X1, 0) + } + if (bytes[toMap(x + 16, y + 16)] === 64) { + this.setRoomFull(x, y, 0, DungeonMapRoom.TYPE_TRAP, DungeonMapRoom.SHAPE_1X1, 0) + } + if (bytes[toMap(x + 16, y + 16)] === 63) { + let width = 32 + let height = 32 + while (bytes[toMap(x, y + 5)] === 63) { + x -= 32 + width += 32 + } + while (bytes[toMap(x + 5, y)] === 63) { + y -= 32 + height += 32 + } + while (bytes[toMap(x + width, y + 5)] === 63) { + width += 32 + } + while (bytes[toMap(x + 5, y + height)] === 63) { + height += 32 + } + + let shape = DungeonMapRoom.SHAPE_1X1 + let rotation = 0 + + if (width === height) { + if (width === 64) { + shape = DungeonMapRoom.SHAPE_2X2 + } + } + if (width > height) { + if (width === 64) { + shape = DungeonMapRoom.SHAPE_1X2 + } + if (width === 96) { + shape = DungeonMapRoom.SHAPE_1X3 + } + if (width === 128) { + shape = DungeonMapRoom.SHAPE_1X4 + } + } + if (width < height) { + rotation = 1 + if (height === 64) { + shape = DungeonMapRoom.SHAPE_1X2 + } + if (height === 96) { + shape = DungeonMapRoom.SHAPE_1X3 + } + if (height === 128) { + shape = DungeonMapRoom.SHAPE_1X4 + } + } + + this.setRoomFull(x, y, rotation, DungeonMapRoom.TYPE_NORMAL, shape, 0) + } + } + for (let x = -200; x < 100; x += 32) { + for (let y = -200; y < 100; y += 32) { + loadRoomAt(x, y) + } + } + } + } + + setRenderTicks(val) { + if (this.renderTicks !== val) { + this.mapChanged() + } + this.renderTicks = val + } + + setDoor(x, y, doorType, rotation) {//doorType 0=normal, 1=wither, 2=blood + if (doorType === -1) { + let id = World.getBlockStateAt(new BlockPos(x, 69, y)).getBlockId() + if (id === 0) doorType = 0 + else if (id === 97) doorType = 0 + else if (id === 173) doorType = 1 + else if (id === 159) doorType = 2 + else return + } + if (this.doors.get(x + "," + y)?.join(",") !== doorType + "," + rotation) { + this.doors.set(x + "," + y, [doorType, rotation]) + this.mapChanged() + } + } + + setRoomFull(x, y, rotation, roomType, shape, checkedState) { + let locstr = x + "," + y + + if (shape === DungeonMapRoom.SHAPE_L && rotation === 2) { + locstr = x + "," + (y + 32) + } + + if (this.rooms.get(locstr) && this.rooms.get(locstr).type !== roomType) { + this.rooms.get(locstr).type = roomType + this.mapChanged() + return + } + if (this.rooms.get(locstr) && this.rooms.get(locstr).checkedState !== checkedState) { + this.rooms.get(locstr).setCheckedState(checkedState) + this.mapChanged() + return + } + if (this.rooms.get(locstr) && this.rooms.get(locstr).shape !== shape) { + this.rooms.get(locstr).shape = shape + this.mapChanged() + return + } + if (this.rooms.get(locstr) && this.rooms.get(locstr).rotation !== rotation) { + this.rooms.get(locstr).rotation = rotation + this.mapChanged() + return + } + if (this.rooms.get(locstr)) { + return + } + + let room = new DungeonMapRoom(roomType, shape, rotation, x, y, undefined) + + this.rooms.set(locstr, room) + + this.mapChanged() + } + + setRoom(x, y, rotation, id) { + let locstr = x + "," + y + + if (DungeonRoomStaticData.getDataFromId(id).shape === 'L' && rotation === 2) { + locstr = x + "," + (y + 32) + } + + if (this.rooms.get(locstr) && this.rooms.get(locstr).roomId !== id) { + this.rooms.get(locstr).setId(id) + this.mapChanged() + return + } + if (this.rooms.get(locstr)) { + return + } + + let room = DungeonMapRoom.fromId(id, x, y, rotation) + + if (room.type === DungeonMapRoom.TYPE_SPAWN) { + this.greenRoomCoords = [x, y] + } + + this.rooms.set(locstr, room) + + this.mapChanged() + } + + getPlayers() { + return this.players + } + + roomSecrets(x, y, rotation, id, curr, max) { + let locstr = x + "," + y + + if (DungeonRoomStaticData.getDataFromId(id).shape === 'L' && rotation === 2) { + locstr = x + "," + (y - 32) + } + + if (this.rooms.get(locstr)) { + this.rooms.get(locstr).setSecrets(curr, max) + } + } + + destroy() { + this.oldImage.getTexture()[m.deleteGlTexture]() + this.image.getTexture()[m.deleteGlTexture]() + this.oldImage = undefined + this.image = undefined + } + + mapChanged() { + if (this.image) { + if (this.oldImage) this.oldImage.getTexture()[m.deleteGlTexture]() + this.oldImage = this.image + this.image = undefined + } + } + + /** + * @returns {Image} + */ + getImage() { + if (!this.image) { + this.image = new Image(this.render()) + this.image.draw(0, 0, 0, 0) + if (this.oldImage) return this.oldImage + } + + return this.image + } + + renderSecrets(size) { + for (let data of this.rooms.entries()) { + let room = data[1] + + if (room.maxSecrets === 0) continue + + let text = room.getSecrets() + let text2 = "&0" + ChatLib.removeFormatting(text) + let width = Renderer.getStringWidth(text) - 6 + + let location = room.getIconLocation() + + Renderer.drawString(text2, this.toImageX(location[0]) * size - width / 2 - 1, this.toImageY(location[1]) * size) + Renderer.drawString(text2, this.toImageX(location[0]) * size - width / 2 + 1, this.toImageY(location[1]) * size) + Renderer.drawString(text2, this.toImageX(location[0]) * size - width / 2, this.toImageY(location[1]) * size - 1) + Renderer.drawString(text2, this.toImageX(location[0]) * size - width / 2, this.toImageY(location[1]) * size + 1) + Renderer.drawString(text, this.toImageX(location[0]) * size - width / 2, this.toImageY(location[1]) * size) + } + } + + /** + * @returns {BufferedImage} + */ + render() { + //create 256x256 image + let image = new BufferedImage(256, 256, BufferedImage.TYPE_INT_ARGB) + + //create graphics rendering context + let graphics = image.createGraphics() + + graphics.translate(256 - 32, 256 - 32) + + //render doors + for (let data of this.doors.entries()) { + let [location, [type, rotation]] = data + location = location.split(",") + let x = parseInt(location[0]) + let y = parseInt(location[1]) + + let doorColor = type === 0 ? DEFAULT_DOOR_COLOR : (type === 1 ? WITHER_DOOR_COLOR : BLOOD_DOOR_COLOR) + + if (rotation === 0) { + if (this.rooms.get((x - 15) + "," + (y + 1))?.type === DungeonMapRoom.TYPE_BLOOD) { + doorColor = BLOOD_DOOR_COLOR + } + if (this.rooms.get((x - 15) + "," + (y + 1))?.type === DungeonMapRoom.TYPE_PUZZLE) { + doorColor = PUZZLE_DOOR_COLOR + } + if (this.rooms.get((x - 15) + "," + (y + 1))?.type === DungeonMapRoom.TYPE_TRAP) { + doorColor = TRAP_DOOR_COLOR + } + if (this.rooms.get((x - 15) + "," + (y + 1))?.type === DungeonMapRoom.TYPE_MINIBOSS) { + doorColor = MINIBOSS_DOOR_COLOR + } + if (this.rooms.get((x - 15) + "," + (y - 31))?.type === DungeonMapRoom.TYPE_BLOOD) { + doorColor = BLOOD_DOOR_COLOR + } + if (this.rooms.get((x - 15) + "," + (y - 31))?.type === DungeonMapRoom.TYPE_PUZZLE) { + doorColor = PUZZLE_DOOR_COLOR + } + if (this.rooms.get((x - 15) + "," + (y - 31))?.type === DungeonMapRoom.TYPE_TRAP) { + doorColor = TRAP_DOOR_COLOR + } + if (this.rooms.get((x - 15) + "," + (y - 31))?.type === DungeonMapRoom.TYPE_MINIBOSS) { + doorColor = MINIBOSS_DOOR_COLOR + } + } + if (rotation === 1) { + if (this.rooms.get((x - 31) + "," + (y - 15))?.type === DungeonMapRoom.TYPE_BLOOD) { + doorColor = BLOOD_DOOR_COLOR + } + if (this.rooms.get((x - 31) + "," + (y - 15))?.type === DungeonMapRoom.TYPE_PUZZLE) { + doorColor = PUZZLE_DOOR_COLOR + } + if (this.rooms.get((x - 31) + "," + (y - 15))?.type === DungeonMapRoom.TYPE_TRAP) { + doorColor = TRAP_DOOR_COLOR + } + if (this.rooms.get((x - 31) + "," + (y - 15))?.type === DungeonMapRoom.TYPE_MINIBOSS) { + doorColor = MINIBOSS_DOOR_COLOR + } + if (this.rooms.get((x + 1) + "," + (y - 15))?.type === DungeonMapRoom.TYPE_BLOOD) { + doorColor = BLOOD_DOOR_COLOR + } + if (this.rooms.get((x + 1) + "," + (y - 15))?.type === DungeonMapRoom.TYPE_PUZZLE) { + doorColor = PUZZLE_DOOR_COLOR + } + if (this.rooms.get((x + 1) + "," + (y - 15))?.type === DungeonMapRoom.TYPE_TRAP) { + doorColor = TRAP_DOOR_COLOR + } + if (this.rooms.get((x + 1) + "," + (y - 15))?.type === DungeonMapRoom.TYPE_MINIBOSS) { + doorColor = MINIBOSS_DOOR_COLOR + } + } + + graphics.setColor(doorColor) + + graphics.fillRect(x + (rotation === 0 ? 0 : 1), y + (rotation === 1 ? 0 : 1), rotation === 0 ? 8 : 6, rotation === 1 ? 8 : 6) + + if (rotation === 0) { + DungeonMapRoom.drawUnknownRoom(graphics, x - 15, y + 1) + DungeonMapRoom.drawUnknownRoom(graphics, x - 15, y - 31) + } + if (rotation === 1) { + DungeonMapRoom.drawUnknownRoom(graphics, x - 31, y - 15) + DungeonMapRoom.drawUnknownRoom(graphics, x + 1, y - 15) + } + } + + //render rooms + for (let data of this.rooms.entries()) { + let room = data[1] + room.draw(graphics, this.renderTicks) + } + + graphics.translate(-256 + 32, -256 + 32) + + return image + } + + toImageX(x) { + return (x + 255 - 32) / 256 + } + + toImageY(y) { + return (y + 255 - 32) / 256 + } +} + +export default DungeonMapData
\ No newline at end of file diff --git a/src/features/dungeonMap2/DungeonMapRoom.js b/src/features/dungeonMap2/DungeonMapRoom.js new file mode 100644 index 0000000..d6ee014 --- /dev/null +++ b/src/features/dungeonMap2/DungeonMapRoom.js @@ -0,0 +1,256 @@ +import DungeonRoomStaticData from "./DungeonRoomStaticData" + +const Color = Java.type("java.awt.Color") + +class DungeonMapRoom { + + static TYPE_SPAWN = 0 + static TYPE_NORMAL = 1 + static TYPE_PUZZLE = 2 + static TYPE_MINIBOSS = 3 + static TYPE_FAIRY = 4 + static TYPE_BLOOD = 5 + static TYPE_TRAP = 7 + static TYPE_UNKNOWN = 6 + + static SHAPE_1X1 = 0 + static SHAPE_1X2 = 1 + static SHAPE_1X3 = 2 + static SHAPE_1X4 = 3 + static SHAPE_2X2 = 4 + static SHAPE_L = 5 + + static fromId(roomId, x, y, rotation) { + let data = DungeonRoomStaticData.getDataFromId(roomId) + let type = DungeonMapRoom.TYPE_NORMAL + switch (data.type) { + case "mobs": + type = DungeonMapRoom.TYPE_NORMAL + break + case "miniboss": + type = DungeonMapRoom.TYPE_NORMAL + break + case "spawn": + type = DungeonMapRoom.TYPE_SPAWN + break + case "puzzle": + type = DungeonMapRoom.TYPE_PUZZLE + break + case "gold": + type = DungeonMapRoom.TYPE_MINIBOSS + break + case "fairy": + type = DungeonMapRoom.TYPE_FAIRY + break + case "blood": + type = DungeonMapRoom.TYPE_BLOOD + break + case "trap": + type = DungeonMapRoom.TYPE_TRAP + break + } + + let shape = DungeonMapRoom.SHAPE_1X1 + switch (data.shape) { + case "1x1": + shape = DungeonMapRoom.SHAPE_1X1 + break + case "1x2": + shape = DungeonMapRoom.SHAPE_1X2 + break + case "1x3": + shape = DungeonMapRoom.SHAPE_1X3 + break + case "1x4": + shape = DungeonMapRoom.SHAPE_1X4 + break + case "2x2": + shape = DungeonMapRoom.SHAPE_2X2 + break + case "L": + shape = DungeonMapRoom.SHAPE_L + break + } + return new DungeonMapRoom(type, shape, rotation, x, y, roomId) + } + + /** + * + * @param {Number} type + * @param {Number} shape + * @param {Number} rotation 0-3 + * @param {Number} x + * @param {Number} y + * @param {String} roomId + */ + constructor(type, shape, rotation, x, y, roomId) { + this.type = type + this.shape = shape + this.rotation = rotation + this.roomId = roomId + this.maxSecrets = roomId ? DungeonRoomStaticData.getDataFromId(roomId).secrets : 0 + this.secrets = 0 + + this.checkedState = 0 + + this.location = [x, y] + } + + setSecrets(curr, max) { + if (this.maxSecrets === 0) return + this.maxSecrets = max + this.secrets = curr + } + + getSecrets() { + let checkColor = "&8" + if (this.checkedState === 1) checkColor = "&f" + if (this.checkedState === 2) checkColor = "&a" + return checkColor + this.secrets + "/" + this.maxSecrets + } + + setId(id) { + if (this.roomId !== id) { + this.roomId = id + + let newRoomData = DungeonMapRoom.fromId(id) + this.type = newRoomData.type + this.shape = newRoomData.shape + this.maxSecrets = newRoomData.maxSecrets + } + } + + setCheckedState(state) { } + + /** + * Renders this room onto the given Graphics2D + * @param {Graphics2D} graphics + */ + draw(graphics, renderTicks) { + + let [roomWidth, roomHeight] = this.getRoomWidthHeight() + + let translateX = this.location[0] + 3 + roomWidth / 2 + let translateY = this.location[1] + 3 + roomHeight / 2 + + graphics.translate(translateX, translateY) + + graphics.setColor(this.getRoomRenderColor()) + + switch (this.shape) { + case DungeonMapRoom.SHAPE_1X1: + case DungeonMapRoom.SHAPE_1X2: + case DungeonMapRoom.SHAPE_1X3: + case DungeonMapRoom.SHAPE_1X4: + case DungeonMapRoom.SHAPE_2X2: + graphics.fillRect(-roomWidth / 2 + 3, -roomHeight / 2 + 3, roomWidth - 6, roomHeight - 6) + break; + case DungeonMapRoom.SHAPE_L: + graphics.rotate(this.rotation * Math.PI / 2) + graphics.fillRect(-(26 + 32) / 2, -(26 + 32) / 2, 26, 26 + 32) + graphics.fillRect(-(26 + 32) / 2, -(26 + 32) / 2, 26 + 32, 26) + graphics.rotate(-this.rotation * Math.PI / 2) + break; + } + + graphics.translate(-translateX, -translateY) + + if (renderTicks || this.maxSecrets === 0) { + if (this.checkedState === 1) { + let loc = this.getIconLocation() + graphics.drawImage(whiteCheck, loc[0] - 2, loc[1] - 2, 10, 10, null) + } + if (this.checkedState === 2) { + let loc = this.getIconLocation() + graphics.drawImage(greenCheck, loc[0] - 2, loc[1] - 2, 10, 10, null) + } + } + } + + getRoomWidthHeight() { + let roomWidth = 32 + let roomHeight = 32 + + switch (this.shape) { + case DungeonMapRoom.SHAPE_1X2: + roomWidth = 64 + break; + case DungeonMapRoom.SHAPE_1X3: + roomWidth = 96 + break; + case DungeonMapRoom.SHAPE_1X4: + roomWidth = 128 + break; + case DungeonMapRoom.SHAPE_2X2: + case DungeonMapRoom.SHAPE_L: + roomWidth = 64 + roomHeight = 64 + break; + } + + if (this.rotation === 1 || this.rotation === 3) { + let tmp = roomWidth + roomWidth = roomHeight + roomHeight = tmp + } + + return [roomWidth, roomHeight] + } + + getRoomRenderColor() { + return roomColorMap.get(this.type) + } + + getIconLocation() { + let [width, height] = this.getRoomWidthHeight() + if (this.shape === DungeonMapRoom.SHAPE_L && this.rotation === 0) { + return [this.location[0] + 16, this.location[1] + 16] + } + if (this.shape === DungeonMapRoom.SHAPE_L && this.rotation === 1) { + return [this.location[0] + 16 + 32, this.location[1] + 16] + } + if (this.shape === DungeonMapRoom.SHAPE_L && this.rotation === 2) { + return [this.location[0] + 16 + 31, this.location[1] + 16 + 31] + } + if (this.shape === DungeonMapRoom.SHAPE_L && this.rotation === 2) { + return [this.location[0] + 16, this.location[1] + 16 + 32] + } + + return [this.location[0] + width / 2, this.location[1] + height / 2] + } + + static drawUnknownRoom(graphics, x, y) { + let roomWidth = 32 + let roomHeight = 32 + + let translateX = x + 3 + roomWidth / 2 + let translateY = y + 3 + roomHeight / 2 + + graphics.translate(translateX, translateY) + + graphics.setColor(roomColorMap.get(DungeonMapRoom.TYPE_UNKNOWN)) + + graphics.fillRect(-13, -13, 26, 26) + + graphics.drawImage(questionMark, -4, -7, 8, 14, null) + + graphics.translate(-translateX, -translateY) + } +} + +let roomColorMap = new Map() +roomColorMap.set(DungeonMapRoom.TYPE_SPAWN, new Color(Renderer.color(0, 124, 0, 255))) +roomColorMap.set(DungeonMapRoom.TYPE_NORMAL, new Color(Renderer.color(114, 67, 27, 255))) +roomColorMap.set(DungeonMapRoom.TYPE_PUZZLE, new Color(Renderer.color(178, 76, 216, 255))) +roomColorMap.set(DungeonMapRoom.TYPE_MINIBOSS, new Color(Renderer.color(229, 229, 51, 255))) +roomColorMap.set(DungeonMapRoom.TYPE_FAIRY, new Color(Renderer.color(242, 127, 165, 255))) +roomColorMap.set(DungeonMapRoom.TYPE_BLOOD, new Color(Renderer.color(255, 0, 0, 255))) +roomColorMap.set(DungeonMapRoom.TYPE_TRAP, new Color(Renderer.color(216, 127, 51, 255))) +roomColorMap.set(DungeonMapRoom.TYPE_UNKNOWN, new Color(Renderer.color(65, 65, 65, 255))) + +const greenCheck = new Image("greenCheckVanilla.png", "https://i.imgur.com/h2WM1LO.png").image +const whiteCheck = new Image("whiteCheckVanilla.png", "https://i.imgur.com/hwEAcnI.png").image +const failedRoom = new Image("failedRoomVanilla.png", "https://i.imgur.com/WqW69z3.png").image +const questionMark = new Image("questionMarkVanilla.png", "https://i.imgur.com/1jyxH9I.png").image + +export default DungeonMapRoom
\ No newline at end of file diff --git a/src/features/dungeonMap2/DungeonRoomStaticData.js b/src/features/dungeonMap2/DungeonRoomStaticData.js new file mode 100644 index 0000000..75d5b1e --- /dev/null +++ b/src/features/dungeonMap2/DungeonRoomStaticData.js @@ -0,0 +1,19 @@ +class DungeonRoomStaticData { + constructor() { + this.fullRoomData = JSON.parse(FileLib.read("SoopyV2", "data/roomdata.json")) + + this.idMap = new Map() + this.fullRoomData.forEach((d, i) => { + d.id.forEach(id => { + this.idMap.set(id, i) + }) + this.idMap.set(d.index, i) + }) + } + + getDataFromId(id) { + return this.fullRoomData[this.idMap.get(id)] + } +} + +export default new DungeonRoomStaticData()
\ No newline at end of file diff --git a/src/features/dungeonMap2/index.js b/src/features/dungeonMap2/index.js new file mode 100644 index 0000000..199bc05 --- /dev/null +++ b/src/features/dungeonMap2/index.js @@ -0,0 +1,312 @@ +/// <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() { + if (!this.FeatureManager || !this.FeatureManager.features["dataLoader"]) return false + 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() +}
\ No newline at end of file diff --git a/src/features/dungeonMap2/metadata.json b/src/features/dungeonMap2/metadata.json new file mode 100644 index 0000000..53e7e03 --- /dev/null +++ b/src/features/dungeonMap2/metadata.json @@ -0,0 +1,8 @@ +{ + "name": "Dungeon Map 2", + "description": "WIP", + "isHidden": true, + "isTogglable": true, + "defaultEnabled": false, + "sortA": 1 +}
\ No newline at end of file |