Skip to content

Commit

Permalink
Merge pull request #127 from odtheking/Room-Scanning-Refactor
Browse files Browse the repository at this point in the history
Room scanning refactor
  • Loading branch information
odtheking authored Nov 3, 2024
2 parents 87917e0 + 8b8b416 commit d6550d0
Show file tree
Hide file tree
Showing 24 changed files with 231 additions and 303 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ object EtherWarpHelper : Module(
if (
etherWarpTriggerBot &&
tbClock.hasTimePassed(etherWarpTBDelay) &&
DungeonUtils.currentFullRoom?.waypoints?.any { etherPos.vec?.equal(it.toVec3()) == true } == true &&
DungeonUtils.currentRoom?.waypoints?.any { etherPos.vec?.equal(it.toVec3()) == true } == true &&
mc.thePlayer.usingEtherWarp
) {
tbClock.update()
Expand Down Expand Up @@ -110,7 +110,7 @@ object EtherWarpHelper : Module(
etherWarpHelper &&
mc.thePlayer.usingEtherWarp
) {
val (_, yaw, pitch) = DungeonUtils.currentFullRoom?.waypoints?.mapNotNull {
val (_, yaw, pitch) = DungeonUtils.currentRoom?.waypoints?.mapNotNull {
etherwarpRotateTo(it.toBlockPos()) ?: return@mapNotNull null
}?.minByOrNull {
val (_, yaw, pitch) = it
Expand Down
10 changes: 5 additions & 5 deletions src/main/kotlin/me/odinmain/commands/impl/DevCommand.kt
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ val devCommand = commodore("oddev") {
|DungeonTime: ${DungeonUtils.dungeonTime}
|currentDungeonPlayer: ${DungeonUtils.currentDungeonPlayer.name}, ${DungeonUtils.currentDungeonPlayer.clazz}, ${DungeonUtils.currentDungeonPlayer.isDead}, ${DungeonUtils.isGhost}
|doorOpener: ${DungeonUtils.doorOpener}
|currentRoom: ${DungeonUtils.currentFullRoom?.room?.data?.name}, roomsPassed: ${DungeonUtils.passedRooms.map { it.room.data.name }}
|currentRoom: ${DungeonUtils.currentRoom?.data?.name}, roomsPassed: ${DungeonUtils.passedRooms.map { it.data.name }}
|Teammates: ${DungeonUtils.dungeonTeammates.joinToString { "§${it.clazz.colorCode}${it.name} (${it.clazz} [${it.clazzLvl}])" }}
|TeammatesNoSelf: ${DungeonUtils.dungeonTeammatesNoSelf.map { it.name }}
|LeapTeammates: ${DungeonUtils.leapTeammates.map { it.name }}
Expand Down Expand Up @@ -138,7 +138,7 @@ val devCommand = commodore("oddev") {
}

literal("roomdata").runs {
val room = DungeonUtils.currentFullRoom
val room = DungeonUtils.currentRoom
val roomCenter = getRoomCenter(mc.thePlayer.posX.toInt(), mc.thePlayer.posZ.toInt())
val core = ScanUtils.getCore(roomCenter)
modMessage(
Expand All @@ -147,8 +147,8 @@ val devCommand = commodore("oddev") {
Middle: ${roomCenter.x}, ${roomCenter.z}
Room: ${DungeonUtils.currentRoomName}
Core: $core
Rotation: ${room?.room?.rotation ?: "NONE"}
Positions: ${room?.components?.joinToString { "(${it.x}, ${it.z})" } ?: "None"}
Rotation: ${room?.rotation ?: "NONE"}
Positions: ${room?.roomComponents?.joinToString { "(${it.x}, ${it.z})" } ?: "None"}
${getChatBreak()}
""".trimIndent(), "")
writeToClipboard(core.toString(), "§aCopied $core to clipboard!")
Expand All @@ -160,7 +160,7 @@ val devCommand = commodore("oddev") {
"""
${getChatBreak()}
Middle: $block
Relative Coords: ${DungeonUtils.currentFullRoom?.getRelativeCoords(block.toVec3())?.toString()}
Relative Coords: ${DungeonUtils.currentRoom?.getRelativeCoords(block.toVec3())?.toString()}
${getChatBreak()}
""".trimIndent(), "")
}
Expand Down
5 changes: 2 additions & 3 deletions src/main/kotlin/me/odinmain/events/impl/DungeonEvents.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package me.odinmain.events.impl


import me.odinmain.utils.skyblock.dungeon.tiles.FullRoom
import me.odinmain.utils.skyblock.dungeon.tiles.Room
import net.minecraftforge.fml.common.eventhandler.Event

abstract class DungeonEvents : Event() {

class RoomEnterEvent(val fullRoom: FullRoom?) : DungeonEvents()
class RoomEnterEvent(val room: Room?) : DungeonEvents()
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ object ExtraStats : Module(
modMessage(getCenteredText("§b${extraStats.secretsFound}§r-§6${DungeonUtils.cryptCount}§r-§c${DungeonUtils.deathCount}"), prefix = "")
modMessage(getCenteredText(if (DungeonUtils.dungeonTeammatesNoSelf.isNotEmpty()) DungeonUtils.dungeonTeammatesNoSelf.joinToString(separator = "§r, ") { "§${it.clazz.colorCode}${it.name}" } else "§3Solo"), prefix = "")
modMessage("", prefix = "")
modMessage(getChatBreak(), prefix = "", chatStyle = createClickStyle(ClickEvent.Action.SUGGEST_COMMAND, "Passed rooms: \n${DungeonUtils.passedRooms.joinToString("\n") { "§a${it.room.data.name}" }}"))
modMessage(getChatBreak(), prefix = "", chatStyle = createClickStyle(ClickEvent.Action.SUGGEST_COMMAND, "Passed rooms: \n${DungeonUtils.passedRooms.joinToString("\n") { "§a${it.data.name}" }}"))
}

init {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import me.odinmain.utils.skyblock.*
import me.odinmain.utils.skyblock.dungeon.DungeonUtils
import me.odinmain.utils.skyblock.dungeon.DungeonUtils.getRealCoords
import me.odinmain.utils.skyblock.dungeon.DungeonUtils.getRelativeCoords
import me.odinmain.utils.skyblock.dungeon.tiles.FullRoom
import me.odinmain.utils.skyblock.dungeon.tiles.Room
import net.minecraft.block.BlockSign
import net.minecraft.client.gui.GuiButton
import net.minecraft.client.gui.GuiScreen
Expand Down Expand Up @@ -70,9 +70,9 @@ object DungeonWaypoints : Module(
var timerSetting: Int by SelectorSetting("Timer Type", TimerType.NONE.displayName, TimerType.getArrayList(), description = "Type of route timer you want to place.").withDependency { !waypointType.equalsOneOf(0, 1, 5) && settingsDropDown }

private val resetButton by ActionSetting("Reset Current Room", description = "Resets the waypoints for the current room.") {
val room = DungeonUtils.currentFullRoom ?: return@ActionSetting modMessage("§cRoom not found!")
val room = DungeonUtils.currentRoom ?: return@ActionSetting modMessage("§cRoom not found!")

val waypoints = DungeonWaypointConfig.waypoints.getOrPut(room.room.data.name) { mutableListOf() }
val waypoints = DungeonWaypointConfig.waypoints.getOrPut(room.data.name) { mutableListOf() }
if (waypoints.isEmpty()) return@ActionSetting modMessage("§cCurrent room does not have any waypoints!")
waypoints.clear()
DungeonWaypointConfig.saveConfig()
Expand Down Expand Up @@ -176,7 +176,7 @@ object DungeonWaypoints : Module(
@SubscribeEvent
fun onRender(event: RenderWorldLastEvent) {
if ((DungeonUtils.inBoss || !DungeonUtils.inDungeons) && !LocationUtils.currentArea.isArea(Island.SinglePlayer)) return
val room = DungeonUtils.currentFullRoom ?: return
val room = DungeonUtils.currentRoom ?: return
startProfile("Dungeon Waypoints")
glList = RenderUtils.drawBoxes(room.waypoints, glList, disableDepth)
if (renderTitle) {
Expand All @@ -187,7 +187,7 @@ object DungeonWaypoints : Module(
}

if (debugWaypoint) {
room.components.forEach {
room.roomComponents.forEach {
Renderer.drawBox(Vec3(it.x.toDouble(), 70.0, it.z.toDouble()).toAABB(), Color.GREEN, fillAlpha = 0)
}
}
Expand All @@ -205,7 +205,7 @@ object DungeonWaypoints : Module(
val sr = ScaledResolution(mc)
val pos = reachPosition
val (text, editText) = pos?.add(offset)?.let {
val room = DungeonUtils.currentFullRoom ?: return
val room = DungeonUtils.currentRoom ?: return
val vec = room.getRelativeCoords(it.add(offset).toVec3())
val waypoint = getWaypoints(room).find { it.toVec3().equal(vec) }

Expand All @@ -223,7 +223,7 @@ object DungeonWaypoints : Module(

@SubscribeEvent
fun onMouseInput(event: MouseEvent) {
if (!allowEdits || event.dwheel.sign == 0 || DungeonUtils.currentFullRoom == null) return
if (!allowEdits || event.dwheel.sign == 0 || DungeonUtils.currentRoom == null) return
distance = (distance + event.dwheel.sign).coerceIn(0.0, 100.0)
event.isCanceled = true
}
Expand All @@ -233,7 +233,7 @@ object DungeonWaypoints : Module(
if (mc.thePlayer.usingEtherWarp) {
val pos = EtherWarpHelper.getEtherPos(mc.thePlayer.renderVec, mc.thePlayer.rotationYaw, mc.thePlayer.rotationPitch)
if (pos.succeeded && pos.pos != null) {
if (DungeonUtils.currentFullRoom?.waypoints?.any { pos.vec?.equal(it.toVec3()) == true && (it.type == WaypointType.BLOCKETHERWARP) } == true) {
if (DungeonUtils.currentRoom?.waypoints?.any { pos.vec?.equal(it.toVec3()) == true && (it.type == WaypointType.BLOCKETHERWARP) } == true) {
event.isCanceled = true
return
}
Expand All @@ -246,7 +246,7 @@ object DungeonWaypoints : Module(
val offsetPos = pos.add(offset)
offset = BlockPos(0.0, 0.0, 0.0)
if (isAir(offsetPos) && !allowMidair) return
val room = DungeonUtils.currentFullRoom ?: return
val room = DungeonUtils.currentRoom ?: return
val vec = room.getRelativeCoords(offsetPos.toVec3())
val block = getBlockAt(offsetPos)
val aabb =
Expand Down Expand Up @@ -281,7 +281,7 @@ object DungeonWaypoints : Module(
@SubscribeEvent
fun onNewRoom(event: DungeonEvents.RoomEnterEvent) {
glList = -1
event.fullRoom?.let { setWaypoints(it) }
event.room?.let { setWaypoints(it) }
}

fun DungeonWaypoint.toVec3() = Vec3(x, y, z)
Expand All @@ -299,9 +299,9 @@ object DungeonWaypoints : Module(
/**
* Sets the waypoints for the current room.
*/
fun setWaypoints(curRoom: FullRoom) {
curRoom.waypoints = arrayListOf<DungeonWaypoint>().apply {
DungeonWaypointConfig.waypoints[curRoom.room.data.name]?.let { waypoints ->
fun setWaypoints(curRoom: Room) {
curRoom.waypoints = mutableSetOf<DungeonWaypoint>().apply {
DungeonWaypointConfig.waypoints[curRoom.data.name]?.let { waypoints ->
addAll(waypoints.map { waypoint ->
val vec = curRoom.getRealCoords(waypoint.toVec3())
waypoint.copy(x = vec.xCoord, y = vec.yCoord, z = vec.zCoord)
Expand All @@ -310,9 +310,8 @@ object DungeonWaypoints : Module(
}
}

fun getWaypoints(room: FullRoom) : MutableList<DungeonWaypoint> {
return DungeonWaypointConfig.waypoints.getOrPut(room.room.data.name) { mutableListOf() }
}
fun getWaypoints(room: Room) : MutableList<DungeonWaypoint> =
DungeonWaypointConfig.waypoints.getOrPut(room.data.name) { mutableListOf() }
}

object GuiSign : GuiScreen() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import me.odinmain.utils.*
import me.odinmain.utils.skyblock.devMessage
import me.odinmain.utils.skyblock.dungeon.DungeonUtils
import me.odinmain.utils.skyblock.dungeon.DungeonUtils.getRelativeCoords
import me.odinmain.utils.skyblock.dungeon.tiles.FullRoom
import me.odinmain.utils.skyblock.dungeon.tiles.Room
import me.odinmain.utils.skyblock.modMessage
import net.minecraft.block.BlockChest
import net.minecraft.block.state.IBlockState
Expand All @@ -30,7 +30,7 @@ object SecretWaypoints {
private var lastClicked: BlockPos? = null

fun onLocked() {
val room = DungeonUtils.currentFullRoom ?: return
val room = DungeonUtils.currentRoom ?: return
getWaypoints(room).find { wp -> wp.toVec3().equal(room.getRelativeCoords(lastClicked?.toVec3() ?: return)) && wp.secret && wp.clicked }?.let {
it.clicked = false
setWaypoints(room)
Expand All @@ -53,7 +53,7 @@ object SecretWaypoints {
val etherpos = lastEtherPos?.pos?.toVec3() ?: return
if (System.currentTimeMillis() - lastEtherTime > 1000) return
if (Vec3(packet.x, packet.y, packet.z).distanceTo(etherpos) > 3) return
val room = DungeonUtils.currentFullRoom ?: return
val room = DungeonUtils.currentRoom ?: return
val waypoints = getWaypoints(room)
waypoints.find { wp -> wp.toVec3().equal(room.getRelativeCoords(etherpos)) && wp.type == WaypointType.ETHERWARP }?.let {
handleTimer(it, waypoints, room)
Expand All @@ -66,7 +66,7 @@ object SecretWaypoints {
}

private fun clickSecret(pos: Vec3, distance: Int, block: IBlockState? = null) {
val room = DungeonUtils.currentFullRoom ?: return
val room = DungeonUtils.currentRoom ?: return
val vec = room.getRelativeCoords(pos)

val waypoints = getWaypoints(room)
Expand Down Expand Up @@ -94,12 +94,12 @@ object SecretWaypoints {
room.forEach { it.clicked = false }
}

DungeonUtils.currentFullRoom?.let { setWaypoints(it) }
DungeonUtils.currentRoom?.let { setWaypoints(it) }
glList = -1
}

fun onPosUpdate(pos: Vec3) {
val room = DungeonUtils.currentFullRoom ?: return
val room = DungeonUtils.currentRoom ?: return

val waypoints = getWaypoints(room)
waypoints.find { wp -> wp.toVec3().addVec(y = 0.5).distanceTo(room.getRelativeCoords(pos)) <= 2 && wp.type == WaypointType.MOVE && !wp.clicked }?.let { wp ->
Expand All @@ -111,7 +111,7 @@ object SecretWaypoints {
}
}

private fun handleTimer(waypoint: DungeonWaypoint, waypoints: MutableList<DungeonWaypoint>, room: FullRoom): Boolean {
private fun handleTimer(waypoint: DungeonWaypoint, waypoints: MutableList<DungeonWaypoint>, room: Room): Boolean {
return when {
waypoint.timer == TimerType.START && (routeTimer?.let { System.currentTimeMillis() - it >= 2000 } == true || routeTimer == null) -> {
modMessage("${routeTimer?.let { "§2Route timer restarted" } ?: "§aRoute timer started"} ")
Expand All @@ -121,7 +121,7 @@ object SecretWaypoints {
true
}
waypoint.timer == TimerType.END && routeTimer != null -> {
modMessage("§aRoute took §c${routeTimer?.let { (System.currentTimeMillis() - it)/1000.0 }?.round(2)}§as to complete! §aRoom: §e${room.room.data.name}§a, §aCheckpoints collected: §9${checkpoints}§a${waypoint.title?.let { name -> ", Route: §d$name" } ?: "."}")
modMessage("§aRoute took §c${routeTimer?.let { (System.currentTimeMillis() - it)/1000.0 }?.round(2)}§as to complete! §aRoom: §e${room.data.name}§a, §aCheckpoints collected: §9${checkpoints}§a${waypoint.title?.let { name -> ", Route: §d$name" } ?: "."}")
routeTimer = null
checkpoints = 0
true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import me.odinmain.utils.*
import me.odinmain.utils.render.Color
import me.odinmain.utils.render.Renderer
import me.odinmain.utils.skyblock.dungeon.DungeonUtils
import me.odinmain.utils.skyblock.dungeon.DungeonUtils.getRealCoords
import me.odinmain.utils.skyblock.getBlockIdAt
import net.minecraft.init.Blocks
import net.minecraft.util.BlockPos
Expand Down Expand Up @@ -38,15 +39,13 @@ object BeamsSolver {

private var currentLanternPairs = ConcurrentHashMap<BlockPos, Pair<BlockPos, Color>>()

fun onRoomEnter(event: RoomEnterEvent) {
val room = event.fullRoom?.room ?: return // <-- orb = orb.orb
if (room.data.name != "Creeper Beams") return reset()
fun onRoomEnter(event: RoomEnterEvent) = with(event.room) {
if (this?.data?.name != "Creeper Beams") return reset()

currentLanternPairs.clear()
lanternPairs.forEach {
val pos = room.vec2.addRotationCoords(room.rotation, x = it[0], z = it[2]).let { vec -> BlockPos(vec.x, it[1], vec.z) }

val pos2 = room.vec2.addRotationCoords(room.rotation, x = it[3], z = it[5]).let { vec -> BlockPos(vec.x, it[4], vec.z) }
val pos = getRealCoords(it[0], it[1], it[2])
val pos2 = getRealCoords(it[3], it[4], it[5])

if (getBlockIdAt(pos) == 169 && getBlockIdAt(pos2) == 169)
currentLanternPairs[pos] = pos2 to colors[currentLanternPairs.size]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import me.odinmain.utils.skyblock.*
import me.odinmain.utils.skyblock.dungeon.*
import net.minecraft.entity.item.EntityArmorStand
import net.minecraft.util.AxisAlignedBB
import net.minecraft.util.BlockPos
import kotlin.collections.set

object BlazeSolver {
Expand All @@ -20,7 +19,7 @@ object BlazeSolver {
private var lastBlazeCount = 10

fun getBlaze() {
val room = DungeonUtils.currentFullRoom?.room ?: return
val room = DungeonUtils.currentRoom ?: return
if (!DungeonUtils.inDungeons || !room.data.name.equalsOneOf("Lower Blaze", "Higher Blaze")) return
val hpMap = mutableMapOf<EntityArmorStand, Int>()
blazes.clear()
Expand All @@ -30,8 +29,9 @@ object BlazeSolver {
hpMap[entity] = hp
blazes.add(entity)
}
blazes.sortBy { hpMap[it] }
if (getBlockIdAt(BlockPos(room.x + 1, 118, room.z)) != 4) blazes.reverse()

if (room.data.name == "Lower Blaze") blazes.sortBy { hpMap[it] }
else blazes.sortByDescending { hpMap[it] }
}

fun onRenderWorld() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,18 @@ object BoulderSolver {
}

fun onRoomEnter(event: DungeonEvents.RoomEnterEvent) {
val room = event.fullRoom?.room ?: return reset()
val room = event.room ?: return reset()
if (room.data.name != "Boulder") return reset()
val roomComponent = room.roomComponents.firstOrNull() ?: return reset()
var str = ""
for (z in -3..2) {
for (x in -3..3) {
room.vec2.addRotationCoords(room.rotation, x * 3, z * 3).let { str += if (getBlockIdAt(BlockPos(it.x, 66, it.z)) == 0) "0" else "1" }
roomComponent.vec3.addRotationCoords(room.rotation, x * 3, z * 3).let { str += if (getBlockIdAt(it.xCoord, 66.0, it.zCoord) == 0) "0" else "1" }
}
}
currentPositions = solutions[str]?.map { sol ->
val render = room.vec2.addRotationCoords(room.rotation, sol[0], sol[1]).let { BlockPos(it.x, 65, it.z) }
val click = room.vec2.addRotationCoords(room.rotation, sol[2], sol[3]).let { BlockPos(it.x, 65, it.z) }
val render = roomComponent.vec3.addRotationCoords(room.rotation, sol[0], sol[1]).let { BlockPos(it.xCoord, 65.0, it.zCoord) }
val click = roomComponent.vec3.addRotationCoords(room.rotation, sol[2], sol[3]).let { BlockPos(it.xCoord, 65.0, it.zCoord) }
BoxPosition(render, click)
}?.toMutableList() ?: return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import me.odinmain.utils.render.Color
import me.odinmain.utils.render.Renderer
import me.odinmain.utils.skyblock.IceFillFloors
import me.odinmain.utils.skyblock.dungeon.DungeonUtils
import me.odinmain.utils.skyblock.dungeon.DungeonUtils.getRealCoords
import me.odinmain.utils.skyblock.dungeon.tiles.Rotations
import me.odinmain.utils.skyblock.isAir
import me.odinmain.utils.skyblock.modMessage
Expand Down Expand Up @@ -41,11 +42,10 @@ object IceFillSolver {
Renderer.draw3DLine(currentPatterns, color = color, depth = true)
}

fun onRoomEnter(event: RoomEnterEvent) {
val room = event.fullRoom?.room ?: return
if (room.data.name != "Ice Fill" || currentPatterns.isNotEmpty()) return
fun onRoomEnter(event: RoomEnterEvent) = with (event.room) {
if (this?.data?.name != "Ice Fill" || currentPatterns.isNotEmpty()) return

scanAllFloors(room.vec3.addRotationCoords(room.rotation, 8), room.rotation)
scanAllFloors(getRealCoords(15, 70, 7).toVec3(), rotation)
}

private fun scanAllFloors(pos: Vec3, rotation: Rotations) {
Expand Down
Loading

0 comments on commit d6550d0

Please sign in to comment.