Skip to content

Commit

Permalink
dungeon waypoints based on rotation clay position, migration might wo…
Browse files Browse the repository at this point in the history
…rk, might not
  • Loading branch information
freebonsai committed Apr 28, 2024
1 parent 1eeaa99 commit 5ecde7a
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 55 deletions.
1 change: 1 addition & 0 deletions odinmain/src/main/kotlin/me/odinmain/OdinMain.kt
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ object OdinMain {
launch { WaypointConfig.loadConfig() }
launch { DungeonWaypointConfig.loadConfig() }
launch { PBConfig.loadConfig() }
launch { DungeonWaypointConfigCLAY }
}

fun loadComplete() = runBlocking {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
package me.odinmain.config

import com.google.gson.GsonBuilder
import com.google.gson.JsonIOException
import com.google.gson.JsonSyntaxException
import com.google.gson.*
import com.google.gson.reflect.TypeToken
import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import kotlinx.coroutines.*
import me.odinmain.OdinMain.mc
import me.odinmain.features.impl.dungeon.DungeonWaypoints.DungeonWaypoint
import me.odinmain.utils.render.Color
import java.io.File
import java.io.IOException

@Deprecated("DEPRECATED CONFIG, ONLY USED FOR MIGRATION, REMOVE AT A LATER DATE!")
object DungeonWaypointConfig {

private val gson = GsonBuilder().registerTypeAdapter(Color::class.java, Color.ColorSerializer()).setPrettyPrinting().create()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package me.odinmain.config

import com.google.gson.*
import com.google.gson.reflect.TypeToken
import kotlinx.coroutines.*
import me.odinmain.OdinMain.mc
import me.odinmain.features.impl.dungeon.DungeonWaypoints.DungeonWaypoint
import me.odinmain.utils.render.Color
import java.io.File
import java.io.IOException

object DungeonWaypointConfigCLAY {
private val gson = GsonBuilder().registerTypeAdapter(Color::class.java, Color.ColorSerializer()).setPrettyPrinting().create()

var waypoints: MutableMap<String, MutableList<DungeonWaypoint>> = mutableMapOf()

private val configFile = File(mc.mcDataDir, "config/odin/dungeon-waypoint-config-CLAY.json").apply {
try {
createNewFile()
} catch (e: Exception) {
println("Error initializing module config")
}
}

fun loadConfig() {
try {
with(configFile.bufferedReader().use { it.readText() }) {
if (this.isEmpty()) return

waypoints = gson.fromJson(
this,
object : TypeToken<MutableMap<String, MutableList<DungeonWaypoint>>>() {}.type
)
}
} catch (e: JsonSyntaxException) {
println("Error parsing configs.")
println(e.message)
e.printStackTrace()
} catch (e: JsonIOException) {
println("Error reading configs.")
}
}

@OptIn(DelicateCoroutinesApi::class)
fun saveConfig() {
GlobalScope.launch(Dispatchers.IO) {
try {
configFile.bufferedWriter().use {
it.write(gson.toJson(waypoints))
}
} catch (e: IOException) {
println("Error saving Waypoint config.")
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package me.odinmain.features.impl.dungeon

import me.odinmain.config.DungeonWaypointConfig
import me.odinmain.config.DungeonWaypointConfigCLAY
import me.odinmain.events.impl.ClickEvent
import me.odinmain.events.impl.EnteredDungeonRoomEvent
import me.odinmain.features.Category
Expand All @@ -10,26 +10,15 @@ import me.odinmain.features.settings.Setting.Companion.withDependency
import me.odinmain.features.settings.impl.*
import me.odinmain.ui.clickgui.util.ColorUtil.withAlpha
import me.odinmain.utils.*
import me.odinmain.utils.render.Color
import me.odinmain.utils.render.RenderUtils
import me.odinmain.utils.render.*
import me.odinmain.utils.render.RenderUtils.bind
import me.odinmain.utils.render.RenderUtils.invoke
import me.odinmain.utils.render.Renderer
import me.odinmain.utils.render.scale
import me.odinmain.utils.skyblock.devMessage
import me.odinmain.utils.skyblock.*
import me.odinmain.utils.skyblock.dungeon.DungeonUtils
import me.odinmain.utils.skyblock.getBlockAt
import me.odinmain.utils.skyblock.isAir
import me.odinmain.utils.skyblock.modMessage
import net.minecraft.client.gui.GuiButton
import net.minecraft.client.gui.GuiScreen
import net.minecraft.client.gui.GuiTextField
import net.minecraft.client.gui.ScaledResolution
import net.minecraft.client.gui.*
import net.minecraft.client.renderer.GlStateManager
import net.minecraft.client.renderer.vertex.DefaultVertexFormats
import net.minecraft.util.AxisAlignedBB
import net.minecraft.util.BlockPos
import net.minecraft.util.Vec3
import net.minecraft.util.*
import net.minecraftforge.client.event.RenderGameOverlayEvent
import net.minecraftforge.client.event.RenderWorldLastEvent
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
Expand Down Expand Up @@ -57,11 +46,11 @@ object DungeonWaypoints : Module(
private val resetButton: () -> Unit by ActionSetting("Reset Current Room") {
val room = DungeonUtils.currentRoom ?: return@ActionSetting modMessage("Room not found!!!")

val waypoints = DungeonWaypointConfig.waypoints.getOrPut(room.room.data.name) { mutableListOf() }
val waypoints = DungeonWaypointConfigCLAY.waypoints.getOrPut(room.room.data.name) { mutableListOf() }
if (!waypoints.removeAll { true }) return@ActionSetting modMessage("Current room does not have any waypoints!")

DungeonWaypointConfig.saveConfig()
DungeonUtils.setWaypoints()
DungeonWaypointConfigCLAY.saveConfig()
DungeonUtils.setWaypoints(room)
glList = -1
modMessage("Successfully reset current room!")
}
Expand All @@ -84,7 +73,7 @@ object DungeonWaypoints : Module(

@SubscribeEvent
fun onRender(event: RenderWorldLastEvent) {
if (DungeonUtils.inBoss || !DungeonUtils.inDungeons) return
//if (DungeonUtils.inBoss || !DungeonUtils.inDungeons) return
val room = DungeonUtils.currentRoom ?: return
startProfile("Dungeon Waypoints")
drawBoxes(room.waypoints)
Expand Down Expand Up @@ -113,13 +102,12 @@ object DungeonWaypoints : Module(
val pos = mc.objectMouseOver?.blockPos ?: return
if (!allowEdits || isAir(pos)) return
val room = DungeonUtils.currentRoom ?: return
val distinct = room.positions.distinct().minByOrNull { it.core } ?: return
val vec = Vec3(pos).subtractVec(x = distinct.x, z = distinct.z).rotateToNorth(room.room.rotation)
val vec = Vec3(pos).subtractVec(x = room.clayPos.x, z = room.clayPos.z).rotateToNorth(room.room.rotation)
val aabb =
if (useBlockSize) getBlockAt(pos).getSelectedBoundingBox(mc.theWorld, BlockPos(0, 0, 0)).expand(0.002, 0.002, 0.002) ?: return
else AxisAlignedBB(.5 - (size / 2), .5 - (size / 2), .5 - (size / 2), .5 + (size / 2), .5 + (size / 2), .5 + (size / 2)).expand(0.002, 0.002, 0.002)

val waypoints = DungeonWaypointConfig.waypoints.getOrPut(room.room.data.name) { mutableListOf() }
val waypoints = DungeonWaypointConfigCLAY.waypoints.getOrPut(room.room.data.name) { mutableListOf() }

val color = when (colorPallet) {
0 -> color
Expand All @@ -134,8 +122,6 @@ object DungeonWaypoints : Module(
GuiSign.setCallback { enteredText ->
waypoints.removeIf { it.toVec3().equal(vec) }
waypoints.add(DungeonWaypoint(vec.xCoord, vec.yCoord, vec.zCoord, color.copy(), filled, !throughWalls, aabb, enteredText))
DungeonWaypointConfig.saveConfig()
DungeonUtils.setWaypoints()
}
mc.displayGuiScreen(GuiSign)
} else if (waypoints.removeIf { it.toVec3().equal(vec) }) {
Expand All @@ -144,8 +130,8 @@ object DungeonWaypoints : Module(
waypoints.add(DungeonWaypoint(vec.xCoord, vec.yCoord, vec.zCoord, color.copy(), filled, !throughWalls, aabb, ""))
devMessage("Added waypoint at $vec")
}
DungeonWaypointConfig.saveConfig()
DungeonUtils.setWaypoints()
DungeonWaypointConfigCLAY.saveConfig()
DungeonUtils.setWaypoints(room)
glList = -1
}

Expand Down Expand Up @@ -219,7 +205,7 @@ object DungeonWaypoints : Module(
if (box.filled) {
GlStateManager.color(box.color.r / 255f, box.color.g / 255f, box.color.b / 255f, box.color.alpha.coerceAtMost(.8f))
RenderUtils.worldRenderer {
begin(7, DefaultVertexFormats.POSITION_NORMAL)
begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_NORMAL)
pos(aabb.minX, aabb.maxY, aabb.minZ).normal(0f, 0f, -1f).endVertex()
pos(aabb.maxX, aabb.maxY, aabb.minZ).normal(0f, 0f, -1f).endVertex()
pos(aabb.maxX, aabb.minY, aabb.minZ).normal(0f, 0f, -1f).endVertex()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@ import me.odinmain.features.impl.render.ClickGUIModule.devMessages
import me.odinmain.features.impl.render.DevPlayers
import net.minecraft.event.ClickEvent
import net.minecraft.event.HoverEvent
import net.minecraft.util.ChatComponentText
import net.minecraft.util.ChatStyle
import net.minecraft.util.EnumChatFormatting
import net.minecraft.util.*
import net.minecraftforge.client.ClientCommandHandler


Expand Down Expand Up @@ -62,7 +60,7 @@ fun sendChatMessage(message: Any) {
* @param prefix If `true`, adds a prefix to the message.
* @param chatStyle Optional chat style to be applied to the message.
*/
fun modMessage(message: Any, prefix: Boolean = true, chatStyle: ChatStyle? = null) {
fun modMessage(message: Any?, prefix: Boolean = true, chatStyle: ChatStyle? = null) {
if (mc.thePlayer == null) return
val chatComponent = ChatComponentText(if (prefix) "§3Odin §8»§r $message" else message.toString())
chatStyle?.let { chatComponent.setChatStyle(it) } // Set chat style using setChatStyle method
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package me.odinmain.utils.skyblock.dungeon
import com.google.common.collect.ComparisonChain
import me.odinmain.OdinMain.mc
import me.odinmain.config.DungeonWaypointConfig
import me.odinmain.config.DungeonWaypointConfigCLAY
import me.odinmain.events.impl.EnteredDungeonRoomEvent
import me.odinmain.features.impl.dungeon.DungeonWaypoints.DungeonWaypoint
import me.odinmain.features.impl.dungeon.DungeonWaypoints.toVec3
Expand All @@ -23,13 +24,10 @@ import net.minecraft.client.network.NetworkPlayerInfo
import net.minecraft.entity.player.EntityPlayer
import net.minecraft.init.Blocks
import net.minecraft.tileentity.TileEntitySkull
import net.minecraft.util.BlockPos
import net.minecraft.util.EnumFacing
import net.minecraft.util.ResourceLocation
import net.minecraft.util.*
import net.minecraft.world.WorldSettings
import net.minecraftforge.event.entity.living.LivingEvent
import net.minecraftforge.event.world.WorldEvent
import net.minecraftforge.event.world.WorldEvent.Load
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent

object DungeonUtils {
Expand All @@ -44,7 +42,7 @@ object DungeonUtils {
inline val cryptsCount get() = currentDungeon?.cryptsCount ?: 0
inline val deathCount get() = currentDungeon?.deathCount ?: 0

data class FullRoom(val room: Room, val positions: List<ExtraRoom>, var waypoints: List<DungeonWaypoint>)
data class FullRoom(val room: Room, var clayPos: BlockPos, val positions: List<ExtraRoom>, var waypoints: List<DungeonWaypoint>)
data class ExtraRoom(val x: Int, val z: Int, val core: Int)
private var lastRoomPos: Pair<Int, Int> = Pair(0, 0)
var currentRoom: FullRoom? = null
Expand Down Expand Up @@ -105,33 +103,48 @@ object DungeonUtils {

val room = scanRoom(xPos, zPos) ?: return
val positions = room.let { findRoomTilesRecursively(it.x, it.z, it, mutableSetOf()) }
currentRoom = FullRoom(room, positions, emptyList())
currentRoom = FullRoom(room, BlockPos(0,0,0), positions, emptyList())
currentRoom?.let {
val topLayer = getTopLayerOfRoom(it.positions.first().x, it.positions.first().z)
it.room.rotation = Rotations.entries.dropLast(1).find { rotation ->
it.positions.any { pos ->
getBlockIdAt(pos.x + rotation.x, topLayer, pos.z + rotation.z) == 159 &&
EnumFacing.HORIZONTALS.all { facing -> getBlockIdAt(pos.x + rotation.x + facing.frontOffsetX, topLayer, pos.z + rotation.z + facing.frontOffsetZ).equalsOneOf(159, 0) }
val blockPos = BlockPos(pos.x + rotation.x, topLayer, pos.z + rotation.z)
val isCorrectClay = getBlockIdAt(blockPos) == 159 &&
EnumFacing.HORIZONTALS.all { facing -> getBlockIdAt(blockPos.add(facing.frontOffsetX, 0, facing.frontOffsetZ)).equalsOneOf(159, 0) }
if (isCorrectClay) it.clayPos = blockPos
return@any isCorrectClay
}
} ?: Rotations.NONE
devMessage("Found rotation ${it.room.rotation}")
devMessage("Found rotation ${it.room.rotation}, clay pos: ${it.clayPos}")
setWaypoints(it)
EnteredDungeonRoomEvent(it).postAndCatch()
}
setWaypoints()
EnteredDungeonRoomEvent(currentRoom).postAndCatch()
}

/**
* Sets the waypoints for the current room.
* this code is way too much list manipulation, but it works
*/
fun setWaypoints() {
val curRoom = currentRoom ?: return
fun setWaypoints(curRoom: FullRoom) {
val room = curRoom.room
val distinct = curRoom.positions.distinct().minByOrNull { it.core } ?: return
curRoom.waypoints = mutableListOf<DungeonWaypoint>().apply {
// THIS IS FOR MIGRATION FROM CONFIGS ON "ALPHA" RELEASES (VERSIONS GOTTEN FROM GITHUB AFTER 1.2.5.BETA4
DungeonWaypointConfig.waypoints[room.data.name]?.let { waypoints ->
val distinct = curRoom.positions.distinct().minByOrNull { it.core } ?: return
waypoints.forEach { waypoint ->
val vecBasedOnClay = waypoint.toVec3().rotateToNorth(room.rotation).addVec(x = distinct.x, z = distinct.z).subtractVec(x = curRoom.clayPos.x, z = curRoom.clayPos.z).rotateAroundNorth(room.rotation)
modMessage(vecBasedOnClay)
DungeonWaypointConfigCLAY.waypoints.getOrPut(room.data.name) { mutableListOf() }.add(
DungeonWaypoint(vecBasedOnClay.xCoord, vecBasedOnClay.yCoord, vecBasedOnClay.zCoord, waypoint.color, waypoint.filled, waypoint.depth, waypoint.aabb, waypoint.title)
)
DungeonWaypointConfigCLAY.saveConfig()
DungeonWaypointConfig.saveConfig()
}
}
DungeonWaypointConfig.waypoints[room.data.name]?.clear()

DungeonWaypointConfigCLAY.waypoints[room.data.name]?.let { waypoints ->
addAll(waypoints.map { waypoint ->
val vec = waypoint.toVec3().rotateAroundNorth(room.rotation).addVec(x = distinct.x, z = distinct.z)
val vec = waypoint.toVec3().rotateAroundNorth(room.rotation).addVec(x = curRoom.clayPos.x, z = curRoom.clayPos.z)
DungeonWaypoint(vec.xCoord, vec.yCoord, vec.zCoord, waypoint.color, waypoint.filled, waypoint.depth, waypoint.aabb, waypoint.title)
})
}
Expand Down

0 comments on commit 5ecde7a

Please sign in to comment.