Skip to content

Commit 582f1b3

Browse files
committed
value builder function
1 parent a5d4eb4 commit 582f1b3

File tree

14 files changed

+77
-67
lines changed

14 files changed

+77
-67
lines changed

src/main/kotlin/com/lambda/interaction/construction/context/BreakContext.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,13 @@ data class BreakContext(
8181
buildLogContext {
8282
text("Break Context:")
8383
pushTab()
84-
text("Block Pos: ${blockPos.toLogContext()}")
84+
text(blockPos.toLogContext())
8585
text(result.toLogContext())
8686
text(rotation.toLogContext())
87-
text("Hotbar Index: $hotbarIndex")
88-
text("Instant Break: $instantBreak")
89-
text("Cached State: $cachedState")
90-
text("Expected State: $expectedState")
91-
text("Sort Mode: $sortMode")
87+
value("Hotbar Index", hotbarIndex)
88+
value("Instant Break", instantBreak)
89+
value("Cached State", cachedState)
90+
value("Expected State", expectedState)
91+
value("Sort Mode", sortMode)
9292
}
9393
}

src/main/kotlin/com/lambda/interaction/construction/context/InteractionContext.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,11 @@ class InteractionContext(
7676
buildLogContext {
7777
text("Interaction Context:")
7878
pushTab()
79-
text("Block Pos: ${blockPos.toLogContext()}")
79+
text(blockPos.toLogContext())
8080
text(result.toLogContext())
8181
text(rotation.toLogContext())
82-
text("Hotbar Index: $hotbarIndex")
83-
text("Cached State: $cachedState")
84-
text("Expected State: $expectedState")
82+
value("Hotbar Index", hotbarIndex)
83+
value("Cached State", cachedState)
84+
value("Expected State", expectedState)
8585
}
8686
}

src/main/kotlin/com/lambda/interaction/construction/context/PlaceContext.kt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,14 @@ data class PlaceContext(
8787
buildLogContext {
8888
text("Place Context:")
8989
pushTab()
90-
text("Block Pos: ${blockPos.toLogContext()}")
90+
text(blockPos.toLogContext())
9191
text(result.toLogContext())
9292
text(rotation.toLogContext())
93-
text("Hotbar Index: $hotbarIndex")
94-
text("Cached State: $cachedState")
95-
text("Expected State: $expectedState")
96-
text("Sneak: $sneak")
97-
text("Inside Block: $insideBlock")
98-
text("Current Dir Is Invalid: $currentDirIsValid")
93+
value("Hotbar Index", hotbarIndex)
94+
value("Cached State", cachedState)
95+
value("Expected State", expectedState)
96+
value("Sneak", sneak)
97+
value("Inside Block", insideBlock)
98+
value("Current Dir Is Invalid", currentDirIsValid)
9999
}
100100
}

src/main/kotlin/com/lambda/interaction/request/DebugLogger.kt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,16 +141,18 @@ class DebugLogger(
141141
companion object {
142142
fun BlockPos.toLogContext(): String {
143143
val pos = if (this is BlockPos.Mutable) toImmutable() else this
144-
return "Pos: ${pos.toShortString()}"
144+
return buildLogContext {
145+
value("Block Pos", pos.toShortString())
146+
}
145147
}
146148

147149
fun BlockHitResult.toLogContext() =
148150
buildLogContext {
149151
text("Block Hit Result:")
150152
pushTab()
151-
text("Side: $side")
152-
text("Block Pos: $blockPos")
153-
text("Pos: $pos")
153+
value("Side", side)
154+
value("Block Pos", blockPos)
155+
value("Pos", pos)
154156
}
155157
}
156158
}

src/main/kotlin/com/lambda/interaction/request/LogContext.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,14 @@ interface LogContext {
4747
logContext += "$text\n"
4848
}
4949

50+
fun value(name: String, value: Any) {
51+
text("$name: $value")
52+
}
53+
54+
fun value(name: String, value: String) {
55+
text("$name: $value")
56+
}
57+
5058
@LogContextDsl
5159
fun pushTab() {
5260
tabs++

src/main/kotlin/com/lambda/interaction/request/breaking/BreakInfo.kt

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -155,24 +155,24 @@ data class BreakInfo(
155155
buildLogContext {
156156
text("Break Info:")
157157
pushTab()
158-
text("Type: $type")
159-
text("Pos: ${context.blockPos.toLogContext()}")
158+
value("Type", type)
159+
text(context.blockPos.toLogContext())
160160
text(context.toLogContext())
161161
text("Details:")
162162
pushTab()
163-
text("Should Progress: $shouldProgress")
164-
text("Rebreak Potential: $rebreakPotential")
163+
value("Should Progress", shouldProgress)
164+
value("Rebreak Potential", rebreakPotential)
165165
text(swapInfo.toLogContext())
166-
text("Swap Stack: $swapStack")
167-
text("Updated This Tick: $updatedThisTick")
168-
text("Updated Pre-Processing This Tick: $updatedPreProcessingThisTick")
169-
text("Progressed This Tick: $progressedThisTick")
170-
text("Breaking: $breaking")
171-
text("Abandoned: $abandoned")
172-
text("Breaking Ticks: $breakingTicks")
173-
text("Sounds Cooldown: $soundsCooldown")
174-
text("Vanilla Instant Breakable: $vanillaInstantBreakable")
175-
text("Rebreakable: $rebreakable")
166+
value("Swap Stack", swapStack)
167+
value("Updated This Tick", updatedThisTick)
168+
value("Updated Pre-Processing This Tick", updatedPreProcessingThisTick)
169+
value("Progressed This Tick", progressedThisTick)
170+
value("Breaking", breaking)
171+
value("Abandoned", abandoned)
172+
value("Breaking Ticks", breakingTicks)
173+
value("Sounds Cooldown", soundsCooldown)
174+
value("Vanilla Instant Breakable", vanillaInstantBreakable)
175+
value("Rebreakable", rebreakable)
176176
}
177177

178178
override fun toString() = "$type, ${context.cachedState}, ${context.blockPos}"

src/main/kotlin/com/lambda/interaction/request/breaking/BreakRequest.kt

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -64,17 +64,17 @@ data class BreakRequest(
6464
buildLogContext {
6565
text("Break Request")
6666
pushTab()
67-
text("Request ID: $requestID")
68-
text("Contexts: ${contexts.size}")
67+
value("Request ID", requestID)
68+
value("Contexts", contexts.size)
6969
text("Callbacks:")
7070
pushTab()
71-
text("onStart: ${onStart != null}")
72-
text("onUpdate: ${onUpdate != null}")
73-
text("onStop: ${onStop != null}")
74-
text("onCancel: ${onCancel != null}")
75-
text("onItemDrop: ${onItemDrop != null}")
76-
text("onReBreakStart: ${onReBreakStart != null}")
77-
text("onReBreak: ${onReBreak != null}")
71+
value("onStart", onStart != null)
72+
value("onUpdate", onUpdate != null)
73+
value("onStop", onStop != null)
74+
value("onCancel", onCancel != null)
75+
value("onItemDrop", onItemDrop != null)
76+
value("onReBreakStart", onReBreakStart != null)
77+
value("onReBreak", onReBreak != null)
7878
}
7979

8080
@DslMarker

src/main/kotlin/com/lambda/interaction/request/breaking/SwapInfo.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@ data class SwapInfo(
4747
buildLogContext {
4848
text("Swap Info:")
4949
pushTab()
50-
text("Type: $type")
51-
text("Swap: $swap")
52-
text("Min Keep Ticks: $minKeepTicks")
53-
text("Valid Swap: $validSwap")
50+
value("Type", type)
51+
value("Swap", swap)
52+
value("Min Keep Ticks", minKeepTicks)
53+
value("Valid Swap", validSwap)
5454
}
5555

5656
companion object {

src/main/kotlin/com/lambda/interaction/request/hotbar/HotbarRequest.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,12 @@ class HotbarRequest(
4646
buildLogContext {
4747
text("Hotbar Request:")
4848
pushTab()
49-
text("Request ID: $requestID")
50-
text("Slot: $slot")
51-
text("Keep Ticks: $keepTicks")
52-
text("Swap Pause: $swapPause")
53-
text("Swap Pause Age: $swapPauseAge")
54-
text("Active Request Age: $activeRequestAge")
49+
value("Request ID", requestID)
50+
value("Slot", slot)
51+
value("Keep Ticks", keepTicks)
52+
value("Swap Pause", swapPause)
53+
value("Swap Pause Age", swapPauseAge)
54+
value("Active Request Age", activeRequestAge)
5555
}
5656

5757
companion object {

src/main/kotlin/com/lambda/interaction/request/interacting/InteractRequest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ data class InteractRequest(
5050
buildLogContext {
5151
text("Interact Request:")
5252
pushTab()
53-
text("Request ID: $requestID")
54-
text("Contexts: ${contexts.size}")
53+
value("Request ID", requestID)
54+
value("Contexts", contexts.size)
5555
}
5656

5757
companion object {

0 commit comments

Comments
 (0)