aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at
diff options
context:
space:
mode:
authorhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-03-03 17:58:55 +0100
committerhannibal2 <24389977+hannibal00212@users.noreply.github.com>2023-03-03 17:58:55 +0100
commit7c0b053b188fee0c1f74b24c441293f6a7d685e4 (patch)
tree99a4c488568b4251599932fc9557af63744ef588 /src/main/java/at
parente859d2873c11d24cbd8966bfcb06c80dd8901ab3 (diff)
downloadskyhanni-7c0b053b188fee0c1f74b24c441293f6a7d685e4.tar.gz
skyhanni-7c0b053b188fee0c1f74b24c441293f6a7d685e4.tar.bz2
skyhanni-7c0b053b188fee0c1f74b24c441293f6a7d685e4.zip
Created GardenAPI
Diffstat (limited to 'src/main/java/at')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java9
-rw-r--r--src/main/java/at/hannibal2/skyhanni/events/GardenToolChangeEvent.kt3
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/GardenAPI.kt76
-rw-r--r--src/main/java/at/hannibal2/skyhanni/features/garden/GardenCropMilestoneDisplay.kt79
4 files changed, 95 insertions, 72 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java
index 8364fcb35..42693324a 100644
--- a/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java
+++ b/src/main/java/at/hannibal2/skyhanni/SkyHanniMod.java
@@ -92,9 +92,8 @@ public class SkyHanniMod {
public void preInit(FMLPreInitializationEvent event) {
logger = LogManager.getLogger("SkyHanni");
- //API and utils
+ // utils
loadModule(this);
- loadModule(new BazaarApi());
loadModule(new ChatManager());
loadModule(new HyPixelData());
loadModule(new DungeonData());
@@ -116,7 +115,11 @@ public class SkyHanniMod {
loadModule(new GardenCropMilestones());
loadModule(new OwnInventoryData());
- //features
+ // APIs
+ loadModule(new BazaarApi());
+ loadModule(new GardenAPI());
+
+ // features
loadModule(new BazaarOrderHelper());
loadModule(new AuctionsHighlighter());
loadModule(new ChatFilter());
diff --git a/src/main/java/at/hannibal2/skyhanni/events/GardenToolChangeEvent.kt b/src/main/java/at/hannibal2/skyhanni/events/GardenToolChangeEvent.kt
new file mode 100644
index 000000000..cc9f6c961
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/events/GardenToolChangeEvent.kt
@@ -0,0 +1,3 @@
+package at.hannibal2.skyhanni.events
+
+class GardenToolChangeEvent: LorenzEvent() \ No newline at end of file
diff --git a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenAPI.kt b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenAPI.kt
new file mode 100644
index 000000000..9febca860
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenAPI.kt
@@ -0,0 +1,76 @@
+package at.hannibal2.skyhanni.features.garden
+
+import at.hannibal2.skyhanni.data.GardenCropMilestones
+import at.hannibal2.skyhanni.data.IslandType
+import at.hannibal2.skyhanni.events.GardenToolChangeEvent
+import at.hannibal2.skyhanni.utils.ItemUtils.name
+import at.hannibal2.skyhanni.utils.LorenzUtils
+import net.minecraft.client.Minecraft
+import net.minecraft.item.ItemStack
+import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
+import net.minecraftforge.fml.common.gameevent.TickEvent
+
+class GardenAPI {
+
+ var tick = 0
+
+ @SubscribeEvent
+ fun onTick(event: TickEvent.ClientTickEvent) {
+ if (event.phase != TickEvent.Phase.START) return
+ if (!inGarden()) return
+ if (tick++ % 5 != 0) return
+
+ val crop = loadCropInHand()
+ if (cropInHand != crop) {
+ cropInHand = crop
+ GardenToolChangeEvent().postAndCatch()
+ }
+ }
+
+ private fun loadCropInHand(): String? {
+ val heldItem = Minecraft.getMinecraft().thePlayer.heldItem ?: return null
+ if (readCounter(heldItem) == -1) return null
+ return getCropTypeFromItem(heldItem)
+ }
+
+ companion object {
+ // TODO use everywhere instead of IslandType.GARDEN
+ fun inGarden() = LorenzUtils.inSkyBlock && LorenzUtils.skyBlockIsland == IslandType.GARDEN
+
+ var cropInHand: String? = null
+
+ fun getCropTypeFromItem(heldItem: ItemStack): String? {
+ val name = heldItem.name ?: return null
+ for ((crop, _) in GardenCropMilestones.cropCounter) {
+ if (name.contains(crop)) {
+ return crop
+ }
+ }
+ if (name.contains("Coco Chopper")) {
+ return "Cocoa Beans"
+ }
+ if (name.contains("Fungi Cutter")) {
+ return "Mushroom"
+ }
+ return null
+ }
+
+ fun readCounter(itemStack: ItemStack): Int {
+ if (itemStack.hasTagCompound()) {
+ val tag = itemStack.tagCompound
+ if (tag.hasKey("ExtraAttributes", 10)) {
+ val ea = tag.getCompoundTag("ExtraAttributes")
+ if (ea.hasKey("mined_crops", 99)) {
+ return ea.getInteger("mined_crops")
+ }
+
+ // only using cultivating when no crops counter is there
+ if (ea.hasKey("farmed_cultivating", 99)) {
+ return ea.getInteger("farmed_cultivating")
+ }
+ }
+ }
+ return -1
+ }
+ }
+} \ 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 62fced2f5..f44749686 100644
--- a/src/main/java/at/hannibal2/skyhanni/features/garden/GardenCropMilestoneDisplay.kt
+++ b/src/main/java/at/hannibal2/skyhanni/features/garden/GardenCropMilestoneDisplay.kt
@@ -3,28 +3,19 @@ package at.hannibal2.skyhanni.features.garden
import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.config.features.Garden
import at.hannibal2.skyhanni.data.GardenCropMilestones
-import at.hannibal2.skyhanni.data.IslandType
-import at.hannibal2.skyhanni.events.CropMilestoneUpdateEvent
-import at.hannibal2.skyhanni.events.GuiRenderEvent
-import at.hannibal2.skyhanni.events.OwnInventorItemUpdateEvent
-import at.hannibal2.skyhanni.events.ProfileJoinEvent
-import at.hannibal2.skyhanni.utils.ItemUtils.name
+import at.hannibal2.skyhanni.events.*
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.LorenzUtils.sorted
import at.hannibal2.skyhanni.utils.NEUItems
import at.hannibal2.skyhanni.utils.RenderUtils.renderStringsAndItems
import at.hannibal2.skyhanni.utils.TimeUtils
-import net.minecraft.client.Minecraft
-import net.minecraft.item.ItemStack
import net.minecraftforge.fml.common.eventhandler.EventPriority
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
-import net.minecraftforge.fml.common.gameevent.TickEvent
import java.util.*
class GardenCropMilestoneDisplay {
private val progressDisplay = mutableListOf<List<Any>>()
private val bestCropDisplay = mutableListOf<List<Any>>()
- private var currentCrop: String? = null
private var needsInventory = false
private val cultivatingData = mutableMapOf<String, Int>()
private val timeTillNextCrop: MutableMap<String, Long> get() = SkyHanniMod.feature.hidden.gardenTimeTillNextCropMilestone
@@ -65,14 +56,14 @@ class GardenCropMilestoneDisplay {
@SubscribeEvent
fun onOwnInventoryItemUpdate(event: OwnInventorItemUpdateEvent) {
val itemStack = event.itemStack
- val counter = readCounter(itemStack)
+ val counter = GardenAPI.readCounter(itemStack)
if (counter == -1) return
- val crop = getCropTypeFromItem(itemStack) ?: return
+ val crop = GardenAPI.getCropTypeFromItem(itemStack) ?: return
if (cultivatingData.containsKey(crop)) {
val old = cultivatingData[crop]!!
val diff = counter - old
GardenCropMilestones.cropCounter[crop] = GardenCropMilestones.cropCounter[crop]!! + diff
- if (currentCrop == crop) {
+ if (GardenAPI.cropInHand == crop) {
calculateSpeed(diff)
update()
}
@@ -113,45 +104,18 @@ class GardenCropMilestoneDisplay {
countInLastSecond++
}
- private fun readCounter(itemStack: ItemStack): Int {
- if (itemStack.hasTagCompound()) {
- val tag = itemStack.tagCompound
- if (tag.hasKey("ExtraAttributes", 10)) {
- val ea = tag.getCompoundTag("ExtraAttributes")
- if (ea.hasKey("mined_crops", 99)) {
- return ea.getInteger("mined_crops")
- }
-
- // only using cultivating when no crops counter is there
- if (ea.hasKey("farmed_cultivating", 99)) {
- return ea.getInteger("farmed_cultivating")
- }
- }
- }
- return -1
- }
-
- var tick = 0
-
@SubscribeEvent
- fun onTick(event: TickEvent.ClientTickEvent) {
- if (event.phase != TickEvent.Phase.START) return
+ fun onGardenToolChange(event: GardenToolChangeEvent) {
if (!isEnabled()) return
- if (tick++ % 5 != 0) return
-
- val cropInHand = getCropInHand()
- if (currentCrop != cropInHand) {
- resetSpeed()
- currentCrop = cropInHand
- update()
- }
+ resetSpeed()
+ update()
}
private fun update() {
progressDisplay.clear()
bestCropDisplay.clear()
- currentCrop?.let {
+ GardenAPI.cropInHand?.let {
val crops = GardenCropMilestones.cropCounter[it]
if (crops == null) {
println("cropCounter is null for '$it'")
@@ -164,7 +128,7 @@ class GardenCropMilestoneDisplay {
}
}
if (config.cropMilestoneBestAlwaysOn) {
- if (currentCrop == null) {
+ if (GardenAPI.cropInHand == null) {
drawBestDisplay(null)
}
}
@@ -263,28 +227,5 @@ class GardenCropMilestoneDisplay {
}
}
- private fun getCropInHand(): String? {
- val heldItem = Minecraft.getMinecraft().thePlayer.heldItem ?: return null
- if (readCounter(heldItem) == -1) return null
- return getCropTypeFromItem(heldItem)
- }
-
- private fun getCropTypeFromItem(heldItem: ItemStack): String? {
- val name = heldItem.name ?: return null
- for ((crop, _) in GardenCropMilestones.cropCounter) {
- if (name.contains(crop)) {
- return crop
- }
- }
- if (name.contains("Coco Chopper")) {
- return "Cocoa Beans"
- }
- if (name.contains("Fungi Cutter")) {
- return "Mushroom"
- }
- return null
- }
-
- private fun isEnabled() =
- LorenzUtils.inSkyBlock && config.cropMilestoneProgress && LorenzUtils.skyBlockIsland == IslandType.GARDEN
+ private fun isEnabled() = GardenAPI.inGarden() && config.cropMilestoneProgress
} \ No newline at end of file