Skip to content

Commit b4afde9

Browse files
committed
place manager logs and other manager debug logger hud elements
1 parent fb7da09 commit b4afde9

File tree

5 files changed

+114
-16
lines changed

5 files changed

+114
-16
lines changed

src/main/kotlin/com/lambda/gui/dsl/ImGuiBuilder.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,24 @@ import imgui.ImGui.endTabItem
8181
import imgui.ImGui.endTooltip
8282
import imgui.ImGui.getBackgroundDrawList
8383
import imgui.ImGui.getColorU32
84+
import imgui.ImGui.getContentRegionAvail
85+
import imgui.ImGui.getCursorPosX
86+
import imgui.ImGui.getCursorPosY
8487
import imgui.ImGui.getFont
8588
import imgui.ImGui.getFontSize
8689
import imgui.ImGui.getForegroundDrawList
90+
import imgui.ImGui.getFrameHeight
91+
import imgui.ImGui.getFrameHeightWithSpacing
8792
import imgui.ImGui.getIO
8893
import imgui.ImGui.getItemID
94+
import imgui.ImGui.getItemRectMaxX
95+
import imgui.ImGui.getItemRectMaxY
96+
import imgui.ImGui.getItemRectMinX
97+
import imgui.ImGui.getItemRectMinY
8998
import imgui.ImGui.getStyle
9099
import imgui.ImGui.getVersion
100+
import imgui.ImGui.getWindowContentRegionMaxX
101+
import imgui.ImGui.getWindowContentRegionMaxY
91102
import imgui.ImGui.getWindowDrawList
92103
import imgui.ImGui.getWindowHeight
93104
import imgui.ImGui.getWindowPos
@@ -96,6 +107,7 @@ import imgui.ImGui.getWindowPosY
96107
import imgui.ImGui.getWindowSize
97108
import imgui.ImGui.getWindowViewport
98109
import imgui.ImGui.getWindowWidth
110+
import imgui.ImGui.image
99111
import imgui.ImGui.inputDouble
100112
import imgui.ImGui.inputFloat
101113
import imgui.ImGui.inputFloat2
@@ -131,6 +143,7 @@ import imgui.ImGui.pushStyleVar
131143
import imgui.ImGui.pushTextWrapPos
132144
import imgui.ImGui.setClipboardText
133145
import imgui.ImGui.setCursorPosX
146+
import imgui.ImGui.setCursorPosY
134147
import imgui.ImGui.sliderFloat
135148
import imgui.ImGui.sliderInt
136149
import imgui.ImGui.textColored

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ object ManagerUtils {
2525
val accumulatedManagerPriority = managers.map { it.stagePriority }.reduce { acc, priority -> acc + priority }
2626
val positionBlockingManagers = getInstances<PositionBlocking>()
2727

28+
fun DebugLogger.newTick() =
29+
system("------------- New Tick -------------")
30+
2831
fun isPosBlocked(pos: BlockPos) =
2932
positionBlockingManagers.any { manager -> manager.blockedPositions.any { blocked -> blocked == pos } }
3033
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import com.lambda.interaction.material.StackSelection
4141
import com.lambda.interaction.material.StackSelection.Companion.select
4242
import com.lambda.interaction.request.Logger
4343
import com.lambda.interaction.request.ManagerUtils.isPosBlocked
44+
import com.lambda.interaction.request.ManagerUtils.newTick
4445
import com.lambda.interaction.request.PositionBlocking
4546
import com.lambda.interaction.request.RequestHandler
4647
import com.lambda.interaction.request.breaking.BreakConfig.BreakConfirmationMode
@@ -106,7 +107,7 @@ object BreakManager : RequestHandler<BreakRequest>(
106107
TickEvent.Player.Post,
107108
onOpen = {
108109
if (activeInfos.isNotEmpty() || breaks.isNotEmpty() || instantBreaks.isNotEmpty())
109-
BreakManager.logger.system("Tick stage ${BreakManager.tickStage?.run { this::class.qualifiedName }}")
110+
BreakManager.logger.newTick()
110111
processRequest(activeRequest)
111112
simulateAbandoned()
112113
},

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

Lines changed: 70 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ import com.lambda.event.events.TickEvent
2525
import com.lambda.event.events.UpdateManagerEvent
2626
import com.lambda.event.listener.SafeListener.Companion.listen
2727
import com.lambda.interaction.construction.context.PlaceContext
28+
import com.lambda.interaction.request.Logger
2829
import com.lambda.interaction.request.ManagerUtils.isPosBlocked
30+
import com.lambda.interaction.request.ManagerUtils.newTick
2931
import com.lambda.interaction.request.PositionBlocking
3032
import com.lambda.interaction.request.RequestHandler
3133
import com.lambda.interaction.request.breaking.BreakManager
@@ -39,6 +41,7 @@ import com.lambda.interaction.request.placing.PlaceManager.processRequest
3941
import com.lambda.interaction.request.placing.PlacedBlockHandler.pendingActions
4042
import com.lambda.interaction.request.placing.PlacedBlockHandler.setPendingConfigs
4143
import com.lambda.interaction.request.placing.PlacedBlockHandler.startPending
44+
import com.lambda.module.hud.PlaceManagerDebug
4245
import com.lambda.util.BlockUtils.blockState
4346
import com.lambda.util.Communication.warn
4447
import com.lambda.util.player.MovementUtils.sneaking
@@ -68,8 +71,12 @@ object PlaceManager : RequestHandler<PlaceRequest>(
6871
TickEvent.Input.Pre,
6972
TickEvent.Input.Post,
7073
TickEvent.Player.Post,
71-
onOpen = { activeRequest?.let { processRequest(it) } }
72-
), PositionBlocking {
74+
onOpen = {
75+
activeRequest?.let { processRequest(it) }
76+
if (potentialPlacements.isNotEmpty())
77+
PlaceManager.logger.system("Tick stage ${PlaceManager.tickStage?.run { this::class.qualifiedName }}")
78+
}
79+
), PositionBlocking, Logger {
7380
private var activeRequest: PlaceRequest? = null
7481
private var potentialPlacements = mutableListOf<PlaceContext>()
7582

@@ -83,6 +90,8 @@ object PlaceManager : RequestHandler<PlaceRequest>(
8390
override val blockedPositions
8491
get() = pendingActions.map { it.context.blockPos }
8592

93+
override val logger = PlaceManagerDebug
94+
8695
fun Any.onPlace(
8796
alwaysListen: Boolean = false,
8897
priority: Int = 0,
@@ -94,6 +103,11 @@ object PlaceManager : RequestHandler<PlaceRequest>(
94103
override fun load(): String {
95104
super.load()
96105

106+
listen<TickEvent.Pre>(priority = Int.MAX_VALUE) {
107+
if (potentialPlacements.isNotEmpty())
108+
logger.newTick()
109+
}
110+
97111
listen<TickEvent.Post>(priority = Int.MIN_VALUE) {
98112
activeRequest = null
99113
placementsThisTick = 0
@@ -135,6 +149,8 @@ object PlaceManager : RequestHandler<PlaceRequest>(
135149
* @see placeBlock
136150
*/
137151
fun SafeContext.processRequest(request: PlaceRequest) {
152+
logger.debug("Processing request (${request.requestID}) at tick stage ${tickStage?.run { this::class.qualifiedName }}")
153+
138154
if (request.fresh) populateFrom(request)
139155

140156
val iterator = potentialPlacements.iterator()
@@ -143,15 +159,22 @@ object PlaceManager : RequestHandler<PlaceRequest>(
143159
val ctx = iterator.next()
144160

145161
if (ctx.sneak) shouldSneak = true
146-
if (!ctx.requestDependencies(request) || !validSneak(player)) return
147-
// if (tickStage !in request.build.placing.placeStageMask) return
162+
if (!ctx.requestDependencies(request)) {
163+
logger.warning("Dependencies failed for ${request.requestID}")
164+
return
165+
}
166+
if (!validSneak(player)) return
167+
// if (tickStage !in request.build.placing.placeStageMask) return
148168

149169
val actionResult = placeBlock(ctx, request, Hand.MAIN_HAND)
150170
if (!actionResult.isAccepted) warn("Placement interaction failed with $actionResult")
151171
placementsThisTick++
152172
iterator.remove()
153173
}
154-
if (potentialPlacements.isEmpty()) activeRequest = null
174+
if (potentialPlacements.isEmpty()) {
175+
if (activeRequest != null) logger.debug("Clearing active request")
176+
activeRequest = null
177+
}
155178
}
156179

157180
/**
@@ -161,10 +184,12 @@ object PlaceManager : RequestHandler<PlaceRequest>(
161184
* @see isPosBlocked
162185
*/
163186
private fun populateFrom(request: PlaceRequest) {
187+
logger.debug("Populating from request (${request.requestID})")
164188
setPendingConfigs(request.build)
165189
potentialPlacements = request.contexts
166190
.filter { !isPosBlocked(it.blockPos) }
167191
.toMutableList()
192+
logger.debug("${potentialPlacements.size} potential placements")
168193

169194
val pendingLimit = (request.maxPendingPlacements - pendingActions.size).coerceAtLeast(0)
170195
maxPlacementsThisTick = (request.placementsPerTick.coerceAtMost(pendingLimit))
@@ -178,8 +203,14 @@ object PlaceManager : RequestHandler<PlaceRequest>(
178203
private fun SafeContext.placeBlock(placeContext: PlaceContext, request: PlaceRequest, hand: Hand): ActionResult {
179204
interaction.syncSelectedSlot()
180205
val hitResult = placeContext.result
181-
if (!world.worldBorder.contains(hitResult.blockPos)) return ActionResult.FAIL
182-
if (gamemode == GameMode.SPECTATOR) return ActionResult.PASS
206+
if (!world.worldBorder.contains(hitResult.blockPos)) {
207+
logger.error("Placement position outside the world border at ${placeContext.blockPos.toShortString()}")
208+
return ActionResult.FAIL
209+
}
210+
if (gamemode == GameMode.SPECTATOR) {
211+
logger.error("Player is in spectator mode")
212+
return ActionResult.PASS
213+
}
183214
return interactBlockInternal(placeContext, request, request.build.placing, hand, hitResult)
184215
}
185216

@@ -200,11 +231,13 @@ object PlaceManager : RequestHandler<PlaceRequest>(
200231
if (!cantInteract) {
201232
val blockState = blockState(hitResult.blockPos)
202233
if (!connection.hasFeature(blockState.block.requiredFeatures)) {
234+
logger.error("Required features not met for $blockState")
203235
return ActionResult.FAIL
204236
}
205237

206238
val actionResult = blockState.onUse(world, player, hitResult)
207239
if (actionResult.isAccepted) {
240+
logger.error("Block state ($blockState) onUse not accepted")
208241
return actionResult
209242
}
210243
}
@@ -243,9 +276,15 @@ object PlaceManager : RequestHandler<PlaceRequest>(
243276

244277
val cantModifyWorld = !player.abilities.allowModifyWorld
245278
val cantPlaceOn = !itemStack.canPlaceOn(cachedBlockPosition)
246-
if (cantModifyWorld && cantPlaceOn) return ActionResult.PASS
279+
if (cantModifyWorld && cantPlaceOn) {
280+
logger.error("Cannot modify world")
281+
return ActionResult.PASS
282+
}
247283

248-
val item = (itemStack.item as? BlockItem) ?: return ActionResult.PASS
284+
val item = (itemStack.item as? BlockItem) ?: run {
285+
logger.error("Item ${itemStack.item.name} is not a block item")
286+
return ActionResult.PASS
287+
}
249288

250289
return place(placeContext, request, hand, hitResult, placeConfig, item, ItemPlacementContext(context))
251290
}
@@ -264,11 +303,23 @@ object PlaceManager : RequestHandler<PlaceRequest>(
264303
item: BlockItem,
265304
context: ItemPlacementContext
266305
): ActionResult {
267-
if (!item.block.isEnabled(world.enabledFeatures)) return ActionResult.FAIL
268-
if (!context.canPlace()) return ActionResult.FAIL
306+
if (!item.block.isEnabled(world.enabledFeatures)) {
307+
logger.error("Block ${item.block.name} is not enabled")
308+
return ActionResult.FAIL
309+
}
310+
if (!context.canPlace()) {
311+
logger.error("Cannot place at ${placeContext.blockPos} with current state ${placeContext.cachedState}")
312+
return ActionResult.FAIL
313+
}
269314

270-
val itemPlacementContext = item.getPlacementContext(context) ?: return ActionResult.FAIL
271-
val blockState = item.getPlacementState(itemPlacementContext) ?: return ActionResult.FAIL
315+
val itemPlacementContext = item.getPlacementContext(context) ?: run {
316+
logger.error("Could not retrieve item placement context")
317+
return ActionResult.FAIL
318+
}
319+
val blockState = item.getPlacementState(itemPlacementContext) ?: run {
320+
logger.error("Could not retrieve placement state")
321+
return ActionResult.FAIL
322+
}
272323

273324
val stackInHand = player.getStackInHand(hand)
274325
val stackCountPre = stackInHand.count
@@ -302,7 +353,10 @@ object PlaceManager : RequestHandler<PlaceRequest>(
302353
// TODO: Implement restriction checks (e.g., world height) to prevent unnecessary server requests when the
303354
// "AwaitThenPlace" confirmation setting is enabled, as the block state setting methods that validate these
304355
// rules are not called.
305-
if (!item.place(itemPlacementContext, blockState)) return ActionResult.FAIL
356+
if (!item.place(itemPlacementContext, blockState)) {
357+
logger.error("Could not place block client side at ${placeContext.blockPos} with placement state ${placeContext.expectedState}")
358+
return ActionResult.FAIL
359+
}
306360

307361
val blockPos = itemPlacementContext.blockPos
308362
var state = world.getBlockState(blockPos)
@@ -318,6 +372,8 @@ object PlaceManager : RequestHandler<PlaceRequest>(
318372
request.onPlace?.invoke(placeContext.blockPos)
319373
}
320374

375+
logger.success("Placed ${placeContext.expectedState} at ${placeContext.blockPos}")
376+
321377
return ActionResult.SUCCESS
322378
}
323379

src/main/kotlin/com/lambda/module/hud/BreakManagerDebug.kt renamed to src/main/kotlin/com/lambda/module/hud/ManagerDebugLoggers.kt

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,30 @@ import com.lambda.interaction.request.DebugLogger
2121

2222
object BreakManagerDebug : DebugLogger(
2323
"Break Manager Logger",
24-
"Logs most of the actions performed in the break manager to aid in debugging"
24+
"Logs actions performed in the break manager to aid in debugging"
25+
)
26+
27+
object PlaceManagerDebug : DebugLogger(
28+
"Place Manager Logger",
29+
"Logs actions performed in the place manager to aid in debugging"
30+
)
31+
32+
object InteractManagerDebug : DebugLogger(
33+
"Interact Manager Logger",
34+
"Logs actions performed in the interact manager to aid in debugging"
35+
)
36+
37+
object RotationManagerDebug : DebugLogger(
38+
"Rotation Manager Logger",
39+
"Logs actions performed in the rotation manager to aid in debugging"
40+
)
41+
42+
object HotbarManagerDebug : DebugLogger(
43+
"Hotbar Manager Logger",
44+
"Logs actions performed in the hotbar manager to aid in debugging"
45+
)
46+
47+
object InventoryManagerDebug : DebugLogger(
48+
"Inventory Manager Logger",
49+
"Logs actions performed in the inventory manager to aid in debugging"
2550
)

0 commit comments

Comments
 (0)