Skip to content

Commit

Permalink
chore: refactor again
Browse files Browse the repository at this point in the history
  • Loading branch information
My-Name-Is-Jeff committed Mar 2, 2024
1 parent e6456c5 commit a3adc32
Show file tree
Hide file tree
Showing 13 changed files with 72 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import gg.skytils.skytilsmod.core.DataFetcher
import gg.skytils.skytilsmod.core.PersistentSave
import gg.skytils.skytilsmod.core.UpdateChecker
import gg.skytils.skytilsmod.features.impl.dungeons.cataclysmicmap.CataclysmicMap
import gg.skytils.skytilsmod.features.impl.dungeons.cataclysmicmap.features.dungeon.DungeonScan
import gg.skytils.skytilsmod.features.impl.dungeons.cataclysmicmap.handlers.DungeonScanner
import gg.skytils.skytilsmod.features.impl.dungeons.cataclysmicmap.utils.ScanUtils
import gg.skytils.skytilsmod.features.impl.events.GriffinBurrows
import gg.skytils.skytilsmod.features.impl.handlers.MayorInfo
Expand Down Expand Up @@ -316,7 +316,7 @@ object SkytilsCommand : BaseCommand("skytils", listOf("st")) {
// Scans the dungeon
"scan" -> {
CataclysmicMap.reset()
DungeonScan.scan()
DungeonScanner.scan()
}
// Copies room data or room core to clipboard
"roomdata" -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ import gg.skytils.skytilsmod.features.impl.dungeons.cataclysmicmap.core.Cataclys
import gg.skytils.skytilsmod.features.impl.dungeons.cataclysmicmap.core.map.Door
import gg.skytils.skytilsmod.features.impl.dungeons.cataclysmicmap.core.map.DoorType
import gg.skytils.skytilsmod.features.impl.dungeons.cataclysmicmap.core.map.RoomState
import gg.skytils.skytilsmod.features.impl.dungeons.cataclysmicmap.features.dungeon.DungeonInfo
import gg.skytils.skytilsmod.features.impl.dungeons.cataclysmicmap.features.dungeon.DungeonScan
import gg.skytils.skytilsmod.features.impl.dungeons.cataclysmicmap.features.dungeon.MapUpdate
import gg.skytils.skytilsmod.features.impl.dungeons.cataclysmicmap.handlers.DungeonInfo
import gg.skytils.skytilsmod.features.impl.dungeons.cataclysmicmap.handlers.DungeonScanner
import gg.skytils.skytilsmod.features.impl.dungeons.cataclysmicmap.handlers.MapUpdater
import gg.skytils.skytilsmod.features.impl.dungeons.cataclysmicmap.utils.MapUtils
import gg.skytils.skytilsmod.utils.RenderUtil
import gg.skytils.skytilsmod.utils.TabListUtils
Expand All @@ -45,7 +45,7 @@ object CataclysmicMap {
fun reset() {
DungeonInfo.reset()
MapUtils.calibrated = false
DungeonScan.hasScanned = false
DungeonScanner.hasScanned = false
}

@SubscribeEvent
Expand All @@ -56,22 +56,22 @@ object CataclysmicMap {
MapUtils.calibrated = MapUtils.calibrateMap()
}

MapUpdate.updateRooms()
MapUpdater.updateRooms()

TabListUtils.tabEntries.let {
MapUpdate.updatePlayers(it)
MapUpdater.updatePlayers()
}

if (DungeonScan.shouldScan) {
DungeonScan.scan()
if (DungeonScanner.shouldScan) {
DungeonScanner.scan()
}
}

@SubscribeEvent
fun onWorldLoad(event: WorldEvent.Load) {
DungeonInfo.reset()
MapUtils.calibrated = false
DungeonScan.hasScanned = false
DungeonScanner.hasScanned = false
}

@SubscribeEvent
Expand All @@ -85,11 +85,22 @@ object CataclysmicMap {
val aabb = AxisAlignedBB(it.x - 1.0, 69.0, it.z - 1.0, it.x + 2.0, 73.0, it.z + 2.0)
val (viewerX, viewerY, viewerZ) = RenderUtil.getViewerPos(event.partialTicks)

val color = if (DungeonInfo.keys > 0) CataclysmicMapConfig.witherDoorKeyColor else CataclysmicMapConfig.witherDoorNoKeyColor
val color =
if (DungeonInfo.keys > 0) CataclysmicMapConfig.witherDoorKeyColor else CataclysmicMapConfig.witherDoorNoKeyColor

UGraphics.disableDepth()
RenderUtil.drawOutlinedBoundingBox(aabb, color.withAlpha(CataclysmicMapConfig.witherDoorOutline), CataclysmicMapConfig.witherDoorOutlineWidth, event.partialTicks)
RenderUtil.drawFilledBoundingBox(matrixStack, aabb.offset(-viewerX, -viewerY, -viewerZ), color, CataclysmicMapConfig.witherDoorFill)
RenderUtil.drawOutlinedBoundingBox(
aabb,
color.withAlpha(CataclysmicMapConfig.witherDoorOutline),
CataclysmicMapConfig.witherDoorOutlineWidth,
event.partialTicks
)
RenderUtil.drawFilledBoundingBox(
matrixStack,
aabb.offset(-viewerX, -viewerY, -viewerZ),
color,
CataclysmicMapConfig.witherDoorFill
)
UGraphics.enableDepth()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ import gg.essential.vigilance.data.*
import java.awt.Color
import java.io.File

object CataclysmicMapConfig : Vigilant(File("./config/skytils/cataclysmicmap/config.toml"), "Cataclysmic Map", sortingBehavior = CategorySorting) {
object CataclysmicMapConfig : Vigilant(
File("./config/skytils/cataclysmicmap/config.toml"),
"Cataclysmic Map",
sortingBehavior = CategorySorting
) {

@Property(
name = "Map Enabled",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import gg.skytils.skytilsmod.Skytils.Companion.mc
import gg.skytils.skytilsmod.core.structure.GuiElement
import gg.skytils.skytilsmod.features.impl.dungeons.DungeonTimer
import gg.skytils.skytilsmod.features.impl.dungeons.cataclysmicmap.core.map.*
import gg.skytils.skytilsmod.features.impl.dungeons.cataclysmicmap.features.dungeon.DungeonInfo
import gg.skytils.skytilsmod.features.impl.dungeons.cataclysmicmap.features.dungeon.DungeonScan
import gg.skytils.skytilsmod.features.impl.dungeons.cataclysmicmap.handlers.DungeonInfo
import gg.skytils.skytilsmod.features.impl.dungeons.cataclysmicmap.handlers.DungeonScanner
import gg.skytils.skytilsmod.features.impl.dungeons.cataclysmicmap.utils.MapUtils
import gg.skytils.skytilsmod.features.impl.dungeons.cataclysmicmap.utils.RenderUtils
import gg.skytils.skytilsmod.listeners.DungeonListener
Expand Down Expand Up @@ -64,8 +64,8 @@ object CataclysmicMapElement : GuiElement(name = "Dungeon Map", x = 0, y = 0) {

if (CataclysmicMapConfig.mapCenter) {
GlStateManager.translate(
-((mc.thePlayer.posX - DungeonScan.startX + 15) * MapUtils.coordMultiplier + MapUtils.startCorner.first - 2),
-((mc.thePlayer.posZ - DungeonScan.startZ + 15) * MapUtils.coordMultiplier + MapUtils.startCorner.second - 2),
-((mc.thePlayer.posX - DungeonScanner.startX + 15) * MapUtils.coordMultiplier + MapUtils.startCorner.first - 2),
-((mc.thePlayer.posZ - DungeonScanner.startZ + 15) * MapUtils.coordMultiplier + MapUtils.startCorner.second - 2),
0.0
)
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package gg.skytils.skytilsmod.features.impl.dungeons.cataclysmicmap.features.dungeon
package gg.skytils.skytilsmod.features.impl.dungeons.cataclysmicmap.core

import gg.skytils.skytilsmod.features.impl.dungeons.cataclysmicmap.core.map.RoomData
import gg.skytils.skytilsmod.features.impl.dungeons.cataclysmicmap.core.map.*
import gg.skytils.skytilsmod.features.impl.dungeons.cataclysmicmap.handlers.DungeonScanner
import gg.skytils.skytilsmod.features.impl.dungeons.cataclysmicmap.utils.MapUtils

class DungeonMap(mapColors: ByteArray) {
class DungeonMapParser(mapColors: ByteArray) {
private var centerColors: ByteArray = ByteArray(121)
private var sideColors: ByteArray = ByteArray(121)

Expand Down Expand Up @@ -62,8 +62,8 @@ class DungeonMap(mapColors: ByteArray) {
fun getTile(arrayX: Int, arrayY: Int): Tile {
val index = arrayY * 11 + arrayX
if (index >= 121) return Unknown(0, 0)
val xPos = DungeonScan.startX + arrayX * (DungeonScan.roomSize shr 1)
val zPos = DungeonScan.startZ + arrayY * (DungeonScan.roomSize shr 1)
val xPos = DungeonScanner.startX + arrayX * (DungeonScanner.roomSize shr 1)
val zPos = DungeonScanner.startZ + arrayY * (DungeonScanner.roomSize shr 1)
return scanTile(arrayX, arrayY, xPos, zPos)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import java.awt.Color

class Room(override val x: Int, override val z: Int, var data: RoomData) : Tile {
var core = 0

// always false
var hasMimic = false
var isSeparator = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package gg.skytils.skytilsmod.features.impl.dungeons.cataclysmicmap.features.dungeon
package gg.skytils.skytilsmod.features.impl.dungeons.cataclysmicmap.handlers

import gg.skytils.skytilsmod.features.impl.dungeons.cataclysmicmap.core.map.*
import gg.skytils.skytilsmod.features.impl.dungeons.cataclysmicmap.core.map.Puzzle
import gg.skytils.skytilsmod.features.impl.dungeons.cataclysmicmap.core.map.Room
import gg.skytils.skytilsmod.features.impl.dungeons.cataclysmicmap.core.map.Tile
import gg.skytils.skytilsmod.features.impl.dungeons.cataclysmicmap.core.map.Unknown

object DungeonInfo {
// 6 x 6 room grid, 11 x 11 with connections
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,21 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package gg.skytils.skytilsmod.features.impl.dungeons.cataclysmicmap.features.dungeon
package gg.skytils.skytilsmod.features.impl.dungeons.cataclysmicmap.handlers

import gg.skytils.skytilsmod.features.impl.dungeons.cataclysmicmap.features.dungeon.DungeonScan.scan
import gg.skytils.skytilsmod.Skytils.Companion.mc
import gg.skytils.skytilsmod.features.impl.dungeons.DungeonFeatures.dungeonFloorNumber
import gg.skytils.skytilsmod.features.impl.dungeons.cataclysmicmap.core.CataclysmicMapElement
import gg.skytils.skytilsmod.features.impl.dungeons.cataclysmicmap.core.map.*
import gg.skytils.skytilsmod.features.impl.dungeons.cataclysmicmap.handlers.DungeonScanner.scan
import gg.skytils.skytilsmod.features.impl.dungeons.cataclysmicmap.utils.ScanUtils
import net.minecraft.init.Blocks
import net.minecraft.util.BlockPos

/**
* Handles everything related to scanning the dungeon. Running [scan] will update the instance of [DungeonInfo].
*/
object DungeonScan {
object DungeonScanner {

/**
* The size of each dungeon room in blocks.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package gg.skytils.skytilsmod.features.impl.dungeons.cataclysmicmap.features.dungeon
package gg.skytils.skytilsmod.features.impl.dungeons.cataclysmicmap.handlers

import gg.skytils.skytilsmod.Skytils.Companion.mc
import gg.skytils.skytilsmod.features.impl.dungeons.cataclysmicmap.core.DungeonMapParser
import gg.skytils.skytilsmod.features.impl.dungeons.cataclysmicmap.core.map.Door
import gg.skytils.skytilsmod.features.impl.dungeons.cataclysmicmap.core.map.DoorType
import gg.skytils.skytilsmod.features.impl.dungeons.cataclysmicmap.core.map.Unknown
Expand All @@ -28,13 +29,12 @@ import gg.skytils.skytilsmod.features.impl.dungeons.cataclysmicmap.utils.MapUtil
import gg.skytils.skytilsmod.features.impl.dungeons.cataclysmicmap.utils.MapUtils.yaw
import gg.skytils.skytilsmod.listeners.DungeonListener
import gg.skytils.skytilsmod.utils.Utils
import net.minecraft.client.network.NetworkPlayerInfo
import net.minecraft.init.Blocks
import net.minecraft.util.BlockPos
import kotlin.math.roundToInt

object MapUpdate {
fun updatePlayers(tabEntries: List<Pair<NetworkPlayerInfo, String>>) {
object MapUpdater {
fun updatePlayers() {
if (DungeonListener.team.isEmpty()) return

val decor = MapUtils.getMapData()?.mapDecorations ?: return
Expand All @@ -49,15 +49,15 @@ object MapUpdate {
if (player.isPlayer || name == mc.thePlayer.name) {
player.yaw = mc.thePlayer.rotationYaw
player.mapX =
((mc.thePlayer.posX - DungeonScan.startX + 15) * MapUtils.coordMultiplier + MapUtils.startCorner.first).roundToInt()
((mc.thePlayer.posX - DungeonScanner.startX + 15) * MapUtils.coordMultiplier + MapUtils.startCorner.first).roundToInt()
player.mapZ =
((mc.thePlayer.posZ - DungeonScan.startZ + 15) * MapUtils.coordMultiplier + MapUtils.startCorner.second).roundToInt()
((mc.thePlayer.posZ - DungeonScanner.startZ + 15) * MapUtils.coordMultiplier + MapUtils.startCorner.second).roundToInt()
}
}
}

fun updateRooms() {
val map = DungeonMap(MapUtils.getMapData()?.colors ?: return)
val map = DungeonMapParser(MapUtils.getMapData()?.colors ?: return)

for (x in 0..10) {
for (z in 0..10) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@

package gg.skytils.skytilsmod.features.impl.dungeons.cataclysmicmap.utils

import gg.skytils.skytilsmod.features.impl.dungeons.cataclysmicmap.features.dungeon.DungeonScan
import gg.skytils.skytilsmod.Skytils.Companion.mc
import gg.skytils.skytilsmod.features.impl.dungeons.DungeonFeatures
import gg.skytils.skytilsmod.features.impl.dungeons.cataclysmicmap.handlers.DungeonScanner
import gg.skytils.skytilsmod.utils.Utils
import net.minecraft.item.ItemMap
import net.minecraft.util.Vec4b
Expand Down Expand Up @@ -53,7 +53,7 @@ object MapUtils {
*/
fun calibrateMap(): Boolean {
val (start, size) = findEntranceCorner()
if (Utils.equalsOneOf(size , 16, 18)) {
if (Utils.equalsOneOf(size, 16, 18)) {
mapRoomSize = size
startCorner = when (DungeonFeatures.dungeonFloorNumber) {
0 -> Pair(22, 22)
Expand All @@ -65,7 +65,7 @@ object MapUtils {
Pair(startX % (mapRoomSize + 4), startZ % (mapRoomSize + 4))
}
}
coordMultiplier = (mapRoomSize + 4.0) / DungeonScan.roomSize
coordMultiplier = (mapRoomSize + 4.0) / DungeonScanner.roomSize
return true
}
return false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@
package gg.skytils.skytilsmod.features.impl.dungeons.cataclysmicmap.utils

import gg.skytils.skytilsmod.Skytils.Companion.mc
import gg.skytils.skytilsmod.features.impl.dungeons.cataclysmicmap.core.CataclysmicMapElement
import gg.skytils.skytilsmod.features.impl.dungeons.cataclysmicmap.core.CataclysmicMapConfig
import gg.skytils.skytilsmod.features.impl.dungeons.cataclysmicmap.core.CataclysmicMapElement
import gg.skytils.skytilsmod.features.impl.dungeons.cataclysmicmap.core.DungeonMapPlayer
import gg.skytils.skytilsmod.features.impl.dungeons.cataclysmicmap.features.dungeon.DungeonScan
import gg.skytils.skytilsmod.features.impl.dungeons.cataclysmicmap.handlers.DungeonScanner
import gg.skytils.skytilsmod.utils.ItemUtil
import gg.skytils.skytilsmod.utils.Utils
import gg.skytils.skytilsmod.utils.bindColor
Expand Down Expand Up @@ -137,8 +137,8 @@ object RenderUtils {
// Translates to the player's location which is updated every tick.
if (player.isPlayer || name == mc.thePlayer.name) {
GlStateManager.translate(
(mc.thePlayer.posX - DungeonScan.startX + 15) * MapUtils.coordMultiplier + MapUtils.startCorner.first,
(mc.thePlayer.posZ - DungeonScan.startZ + 15) * MapUtils.coordMultiplier + MapUtils.startCorner.second,
(mc.thePlayer.posX - DungeonScanner.startX + 15) * MapUtils.coordMultiplier + MapUtils.startCorner.first,
(mc.thePlayer.posZ - DungeonScanner.startZ + 15) * MapUtils.coordMultiplier + MapUtils.startCorner.second,
0.0
)
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@

package gg.skytils.skytilsmod.features.impl.dungeons.cataclysmicmap.utils

import gg.skytils.skytilsmod.features.impl.dungeons.cataclysmicmap.core.map.RoomData
import gg.skytils.skytilsmod.features.impl.dungeons.cataclysmicmap.core.map.Room
import gg.skytils.skytilsmod.Skytils.Companion.json
import gg.skytils.skytilsmod.Skytils.Companion.mc
import gg.skytils.skytilsmod.features.impl.dungeons.cataclysmicmap.features.dungeon.DungeonInfo
import gg.skytils.skytilsmod.features.impl.dungeons.cataclysmicmap.features.dungeon.DungeonScan
import gg.skytils.skytilsmod.features.impl.dungeons.cataclysmicmap.core.map.Room
import gg.skytils.skytilsmod.features.impl.dungeons.cataclysmicmap.core.map.RoomData
import gg.skytils.skytilsmod.features.impl.dungeons.cataclysmicmap.handlers.DungeonInfo
import gg.skytils.skytilsmod.features.impl.dungeons.cataclysmicmap.handlers.DungeonScanner
import gg.skytils.skytilsmod.utils.Utils
import kotlinx.serialization.ExperimentalSerializationApi
import kotlinx.serialization.json.decodeFromStream
Expand Down Expand Up @@ -51,14 +51,14 @@ object ScanUtils {
}

fun getRoomCenter(posX: Int, posZ: Int): Pair<Int, Int> {
val roomX = ((posX - DungeonScan.startX) / 32f).roundToInt()
val roomZ = ((posZ - DungeonScan.startZ) / 32f).roundToInt()
return (roomX * 32 + DungeonScan.startX) to (roomZ * 32 + DungeonScan.startZ)
val roomX = ((posX - DungeonScanner.startX) / 32f).roundToInt()
val roomZ = ((posZ - DungeonScanner.startZ) / 32f).roundToInt()
return (roomX * 32 + DungeonScanner.startX) to (roomZ * 32 + DungeonScanner.startZ)
}

fun getRoomFromPos(pos: BlockPos): Room? {
val x = ((pos.x - DungeonScan.startX + 15) shr 5)
val z = ((pos.z - DungeonScan.startZ + 15) shr 5)
val x = ((pos.x - DungeonScanner.startX + 15) shr 5)
val z = ((pos.z - DungeonScanner.startZ + 15) shr 5)
val room = DungeonInfo.dungeonList.getOrNull(x * 2 + z * 22)
return if (room is Room) room else null
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import gg.skytils.skytilsmod.features.impl.dungeons.DungeonFeatures
import gg.skytils.skytilsmod.features.impl.dungeons.DungeonTimer
import gg.skytils.skytilsmod.features.impl.dungeons.ScoreCalculation
import gg.skytils.skytilsmod.features.impl.dungeons.cataclysmicmap.core.DungeonMapPlayer
import gg.skytils.skytilsmod.features.impl.dungeons.cataclysmicmap.features.dungeon.DungeonInfo
import gg.skytils.skytilsmod.features.impl.dungeons.cataclysmicmap.handlers.DungeonInfo
import gg.skytils.skytilsmod.features.impl.handlers.CooldownTracker
import gg.skytils.skytilsmod.features.impl.handlers.SpiritLeap
import gg.skytils.skytilsmod.mixins.transformers.accessors.AccessorChatComponentText
Expand Down

0 comments on commit a3adc32

Please sign in to comment.