aboutsummaryrefslogtreecommitdiff
path: root/mod/src/main/kotlin/moe/nea/ledger/modules/CaducousFeederDetection.kt
blob: b64c7e5b49c76c89a9cf23d47a6fd28f17649962 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package moe.nea.ledger.modules

import moe.nea.ledger.ItemChange
import moe.nea.ledger.ItemId
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
		if (!player.inventory.mainInventory.any { it?.getInternalId() == ItemIds.ULTIMATE_CARROT_CANDY }) return
		if (stack.getDisplayNameU() != "§aUse Caducous Feeder") return
		val petId = slot.inventory.getStackInSlot(13)?.getInternalId() ?: ItemId.NIL

		logger.logEntry(
			LedgerEntry(
				TransactionType.CADUCOUS_FEEDER_USED,
				Instant.now(),
				listOf(
					ItemChange.lose(ItemIds.ULTIMATE_CARROT_CANDY, 1),
					ItemChange(petId, 1.0, ItemChange.ChangeDirection.TRANSFORM),
				)
			)
		)
	}
}