Add Pristine Profit Tracker

This commit is contained in:
Linnea Gräf
2024-01-15 00:32:43 +01:00
parent c49b65835d
commit ac151c8ebc
16 changed files with 557 additions and 15 deletions

View File

@@ -0,0 +1,24 @@
/*
* SPDX-FileCopyrightText: 2024 Linnea Gräf <nea@nea.moe>
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
package moe.nea.firmament.util
import moe.nea.firmament.repo.HypixelStaticData
enum class BazaarPriceStrategy {
BUY_ORDER,
SELL_ORDER,
NPC_SELL;
fun getSellPrice(skyblockId: SkyblockId): Double {
val bazaarEntry = HypixelStaticData.bazaarData[skyblockId] ?: return 0.0
return when (this) {
BUY_ORDER -> bazaarEntry.quickStatus.sellPrice
SELL_ORDER -> bazaarEntry.quickStatus.buyPrice
NPC_SELL -> TODO()
}
}
}

View File

@@ -91,7 +91,7 @@ abstract class FragmentGuiScreen(
verticalAmount: Double
): Boolean {
return ifPopup {
it.mouseScrolled(mouseX, mouseY, verticalAmount)
it.mouseScrolled(mouseX, mouseY, horizontalAmount, verticalAmount)
}
}
}

View File

@@ -14,6 +14,7 @@ import net.minecraft.client.gui.screen.ingame.HandledScreen
import net.minecraft.network.message.ArgumentSignatureDataMap
import net.minecraft.network.message.LastSeenMessagesCollector.LastSeenMessages
import net.minecraft.network.packet.c2s.play.CommandExecutionC2SPacket
import net.minecraft.resource.ReloadableResourceManagerImpl
import net.minecraft.text.Text
import net.minecraft.util.math.BlockPos
import moe.nea.firmament.events.TickEvent
@@ -59,6 +60,7 @@ object MC {
player?.networkHandler?.sendCommand(command)
}
inline val resourceManager get() = (MinecraftClient.getInstance().resourceManager as ReloadableResourceManagerImpl)
inline val networkHandler get() = player?.networkHandler
inline val instance get() = MinecraftClient.getInstance()
inline val keyboard get() = MinecraftClient.getInstance().keyboard

View File

@@ -8,10 +8,60 @@ package moe.nea.firmament.util
import io.github.moulberry.moulconfig.common.MyResourceLocation
import io.github.moulberry.moulconfig.gui.GuiContext
import io.github.moulberry.moulconfig.xml.ChildCount
import io.github.moulberry.moulconfig.xml.XMLContext
import io.github.moulberry.moulconfig.xml.XMLGuiLoader
import io.github.moulberry.moulconfig.xml.XMLUniverse
import javax.xml.namespace.QName
import me.shedaniel.math.Color
import org.w3c.dom.Element
import moe.nea.firmament.gui.BarComponent
object MoulConfigUtils {
val universe = XMLUniverse.getDefaultUniverse()
val firmUrl = "http://nea.moe/Firmament"
val universe = XMLUniverse.getDefaultUniverse().also { uni ->
uni.registerMapper(java.awt.Color::class.java) {
if (it.startsWith("#")) {
val hexString = it.substring(1)
val hex = hexString.toInt(16)
if (hexString.length == 6) {
return@registerMapper java.awt.Color(hex)
}
if (hexString.length == 8) {
return@registerMapper java.awt.Color(hex, true)
}
error("Hexcolor $it needs to be exactly 6 or 8 hex digits long")
}
return@registerMapper java.awt.Color(it.toInt(), true)
}
uni.registerMapper(Color::class.java) {
val color = uni.mapXMLObject(it, java.awt.Color::class.java)
Color.ofRGBA(color.red, color.green, color.blue, color.alpha)
}
uni.registerLoader(object : XMLGuiLoader<BarComponent> {
override fun getName(): QName {
return QName(firmUrl, "Bar")
}
override fun createInstance(context: XMLContext<*>, element: Element): BarComponent {
return BarComponent(
context.getPropertyFromAttribute(element, QName("progress"), Double::class.java)!!,
context.getPropertyFromAttribute(element, QName("total"), Double::class.java)!!,
context.getPropertyFromAttribute(element, QName("fillColor"), Color::class.java)!!.get(),
context.getPropertyFromAttribute(element, QName("emptyColor"), Color::class.java)!!.get(),
)
}
override fun getChildCount(): ChildCount {
return ChildCount.NONE
}
override fun getAttributeNames(): Map<String, Boolean> {
return mapOf("progress" to true, "total" to true, "emptyColor" to true, "fillColor" to true)
}
})
}
fun loadGui(name: String, bindTo: Any): GuiContext {
return GuiContext(universe.load(bindTo, MyResourceLocation("firmament", "gui/$name.xml")))
}

View File

@@ -7,22 +7,42 @@
package moe.nea.firmament.util
import kotlin.time.Duration
import kotlin.time.ExperimentalTime
import kotlin.time.TimeSource
import kotlin.time.Duration.Companion.milliseconds
@OptIn(ExperimentalTime::class)
class TimeMark private constructor(private val timeMark: TimeSource.Monotonic.ValueTimeMark?) : Comparable<TimeMark> {
fun passedTime() = timeMark?.elapsedNow() ?: Duration.INFINITE
class TimeMark private constructor(private val timeMark: Long) : Comparable<TimeMark> {
fun passedTime() = if (timeMark == 0L) Duration.INFINITE else (System.currentTimeMillis() - timeMark).milliseconds
operator fun minus(other: TimeMark): Duration {
if (other.timeMark == timeMark)
return 0.milliseconds
if (other.timeMark == 0L)
return Duration.INFINITE
if (timeMark == 0L)
return -Duration.INFINITE
return (timeMark - other.timeMark).milliseconds
}
companion object {
fun now() = TimeMark(TimeSource.Monotonic.markNow())
fun farPast() = TimeMark(null)
fun now() = TimeMark(System.currentTimeMillis())
fun farPast() = TimeMark(0L)
fun ago(timeDelta: Duration): TimeMark {
if (timeDelta.isFinite()) {
return TimeMark(System.currentTimeMillis() - timeDelta.inWholeMilliseconds)
}
require(timeDelta.isPositive())
return farPast()
}
}
override fun hashCode(): Int {
return timeMark.hashCode()
}
override fun equals(other: Any?): Boolean {
return other is TimeMark && other.timeMark == timeMark
}
override fun compareTo(other: TimeMark): Int {
if (this.timeMark == other.timeMark) return 0
if (this.timeMark == null) return -1
if (other.timeMark == null) return -1
return this.timeMark.compareTo(other.timeMark)
}
}

View File

@@ -6,5 +6,13 @@
package moe.nea.firmament.util
import java.util.regex.Matcher
import java.util.regex.Pattern
inline fun <T> String.ifMatches(regex: Regex, block: (MatchResult) -> T): T? =
regex.matchEntire(this)?.let(block)
inline fun <T> Pattern.useMatch(string: String, block: Matcher.() -> T): T? =
matcher(string)
.takeIf(Matcher::matches)
?.let(block)

View File

@@ -0,0 +1,11 @@
/*
* SPDX-FileCopyrightText: 2024 Linnea Gräf <nea@nea.moe>
*
* SPDX-License-Identifier: GPL-3.0-or-later
*/
package moe.nea.firmament.util
fun parseIntWithComma(string: String): Int {
return string.replace(",", "").toInt()
}