Skip to content

Commit

Permalink
Feature: Display current and upcoming mining events (hannibal002#1040)
Browse files Browse the repository at this point in the history
Co-authored-by: Thunderblade73 <85900443+Thunderblade73@users.noreply.github.com>
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
  • Loading branch information
3 people authored Mar 10, 2024
1 parent cb62e10 commit 498afd5
Show file tree
Hide file tree
Showing 9 changed files with 241 additions and 104 deletions.
2 changes: 2 additions & 0 deletions src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ import at.hannibal2.skyhanni.features.mining.DeepCavernsParkour
import at.hannibal2.skyhanni.features.mining.HighlightMiningCommissionMobs
import at.hannibal2.skyhanni.features.mining.KingTalismanHelper
import at.hannibal2.skyhanni.features.mining.crystalhollows.CrystalHollowsNamesInCore
import at.hannibal2.skyhanni.features.mining.eventtracker.MiningEventDisplay
import at.hannibal2.skyhanni.features.mining.eventtracker.MiningEventTracker
import at.hannibal2.skyhanni.features.mining.powdertracker.PowderTracker
import at.hannibal2.skyhanni.features.minion.InfernoMinionFeatures
Expand Down Expand Up @@ -676,6 +677,7 @@ class SkyHanniMod {
loadModule(ArachneChatMessageHider())
loadModule(ShowItemUuid())
loadModule(FrozenTreasureTracker)
loadModule(MiningEventDisplay)
loadModule(SlayerRngMeterDisplay())
loadModule(GhostCounter)
loadModule(RiftTimer())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,50 +1,47 @@
package at.hannibal2.skyhanni.config.features.mining;

import at.hannibal2.skyhanni.config.FeatureToggle;
import at.hannibal2.skyhanni.config.core.config.Position;
import com.google.gson.annotations.Expose;
import io.github.moulberry.moulconfig.annotations.ConfigEditorBoolean;
import io.github.moulberry.moulconfig.annotations.ConfigEditorDropdown;
import io.github.moulberry.moulconfig.annotations.ConfigOption;

public class MiningEventConfig {

// @Expose
// @ConfigOption(name = "Enabled", desc = "Show information about upcoming Dwarven Mines and Crystal Hollows mining events, also enables you sending data.")
// @ConfigEditorBoolean
// @FeatureToggle
// public boolean enabled = true;
//
// @Expose
// @ConfigOption(name = "Show Outside Mining Islands", desc = "Shows the event tracker when you are not inside of the Dwarven Mines or Crystal Hollows.")
// @ConfigEditorBoolean
// public boolean outsideMining = true;
//
// @Expose
// @ConfigOption(name = "What to Show", desc = "Choose which island's events are shown in the gui.")
// @ConfigEditorDropdown
// public ShowType showType = ShowType.BOTH;
//
// @Expose
// @ConfigOption(name = "Show Warnings For Events", desc = "Shows the warnings when select mining events are about to start.")
// @ConfigEditorBoolean
// @FeatureToggle
// public boolean showWarnings = false;

//todo remove when released
@Expose
@ConfigOption(name = "Send Test data", desc = "Sends test data to make sure the api works.")
@ConfigOption(name = "Enabled", desc = "Show information about upcoming Dwarven Mines and Crystal Hollows mining events, " +
"also enables you sending data. §eTakes up to a minute to sync new events.")
@ConfigEditorBoolean
@FeatureToggle
public boolean sendData = true;
public boolean enabled = true;

// @Expose
// @ConfigOption(name = "Events to Warn for", desc = "Choose which mining events you get warned about.")
// @ConfigEditorDraggableList
// public List<MiningEvent> eventsToWarn = new ArrayList<>(Collections.singletonList(MiningEvent.DOUBLE_POWDER));
@Expose
@ConfigOption(name = "Show Outside Mining Islands", desc = "Shows the event tracker when you are not inside of the Dwarven Mines or Crystal Hollows.")
@ConfigEditorBoolean
public boolean outsideMining = false;

@Expose
@ConfigOption(name = "What to Show", desc = "Choose which island's events are shown in the gui.")
@ConfigEditorDropdown
public ShowType showType = ShowType.BOTH;

@Expose
@ConfigOption(name = "Compressed Format", desc = "Compresses the event names so that they are shorter.")
@ConfigEditorBoolean
public boolean compressedFormat = false;

@Expose
@ConfigOption(name = "Show Passed Events", desc = "Shows the most recent passed event at the start greyed out. " +
"§eTakes a little while to save last event.")
@ConfigEditorBoolean
public boolean passedEvents = false;

public enum ShowType {
BOTH("Both Mining Islands"),
CRYSTAL("Crystal Hollows Only"),
DWARVEN("Dwarven Mines Only"),
CURRENT("Current Island Only"),
;

private final String str;
Expand All @@ -58,4 +55,7 @@ public String toString() {
return str;
}
}

@Expose
public Position position = new Position(15, 70, false, true);
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,39 @@ import at.hannibal2.skyhanni.data.IslandType
import com.google.gson.annotations.Expose
import com.google.gson.annotations.SerializedName

data class MiningEventData(
data class MiningEventDataSend(
@Expose @SerializedName("server_type") val serverType: IslandType,
@Expose @SerializedName("server_id") val serverId: String,
@Expose val event: MiningEvent,
@Expose val event: MiningEventType,
@Expose @SerializedName("time_left") val timeRemaining: Long,
@Expose @SerializedName("reporter_uuid") val uuid: String
)

data class MiningEventDataReceive(
@Expose val success: Boolean,
@Expose val data: MiningEventData,
@Expose val cause: String
)

data class MiningEventData(
@Expose @SerializedName("event_datas") val eventData: Map<IslandType, Map<MiningEventType, EventData>>,
@Expose @SerializedName("running_events") val runningEvents: Map<IslandType, List<RunningEventType>>,
@Expose @SerializedName("total_lobbys") val totalLobbies: Map<IslandType, Int>,
@Expose @SerializedName("update_in") val updateIn: Long,
@Expose @SerializedName("curr_time") val currentTime: Long
)

data class EventData(
@Expose @SerializedName("starts_at_min") val startMin: Long,
@Expose @SerializedName("starts_at_max") val startMax: Long,
@Expose @SerializedName("ends_at_min") val endMin: Long,
@Expose @SerializedName("ends_at_max") val endMax: Long,
@Expose @SerializedName("lobby_count") val lobbyCount: Int
)

data class RunningEventType(
@Expose val event: MiningEventType,
@Expose @SerializedName("ends_at") val endsAt: Long,
@Expose @SerializedName("lobby_count") val lobbyCount: Int,
@Expose @SerializedName("is_double") val isDoubleEvent: Boolean
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
package at.hannibal2.skyhanni.features.mining.eventtracker

import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.config.features.mining.MiningEventConfig
import at.hannibal2.skyhanni.data.IslandType
import at.hannibal2.skyhanni.events.GuiRenderEvent
import at.hannibal2.skyhanni.events.LorenzTickEvent
import at.hannibal2.skyhanni.features.fame.ReminderUtils
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.LorenzUtils.isInIsland
import at.hannibal2.skyhanni.utils.RenderUtils.renderStrings
import at.hannibal2.skyhanni.utils.SimpleTimeMark.Companion.asTimeMark
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent

object MiningEventDisplay {
private val config get() = SkyHanniMod.feature.mining.miningEvent
private var display = mutableListOf<String>()

private var dwarvenEvents = listOf<RunningEventType>()
private var crystalEvents = listOf<RunningEventType>()
private var lastDwarvenEvent: MiningEventType? = null
private var lastCrystalEvent: MiningEventType? = null

@SubscribeEvent
fun onTick(event: LorenzTickEvent) {
if (!event.repeatSeconds(1)) return
updateDisplay()
}

@SubscribeEvent
fun onRenderOverlay(event: GuiRenderEvent.GuiOverlayRenderEvent) {
if (!shouldDisplay()) return
config.position.renderStrings(display, posLabel = "Upcoming Events Display")
}

private fun updateDisplay() {
display.clear()
updateEvents(IslandType.DWARVEN_MINES, dwarvenEvents, lastDwarvenEvent)
updateEvents(IslandType.CRYSTAL_HOLLOWS, crystalEvents, lastCrystalEvent)
}

private fun updateEvents(islandType: IslandType, events: List<RunningEventType>, lastEvent: MiningEventType?) {
val shouldShow = when (config.showType) {
MiningEventConfig.ShowType.DWARVEN -> islandType == IslandType.DWARVEN_MINES
MiningEventConfig.ShowType.CRYSTAL -> islandType == IslandType.CRYSTAL_HOLLOWS
MiningEventConfig.ShowType.CURRENT -> islandType.isInIsland()
else -> true
}

events.firstOrNull()?.let { firstEvent ->
if (firstEvent.endsAt.asTimeMark().isInPast()) {
when (islandType) {
IslandType.DWARVEN_MINES -> lastDwarvenEvent = firstEvent.event
IslandType.CRYSTAL_HOLLOWS -> lastCrystalEvent = firstEvent.event
else -> Unit
}
}
}

if (shouldShow) {
val upcomingEvents = formatUpcomingEvents(events, lastEvent)
display.add("§a${islandType.displayName}§8: $upcomingEvents")
}
}

private fun formatUpcomingEvents(events: List<RunningEventType>, lastEvent: MiningEventType?): String {
val upcoming = events.filter { !it.endsAt.asTimeMark().isInPast() }
.map { if (it.isDoubleEvent) "${it.event} §8-> ${it.event}" else it.event.toString() }
.toMutableList()

if (upcoming.isEmpty()) upcoming.add("§7???")
if (config.passedEvents && upcoming.size < 4) lastEvent?.let { upcoming.add(0, it.toPastString()) }
return upcoming.joinToString(" §8-> ")
}

fun updateData(eventData: MiningEventData) {
eventData.runningEvents.forEach { (islandType, events) ->
when (islandType) {
IslandType.DWARVEN_MINES -> dwarvenEvents =
(events.sortedBy { it.endsAt - it.event.defaultLength.inWholeMilliseconds })

IslandType.CRYSTAL_HOLLOWS -> crystalEvents =
(events.sortedBy { it.endsAt - it.event.defaultLength.inWholeMilliseconds })
else -> Unit
}
}
}

private fun shouldDisplay() = LorenzUtils.inSkyBlock && config.enabled && !ReminderUtils.isBusy() &&
!(!config.outsideMining && !LorenzUtils.inAdvancedMiningIsland())
}
Loading

0 comments on commit 498afd5

Please sign in to comment.