Skip to content

Commit

Permalink
changing most classes to objects (hannibal002#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
CalMWolfs authored May 14, 2024
1 parent d4a0311 commit 15d9442
Show file tree
Hide file tree
Showing 274 changed files with 1,610 additions and 1,728 deletions.
512 changes: 257 additions & 255 deletions src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ object Commands {
registerCommand(
"shlimbo",
"Warps you to Limbo."
) { MiscFeatures().goToLimbo() }
) { MiscFeatures.goToLimbo() }
registerCommand(
"shlanedetection",
"Detect a farming lane in garden"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ package at.hannibal2.skyhanni.config.core.config.gui

import at.hannibal2.skyhanni.config.core.config.Position
import at.hannibal2.skyhanni.data.GuiEditManager
import at.hannibal2.skyhanni.data.GuiEditManager.Companion.getAbsX
import at.hannibal2.skyhanni.data.GuiEditManager.Companion.getAbsY
import at.hannibal2.skyhanni.data.GuiEditManager.Companion.getDummySize
import at.hannibal2.skyhanni.data.GuiEditManager.getAbsX
import at.hannibal2.skyhanni.data.GuiEditManager.getAbsY
import at.hannibal2.skyhanni.data.GuiEditManager.getDummySize
import at.hannibal2.skyhanni.data.OtherInventoryData
import at.hannibal2.skyhanni.mixins.transformers.gui.AccessorGuiContainer
import at.hannibal2.skyhanni.utils.GuiRenderUtils
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ public static class DungeonStorage {
public Map<DungeonFloor, Integer> bosses = new HashMap<>();

@Expose
public List<DungeonStorage.DungeonRunInfo> runs = CroesusChestTracker.Companion.generateMaxChestAsList();
public List<DungeonStorage.DungeonRunInfo> runs = CroesusChestTracker.generateMaxChestAsList();

public static class DungeonRunInfo {

Expand Down
25 changes: 9 additions & 16 deletions src/main/java/at/hannibal2/skyhanni/data/EntityMovementData.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,18 @@ import net.minecraft.client.Minecraft
import net.minecraft.entity.Entity
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent

class EntityMovementData {
object EntityMovementData {

companion object {
private val warpingPattern by RepoPattern.pattern(
"data.entity.warping",
"§7(?:Warping|Warping you to your SkyBlock island|Warping using transfer token|Finding player|Sending a visit request)\\.\\.\\."
)

private val entityLocation = mutableMapOf<Entity, LorenzVec>()
private val entityLocation = mutableMapOf<Entity, LorenzVec>()

fun addToTrack(entity: Entity) {
if (entity !in entityLocation) {
entityLocation[entity] = entity.getLorenzVec()
}
fun addToTrack(entity: Entity) {
if (entity !in entityLocation) {
entityLocation[entity] = entity.getLorenzVec()
}
}

Expand All @@ -46,15 +48,6 @@ class EntityMovementData {
}
}

private val warpingPattern by RepoPattern.pattern(
"warping",
"§7Warping...|" +
"§7Warping you to your SkyBlock island...|" +
"§7Warping using transfer token...|" +
"§7Finding player...|" +
"§7Sending a visit request..."
)

@SubscribeEvent
fun onChat(event: LorenzChatEvent) {
if (!LorenzUtils.inSkyBlock) return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.mc.McClient
import kotlin.concurrent.fixedRateTimer

class FixedRateTimerManager {
object FixedRateTimerManager {
private var totalSeconds = 0

init {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import at.hannibal2.skyhanni.utils.NumberUtil.romanToDecimalIfNecessary
import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent

class GardenComposterUpgradesData {
object GardenComposterUpgradesData {

@SubscribeEvent
fun onInventoryOpen(event: InventoryFullyOpenedEvent) {
Expand Down
58 changes: 33 additions & 25 deletions src/main/java/at/hannibal2/skyhanni/data/GardenCropUpgrades.kt
Original file line number Diff line number Diff line change
@@ -1,52 +1,60 @@
package at.hannibal2.skyhanni.data

import at.hannibal2.skyhanni.events.CropUpgradeUpdateEvent
import at.hannibal2.skyhanni.events.InventoryFullyOpenedEvent
import at.hannibal2.skyhanni.events.LorenzChatEvent
import at.hannibal2.skyhanni.features.garden.CropType
import at.hannibal2.skyhanni.features.garden.CropType.Companion.getByNameOrNull
import at.hannibal2.skyhanni.features.garden.GardenAPI
import at.hannibal2.skyhanni.utils.ItemUtils.getLore
import at.hannibal2.skyhanni.utils.ItemUtils.name
import at.hannibal2.skyhanni.utils.NumberUtil.formatInt
import at.hannibal2.skyhanni.utils.StringUtils.matchFirst
import at.hannibal2.skyhanni.utils.StringUtils.matchMatcher
import at.hannibal2.skyhanni.utils.StringUtils.removeColor
import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent

class GardenCropUpgrades {
object GardenCropUpgrades {

// TODO USE SH-REPO
private val tierPattern = "§7Current Tier: §[0-9a-e](\\d)§7/§a9".toRegex()
private val chatUpgradePattern = " {2}§r§6§lCROP UPGRADE §e§f([\\w ]+)§7 #(\\d)".toRegex()
private val patternGroup = RepoPattern.group("garden.cropupgrades")
private val tierPattern by patternGroup.pattern(
"tier",
"§7Current Tier: §.(?<level>\\d)§7/§a9"
)
private val chatUpgradePattern by patternGroup.pattern(
"chatupgrade",
"\\s+§r§6§lCROP UPGRADE §e(?<crop>[\\w ]+)§7 #(?<tier>\\d)"
)

private val cropUpgrades: MutableMap<CropType, Int>? get() = GardenAPI.storage?.cropUpgrades

@SubscribeEvent
fun onChat(event: LorenzChatEvent) {
chatUpgradePattern.matchEntire(event.message)?.groups?.let { matches ->
val crop = getByNameOrNull(matches[1]!!.value) ?: return
val level = matches[2]!!.value.toInt()
crop.setUpgradeLevel(level)
if (!GardenAPI.inGarden()) return

chatUpgradePattern.matchMatcher(event.message) {
val crop = CropType.getByNameOrNull(group("crop"))
val level = group("tier").formatInt()
crop?.setUpgradeLevel(level)
}
CropUpgradeUpdateEvent().postAndCatch()
}

@SubscribeEvent
fun onInventoryOpen(event: InventoryFullyOpenedEvent) {
if (!GardenAPI.inGarden()) return
if (event.inventoryName != "Crop Upgrades") return
event.inventoryItems.forEach { (_, item) ->
val crop = CropType.getByNameOrNull(item.name.removeColor()) ?: return@forEach
val level = item.getLore()
.firstNotNullOfOrNull { tierPattern.matchEntire(it)?.groups?.get(1)?.value?.toIntOrNull() } ?: 0
crop.setUpgradeLevel(level)

for (item in event.inventoryItems.values) {
val crop = CropType.getByNameOrNull(item.name.removeColor()) ?: continue
item.getLore().matchFirst(tierPattern) {
val level = group("level").formatInt()
crop.setUpgradeLevel(level)
}
}
CropUpgradeUpdateEvent().postAndCatch()
}

companion object {
fun CropType.getUpgradeLevel() = cropUpgrades?.get(this)

private val cropUpgrades: MutableMap<CropType, Int>? get() = GardenAPI.storage?.cropUpgrades

fun CropType.getUpgradeLevel() = cropUpgrades?.get(this)

fun CropType.setUpgradeLevel(level: Int) {
cropUpgrades?.put(this, level)
}
private fun CropType.setUpgradeLevel(level: Int) {
cropUpgrades?.put(this, level)
}
}
111 changes: 54 additions & 57 deletions src/main/java/at/hannibal2/skyhanni/data/GuiEditManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,14 @@ import kotlin.time.Duration.Companion.milliseconds
import kotlin.time.Duration.Companion.minutes
import kotlin.time.Duration.Companion.seconds

class GuiEditManager {
object GuiEditManager {

private var lastHotkeyPressed = SimpleTimeMark.farPast()

private var currentPositions = TimeLimitedCache<String, Position>(15.seconds)
private var currentBorderSize = mutableMapOf<String, Pair<Int, Int>>()
private var lastMovedGui: String? = null

@SubscribeEvent
fun onKeyClick(event: LorenzKeyPressEvent) {
if (event.keyCode != SkyHanniMod.feature.gui.keyBindOpen) return
Expand Down Expand Up @@ -66,77 +70,70 @@ class GuiEditManager {
}
}

companion object {

private var currentPositions = TimeLimitedCache<String, Position>(15.seconds)
private var currentBorderSize = mutableMapOf<String, Pair<Int, Int>>()
private var lastMovedGui: String? = null

@JvmStatic
fun add(position: Position, posLabel: String, x: Int, y: Int) {
var name = position.internalName
if (name == null) {
name = if (posLabel == "none") "none " + UUID.randomUUID() else posLabel
position.internalName = name
}
currentPositions.put(name, position)
currentBorderSize[posLabel] = Pair(x, y)
@JvmStatic
fun add(position: Position, posLabel: String, x: Int, y: Int) {
var name = position.internalName
if (name == null) {
name = if (posLabel == "none") "none " + UUID.randomUUID() else posLabel
position.internalName = name
}
currentPositions.put(name, position)
currentBorderSize[posLabel] = Pair(x, y)
}

private var lastHotkeyReminded = SimpleTimeMark.farPast()

@JvmStatic
fun openGuiPositionEditor(hotkeyReminder: Boolean) {
SkyHanniMod.screenToOpen = GuiPositionEditor(
currentPositions.values().toList(),
2,
Minecraft.getMinecraft().currentScreen as? GuiContainer
private var lastHotkeyReminded = SimpleTimeMark.farPast()

@JvmStatic
fun openGuiPositionEditor(hotkeyReminder: Boolean) {
SkyHanniMod.screenToOpen = GuiPositionEditor(
currentPositions.values().toList(),
2,
Minecraft.getMinecraft().currentScreen as? GuiContainer
)
if (hotkeyReminder && lastHotkeyReminded.passedSince() > 30.minutes) {
lastHotkeyReminded = SimpleTimeMark.now()
ChatUtils.chat(
"§eTo edit hidden GUI elements:\n" +
" §7- §e1. Set a key in /sh edit.\n" +
" §7- §e2. Click that key while the GUI element is visible."
)
if (hotkeyReminder && lastHotkeyReminded.passedSince() > 30.minutes) {
lastHotkeyReminded = SimpleTimeMark.now()
ChatUtils.chat(
"§eTo edit hidden GUI elements:\n" +
" §7- §e1. Set a key in /sh edit.\n" +
" §7- §e2. Click that key while the GUI element is visible."
)
}
}
}

@JvmStatic
fun renderLast() {
if (!isInGui()) return
if (!SkyHanniDebugsAndTests.globalRender) return
@JvmStatic
fun renderLast() {
if (!isInGui()) return
if (!SkyHanniDebugsAndTests.globalRender) return

GlStateManager.translate(0f, 0f, 200f)
GlStateManager.translate(0f, 0f, 200f)

GuiRenderEvent.GuiOverlayRenderEvent().postAndCatch()
GuiRenderEvent.GuiOverlayRenderEvent().postAndCatch()

GlStateManager.pushMatrix()
GlStateManager.enableDepth()
GuiRenderEvent.ChestGuiOverlayRenderEvent().postAndCatch()
GlStateManager.popMatrix()
GlStateManager.pushMatrix()
GlStateManager.enableDepth()
GuiRenderEvent.ChestGuiOverlayRenderEvent().postAndCatch()
GlStateManager.popMatrix()

GlStateManager.translate(0f, 0f, -200f)
}
GlStateManager.translate(0f, 0f, -200f)
}

fun isInGui() = Minecraft.getMinecraft().currentScreen is GuiPositionEditor
fun isInGui() = Minecraft.getMinecraft().currentScreen is GuiPositionEditor

fun Position.getDummySize(random: Boolean = false): Vector2i {
if (random) return Vector2i(5, 5)
val (x, y) = currentBorderSize[internalName] ?: return Vector2i(1, 1)
return Vector2i((x * effectiveScale).toInt(), (y * effectiveScale).toInt())
}
fun Position.getDummySize(random: Boolean = false): Vector2i {
if (random) return Vector2i(5, 5)
val (x, y) = currentBorderSize[internalName] ?: return Vector2i(1, 1)
return Vector2i((x * effectiveScale).toInt(), (y * effectiveScale).toInt())
}

fun Position.getAbsX() = getAbsX0(getDummySize(true).x)
fun Position.getAbsX() = getAbsX0(getDummySize(true).x)

fun Position.getAbsY() = getAbsY0(getDummySize(true).y)
fun Position.getAbsY() = getAbsY0(getDummySize(true).y)

fun GuiProfileViewer.anyTextBoxFocused() =
this.getPropertiesWithType<GuiElementTextField>().any { it.focus }
fun GuiProfileViewer.anyTextBoxFocused() =
this.getPropertiesWithType<GuiElementTextField>().any { it.focus }

fun handleGuiPositionMoved(guiName: String) {
lastMovedGui = guiName
}
fun handleGuiPositionMoved(guiName: String) {
lastMovedGui = guiName
}
}

Expand Down
18 changes: 9 additions & 9 deletions src/main/java/at/hannibal2/skyhanni/data/ItemAddManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,9 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import kotlin.time.Duration.Companion.milliseconds
import kotlin.time.Duration.Companion.seconds

class ItemAddManager {
enum class Source {
ITEM_ADD,
SACKS,
;
}
object ItemAddManager {
private var lastDiceRoll = SimpleTimeMark.farPast()
private var superCraftedItems = TimeLimitedSet<NEUInternalName>(30.seconds)

private val diceRollChatPattern by RepoPattern.pattern(
"data.itemmanager.diceroll",
Expand Down Expand Up @@ -83,9 +80,6 @@ class ItemAddManager {
ItemAddEvent(internalName, amount, this).postAndCatch()
}

private var lastDiceRoll = SimpleTimeMark.farPast()
private var superCraftedItems = TimeLimitedSet<NEUInternalName>(30.seconds)

@SubscribeEvent
fun onChat(event: LorenzChatEvent) {
if (diceRollChatPattern.matches(event.message)) {
Expand All @@ -97,4 +91,10 @@ class ItemAddManager {
superCraftedItems.add(internalName)
}
}

enum class Source {
ITEM_ADD,
SACKS,
;
}
}
24 changes: 1 addition & 23 deletions src/main/java/at/hannibal2/skyhanni/data/ItemClickData.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import net.minecraft.network.play.client.C08PacketPlayerBlockPlacement
import net.minecraft.network.play.client.C0APacketAnimation
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent

class ItemClickData {
object ItemClickData {

@SubscribeEvent
fun onItemClickSend(event: PacketEvent.SendEvent) {
Expand Down Expand Up @@ -57,26 +57,4 @@ class ItemClickData {
}
}
}

/* @SubscribeEvent
fun onEntityClick(event: InputEvent) {
if (!LorenzUtils.inSkyBlock) return
val minecraft = Minecraft.getMinecraft()
val attackKey = minecraft.gameSettings.keyBindAttack
val useKey = minecraft.gameSettings.keyBindUseItem
val clickType = when {
attackKey.isKeyDown -> ClickType.LEFT_CLICK
useKey.isKeyDown -> ClickType.RIGHT_CLICK
else -> return
}
val clickedEntity = minecraft.pointedEntity
if (minecraft.thePlayer == null) return
if (clickedEntity == null) return
EntityClickEvent(clickType, clickedEntity, InventoryUtils.getItemInHand()).postAndCatch()
} */
}
Loading

0 comments on commit 15d9442

Please sign in to comment.