aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
authorLinnea Gräf <nea@nea.moe>2024-02-21 22:45:21 +0100
committerLinnea Gräf <nea@nea.moe>2024-02-21 22:45:21 +0100
commitbf0c287e020f3c414b4a3e2a4456452d8e07ce59 (patch)
treef5b42046f20cb5eab9421c78bbdff4797b3fb738 /src/main
parent619652c75b2dda06550cc8c89d0b0d5b70d3ba6f (diff)
downloadLocalTransactionLedger-bf0c287e020f3c414b4a3e2a4456452d8e07ce59.tar.gz
LocalTransactionLedger-bf0c287e020f3c414b4a3e2a4456452d8e07ce59.tar.bz2
LocalTransactionLedger-bf0c287e020f3c414b4a3e2a4456452d8e07ce59.zip
Add flip order -> buy order claim detection
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/moe/nea/ledger/BazaarOrderDetection.kt32
-rw-r--r--src/main/java/moe/nea/ledger/mixin/AccessorGuiEditSign.java12
2 files changed, 44 insertions, 0 deletions
diff --git a/src/main/java/moe/nea/ledger/BazaarOrderDetection.kt b/src/main/java/moe/nea/ledger/BazaarOrderDetection.kt
index 1cb23bc..79ba65b 100644
--- a/src/main/java/moe/nea/ledger/BazaarOrderDetection.kt
+++ b/src/main/java/moe/nea/ledger/BazaarOrderDetection.kt
@@ -1,5 +1,8 @@
package moe.nea.ledger
+import moe.nea.ledger.mixin.AccessorGuiEditSign
+import net.minecraft.client.gui.inventory.GuiEditSign
+import net.minecraftforge.client.event.GuiScreenEvent
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import java.util.regex.Pattern
@@ -9,9 +12,38 @@ class BazaarOrderDetection(val ledger: LedgerLogger, val ids: ItemIdProvider) {
Pattern.compile("\\[Bazaar] Claimed (?<amount>$SHORT_NUMBER_PATTERN)x (?<what>.*) worth (?<coins>$SHORT_NUMBER_PATTERN) coins? bought for $SHORT_NUMBER_PATTERN each!")
val sellOrderClaimed =
Pattern.compile("\\[Bazaar] Claimed (?<coins>$SHORT_NUMBER_PATTERN) coins? from selling (?<amount>$SHORT_NUMBER_PATTERN)x (?<what>.*) at $SHORT_NUMBER_PATTERN each!")
+ val orderFlipped =
+ Pattern.compile("\\[Bazaar] Order Flipped! (?<amount>$SHORT_NUMBER_PATTERN)x (?<what>.*) for (?<coins>$SHORT_NUMBER_PATTERN) coins? of total expected profit.")
+ val previousPricePattern =
+ Pattern.compile("(?<price>$SHORT_NUMBER_PATTERN)/u")
+ var lastFlippedPreviousPrice = 0.0
+
+ @SubscribeEvent
+ fun detectSignFlip(event: GuiScreenEvent.InitGuiEvent) {
+ val gui = event.gui
+ if (gui !is GuiEditSign) return
+ gui as AccessorGuiEditSign
+ val text = gui.tileEntity_ledger.signText
+ if (text[2].unformattedText != "Previous price:") return
+ previousPricePattern.useMatcher(text[3].unformattedText) {
+ lastFlippedPreviousPrice = parseShortNumber(group("price"))
+ }
+ }
@SubscribeEvent
fun detectBuyOrders(event: ChatReceived) {
+ orderFlipped.useMatcher(event.message) {
+ val amount = parseShortNumber(group("amount")).toInt()
+ ledger.logEntry(
+ LedgerEntry(
+ "BAZAAR_BUY_ORDER",
+ event.timestamp,
+ lastFlippedPreviousPrice * amount,
+ ids.findForName(group("what")),
+ amount,
+ )
+ )
+ }
buyOrderClaimed.useMatcher(event.message) {
ledger.logEntry(
LedgerEntry(
diff --git a/src/main/java/moe/nea/ledger/mixin/AccessorGuiEditSign.java b/src/main/java/moe/nea/ledger/mixin/AccessorGuiEditSign.java
new file mode 100644
index 0000000..52b8911
--- /dev/null
+++ b/src/main/java/moe/nea/ledger/mixin/AccessorGuiEditSign.java
@@ -0,0 +1,12 @@
+package moe.nea.ledger.mixin;
+
+import net.minecraft.client.gui.inventory.GuiEditSign;
+import net.minecraft.tileentity.TileEntitySign;
+import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.gen.Accessor;
+
+@Mixin(GuiEditSign.class)
+public interface AccessorGuiEditSign {
+ @Accessor("tileSign")
+ TileEntitySign getTileEntity_ledger();
+}