From 02830fc904792aa1945f5072e0815dbf02baebe7 Mon Sep 17 00:00:00 2001
From: jani270 <69345714+jani270@users.noreply.github.com>
Date: Fri, 24 Jan 2025 23:23:50 +0100
Subject: feat: Caducous (Hard word) Feeder Detection

---
 .../main/kotlin/moe/nea/ledger/TransactionType.kt  |  1 +
 mod/src/main/kotlin/moe/nea/ledger/Ledger.kt       |  2 +
 .../nea/ledger/modules/CaducousFeederDetection.kt  | 46 ++++++++++++++++++++++
 3 files changed, 49 insertions(+)
 create mode 100644 mod/src/main/kotlin/moe/nea/ledger/modules/CaducousFeederDetection.kt

diff --git a/basetypes/src/main/kotlin/moe/nea/ledger/TransactionType.kt b/basetypes/src/main/kotlin/moe/nea/ledger/TransactionType.kt
index e1413a6..527b6cd 100644
--- a/basetypes/src/main/kotlin/moe/nea/ledger/TransactionType.kt
+++ b/basetypes/src/main/kotlin/moe/nea/ledger/TransactionType.kt
@@ -17,6 +17,7 @@ enum class TransactionType {
 	BAZAAR_SELL_ORDER,
 	BITS_PURSE_STATUS,
 	BOOSTER_COOKIE_ATE,
+	CADUCOUS_FEEDER_USED,
 	CAPSAICIN_EYEDROPS_USED,
 	COMMUNITY_SHOP_BUY,
 	CORPSE_DESECRATED,
diff --git a/mod/src/main/kotlin/moe/nea/ledger/Ledger.kt b/mod/src/main/kotlin/moe/nea/ledger/Ledger.kt
index b126c4a..9bbc8e1 100644
--- a/mod/src/main/kotlin/moe/nea/ledger/Ledger.kt
+++ b/mod/src/main/kotlin/moe/nea/ledger/Ledger.kt
@@ -22,6 +22,7 @@ import moe.nea.ledger.modules.BazaarDetection
 import moe.nea.ledger.modules.BazaarOrderDetection
 import moe.nea.ledger.modules.BitsDetection
 import moe.nea.ledger.modules.BitsShopDetection
+import moe.nea.ledger.modules.CaducousFeederDetection
 import moe.nea.ledger.modules.DragonEyePlacementDetection
 import moe.nea.ledger.modules.DragonSacrificeDetection
 import moe.nea.ledger.modules.DungeonChestDetection
@@ -136,6 +137,7 @@ class Ledger {
 			BazaarOrderDetection::class.java,
 			BitsDetection::class.java,
 			BitsShopDetection::class.java,
+			CaducousFeederDetection::class.java,
 			ConfigCommand::class.java,
 			DebugDataCommand::class.java,
 			DragonEyePlacementDetection::class.java,
diff --git a/mod/src/main/kotlin/moe/nea/ledger/modules/CaducousFeederDetection.kt b/mod/src/main/kotlin/moe/nea/ledger/modules/CaducousFeederDetection.kt
new file mode 100644
index 0000000..76374ef
--- /dev/null
+++ b/mod/src/main/kotlin/moe/nea/ledger/modules/CaducousFeederDetection.kt
@@ -0,0 +1,46 @@
+package moe.nea.ledger.modules
+
+import moe.nea.ledger.ItemChange
+import moe.nea.ledger.LedgerEntry
+import moe.nea.ledger.LedgerLogger
+import moe.nea.ledger.TransactionType
+import moe.nea.ledger.events.GuiClickEvent
+import moe.nea.ledger.gen.ItemIds
+import moe.nea.ledger.getDisplayNameU
+import moe.nea.ledger.getInternalId
+import moe.nea.ledger.unformattedString
+import moe.nea.ledger.utils.di.Inject
+import net.minecraft.client.Minecraft
+import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
+import java.time.Instant
+
+class CaducousFeederDetection {
+
+    @Inject
+    lateinit var logger: LedgerLogger
+
+    @Inject
+    lateinit var minecraft: Minecraft
+
+    @SubscribeEvent
+    fun onFeederClick(event: GuiClickEvent) {
+        val slot = event.slotIn ?: return
+        val displayName = slot.inventory.displayName.unformattedText
+        if (!displayName.unformattedString().contains("Confirm Caducous Feeder")) return
+        val stack = slot.stack ?: return
+        val player = minecraft.thePlayer ?: return
+        val hasCarrotCandy = player.inventory.mainInventory.any { it?.getInternalId() == ItemIds.ULTIMATE_CARROT_CANDY }
+
+        if (hasCarrotCandy && stack.getDisplayNameU() == "§aUse Caducous Feeder") {
+            logger.logEntry(
+                LedgerEntry(
+                    TransactionType.CADUCOUS_FEEDER_USED,
+                    Instant.now(),
+                    listOf(
+                        ItemChange.lose(ItemIds.ULTIMATE_CARROT_CANDY, 1)
+                    )
+                )
+            )
+        }
+    }
+}
\ No newline at end of file
-- 
cgit