aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java1
-rw-r--r--src/main/java/at/hannibal2/skyhanni/api/CollectionAPI.kt5
-rw-r--r--src/main/java/at/hannibal2/skyhanni/config/Features.java5
-rw-r--r--src/main/java/at/hannibal2/skyhanni/config/features/Garden.java19
-rw-r--r--src/main/java/at/hannibal2/skyhanni/events/CollectionUpdateEvent.kt3
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/EliteFarmingWeight.kt136
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/GardenCropMilestoneDisplay.kt1
7 files changed, 170 insertions, 0 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java
index 61f8db0cd..dedfb7316 100644
--- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java
+++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java
@@ -217,6 +217,7 @@ public class SkyHanniMod {
loadModule(new GardenOptimalSpeed());
loadModule(new GardenDeskInSBMenu());
loadModule(new GardenLevelDisplay());
+ loadModule(new EliteFarmingWeight());
Commands.INSTANCE.init();
diff --git a/src/main/java/at/hannibal2/skyhanni/api/CollectionAPI.kt b/src/main/java/at/hannibal2/skyhanni/api/CollectionAPI.kt
index af1be6bc4..0a8fc7a80 100644
--- a/src/main/java/at/hannibal2/skyhanni/api/CollectionAPI.kt
+++ b/src/main/java/at/hannibal2/skyhanni/api/CollectionAPI.kt
@@ -1,5 +1,6 @@
package at.hannibal2.skyhanni.api
+import at.hannibal2.skyhanni.events.CollectionUpdateEvent
import at.hannibal2.skyhanni.events.InventoryOpenEvent
import at.hannibal2.skyhanni.events.ProfileApiDataLoadedEvent
import at.hannibal2.skyhanni.events.ProfileJoinEvent
@@ -41,6 +42,8 @@ class CollectionAPI {
}
collectionValue[itemName] = counter
}
+
+ CollectionUpdateEvent().postAndCatch()
}
@SubscribeEvent
@@ -61,6 +64,7 @@ class CollectionAPI {
collectionValue[name] = counter
}
}
+ CollectionUpdateEvent().postAndCatch()
}
if (inventoryName.endsWith(" Collections")) {
@@ -85,6 +89,7 @@ class CollectionAPI {
}
}
}
+ CollectionUpdateEvent().postAndCatch()
}
}
diff --git a/src/main/java/at/hannibal2/skyhanni/config/Features.java b/src/main/java/at/hannibal2/skyhanni/config/Features.java
index ec666b099..ad67a647a 100644
--- a/src/main/java/at/hannibal2/skyhanni/config/Features.java
+++ b/src/main/java/at/hannibal2/skyhanni/config/Features.java
@@ -208,6 +208,11 @@ public class Features extends Config {
editOverlay(activeConfigCategory, 200, 16, garden.gardenLevelPos);
return;
}
+
+ if (runnableId.equals("eliteFarmingWeight")) {
+ editOverlay(activeConfigCategory, 200, 16, garden.eliteFarmingWeightPos);
+ return;
+ }
}
@Expose
diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/Garden.java b/src/main/java/at/hannibal2/skyhanni/config/features/Garden.java
index 9230247ee..3de40bad0 100644
--- a/src/main/java/at/hannibal2/skyhanni/config/features/Garden.java
+++ b/src/main/java/at/hannibal2/skyhanni/config/features/Garden.java
@@ -311,6 +311,25 @@ public class Garden {
public Position gardenLevelPos = new Position(-375, -215, false, true);
@Expose
+ @ConfigOption(name = "Elite Farming Weight", desc = "")
+ @ConfigEditorAccordion(id = 10)
+ public boolean eliteFarmingWeight = false;
+
+ @Expose
+ @ConfigOption(name = "Display", desc = "Display your farming weight on screen. " +
+ "The calculation and api is provided by The Elite SkyBlock Farmers. " +
+ "See §ehttps://elitebot.dev/info §7for more info.")
+ @ConfigEditorBoolean
+ @ConfigAccordionId(id = 10)
+ public boolean eliteFarmingWeightDisplay = true;
+
+ @Expose
+ @ConfigOption(name = "Farming Weight Position", desc = "")
+ @ConfigEditorButton(runnableId = "eliteFarmingWeight", buttonText = "Edit")
+ @ConfigAccordionId(id = 10)
+ public Position eliteFarmingWeightPos = new Position(-370, -167, false, true);
+
+ @Expose
@ConfigOption(name = "Plot Price", desc = "Show the price of the plot in coins when inside the Configure Plots inventory.")
@ConfigEditorBoolean
public boolean plotPrice = true;
diff --git a/src/main/java/at/hannibal2/skyhanni/events/CollectionUpdateEvent.kt b/src/main/java/at/hannibal2/skyhanni/events/CollectionUpdateEvent.kt
new file mode 100644
index 000000000..02be903db
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/events/CollectionUpdateEvent.kt
@@ -0,0 +1,3 @@
+package at.hannibal2.skyhanni.events
+
+class CollectionUpdateEvent: LorenzEvent() \ No newline at end of file
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/EliteFarmingWeight.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/EliteFarmingWeight.kt
new file mode 100644
index 000000000..d35f9c5e8
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/EliteFarmingWeight.kt
@@ -0,0 +1,136 @@
+package at.hannibal2.skyhanni.features.garden
+
+import at.hannibal2.skyhanni.SkyHanniMod
+import at.hannibal2.skyhanni.api.CollectionAPI
+import at.hannibal2.skyhanni.data.HyPixelData
+import at.hannibal2.skyhanni.events.CollectionUpdateEvent
+import at.hannibal2.skyhanni.events.GuiRenderEvent
+import at.hannibal2.skyhanni.utils.APIUtil
+import at.hannibal2.skyhanni.utils.LorenzUtils.round
+import at.hannibal2.skyhanni.utils.RenderUtils.renderString
+import com.google.gson.JsonObject
+import kotlinx.coroutines.Dispatchers
+import kotlinx.coroutines.launch
+import kotlinx.coroutines.withContext
+import net.minecraft.client.Minecraft
+import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
+import java.text.DecimalFormat
+
+class EliteFarmingWeight {
+
+ @SubscribeEvent
+ fun onCollectionUpdate(event: CollectionUpdateEvent) {
+ if (!config.eliteFarmingWeightDisplay) return
+ update()
+ }
+
+ @SubscribeEvent
+ fun onRenderOverlay(event: GuiRenderEvent.GameOverlayRenderEvent) {
+ if (!isEnabled()) return
+
+ config.eliteFarmingWeightPos.renderString(display)
+ }
+
+ private fun isEnabled() = GardenAPI.inGarden() && config.eliteFarmingWeightDisplay
+
+ companion object {
+ private val config get() = SkyHanniMod.feature.garden
+ private val extraCollection = mutableMapOf<String, Long>()
+ private var display = ""
+
+ fun addCrop(crop: String, diff: Int) {
+ if (!config.eliteFarmingWeightDisplay) return
+ val old = extraCollection[crop] ?: 0L
+ extraCollection[crop] = old + diff
+ update()
+ }
+
+ private fun update() = SkyHanniMod.coroutineScope.launch {
+ val collectionWeight = calculateCollectionWeight()
+ val cropWeight = collectionWeight.values.sum()
+
+ val bonusWeight = if (apiError) 0 else getBonusWeight()
+
+ val totalWeight = cropWeight + bonusWeight
+ val s = DecimalFormat("#,##0.00").format(totalWeight)
+ display = "§6Farming Weight§7: §e$s"
+ }
+
+ private suspend fun getBonusWeight(): Int {
+ for (profileEntry in getApiResult()["profiles"].asJsonObject.entrySet()) {
+ val profile = profileEntry.value.asJsonObject
+ val profileName = profile["cute_name"].asString
+ val profile1 = HyPixelData.profile
+ if (profileName.lowercase() == profile1) {
+ return profile["farming"].asJsonObject["bonus"].asInt
+ }
+ }
+ return 0
+ }
+
+ private var apiCache: JsonObject? = null
+ private var apiError = false
+
+ private suspend fun getApiResult(): JsonObject {
+ apiCache?.let { return it }
+ val result: JsonObject?
+ try {
+ val uuid = Minecraft.getMinecraft().thePlayer.uniqueID.toString().replace("-", "")
+ val url = "https://elitebot.dev/api/weight/$uuid"
+ result = withContext(Dispatchers.IO) { APIUtil.getJSONResponse(url) }.asJsonObject
+ } catch (e: Error) {
+ apiError = true
+ e.printStackTrace()
+ throw Error(e)
+ }
+ apiCache = result
+ return result
+ }
+
+ private fun calculateCollectionWeight(): MutableMap<String, Double> {
+ val weightPerCrop = mutableMapOf<String, Double>()
+ var totalWeight = 0.0
+ for ((cropName, factor) in factorPerCrop) {
+ val collection = getCollection(cropName)
+ val weight = (collection / factor).round(2)
+ weightPerCrop[cropName] = weight
+ totalWeight += weight
+ }
+ weightPerCrop["Mushroom"] = specialMushroomWeight(weightPerCrop, totalWeight)
+ return weightPerCrop
+ }
+
+ private fun specialMushroomWeight(weightPerCrop: MutableMap<String, Double>, totalWeight: Double): Double {
+ val cactusWeight = weightPerCrop["Cactus"]!!
+ val sugarCaneWeight = weightPerCrop["Sugar Cane"]!!
+ val doubleBreakRatio = (cactusWeight + sugarCaneWeight) / totalWeight;
+ val normalRatio = (totalWeight - cactusWeight - sugarCaneWeight) / totalWeight;
+
+ val mushroomFactor = factorPerCrop["Mushroom"]!!
+ val mushroomCollection = getCollection("Mushroom")
+ return doubleBreakRatio * (mushroomCollection / (2 * mushroomFactor)) + normalRatio * (mushroomCollection / mushroomFactor)
+ }
+
+ private fun getCollection(cropName: String): Double {
+ val l = (extraCollection[cropName]
+ ?: 0L)
+ val ll = CollectionAPI.getCollectionCounter(cropName)?.second ?: 0L
+ return (ll + l).toDouble()
+ }
+
+ private val factorPerCrop by lazy {
+ mapOf(
+ "wheat" to 100_000.0,
+ "Carrot" to 300_000.0,
+ "Potato" to 300_000.0,
+ "Sugar Cane" to 200_000.0,
+ "Nether Wart" to 250_000.0,
+ "Pumpkin" to 87_095.11,
+ "Melon" to 435_466.47,
+ "Mushroom" to 168_925.53,
+ "Cocoa Beans" to 257_214.64,
+ "Cactus" to 169_389.33,
+ )
+ }
+ }
+} \ No newline at end of file
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenCropMilestoneDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenCropMilestoneDisplay.kt
index 2854aec45..756922f0a 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenCropMilestoneDisplay.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenCropMilestoneDisplay.kt
@@ -53,6 +53,7 @@ class GardenCropMilestoneDisplay {
val old = cultivatingData[crop]!!
val diff = counter - old
GardenCropMilestones.cropCounter[crop] = GardenCropMilestones.cropCounter[crop]!! + diff
+ EliteFarmingWeight.addCrop(crop, diff)
if (GardenAPI.cropInHand == crop) {
calculateSpeed(diff)
update()