diff options
Diffstat (limited to 'features')
-rw-r--r-- | features/dungeonMap/index.js | 3 | ||||
-rw-r--r-- | features/dungeonMap2/DungeonMapData.js | 452 | ||||
-rw-r--r-- | features/dungeonMap2/DungeonMapRoom.js | 142 | ||||
-rw-r--r-- | features/dungeonMap2/index.js | 139 |
4 files changed, 710 insertions, 26 deletions
diff --git a/features/dungeonMap/index.js b/features/dungeonMap/index.js index 4befbbf..7045c81 100644 --- a/features/dungeonMap/index.js +++ b/features/dungeonMap/index.js @@ -701,7 +701,7 @@ class DungeonMap extends Feature { roomWidth1++ } let roomWidth = Math.floor(Math.max(roomWidth1, roomWidth2) * 5 / 4) - // console.log(roomWidth) + this.mapScale = 32 / roomWidth let mortLocationOnMap roomOffsets = [rx % roomWidth - 3, ry % roomWidth - 3] @@ -813,6 +813,7 @@ class DungeonMap extends Feature { if (mortLocationOnMap && this.mortLocation) { this.offset = [mortLocationOnMap[0] - this.mortLocation[0] / this.mapScale, mortLocationOnMap[1] - this.mortLocation[1] / this.mapScale] // this.renderImage.setRGB(mortLocationOnMap[0], mortLocationOnMap[1], Renderer.color(255, 0, 0)) + ChatLib.chat(roomWidth + " " + this.offset.join(", ")) } } diff --git a/features/dungeonMap2/DungeonMapData.js b/features/dungeonMap2/DungeonMapData.js index 15ffcca..9a67c11 100644 --- a/features/dungeonMap2/DungeonMapData.js +++ b/features/dungeonMap2/DungeonMapData.js @@ -1,45 +1,371 @@ -import { m } from "../../../mappings/mappings" +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.greenRoom = undefined + 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.greenRoom = locstr + this.greenRoomCoords = [x, y] } - console.log(room.type) 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) { - this.image.getTexture()[m.deleteGlTexture]() + if (this.oldImage) this.oldImage.getTexture()[m.deleteGlTexture]() + this.oldImage = this.image this.image = undefined } } @@ -50,10 +376,33 @@ class DungeonMapData { 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} */ @@ -61,20 +410,105 @@ class DungeonMapData { //create 256x256 image let image = new BufferedImage(256, 256, BufferedImage.TYPE_INT_ARGB) - //if green room data not found yet then map should be empty - if (!this.greenRoom) return image - //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, 256, 256) + 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/features/dungeonMap2/DungeonMapRoom.js b/features/dungeonMap2/DungeonMapRoom.js index 10f26e2..5b1dc1a 100644 --- a/features/dungeonMap2/DungeonMapRoom.js +++ b/features/dungeonMap2/DungeonMapRoom.js @@ -10,6 +10,7 @@ class DungeonMapRoom { static TYPE_MINIBOSS = 3 static TYPE_FAIRY = 4 static TYPE_BLOOD = 5 + static TYPE_TRAP = 7 static TYPE_UNKNOWN = 6 static SHAPE_1X1 = 0 @@ -44,6 +45,9 @@ class DungeonMapRoom { case "blood": type = DungeonMapRoom.TYPE_BLOOD break + case "trap": + type = DungeonMapRoom.TYPE_TRAP + break } let shape = DungeonMapRoom.SHAPE_1X1 @@ -84,42 +88,162 @@ class DungeonMapRoom { 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) { - this.roomId = 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, xOff, yOff) { + 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()) + graphics.rotate(this.rotation * Math.PI / 2) switch (this.shape) { case DungeonMapRoom.SHAPE_1X1: - graphics.fillRect(this.location[0] + xOff + 3, this.location[1] + yOff + 3, 26, 26) + graphics.fillRect(-13, -13, 26, 26) break; case DungeonMapRoom.SHAPE_1X2: - graphics.fillRect(this.location[0] + xOff + 3, this.location[1] + yOff + 3, 26 + 32, 26) + graphics.fillRect(-(26 + 32) / 2, -13, 26 + 32, 26) break; case DungeonMapRoom.SHAPE_1X3: - graphics.fillRect(this.location[0] + xOff + 3, this.location[1] + yOff + 3, 26 + 64, 26) + graphics.fillRect(-(26 + 64) / 2, -13, 26 + 64, 26) break; case DungeonMapRoom.SHAPE_1X4: - graphics.fillRect(this.location[0] + xOff + 3, this.location[1] + yOff + 3, 26 + 96, 26) + graphics.fillRect(-(26 + 96) / 2, -13, 26 + 96, 26) + break; + case DungeonMapRoom.SHAPE_2X2: + graphics.fillRect(-(26 + 32) / 2, -(26 + 32) / 2, 26 + 32, 26 + 32) + break; + case DungeonMapRoom.SHAPE_L: + graphics.fillRect(-(26 + 32) / 2, -(26 + 32) / 2, 26, 26 + 32) + graphics.fillRect(-(26 + 32) / 2, -(26 + 32) / 2, 26 + 32, 26) break; } + graphics.rotate(-this.rotation * Math.PI / 2) + + 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() @@ -129,6 +253,12 @@ roomColorMap.set(DungeonMapRoom.TYPE_PUZZLE, new Color(Renderer.color(178, 76, 2 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/features/dungeonMap2/index.js b/features/dungeonMap2/index.js index c807e85..1ec9cc0 100644 --- a/features/dungeonMap2/index.js +++ b/features/dungeonMap2/index.js @@ -5,8 +5,12 @@ 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 AlphaComposite = Java.type("java.awt.AlphaComposite") +const DefaultVertexFormats = Java.type("net.minecraft.client.renderer.vertex.DefaultVertexFormats") +const MCTessellator = Java.type("net.minecraft.client.renderer.Tessellator") class DungeonMap extends Feature { constructor() { @@ -18,53 +22,165 @@ class DungeonMap extends Feature { new SettingBase("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 + this.defaultPlayerImage = renderLibs.getImage("https://crafatar.com/avatars/dc8c39647b294e03ae9ed13ebd65dd29?size=8", true) + + 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()) { - this.lastRoomId = undefined - this.currentDungeon = undefined + 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) { + if (roomid !== this.lastRoomId && Date.now() - this.lastChange > 500) { this.lastRoomId = roomid let roomWorldData = this.getRoomWorldData() - this.currentDungeon.setRoom(roomWorldData.x, roomWorldData.y, roomWorldData.rotation, roomid) + + 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) { - let x = 10 - let y = 10 - let size = 100 + 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() @@ -107,8 +223,8 @@ class DungeonMap extends Feature { if (one === 0 && three === 0) return 0 if (two === 0 && three === 0) return 1 - if (one === 0 && four === 0) return 2 - if (two === 0 && four === 0) return 3//3 IS SO TOXIK HGOLY HEL I HATE L SHAPE ROOMS WHY DO THIS TO ME + 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 @@ -179,6 +295,9 @@ class DungeonMap extends Feature { 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) |