aboutsummaryrefslogtreecommitdiff
path: root/mod/src/main/kotlin/moe/nea/ledger/utils
diff options
context:
space:
mode:
authorLinnea Gräf <nea@nea.moe>2025-01-30 20:11:37 +0100
committerLinnea Gräf <nea@nea.moe>2025-01-30 20:11:37 +0100
commit8e386bcf8d10784fc7784333be9e4470598c71d4 (patch)
treef0bd83c41bd083b6708703d420fe466b5f66111a /mod/src/main/kotlin/moe/nea/ledger/utils
parente51a59636129c35b58dbdda83b141b539a87e6fe (diff)
downloadLocalTransactionLedger-8e386bcf8d10784fc7784333be9e4470598c71d4.tar.gz
LocalTransactionLedger-8e386bcf8d10784fc7784333be9e4470598c71d4.tar.bz2
LocalTransactionLedger-8e386bcf8d10784fc7784333be9e4470598c71d4.zip
feat: Add ledger event as a baseclass for events with error reportingHEADnightlymaster
Diffstat (limited to 'mod/src/main/kotlin/moe/nea/ledger/utils')
-rw-r--r--mod/src/main/kotlin/moe/nea/ledger/utils/ScreenUtil.kt29
-rw-r--r--mod/src/main/kotlin/moe/nea/ledger/utils/telemetry/Span.kt3
2 files changed, 31 insertions, 1 deletions
diff --git a/mod/src/main/kotlin/moe/nea/ledger/utils/ScreenUtil.kt b/mod/src/main/kotlin/moe/nea/ledger/utils/ScreenUtil.kt
new file mode 100644
index 0000000..0305126
--- /dev/null
+++ b/mod/src/main/kotlin/moe/nea/ledger/utils/ScreenUtil.kt
@@ -0,0 +1,29 @@
+package moe.nea.ledger.utils
+
+import moe.nea.ledger.mixin.AccessorContainerDispenser
+import moe.nea.ledger.mixin.AccessorContainerHopper
+import net.minecraft.client.gui.GuiScreen
+import net.minecraft.client.gui.inventory.GuiContainer
+import net.minecraft.inventory.ContainerChest
+import net.minecraft.inventory.IInventory
+
+object ScreenUtil {
+ fun estimateInventory(screen: GuiScreen?): IInventory? {
+ if (screen !is GuiContainer) {
+ return null
+ }
+ val container = screen.inventorySlots ?: return null
+ if (container is ContainerChest)
+ return container.lowerChestInventory
+ if (container is AccessorContainerDispenser)
+ return container.dispenserInventory_ledger
+ if (container is AccessorContainerHopper)
+ return container.hopperInventory_ledger
+ return null
+
+ }
+
+ fun estimateName(screen: GuiScreen?): String? {
+ return estimateInventory(screen)?.name
+ }
+} \ No newline at end of file
diff --git a/mod/src/main/kotlin/moe/nea/ledger/utils/telemetry/Span.kt b/mod/src/main/kotlin/moe/nea/ledger/utils/telemetry/Span.kt
index 0d680a9..8b8e284 100644
--- a/mod/src/main/kotlin/moe/nea/ledger/utils/telemetry/Span.kt
+++ b/mod/src/main/kotlin/moe/nea/ledger/utils/telemetry/Span.kt
@@ -2,9 +2,10 @@ package moe.nea.ledger.utils.telemetry
class Span(val parent: Span?) : AutoCloseable {
companion object {
+ val rootSpan = Span(null)
private val _current = object : InheritableThreadLocal<Span>() {
override fun initialValue(): Span {
- return Span(null)
+ return Span(rootSpan)
}
override fun childValue(parentValue: Span?): Span {