Skip to content

Commit a5d4eb4

Browse files
committed
toLogContext for all manager contexts
1 parent dbdab88 commit a5d4eb4

File tree

7 files changed

+67
-9
lines changed

7 files changed

+67
-9
lines changed

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

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,11 @@ import com.lambda.graphics.renderer.esp.DirectionMask
2121
import com.lambda.graphics.renderer.esp.DirectionMask.exclude
2222
import com.lambda.graphics.renderer.esp.ShapeBuilder
2323
import com.lambda.interaction.material.StackSelection
24+
import com.lambda.interaction.request.DebugLogger.LogEntry.Companion.toLogContext
25+
import com.lambda.interaction.request.LogContext
26+
import com.lambda.interaction.request.LogContext.Companion.buildLogContext
2427
import com.lambda.interaction.request.breaking.BreakConfig
25-
import com.lambda.interaction.request.breaking.BreakRequest
2628
import com.lambda.interaction.request.hotbar.HotbarManager
27-
import com.lambda.interaction.request.hotbar.HotbarRequest
2829
import com.lambda.interaction.request.rotating.RotationRequest
2930
import com.lambda.util.BlockUtils.emptyState
3031
import net.minecraft.block.BlockState
@@ -42,7 +43,7 @@ data class BreakContext(
4243
var instantBreak: Boolean,
4344
override var cachedState: BlockState,
4445
val sortMode: BreakConfig.SortMode
45-
) : BuildContext() {
46+
) : BuildContext(), LogContext {
4647
private val baseColor = Color(222, 0, 0, 25)
4748
private val sideColor = Color(222, 0, 0, 100)
4849

@@ -75,4 +76,18 @@ data class BreakContext(
7576
override fun ShapeBuilder.buildRenderer() {
7677
box(blockPos, cachedState, baseColor, sideColor, DirectionMask.ALL.exclude(result.side))
7778
}
79+
80+
override fun toLogContext() =
81+
buildLogContext {
82+
text("Break Context:")
83+
pushTab()
84+
text("Block Pos: ${blockPos.toLogContext()}")
85+
text(result.toLogContext())
86+
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")
92+
}
7893
}

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ package com.lambda.interaction.construction.context
1919

2020
import com.lambda.graphics.renderer.esp.DirectionMask.mask
2121
import com.lambda.graphics.renderer.esp.ShapeBuilder
22+
import com.lambda.interaction.request.DebugLogger.LogEntry.Companion.toLogContext
23+
import com.lambda.interaction.request.LogContext
24+
import com.lambda.interaction.request.LogContext.Companion.buildLogContext
2225
import com.lambda.interaction.request.Request.Companion.submit
2326
import com.lambda.interaction.request.hotbar.HotbarManager
2427
import com.lambda.interaction.request.hotbar.HotbarRequest
@@ -36,7 +39,7 @@ class InteractionContext(
3639
override var hotbarIndex: Int,
3740
override var cachedState: BlockState,
3841
override val expectedState: BlockState,
39-
) : BuildContext() {
42+
) : BuildContext(), LogContext {
4043
private val baseColor = Color(35, 254, 79, 25)
4144
private val sideColor = Color(35, 254, 79, 100)
4245

@@ -68,4 +71,16 @@ class InteractionContext(
6871
val validRotation = if (request.rotate) submit(rotation, false).done else true
6972
return hotbarRequest.done && validRotation
7073
}
74+
75+
override fun toLogContext() =
76+
buildLogContext {
77+
text("Interaction Context:")
78+
pushTab()
79+
text("Block Pos: ${blockPos.toLogContext()}")
80+
text(result.toLogContext())
81+
text(rotation.toLogContext())
82+
text("Hotbar Index: $hotbarIndex")
83+
text("Cached State: $cachedState")
84+
text("Expected State: $expectedState")
85+
}
7186
}

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

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,17 @@
1818
package com.lambda.interaction.construction.context
1919

2020
import com.lambda.Lambda.mc
21-
import com.lambda.context.SafeContext
22-
import com.lambda.graphics.renderer.esp.DirectionMask
23-
import com.lambda.graphics.renderer.esp.DirectionMask.exclude
2421
import com.lambda.graphics.renderer.esp.DirectionMask.mask
2522
import com.lambda.graphics.renderer.esp.ShapeBuilder
23+
import com.lambda.interaction.request.DebugLogger.LogEntry.Companion.toLogContext
24+
import com.lambda.interaction.request.LogContext
25+
import com.lambda.interaction.request.LogContext.Companion.buildLogContext
2626
import com.lambda.interaction.request.Request.Companion.submit
2727
import com.lambda.interaction.request.hotbar.HotbarManager
2828
import com.lambda.interaction.request.hotbar.HotbarRequest
2929
import com.lambda.interaction.request.placing.PlaceRequest
3030
import com.lambda.interaction.request.rotating.RotationRequest
3131
import com.lambda.util.BlockUtils
32-
import com.lambda.util.BlockUtils.blockState
3332
import net.minecraft.block.BlockState
3433
import net.minecraft.util.hit.BlockHitResult
3534
import net.minecraft.util.math.BlockPos
@@ -45,7 +44,7 @@ data class PlaceContext(
4544
val sneak: Boolean,
4645
val insideBlock: Boolean,
4746
val currentDirIsValid: Boolean = false
48-
) : BuildContext() {
47+
) : BuildContext(), LogContext {
4948
private val baseColor = Color(35, 188, 254, 25)
5049
private val sideColor = Color(35, 188, 254, 100)
5150

@@ -83,4 +82,19 @@ data class PlaceContext(
8382
} else true
8483
return hotbarRequest.done && validRotation
8584
}
85+
86+
override fun toLogContext() =
87+
buildLogContext {
88+
text("Place Context:")
89+
pushTab()
90+
text("Block Pos: ${blockPos.toLogContext()}")
91+
text(result.toLogContext())
92+
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")
99+
}
86100
}

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,15 @@ package com.lambda.interaction.request
2020
import com.lambda.Lambda.mc
2121
import com.lambda.gui.LambdaScreen
2222
import com.lambda.gui.dsl.ImGuiBuilder
23+
import com.lambda.interaction.request.LogContext.Companion.buildLogContext
2324
import com.lambda.module.hud.ManagerDebugLoggers.maxLogEntries
2425
import com.lambda.util.math.a
2526
import imgui.ImGui
2627
import imgui.flag.ImGuiCol
2728
import imgui.flag.ImGuiWindowFlags
2829
import imgui.type.ImBoolean
2930
import imgui.type.ImFloat
31+
import net.minecraft.util.hit.BlockHitResult
3032
import net.minecraft.util.math.BlockPos
3133
import java.awt.Color
3234
import java.util.*
@@ -141,6 +143,15 @@ class DebugLogger(
141143
val pos = if (this is BlockPos.Mutable) toImmutable() else this
142144
return "Pos: ${pos.toShortString()}"
143145
}
146+
147+
fun BlockHitResult.toLogContext() =
148+
buildLogContext {
149+
text("Block Hit Result:")
150+
pushTab()
151+
text("Side: $side")
152+
text("Block Pos: $blockPos")
153+
text("Pos: $pos")
154+
}
144155
}
145156
}
146157

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ data class BreakInfo(
157157
pushTab()
158158
text("Type: $type")
159159
text("Pos: ${context.blockPos.toLogContext()}")
160+
text(context.toLogContext())
160161
text("Details:")
161162
pushTab()
162163
text("Should Progress: $shouldProgress")

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,6 @@ data class InteractionInfo(
3232
buildLogContext {
3333
text("Interaction Info:")
3434
pushTab()
35+
text(context.toLogContext())
3536
}
3637
}

src/main/kotlin/com/lambda/interaction/request/placing/PlaceInfo.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ data class PlaceInfo(
3434
buildLogContext {
3535
text("Place Info:")
3636
pushTab()
37+
text(context.toLogContext())
3738
text("Callbacks:")
3839
pushTab()
3940
text("onPlace: ${onPlace != null}")

0 commit comments

Comments
 (0)