aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/at')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java5
-rw-r--r--src/main/java/at/hannibal2/skyhanni/config/features/Garden.java6
-rw-r--r--src/main/java/at/hannibal2/skyhanni/config/features/Hidden.java4
-rw-r--r--src/main/java/at/hannibal2/skyhanni/data/GardenComposterUpgradesData.kt30
-rw-r--r--src/main/java/at/hannibal2/skyhanni/data/model/ComposterUpgrade.kt18
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/ComposterDisplay.kt118
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/CropMoneyDisplay.kt2
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/EliteFarmingWeight.kt2
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/FarmingFortuneDisplay.kt4
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/GardenAPI.kt67
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/GardenBestCropTime.kt4
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/GardenCropMilestoneDisplay.kt6
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/GardenInventoryNumbers.kt12
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/GardenNextJacobContest.kt2
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/GardenVisitorFeatures.kt2
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/ToolTooltipTweaks.kt2
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/composter/ComposterAPI.kt17
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/composter/ComposterDisplay.kt176
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/composter/GardenComposterInventoryFeatures.kt (renamed from src/main/java/at/hannibal2/skyhanni/features/garden/GardenComposterInventoryFeatures.kt)5
-rw-r--r--src/main/java/at/hannibal2/skyhanni/utils/TimeUtils.kt1
20 files changed, 305 insertions, 178 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java
index 12e9929bf..96e71a779 100644
--- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java
+++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java
@@ -25,7 +25,9 @@ import at.hannibal2.skyhanni.features.event.diana.GriffinBurrowParticleFinder;
import at.hannibal2.skyhanni.features.event.diana.SoopyGuessBurrow;
import at.hannibal2.skyhanni.features.fishing.*;
import at.hannibal2.skyhanni.features.garden.*;
+import at.hannibal2.skyhanni.features.garden.composter.ComposterDisplay;
import at.hannibal2.skyhanni.features.garden.composter.ComposterInventoryNumbers;
+import at.hannibal2.skyhanni.features.garden.composter.GardenComposterInventoryFeatures;
import at.hannibal2.skyhanni.features.inventory.*;
import at.hannibal2.skyhanni.features.itemabilities.FireVeilWandParticles;
import at.hannibal2.skyhanni.features.itemabilities.abilitycooldown.ItemAbilityCooldown;
@@ -136,10 +138,11 @@ public class SkyHanniMod {
loadModule(UpdateManager.INSTANCE);
loadModule(new CropAccessoryData());
loadModule(new MayorElectionData());
+ loadModule(new GardenComposterUpgradesData());
// APIs
loadModule(new BazaarApi());
- loadModule(new GardenAPI());
+ loadModule(GardenAPI.INSTANCE);
loadModule(new CollectionAPI());
// features
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 6fbe69ad2..c539d4c3a 100644
--- a/src/main/java/at/hannibal2/skyhanni/config/features/Garden.java
+++ b/src/main/java/at/hannibal2/skyhanni/config/features/Garden.java
@@ -797,7 +797,7 @@ public class Garden {
@Expose
@ConfigOption(name = "True Farming Fortune", desc = "")
- @ConfigEditorAccordion(id = 18)
+ @ConfigEditorAccordion(id = 22)
public boolean farmingFortune = false;
@Expose
@@ -806,7 +806,7 @@ public class Garden {
desc = "Displays current farming fortune, including crop-specific bonuses."
)
@ConfigEditorBoolean
- @ConfigAccordionId(id = 18)
+ @ConfigAccordionId(id = 22)
public boolean farmingFortuneDisplay = true;
@Expose
@@ -816,7 +816,7 @@ public class Garden {
" the chance for bonus drops. "
)
@ConfigEditorBoolean
- @ConfigAccordionId(id = 18)
+ @ConfigAccordionId(id = 22)
public boolean farmingFortuneDropMultiplier = false;
@Expose
diff --git a/src/main/java/at/hannibal2/skyhanni/config/features/Hidden.java b/src/main/java/at/hannibal2/skyhanni/config/features/Hidden.java
index 4638f816d..f1b161474 100644
--- a/src/main/java/at/hannibal2/skyhanni/config/features/Hidden.java
+++ b/src/main/java/at/hannibal2/skyhanni/config/features/Hidden.java
@@ -1,5 +1,6 @@
package at.hannibal2.skyhanni.config.features;
+import at.hannibal2.skyhanni.data.model.ComposterUpgrade;
import at.hannibal2.skyhanni.features.garden.CropAccessory;
import at.hannibal2.skyhanni.features.garden.CropType;
import com.google.gson.annotations.Expose;
@@ -64,4 +65,7 @@ public class Hidden {
@Expose
public Map<String, Integer> gardenFarmingArmorDrops = new HashMap<>();
+
+ @Expose
+ public Map<ComposterUpgrade, Integer> gardenComposterUpgrades = new HashMap<>();
}
diff --git a/src/main/java/at/hannibal2/skyhanni/data/GardenComposterUpgradesData.kt b/src/main/java/at/hannibal2/skyhanni/data/GardenComposterUpgradesData.kt
new file mode 100644
index 000000000..126cd52ea
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/data/GardenComposterUpgradesData.kt
@@ -0,0 +1,30 @@
+package at.hannibal2.skyhanni.data
+
+import at.hannibal2.skyhanni.data.model.ComposterUpgrade
+import at.hannibal2.skyhanni.events.InventoryOpenEvent
+import at.hannibal2.skyhanni.features.garden.GardenAPI
+import at.hannibal2.skyhanni.features.garden.composter.ComposterAPI
+import at.hannibal2.skyhanni.utils.ItemUtils.name
+import at.hannibal2.skyhanni.utils.NumberUtil.romanToDecimalIfNeeded
+import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
+
+class GardenComposterUpgradesData {
+
+ @SubscribeEvent
+ fun onInventoryOpen(event: InventoryOpenEvent) {
+ if (!GardenAPI.inGarden()) return
+ if (event.inventoryName != "Composter Upgrades") return
+ for (item in event.inventoryItems.values) {
+ val itemName = item.name ?: continue
+ val matcher = ComposterUpgrade.regex.matcher(itemName)
+ if (!matcher.matches()) continue
+
+ if (matcher.groupCount() != 0) {
+ val name = matcher.group("name")
+ val level = matcher.group("level")?.romanToDecimalIfNeeded() ?: 0
+ val composterUpgrade = ComposterUpgrade.getByName(name)!!
+ ComposterAPI.composterUpgrades[composterUpgrade] = level
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/src/main/java/at/hannibal2/skyhanni/data/model/ComposterUpgrade.kt b/src/main/java/at/hannibal2/skyhanni/data/model/ComposterUpgrade.kt
new file mode 100644
index 000000000..83a106ca8
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/data/model/ComposterUpgrade.kt
@@ -0,0 +1,18 @@
+package at.hannibal2.skyhanni.data.model
+
+enum class ComposterUpgrade(val displayName: String) {
+ COMPOSTER_SPEED("Composter Speed"),
+ ORGANIC_MATTER_CAP("Organic Matter Cap"),
+ MULTI_DROP("Multi Drop"),
+ COST_REDUCTION("Cost Reduction"),
+ FUEL_CAP("Fuel Cap"),
+ ;
+
+ companion object {
+ private fun regexValues() = values().joinToString("|") { it.displayName }
+
+ val regex = "§a(?<name>${regexValues()})(?: (?<level>.*))?".toPattern()
+
+ fun getByName(name: String) = values().firstOrNull { it.displayName == name }
+ }
+} \ No newline at end of file
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/ComposterDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/ComposterDisplay.kt
deleted file mode 100644
index 23316166f..000000000
--- a/src/main/java/at/hannibal2/skyhanni/features/garden/ComposterDisplay.kt
+++ /dev/null
@@ -1,118 +0,0 @@
-package at.hannibal2.skyhanni.features.garden
-
-import at.hannibal2.skyhanni.SkyHanniMod
-import at.hannibal2.skyhanni.data.SendTitleHelper
-import at.hannibal2.skyhanni.events.GuiRenderEvent
-import at.hannibal2.skyhanni.events.TabListUpdateEvent
-import at.hannibal2.skyhanni.utils.LorenzUtils
-import at.hannibal2.skyhanni.utils.LorenzUtils.addAsSingletonList
-import at.hannibal2.skyhanni.utils.NEUItems
-import at.hannibal2.skyhanni.utils.NumberUtil.formatNumber
-import at.hannibal2.skyhanni.utils.RenderUtils.renderStringsAndItems
-import at.hannibal2.skyhanni.utils.StringUtils.removeColor
-import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
-import java.util.regex.Pattern
-
-class ComposterDisplay {
- private val config get() = SkyHanniMod.feature.garden
- private val hidden get() = SkyHanniMod.feature.hidden
- private var display = listOf<List<Any>>()
-
- enum class DataType(val pattern: String, val icon: String) {
- ORGANIC_MATTER(" Organic Matter: §r(.*)", "WHEAT"),
- FUEL(" Fuel: §r(.*)", "OIL_BARREL"),
- TIME_LEFT(" Time Left: §r(.*)", "WATCH"),
- STORED_COMPOST(" Stored Compost: §r(.*)", "COMPOST");
-
- val displayItem by lazy {
- NEUItems.getItemStack(icon)
- }
-
- fun addToList(map: Map<DataType, String>): List<Any> {
- return listOf(displayItem, map[this]!!)
- }
- }
-
- @SubscribeEvent
- fun onTabListUpdate(event: TabListUpdateEvent) {
- if (!isEnabled()) return
-
- var next = false
- val data = mutableMapOf<DataType, String>()
-
- for (line in event.tabList) {
- if (line == "§b§lComposter:") {
- next = true
- continue
- }
- if (next) {
- if (line == "") break
- for (type in DataType.values()) {
- val pattern = Pattern.compile(type.pattern)
- val matcher = pattern.matcher(line)
- if (matcher.matches()) {
- data[type] = matcher.group(1)
- }
- }
- }
- }
-
- val newList = mutableListOf<List<Any>>()
- newList.addAsSingletonList("§bComposter")
-
- for (type in DataType.values()) {
- if (!data.containsKey(type)) return
- }
-
- newList.add(DataType.TIME_LEFT.addToList(data))
-
- val list = mutableListOf<Any>()
- list.addAll(DataType.ORGANIC_MATTER.addToList(data))
- list.add(" ")
- list.addAll(DataType.FUEL.addToList(data))
- newList.add(list)
-
- newList.add(DataType.STORED_COMPOST.addToList(data))
-
- display = newList
-
- notify(data)
- }
-
- private fun notify(data: MutableMap<DataType, String>) {
- if (!config.composterNotifyLowEnabled) return
-
- data[DataType.ORGANIC_MATTER]?.removeColor()?.formatNumber()?.let {
- if (it <= config.composterNotifyLowOrganicMatter) {
- if (System.currentTimeMillis() >= hidden.informedAboutLowMatter) {
- if (config.composterNotifyLowTitle) {
- SendTitleHelper.sendTitle("§cYour Organic Matter is low", 4_000)
- }
- LorenzUtils.chat("§e[SkyHanni] §cYour Organic Matter is low!")
- hidden.informedAboutLowMatter = System.currentTimeMillis() + 30_000
- }
- }
- }
-
- data[DataType.FUEL]?.removeColor()?.formatNumber()?.let {
- if (it <= config.composterNotifyLowFuel &&
- System.currentTimeMillis() >= hidden.informedAboutLowFuel
- ) {
- if (config.composterNotifyLowTitle) {
- SendTitleHelper.sendTitle("§cYour Fuel is low", 4_000)
- }
- LorenzUtils.chat("§e[SkyHanni] §cYour Fuel is low!")
- hidden.informedAboutLowFuel = System.currentTimeMillis() + 30_000
- }
- }
- }
-
- @SubscribeEvent
- fun onRenderOverlay(event: GuiRenderEvent.GameOverlayRenderEvent) {
- if (isEnabled()) {
- config.composterDisplayPos.renderStringsAndItems(display, posLabel = "Composter Display")
- }
- }
-
- fun isEnabled() = config.composterDisplayEnabled && GardenAPI.inGarden()
-} \ No newline at end of file
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/CropMoneyDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/CropMoneyDisplay.kt
index 28881b7f1..2bb43af93 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/garden/CropMoneyDisplay.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/CropMoneyDisplay.kt
@@ -5,7 +5,7 @@ import at.hannibal2.skyhanni.events.GardenToolChangeEvent
import at.hannibal2.skyhanni.events.GuiRenderEvent
import at.hannibal2.skyhanni.features.bazaar.BazaarApi
import at.hannibal2.skyhanni.features.bazaar.BazaarData
-import at.hannibal2.skyhanni.features.garden.GardenAPI.Companion.getSpeed
+import at.hannibal2.skyhanni.features.garden.GardenAPI.getSpeed
import at.hannibal2.skyhanni.utils.ItemUtils.name
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.LorenzUtils.addAsSingletonList
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/EliteFarmingWeight.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/EliteFarmingWeight.kt
index b82c44558..bbcdd13dc 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/garden/EliteFarmingWeight.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/EliteFarmingWeight.kt
@@ -4,7 +4,7 @@ import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.data.HypixelData
import at.hannibal2.skyhanni.events.GardenToolChangeEvent
import at.hannibal2.skyhanni.events.GuiRenderEvent
-import at.hannibal2.skyhanni.features.garden.GardenAPI.Companion.getSpeed
+import at.hannibal2.skyhanni.features.garden.GardenAPI.getSpeed
import at.hannibal2.skyhanni.utils.APIUtil
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.LorenzUtils.round
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/FarmingFortuneDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/FarmingFortuneDisplay.kt
index 60d70e691..22e330281 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/garden/FarmingFortuneDisplay.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/FarmingFortuneDisplay.kt
@@ -8,8 +8,8 @@ import at.hannibal2.skyhanni.data.GardenCropUpgrades.Companion.getUpgradeLevel
import at.hannibal2.skyhanni.events.*
import at.hannibal2.skyhanni.features.garden.CropType.Companion.getCropType
import at.hannibal2.skyhanni.features.garden.CropType.Companion.getTurboCrop
-import at.hannibal2.skyhanni.features.garden.GardenAPI.Companion.addCropIcon
-import at.hannibal2.skyhanni.features.garden.GardenAPI.Companion.getCropType
+import at.hannibal2.skyhanni.features.garden.GardenAPI.addCropIcon
+import at.hannibal2.skyhanni.features.garden.GardenAPI.getCropType
import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName
import at.hannibal2.skyhanni.utils.ItemUtils.getLore
import at.hannibal2.skyhanni.utils.LorenzUtils
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenAPI.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenAPI.kt
index 418b22960..192746e0a 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenAPI.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenAPI.kt
@@ -15,7 +15,14 @@ import net.minecraftforge.fml.common.eventhandler.EventPriority
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import net.minecraftforge.fml.common.gameevent.TickEvent
-class GardenAPI {
+object GardenAPI {
+ private val cropsPerSecond: MutableMap<CropType, Int> get() = SkyHanniMod.feature.hidden.gardenCropsPerSecond
+
+ var toolInHand: String? = null
+ var cropInHand: CropType? = null
+ var mushroomCowPet = false
+ var onBarnPlot = false
+
var tick = 0
@SubscribeEvent
@@ -93,45 +100,37 @@ class GardenAPI {
}
}
- companion object {
- var toolInHand: String? = null
- private val cropsPerSecond: MutableMap<CropType, Int> get() = SkyHanniMod.feature.hidden.gardenCropsPerSecond
- var cropInHand: CropType? = null
- var mushroomCowPet = false
- var onBarnPlot = false
-
- fun inGarden() = LorenzUtils.inSkyBlock && LorenzUtils.skyBlockIsland == IslandType.GARDEN
+ fun inGarden() = LorenzUtils.inSkyBlock && LorenzUtils.skyBlockIsland == IslandType.GARDEN
- fun ItemStack.getCropType(): CropType? {
- val internalName = getInternalName()
- return CropType.values().firstOrNull { internalName.startsWith(it.toolName) }
- }
+ fun ItemStack.getCropType(): CropType? {
+ val internalName = getInternalName()
+ return CropType.values().firstOrNull { internalName.startsWith(it.toolName) }
+ }
- fun readCounter(itemStack: ItemStack): Int = itemStack.getHoeCounter() ?: itemStack.getCultivatingCounter() ?: -1
+ fun readCounter(itemStack: ItemStack): Int = itemStack.getHoeCounter() ?: itemStack.getCultivatingCounter() ?: -1
- fun CropType.getSpeed(): Int {
- val speed = cropsPerSecond[this]
- if (speed != null) return speed
+ fun CropType.getSpeed(): Int {
+ val speed = cropsPerSecond[this]
+ if (speed != null) return speed
- val message = "Set speed for $this to -1!"
- println(message)
- LorenzUtils.debug(message)
- setSpeed(-1)
- return -1
- }
+ val message = "Set speed for $this to -1!"
+ println(message)
+ LorenzUtils.debug(message)
+ setSpeed(-1)
+ return -1
+ }
- fun CropType.setSpeed(speed: Int) {
- cropsPerSecond[this] = speed
- }
+ fun CropType.setSpeed(speed: Int) {
+ cropsPerSecond[this] = speed
+ }
- fun MutableList<Any>.addCropIcon(crop: CropType) {
- try {
- add(crop.icon)
- } catch (e: NullPointerException) {
- e.printStackTrace()
- }
+ fun MutableList<Any>.addCropIcon(crop: CropType) {
+ try {
+ add(crop.icon)
+ } catch (e: NullPointerException) {
+ e.printStackTrace()
}
-
- fun isSpeedDataEmpty() = cropsPerSecond.values.sum() < 0
}
+
+ fun isSpeedDataEmpty() = cropsPerSecond.values.sum() < 0
} \ No newline at end of file
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenBestCropTime.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenBestCropTime.kt
index 06f82fbee..049ef2552 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenBestCropTime.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenBestCropTime.kt
@@ -3,8 +3,8 @@ package at.hannibal2.skyhanni.features.garden
import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.data.GardenCropMilestones
import at.hannibal2.skyhanni.data.GardenCropMilestones.Companion.getCounter
-import at.hannibal2.skyhanni.features.garden.GardenAPI.Companion.addCropIcon
-import at.hannibal2.skyhanni.features.garden.GardenAPI.Companion.getSpeed
+import at.hannibal2.skyhanni.features.garden.GardenAPI.addCropIcon
+import at.hannibal2.skyhanni.features.garden.GardenAPI.getSpeed
import at.hannibal2.skyhanni.utils.LorenzUtils.addAsSingletonList
import at.hannibal2.skyhanni.utils.LorenzUtils.sorted
import at.hannibal2.skyhanni.utils.TimeUtils
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 78f3bf836..2036a0a44 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenCropMilestoneDisplay.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenCropMilestoneDisplay.kt
@@ -9,9 +9,9 @@ import at.hannibal2.skyhanni.data.MayorElectionData
import at.hannibal2.skyhanni.data.SendTitleHelper
import at.hannibal2.skyhanni.events.*
import at.hannibal2.skyhanni.features.garden.CropType.Companion.getCropType
-import at.hannibal2.skyhanni.features.garden.GardenAPI.Companion.addCropIcon
-import at.hannibal2.skyhanni.features.garden.GardenAPI.Companion.getCropType
-import at.hannibal2.skyhanni.features.garden.GardenAPI.Companion.setSpeed
+import at.hannibal2.skyhanni.features.garden.GardenAPI.addCropIcon
+import at.hannibal2.skyhanni.features.garden.GardenAPI.getCropType
+import at.hannibal2.skyhanni.features.garden.GardenAPI.setSpeed
import at.hannibal2.skyhanni.utils.BlockUtils.isBabyCrop
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.LorenzUtils.addAsSingletonList
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenInventoryNumbers.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenInventoryNumbers.kt
index 708a50be9..53815205c 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenInventoryNumbers.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenInventoryNumbers.kt
@@ -1,6 +1,7 @@
package at.hannibal2.skyhanni.features.garden
import at.hannibal2.skyhanni.SkyHanniMod
+import at.hannibal2.skyhanni.data.model.ComposterUpgrade
import at.hannibal2.skyhanni.events.RenderItemTipEvent
import at.hannibal2.skyhanni.utils.InventoryUtils
import at.hannibal2.skyhanni.utils.ItemUtils.getLore
@@ -10,11 +11,8 @@ import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import java.util.regex.Pattern
class GardenInventoryNumbers {
-
private var patternTierProgress = Pattern.compile("§7Progress to Tier (.*): §e(?:.*)")
private var patternUpgradeTier = Pattern.compile("§7Current Tier: §[ea](.*)§7/§a.*")
- private val patternComposterUpgrades =
- Pattern.compile("§a(?:Composter Speed|Multi Drop|Fuel Cap|Organic Matter Cap|Cost Reduction) ?(.*)?")
@SubscribeEvent
fun onRenderItemTip(event: RenderItemTipEvent) {
@@ -44,12 +42,10 @@ class GardenInventoryNumbers {
if (!SkyHanniMod.feature.garden.numberComposterUpgrades) return
event.stack.name?.let {
- val matcher = patternComposterUpgrades.matcher(it)
+ val matcher = ComposterUpgrade.regex.matcher(it)
if (matcher.matches()) {
- event.stackTip = if (matcher.groupCount() != 0) {
- val group = matcher.group(1)
- "" + group.romanToDecimalIfNeeded()
- } else "0"
+ val level = matcher.group("level")?.romanToDecimalIfNeeded() ?: 0
+ event.stackTip = "$level"
}
}
}
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenNextJacobContest.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenNextJacobContest.kt
index e056ba510..5786cae72 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenNextJacobContest.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenNextJacobContest.kt
@@ -2,7 +2,7 @@ package at.hannibal2.skyhanni.features.garden
import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.events.*
-import at.hannibal2.skyhanni.features.garden.GardenAPI.Companion.addCropIcon
+import at.hannibal2.skyhanni.features.garden.GardenAPI.addCropIcon
import at.hannibal2.skyhanni.utils.ItemUtils.getLore
import at.hannibal2.skyhanni.utils.ItemUtils.name
import at.hannibal2.skyhanni.utils.LorenzUtils
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenVisitorFeatures.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenVisitorFeatures.kt
index 3943edd9c..893b0434a 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenVisitorFeatures.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenVisitorFeatures.kt
@@ -3,7 +3,7 @@ package at.hannibal2.skyhanni.features.garden
import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.data.SendTitleHelper
import at.hannibal2.skyhanni.events.*
-import at.hannibal2.skyhanni.features.garden.GardenAPI.Companion.getSpeed
+import at.hannibal2.skyhanni.features.garden.GardenAPI.getSpeed
import at.hannibal2.skyhanni.mixins.hooks.RenderLivingEntityHelper
import at.hannibal2.skyhanni.utils.*
import at.hannibal2.skyhanni.utils.ItemUtils.getInternalName
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/ToolTooltipTweaks.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/ToolTooltipTweaks.kt
index 4c4553cb8..f5f77b39e 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/garden/ToolTooltipTweaks.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/ToolTooltipTweaks.kt
@@ -2,7 +2,7 @@ package at.hannibal2.skyhanni.features.garden
import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.events.LorenzToolTipEvent
-import at.hannibal2.skyhanni.features.garden.GardenAPI.Companion.getCropType
+import at.hannibal2.skyhanni.features.garden.GardenAPI.getCropType
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.SkyBlockItemModifierUtils.getEnchantments
import at.hannibal2.skyhanni.utils.SkyBlockItemModifierUtils.getFarmingForDummiesCount
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/composter/ComposterAPI.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/composter/ComposterAPI.kt
new file mode 100644
index 000000000..35d144a12
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/composter/ComposterAPI.kt
@@ -0,0 +1,17 @@
+package at.hannibal2.skyhanni.features.garden.composter
+
+import at.hannibal2.skyhanni.SkyHanniMod
+import at.hannibal2.skyhanni.data.model.ComposterUpgrade
+import at.hannibal2.skyhanni.utils.NumberUtil.formatNumber
+import at.hannibal2.skyhanni.utils.StringUtils.removeColor
+
+object ComposterAPI {
+ var tabListData = mapOf<ComposterDisplay.DataType, String>()
+ val composterUpgrades: MutableMap<ComposterUpgrade, Int> get() = SkyHanniMod.feature.hidden.gardenComposterUpgrades
+
+ fun ComposterUpgrade.getLevel() = composterUpgrades[this] ?: 0
+
+ fun getFuel() = tabListData[ComposterDisplay.DataType.FUEL]?.removeColor()?.formatNumber() ?: 0
+
+ fun getOrganicMatter() = tabListData[ComposterDisplay.DataType.ORGANIC_MATTER]?.removeColor()?.formatNumber() ?: 0
+} \ No newline at end of file
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/composter/ComposterDisplay.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/composter/ComposterDisplay.kt
new file mode 100644
index 000000000..3544511fc
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/composter/ComposterDisplay.kt
@@ -0,0 +1,176 @@
+package at.hannibal2.skyhanni.features.garden.composter
+
+import at.hannibal2.skyhanni.SkyHanniMod
+import at.hannibal2.skyhanni.data.SendTitleHelper
+import at.hannibal2.skyhanni.data.model.ComposterUpgrade
+import at.hannibal2.skyhanni.events.GuiRenderEvent
+import at.hannibal2.skyhanni.events.TabListUpdateEvent
+import at.hannibal2.skyhanni.features.garden.GardenAPI
+import at.hannibal2.skyhanni.features.garden.composter.ComposterAPI.getLevel
+import at.hannibal2.skyhanni.utils.LorenzUtils
+import at.hannibal2.skyhanni.utils.LorenzUtils.addAsSingletonList
+import at.hannibal2.skyhanni.utils.NEUItems
+import at.hannibal2.skyhanni.utils.RenderUtils.renderStringsAndItems
+import at.hannibal2.skyhanni.utils.TimeUtils
+import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
+import java.util.regex.Pattern
+import kotlin.time.Duration
+import kotlin.time.Duration.Companion.minutes
+import kotlin.time.DurationUnit
+
+class ComposterDisplay {
+ private val config get() = SkyHanniMod.feature.garden
+ private val hidden get() = SkyHanniMod.feature.hidden
+ private var display = listOf<List<Any>>()
+ private var composterEmptyTime: Duration? = null
+
+ private var tabListData by ComposterAPI::tabListData
+
+ enum class DataType(val pattern: String, val icon: String) {
+ ORGANIC_MATTER(" Organic Matter: §r(.*)", "WHEAT"),
+ FUEL(" Fuel: §r(.*)", "OIL_BARREL"),
+ TIME_LEFT(" Time Left: §r(.*)", "WATCH"),
+ STORED_COMPOST(" Stored Compost: §r(.*)", "COMPOST");
+
+ val displayItem by lazy {
+ NEUItems.getItemStack(icon)
+ }
+
+ fun addToList(map: Map<DataType, String>): List<Any> {
+ return listOf(displayItem, map[this]!!)
+ }
+ }
+
+ @SubscribeEvent
+ fun onTabListUpdate(event: TabListUpdateEvent) {
+ if (!isEnabled()) return
+
+ readData(event.tabList)
+
+ if (tabListData.isNotEmpty()) {
+ calculateEmptyTime()
+ updateDisplay()
+ sendNotify()
+ }
+ }
+
+ private fun calculateEmptyTime() {
+ val organicMatter = ComposterAPI.getOrganicMatter()
+ val fuel = ComposterAPI.getFuel()
+
+ if (ComposterAPI.composterUpgrades.isEmpty()) {
+ composterEmptyTime = null
+ return
+ }
+
+ val speedUpgrade = ComposterUpgrade.COMPOSTER_SPEED.getLevel()
+ val speedFactor = 1 + speedUpgrade * 0.2
+ val baseDuration = 10.minutes
+ val timePerCompost = baseDuration / speedFactor
+
+ val costReduction = ComposterUpgrade.COST_REDUCTION.getLevel()
+ val costFactor = 1.0 - costReduction.toDouble() / 100
+ val organicMatterRequired = 4_000.0 * costFactor
+ val fuelRequired = 2_000.0 * costFactor
+
+ val organicMatterRemaining = organicMatter / organicMatterRequired
+ val fuelRemaining = fuel / fuelRequired
+
+ val endOfOrganicMatter = timePerCompost * organicMatterRemaining
+ val endOfFuel = timePerCompost * fuelRemaining
+ composterEmptyTime = if (endOfOrganicMatter > endOfFuel) endOfFuel else endOfOrganicMatter
+ }
+
+ private fun updateDisplay() {
+ val newDisplay = mutableListOf<List<Any>>()
+ newDisplay.addAsSingletonList("§bComposter")
+
+
+ newDisplay.add(DataType.TIME_LEFT.addToList(tabListData))
+
+ val list = mutableListOf<Any>()
+ list.addAll(DataType.ORGANIC_MATTER.addToList(tabListData))
+ list.add(" ")
+ list.addAll(DataType.FUEL.addToList(tabListData))
+ newDisplay.add(list)
+
+ newDisplay.add(DataType.STORED_COMPOST.addToList(tabListData))
+ newDisplay.add(addComposterEmptyTime(composterEmptyTime))
+
+ display = newDisplay
+ }
+
+ private fun addComposterEmptyTime(emptyTime: Duration?): List<Any> {
+ return if (emptyTime != null) {
+ val millis = emptyTime.toDouble(DurationUnit.MILLISECONDS).toLong()
+ val format = TimeUtils.formatDuration(millis, maxUnits = 2)
+ listOf(NEUItems.getItemStack("BUCKET"), "§b$format")
+ } else {
+ listOf("§cOpen Composter Upgrades!")
+ }
+ }
+
+ private fun readData(tabList: List<String>) {
+ var next = false
+ val newData = mutableMapOf<DataType, String>()
+
+ for (line in tabList) {
+ if (line == "§b§lComposter:") {
+ next = true
+ continue
+ }
+ if (next) {
+ if (line == "") break
+ for (type in DataType.values()) {
+ val pattern = Pattern.compile(type.pattern)
+ val matcher = pattern.matcher(line)
+ if (matcher.matches()) {
+ newData[type] = matcher.group(1)
+ }
+ }
+ }
+ }
+
+ for (type in DataType.values()) {
+ if (!newData.containsKey(type)) {
+ tabListData = emptyMap()
+ return
+ }
+ }
+
+ tabListData = newData
+ }
+
+ private fun sendNotify() {
+ if (!config.composterNotifyLowEnabled) return
+
+ if (ComposterAPI.getOrganicMatter() <= config.composterNotifyLowOrganicMatter) {
+ if (System.currentTimeMillis() >= hidden.informedAboutLowMatter) {
+ if (config.composterNotifyLowTitle) {
+ SendTitleHelper.sendTitle("§cYour Organic Matter is low", 4_000)
+ }
+ LorenzUtils.chat("§e[SkyHanni] §cYour Organic Matter is low!")
+ hidden.informedAboutLowMatter = System.currentTimeMillis() + 30_000
+ }
+ }
+
+ if (ComposterAPI.getFuel() <= config.composterNotifyLowFuel &&
+ System.currentTimeMillis() >= hidden.informedAboutLowFuel
+ ) {
+ if (config.composterNotifyLowTitle) {
+ SendTitleHelper.sendTitle("§cYour Fuel is low", 4_000)
+ }
+ LorenzUtils.chat("§e[SkyHanni] §cYour Fuel is low!")
+ hidden.informedAboutLowFuel = System.currentTimeMillis() + 30_000
+ }
+ }
+
+ @SubscribeEvent
+ fun onRenderOverlay(event: GuiRenderEvent.GameOverlayRenderEvent) {
+ if (isEnabled()) {
+ config.composterDisplayPos.renderStringsAndItems(display, posLabel = "Composter Display")
+ }
+ }
+
+ fun isEnabled() = config.composterDisplayEnabled && GardenAPI.inGarden()
+} \ No newline at end of file
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenComposterInventoryFeatures.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/composter/GardenComposterInventoryFeatures.kt
index a14d5ac39..538b971e9 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenComposterInventoryFeatures.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/composter/GardenComposterInventoryFeatures.kt
@@ -1,7 +1,8 @@
-package at.hannibal2.skyhanni.features.garden
+package at.hannibal2.skyhanni.features.garden.composter
import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.events.GuiContainerEvent
+import at.hannibal2.skyhanni.features.garden.GardenAPI
import at.hannibal2.skyhanni.utils.*
import at.hannibal2.skyhanni.utils.ItemUtils.getLore
import at.hannibal2.skyhanni.utils.RenderUtils.highlight
@@ -11,7 +12,7 @@ import net.minecraftforge.event.entity.player.ItemTooltipEvent
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
class GardenComposterInventoryFeatures {
- val config get() = SkyHanniMod.feature.garden
+ private val config get() = SkyHanniMod.feature.garden
@SubscribeEvent
fun onTooltip(event: ItemTooltipEvent) {
diff --git a/src/main/java/at/hannibal2/skyhanni/utils/TimeUtils.kt b/src/main/java/at/hannibal2/skyhanni/utils/TimeUtils.kt
index 1491662c1..253be7938 100644
--- a/src/main/java/at/hannibal2/skyhanni/utils/TimeUtils.kt
+++ b/src/main/java/at/hannibal2/skyhanni/utils/TimeUtils.kt
@@ -55,6 +55,7 @@ object TimeUtils {
return builder.toString()
}
+ // TODO: use kotlin Duration
fun getMillis(string: String): Long {
val matcher = pattern.matcher(string.lowercase().trim())
if (!matcher.matches()) return tryAlternativeFormat(string)