From 858553d2b7d376a57417e45f7e87de7a774f5288 Mon Sep 17 00:00:00 2001 From: beanbag44 Date: Thu, 21 Aug 2025 02:49:13 +0100 Subject: [PATCH 01/38] initial logger hud --- .../kotlin/com/lambda/gui/dsl/ImGuiBuilder.kt | 135 +++++++++++++++++- .../lambda/interaction/request/DebugLogger.kt | 114 +++++++++++++++ .../com/lambda/interaction/request/Logger.kt | 22 +++ .../interaction/request/ManagerUtils.kt | 1 + .../request/breaking/BreakManager.kt | 4 +- .../lambda/module/hud/BreakManagerDebug.kt | 34 +++++ 6 files changed, 303 insertions(+), 7 deletions(-) create mode 100644 src/main/kotlin/com/lambda/interaction/request/DebugLogger.kt create mode 100644 src/main/kotlin/com/lambda/interaction/request/Logger.kt create mode 100644 src/main/kotlin/com/lambda/module/hud/BreakManagerDebug.kt diff --git a/src/main/kotlin/com/lambda/gui/dsl/ImGuiBuilder.kt b/src/main/kotlin/com/lambda/gui/dsl/ImGuiBuilder.kt index a00e84185..ca8647170 100644 --- a/src/main/kotlin/com/lambda/gui/dsl/ImGuiBuilder.kt +++ b/src/main/kotlin/com/lambda/gui/dsl/ImGuiBuilder.kt @@ -36,15 +36,130 @@ package com.lambda.gui.dsl -import com.lambda.context.SafeContext import com.lambda.gui.dsl.ImGuiBuilder.text import com.lambda.module.modules.client.ClickGui -import com.lambda.threading.runSafe import com.lambda.util.math.Vec2d -import imgui.* -import imgui.ImGui.* -import imgui.flag.* -import imgui.type.* +import imgui.ImDrawList +import imgui.ImFont +import imgui.ImGui +import imgui.ImGui.begin +import imgui.ImGui.beginChild +import imgui.ImGui.beginCombo +import imgui.ImGui.beginDragDropSource +import imgui.ImGui.beginDragDropTarget +import imgui.ImGui.beginGroup +import imgui.ImGui.beginMainMenuBar +import imgui.ImGui.beginMenu +import imgui.ImGui.beginMenuBar +import imgui.ImGui.beginPopup +import imgui.ImGui.beginPopupContextItem +import imgui.ImGui.beginPopupContextVoid +import imgui.ImGui.beginPopupContextWindow +import imgui.ImGui.beginPopupModal +import imgui.ImGui.beginTabBar +import imgui.ImGui.beginTabItem +import imgui.ImGui.beginTooltip +import imgui.ImGui.calcTextSize +import imgui.ImGui.collapsingHeader +import imgui.ImGui.colorButton +import imgui.ImGui.colorEdit4 +import imgui.ImGui.colorPicker4 +import imgui.ImGui.dragFloat +import imgui.ImGui.dragInt +import imgui.ImGui.end +import imgui.ImGui.endChild +import imgui.ImGui.endCombo +import imgui.ImGui.endDragDropSource +import imgui.ImGui.endDragDropTarget +import imgui.ImGui.endGroup +import imgui.ImGui.endMainMenuBar +import imgui.ImGui.endMenu +import imgui.ImGui.endMenuBar +import imgui.ImGui.endPopup +import imgui.ImGui.endTabBar +import imgui.ImGui.endTabItem +import imgui.ImGui.endTooltip +import imgui.ImGui.getBackgroundDrawList +import imgui.ImGui.getColorU32 +import imgui.ImGui.getFont +import imgui.ImGui.getFontSize +import imgui.ImGui.getForegroundDrawList +import imgui.ImGui.getIO +import imgui.ImGui.getItemID +import imgui.ImGui.getStyle +import imgui.ImGui.getVersion +import imgui.ImGui.getWindowDrawList +import imgui.ImGui.getWindowHeight +import imgui.ImGui.getWindowPos +import imgui.ImGui.getWindowPosX +import imgui.ImGui.getWindowPosY +import imgui.ImGui.getWindowSize +import imgui.ImGui.getWindowViewport +import imgui.ImGui.getWindowWidth +import imgui.ImGui.inputDouble +import imgui.ImGui.inputFloat +import imgui.ImGui.inputFloat2 +import imgui.ImGui.inputFloat3 +import imgui.ImGui.inputFloat4 +import imgui.ImGui.isAnyItemActive +import imgui.ImGui.isAnyItemFocused +import imgui.ImGui.isAnyItemHovered +import imgui.ImGui.isItemActivated +import imgui.ImGui.isItemActive +import imgui.ImGui.isItemClicked +import imgui.ImGui.isItemDeactivated +import imgui.ImGui.isItemDeactivatedAfterEdit +import imgui.ImGui.isItemEdited +import imgui.ImGui.isItemFocused +import imgui.ImGui.isItemHovered +import imgui.ImGui.isItemToggledOpen +import imgui.ImGui.isMouseClicked +import imgui.ImGui.isWindowAppearing +import imgui.ImGui.isWindowCollapsed +import imgui.ImGui.isWindowHovered +import imgui.ImGui.popFont +import imgui.ImGui.popID +import imgui.ImGui.popItemWidth +import imgui.ImGui.popStyleColor +import imgui.ImGui.popStyleVar +import imgui.ImGui.popTextWrapPos +import imgui.ImGui.pushFont +import imgui.ImGui.pushID +import imgui.ImGui.pushItemWidth +import imgui.ImGui.pushStyleColor +import imgui.ImGui.pushStyleVar +import imgui.ImGui.pushTextWrapPos +import imgui.ImGui.setClipboardText +import imgui.ImGui.setCursorPosX +import imgui.ImGui.sliderFloat +import imgui.ImGui.sliderInt +import imgui.ImGui.textColored +import imgui.ImGui.textUnformatted +import imgui.ImGui.treeNode +import imgui.ImGui.treePop +import imgui.ImGuiIO +import imgui.ImGuiStyle +import imgui.ImGuiTextFilter +import imgui.ImGuiViewport +import imgui.ImVec2 +import imgui.flag.ImDrawListFlags +import imgui.flag.ImGuiCol +import imgui.flag.ImGuiColorEditFlags +import imgui.flag.ImGuiComboFlags +import imgui.flag.ImGuiDir +import imgui.flag.ImGuiHoveredFlags +import imgui.flag.ImGuiInputTextFlags +import imgui.flag.ImGuiMouseButton +import imgui.flag.ImGuiPopupFlags +import imgui.flag.ImGuiSelectableFlags +import imgui.flag.ImGuiTabBarFlags +import imgui.flag.ImGuiTreeNodeFlags +import imgui.flag.ImGuiWindowFlags +import imgui.type.ImBoolean +import imgui.type.ImDouble +import imgui.type.ImFloat +import imgui.type.ImInt +import imgui.type.ImString import net.minecraft.util.math.Vec2f import net.minecraft.util.math.Vec3d import net.minecraft.util.math.Vec3i @@ -314,6 +429,14 @@ object ImGuiBuilder { @ImGuiDsl fun text(text: String) = textUnformatted(text) + /** + * Text with coloring + * + * @param text The text to display + */ + @ImGuiDsl + fun textColored(text: String, color: Color) = textColored(getColorU32(color.rgb), text) + /** * Text with disabled coloring. * diff --git a/src/main/kotlin/com/lambda/interaction/request/DebugLogger.kt b/src/main/kotlin/com/lambda/interaction/request/DebugLogger.kt new file mode 100644 index 000000000..f450d6cd6 --- /dev/null +++ b/src/main/kotlin/com/lambda/interaction/request/DebugLogger.kt @@ -0,0 +1,114 @@ +/* + * Copyright 2025 Lambda + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.lambda.interaction.request + +import com.lambda.gui.dsl.ImGuiBuilder +import com.lambda.module.HudModule +import com.lambda.module.tag.ModuleTag +import imgui.ImGui +import imgui.type.ImBoolean +import java.awt.Color +import java.util.* + +class DebugLogger(name: String, description: String) : HudModule( + name, description, ModuleTag.HUD +) { + private val logs = LinkedList() + private var maxLogEntries: Int = 100 + + private val autoScroll = ImBoolean(true) + private val wrapText = ImBoolean(false) + private val showDebug = ImBoolean(true) + private val showSuccess = ImBoolean(true) + private val showWarning = ImBoolean(true) + private val showError = ImBoolean(true) + + fun log(message: String, logColor: LogType) { + logs.add(LogEntry(message, logColor)) + if (logs.size > maxLogEntries) { + logs.removeFirst() + } + } + + fun logDebug(message: String) = log(message, LogType.Debug) + fun logSuccess(message: String) = log(message, LogType.Success) + fun logWarning(message: String) = log(message, LogType.Warning) + fun logError(message: String) = log(message, LogType.Error) + + override fun ImGuiBuilder.buildLayout() { + checkbox("Auto-scroll", autoScroll) + sameLine() + checkbox("Debug", showDebug) + sameLine() + checkbox("Info", showSuccess) + sameLine() + checkbox("Warn", showWarning) + sameLine() + checkbox("Error", showError) + + separator() + + child("Log Content") { + if (wrapText.get()) ImGui.pushTextWrapPos() + + logs.forEach { logEntry -> + if (shouldDisplay(logEntry)) { + when (val type = logEntry.type) { + LogType.Debug -> textColored("[DEBUG]", type.color) + LogType.Success -> textColored("[SUCCESS]", type.color) + LogType.Warning -> textColored("[WARNING]", type.color) + LogType.Error -> textColored("[ERROR]", type.color) + } + + sameLine() + } + } + + if (wrapText.get()) ImGui.popTextWrapPos() + + if (autoScroll.get()) { + ImGui.setScrollHereY(1f) + } + } + + button("Clear") { clear() } + } + + fun shouldDisplay(logEntry: LogEntry) = + when (logEntry.type) { + LogType.Debug -> showDebug.get() + LogType.Success -> showSuccess.get() + LogType.Warning -> showWarning.get() + LogType.Error -> showError.get() + } + + fun clear() = logs.clear() + + + data class LogEntry( + val message: String, + val type: LogType + ) + + enum class LogType(val color: Color) { + Debug(Color.WHITE), + Success(Color.GREEN), + Warning(Color.YELLOW), + Error(Color.RED) + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/interaction/request/Logger.kt b/src/main/kotlin/com/lambda/interaction/request/Logger.kt new file mode 100644 index 000000000..768595363 --- /dev/null +++ b/src/main/kotlin/com/lambda/interaction/request/Logger.kt @@ -0,0 +1,22 @@ +/* + * Copyright 2025 Lambda + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.lambda.interaction.request + +interface Logger { + val logger: DebugLogger +} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/interaction/request/ManagerUtils.kt b/src/main/kotlin/com/lambda/interaction/request/ManagerUtils.kt index 805f18e91..605d171b0 100644 --- a/src/main/kotlin/com/lambda/interaction/request/ManagerUtils.kt +++ b/src/main/kotlin/com/lambda/interaction/request/ManagerUtils.kt @@ -24,6 +24,7 @@ object ManagerUtils { val managers = getInstances>() val accumulatedManagerPriority = managers.map { it.stagePriority }.reduce { acc, priority -> acc + priority } val positionBlockingManagers = getInstances() + val loggingManagers = getInstances() fun isPosBlocked(pos: BlockPos) = positionBlockingManagers.any { manager -> manager.blockedPositions.any { blocked -> blocked == pos } } diff --git a/src/main/kotlin/com/lambda/interaction/request/breaking/BreakManager.kt b/src/main/kotlin/com/lambda/interaction/request/breaking/BreakManager.kt index 86967035d..0992dd862 100644 --- a/src/main/kotlin/com/lambda/interaction/request/breaking/BreakManager.kt +++ b/src/main/kotlin/com/lambda/interaction/request/breaking/BreakManager.kt @@ -39,6 +39,7 @@ import com.lambda.interaction.construction.simulation.BuildSimulator.simulate import com.lambda.interaction.construction.verify.TargetState import com.lambda.interaction.material.StackSelection import com.lambda.interaction.material.StackSelection.Companion.select +import com.lambda.interaction.request.Logger import com.lambda.interaction.request.ManagerUtils.isPosBlocked import com.lambda.interaction.request.PositionBlocking import com.lambda.interaction.request.RequestHandler @@ -69,6 +70,7 @@ import com.lambda.interaction.request.breaking.SwapInfo.Companion.getSwapInfo import com.lambda.interaction.request.interacting.InteractionManager import com.lambda.interaction.request.placing.PlaceManager import com.lambda.interaction.request.rotating.RotationRequest +import com.lambda.module.hud.BreakManagerDebug import com.lambda.threading.runSafe import com.lambda.util.BlockUtils.blockState import com.lambda.util.BlockUtils.calcItemBlockBreakingDelta @@ -102,7 +104,7 @@ object BreakManager : RequestHandler( TickEvent.Player.Post, onOpen = { processRequest(activeRequest); simulateAbandoned() }, onClose = { checkForCancels() } -), PositionBlocking { +), PositionBlocking, Logger by BreakManagerDebug { private val breakInfos = arrayOfNulls(2) private val activeInfos diff --git a/src/main/kotlin/com/lambda/module/hud/BreakManagerDebug.kt b/src/main/kotlin/com/lambda/module/hud/BreakManagerDebug.kt new file mode 100644 index 000000000..a7b64defc --- /dev/null +++ b/src/main/kotlin/com/lambda/module/hud/BreakManagerDebug.kt @@ -0,0 +1,34 @@ +/* + * Copyright 2025 Lambda + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.lambda.module.hud + +import com.lambda.gui.dsl.ImGuiBuilder +import com.lambda.interaction.request.DebugLogger +import com.lambda.interaction.request.Logger +import com.lambda.module.HudModule +import com.lambda.module.tag.ModuleTag + +object BreakManagerDebug : HudModule( + "Break Manager Logger", + "Logs most of the actions performed in the break manager to aid in debugging", + ModuleTag.HUD +), Logger { + override val logger = DebugLogger(name, description) + + override fun ImGuiBuilder.buildLayout() = with(logger) { buildLayout() } +} \ No newline at end of file From 2fccb8c0db5dab10f9c78dab8ad5c529ac58d5dc Mon Sep 17 00:00:00 2001 From: beanbag44 Date: Thu, 21 Aug 2025 04:22:14 +0100 Subject: [PATCH 02/38] add logs --- .../kotlin/com/lambda/gui/dsl/ImGuiBuilder.kt | 10 +++- .../construction/context/BreakContext.kt | 9 ---- .../lambda/interaction/request/DebugLogger.kt | 13 +++-- .../com/lambda/interaction/request/Request.kt | 1 + .../request/breaking/BreakManager.kt | 53 ++++++++++++++----- .../request/breaking/BreakRequest.kt | 4 ++ .../request/hotbar/HotbarRequest.kt | 6 +++ .../request/interacting/InteractRequest.kt | 6 +++ .../request/inventory/InventoryRequest.kt | 6 +++ .../request/placing/PlaceRequest.kt | 6 +++ .../request/rotating/RotationRequest.kt | 6 +++ 11 files changed, 92 insertions(+), 28 deletions(-) diff --git a/src/main/kotlin/com/lambda/gui/dsl/ImGuiBuilder.kt b/src/main/kotlin/com/lambda/gui/dsl/ImGuiBuilder.kt index ca8647170..789268847 100644 --- a/src/main/kotlin/com/lambda/gui/dsl/ImGuiBuilder.kt +++ b/src/main/kotlin/com/lambda/gui/dsl/ImGuiBuilder.kt @@ -435,7 +435,15 @@ object ImGuiBuilder { * @param text The text to display */ @ImGuiDsl - fun textColored(text: String, color: Color) = textColored(getColorU32(color.rgb), text) + fun textColored(text: String, color: Color) = textColored( + getColorU32( + color.red / 255f, + color.green / 255f, + color.blue / 255f, + color.alpha / 255f + ), + text + ) /** * Text with disabled coloring. diff --git a/src/main/kotlin/com/lambda/interaction/construction/context/BreakContext.kt b/src/main/kotlin/com/lambda/interaction/construction/context/BreakContext.kt index 04cef97b8..edad38ca0 100644 --- a/src/main/kotlin/com/lambda/interaction/construction/context/BreakContext.kt +++ b/src/main/kotlin/com/lambda/interaction/construction/context/BreakContext.kt @@ -22,9 +22,7 @@ import com.lambda.graphics.renderer.esp.DirectionMask import com.lambda.graphics.renderer.esp.DirectionMask.exclude import com.lambda.interaction.material.StackSelection import com.lambda.interaction.request.breaking.BreakConfig -import com.lambda.interaction.request.breaking.BreakRequest import com.lambda.interaction.request.hotbar.HotbarManager -import com.lambda.interaction.request.hotbar.HotbarRequest import com.lambda.interaction.request.rotating.RotationRequest import com.lambda.util.BlockUtils.emptyState import net.minecraft.block.BlockState @@ -76,11 +74,4 @@ data class BreakContext( withState(cachedState, blockPos, baseColor, DirectionMask.ALL.exclude(result.side)) withState(cachedState, blockPos, sideColor, result.side) } - - fun requestSwap(breakRequest: BreakRequest, minKeepTicks: Int = 0): Boolean = - HotbarRequest( - hotbarIndex, - breakRequest.hotbar, - breakRequest.hotbar.keepTicks.coerceAtLeast(minKeepTicks) - ).submit(false).done } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/interaction/request/DebugLogger.kt b/src/main/kotlin/com/lambda/interaction/request/DebugLogger.kt index f450d6cd6..1e4a62ed7 100644 --- a/src/main/kotlin/com/lambda/interaction/request/DebugLogger.kt +++ b/src/main/kotlin/com/lambda/interaction/request/DebugLogger.kt @@ -38,21 +38,23 @@ class DebugLogger(name: String, description: String) : HudModule( private val showWarning = ImBoolean(true) private val showError = ImBoolean(true) - fun log(message: String, logColor: LogType) { + private fun log(message: String, logColor: LogType) { logs.add(LogEntry(message, logColor)) if (logs.size > maxLogEntries) { logs.removeFirst() } } - fun logDebug(message: String) = log(message, LogType.Debug) - fun logSuccess(message: String) = log(message, LogType.Success) - fun logWarning(message: String) = log(message, LogType.Warning) - fun logError(message: String) = log(message, LogType.Error) + fun debug(message: String) = log(message, LogType.Debug) + fun success(message: String) = log(message, LogType.Success) + fun warning(message: String) = log(message, LogType.Warning) + fun error(message: String) = log(message, LogType.Error) override fun ImGuiBuilder.buildLayout() { checkbox("Auto-scroll", autoScroll) sameLine() + checkbox("Wrap Text", wrapText) + sameLine() checkbox("Debug", showDebug) sameLine() checkbox("Info", showSuccess) @@ -76,6 +78,7 @@ class DebugLogger(name: String, description: String) : HudModule( } sameLine() + textColored(logEntry.message, logEntry.type.color) } } diff --git a/src/main/kotlin/com/lambda/interaction/request/Request.kt b/src/main/kotlin/com/lambda/interaction/request/Request.kt index d2c64d42e..e3998af79 100644 --- a/src/main/kotlin/com/lambda/interaction/request/Request.kt +++ b/src/main/kotlin/com/lambda/interaction/request/Request.kt @@ -18,6 +18,7 @@ package com.lambda.interaction.request abstract class Request { + abstract val requestID: Int abstract val config: RequestConfig var fresh = true diff --git a/src/main/kotlin/com/lambda/interaction/request/breaking/BreakManager.kt b/src/main/kotlin/com/lambda/interaction/request/breaking/BreakManager.kt index 0992dd862..8fd6ca902 100644 --- a/src/main/kotlin/com/lambda/interaction/request/breaking/BreakManager.kt +++ b/src/main/kotlin/com/lambda/interaction/request/breaking/BreakManager.kt @@ -67,6 +67,7 @@ import com.lambda.interaction.request.breaking.BrokenBlockHandler.pendingActions import com.lambda.interaction.request.breaking.BrokenBlockHandler.setPendingConfigs import com.lambda.interaction.request.breaking.BrokenBlockHandler.startPending import com.lambda.interaction.request.breaking.SwapInfo.Companion.getSwapInfo +import com.lambda.interaction.request.hotbar.HotbarRequest import com.lambda.interaction.request.interacting.InteractionManager import com.lambda.interaction.request.placing.PlaceManager import com.lambda.interaction.request.rotating.RotationRequest @@ -319,6 +320,7 @@ object BreakManager : RequestHandler( */ private fun SafeContext.processRequest(breakRequest: BreakRequest?) { breakRequest?.let { request -> + logger.debug("Processing request (${request.requestID}) at tick stage ${tickStage?.run { this::class.qualifiedName }}") if (request.fresh) populateFrom(request) } @@ -343,6 +345,7 @@ object BreakManager : RequestHandler( } if (instantBreaks.isEmpty() && breaks.isEmpty()) { + if (activeRequest != null) logger.debug("Clearing active request") activeRequest = null } if (breaksThisTick > 0 || activeInfos.isNotEmpty()) { @@ -359,6 +362,8 @@ object BreakManager : RequestHandler( * @see canAccept */ private fun SafeContext.populateFrom(request: BreakRequest) { + logger.debug("Populating from request (${request.requestID})") + // Sanitize the new breaks val newBreaks = request.contexts .distinctBy { it.blockPos } @@ -370,6 +375,7 @@ object BreakManager : RequestHandler( .forEach { info -> newBreaks.find { ctx -> ctx.blockPos == info.context.blockPos && canAccept(ctx) }?.let { ctx -> if ((!info.updatedThisTick || info.type == RedundantSecondary) || info.abandoned) { + logger.debug("Updating info for ${info.type}") if (info.type == RedundantSecondary) info.request.onStart?.invoke(info.context.blockPos) else if (info.abandoned) { @@ -389,10 +395,14 @@ object BreakManager : RequestHandler( .filter { it.instantBreak } .toMutableList() + logger.debug("${instantBreaks.size} unprocessed instant breaks") + breaks = newBreaks .filter { !it.instantBreak } .toMutableList() + logger.debug("${breaks.size} unprocessed instant breaks") + val breakConfig = request.config val pendingLimit = (breakConfig.maxPendingBreaks - pendingBreakCount).coerceAtLeast(0) maxBreaksThisTick = breakConfig.breaksPerTick.coerceAtMost(pendingLimit) @@ -417,9 +427,11 @@ object BreakManager : RequestHandler( activeInfos .filter { it.updatedThisTick } .let { infos -> + if (infos.isNotEmpty()) logger.debug("Handling pre-processing") rotationRequest = infos.firstOrNull { info -> info.breakConfig.rotateForBreak } ?.let { info -> val rotation = info.context.rotation + logger.debug("Requesting rotation (${rotation.requestID})") rotation.submit(false) } @@ -430,8 +442,18 @@ object BreakManager : RequestHandler( infos.firstOrNull()?.let { info -> infos.lastOrNull { it.swapInfo.swap && it.shouldProgress }?.let { last -> val minSwapTicks = max(info.swapInfo.minKeepTicks, last.swapInfo.minKeepTicks) - if (!info.context.requestSwap(info.request, minSwapTicks)) + val hotbarRequest = with(info) { + HotbarRequest( + context.hotbarIndex, + request.hotbar, + request.hotbar.keepTicks.coerceAtLeast(minSwapTicks) + ).submit(false) + } + logger.debug("Submitting request for hotbar index ${info.context.hotbarIndex} with min swap ticks $minSwapTicks (${hotbarRequest.requestID})") + if (!hotbarRequest.done) { + logger.debug("hotbar request failed (${hotbarRequest.requestID})") return false + } if (minSwapTicks > 0) { val alreadySwapped = swappedThisTick currentStack = info.swapStack @@ -450,6 +472,7 @@ object BreakManager : RequestHandler( * @return false if a break could not be performed. */ private fun SafeContext.performInstantBreaks(request: BreakRequest): Boolean { + if (instantBreaks.isNotEmpty()) logger.debug("Processing instant breaks") val iterator = instantBreaks.iterator() while (iterator.hasNext()) { if (breaksThisTick + 1 > maxBreaksThisTick) return false @@ -478,6 +501,7 @@ object BreakManager : RequestHandler( * @see initNewBreak */ private fun SafeContext.processNewBreaks(request: BreakRequest): Boolean { + if (breaks.isNotEmpty()) logger.debug("Processing new breaks") val iterator = breaks.iterator() while (iterator.hasNext()) { val ctx = iterator.next() @@ -515,8 +539,9 @@ object BreakManager : RequestHandler( return secondaryBreak } + logger.debug("Transforming ${primaryInfo.type} to $Secondary") primaryInfo.stopBreakPacket(world, interaction) - primaryInfo.makeSecondary() + secondaryBreak = primaryInfo.apply { type = Secondary } return@let } @@ -605,6 +630,8 @@ object BreakManager : RequestHandler( } private fun BreakInfo.updatePreProcessing(player: ClientPlayerEntity, world: BlockView) { + logger.debug("Updating pre-processing for $type") + shouldProgress = !progressedThisTick && tickStage in breakConfig.breakStageMask && (rotated || type != Primary) @@ -617,17 +644,6 @@ object BreakManager : RequestHandler( swapInfo = getSwapInfo(this, player, world) } - /** - * Makes the [BreakInfo] a secondary if not already. - */ - private fun BreakInfo.makeSecondary() { - if (secondaryBreak === this) return - secondaryBreak = this.apply { - type = Secondary - } - primaryBreak = null - } - /** * Attempts to cancel the break. * @@ -643,6 +659,7 @@ object BreakManager : RequestHandler( if (type == RedundantSecondary || abandoned) return@runSafe when (type) { Primary -> { + logger.debug("Cancelling $type") nullify() setBreakingTextureStage(player, world, -1) abortBreakPacket(world, interaction) @@ -650,10 +667,12 @@ object BreakManager : RequestHandler( } Secondary -> { if (breakConfig.unsafeCancels) { + logger.warning("Making $type redundant") type = RedundantSecondary setBreakingTextureStage(player, world, -1) request.onCancel?.invoke(context.blockPos) } else { + logger.debug("Abandoning $type") abandoned = true } } @@ -713,6 +732,7 @@ object BreakManager : RequestHandler( if (blockState.isEmpty) { info.nullify() info.request.onCancel?.invoke(ctx.blockPos) + logger.warning("Block state was unexpectedly empty") return false } @@ -723,6 +743,7 @@ object BreakManager : RequestHandler( ctx.blockPos, config ) * (info.breakingTicks - config.fudgeFactor) + logger.debug("${info.type} progress: $progress, breaking ticks: ${info.breakingTicks}") if (config.sounds) { if (info.soundsCooldown % 4.0f == 0.0f) { @@ -751,6 +772,7 @@ object BreakManager : RequestHandler( val swing = config.swing if (progress >= info.getBreakThreshold() && info.swapInfo.canCompleteBreak) { + logger.success("Breaking ${info.type}") if (info.type == Primary) { onBlockBreak(info) info.stopBreakPacket(world, interaction) @@ -777,8 +799,10 @@ object BreakManager : RequestHandler( val ctx = info.context if (info.rebreakPotential.isPossible()) { + logger.debug("Handling potential rebreak") when (val rebreakResult = RebreakHandler.handleUpdate(info.context, info.request)) { is RebreakResult.StillBreaking -> { + logger.debug("Rebreak not complete") primaryBreak = rebreakResult.breakInfo.apply { type = Primary RebreakHandler.clearRebreak() @@ -792,6 +816,7 @@ object BreakManager : RequestHandler( return true } is RebreakResult.Rebroke -> { + logger.debug("Rebroke") info.type = Rebreak info.nullify() info.request.onReBreak?.invoke(ctx.blockPos) @@ -825,9 +850,11 @@ object BreakManager : RequestHandler( val progress = blockState.calcBreakDelta(player, world, ctx.blockPos, info.breakConfig) info.vanillaInstantBreakable = progress >= 1 && info.swapInfo.canCompleteBreak if (progress >= info.getBreakThreshold() && info.swapInfo.canCompleteBreak) { + logger.success("Instantly breaking") onBlockBreak(info) if (!info.vanillaInstantBreakable) breakCooldown = info.breakConfig.breakDelay } else { + logger.debug("Starting ${info.type}") info.apply { breaking = true breakingTicks = 1 diff --git a/src/main/kotlin/com/lambda/interaction/request/breaking/BreakRequest.kt b/src/main/kotlin/com/lambda/interaction/request/breaking/BreakRequest.kt index 3fe4abfe9..0c23c8200 100644 --- a/src/main/kotlin/com/lambda/interaction/request/breaking/BreakRequest.kt +++ b/src/main/kotlin/com/lambda/interaction/request/breaking/BreakRequest.kt @@ -41,6 +41,8 @@ data class BreakRequest( val inventory: InventoryConfig = TaskFlowModule.inventory, val interact: InteractionConfig = TaskFlowModule.interaction ) : Request() { + override val requestID = ++requestCount + override val config = build.breaking var onStart: ((BlockPos) -> Unit)? = null var onUpdate: ((BlockPos) -> Unit)? = null @@ -111,6 +113,8 @@ data class BreakRequest( } companion object { + var requestCount = 0 + @BreakRequestBuilder fun breakRequest( contexts: Collection, diff --git a/src/main/kotlin/com/lambda/interaction/request/hotbar/HotbarRequest.kt b/src/main/kotlin/com/lambda/interaction/request/hotbar/HotbarRequest.kt index 6ef88613a..a5820e074 100644 --- a/src/main/kotlin/com/lambda/interaction/request/hotbar/HotbarRequest.kt +++ b/src/main/kotlin/com/lambda/interaction/request/hotbar/HotbarRequest.kt @@ -25,6 +25,8 @@ class HotbarRequest( override var keepTicks: Int = config.keepTicks, override var swapPause: Int = config.swapPause ) : Request(), HotbarConfig by config { + override val requestID = ++requestCount + var activeRequestAge = 0 var swapPauseAge = 0 @@ -37,4 +39,8 @@ class HotbarRequest( override fun submit(queueIfClosed: Boolean) = HotbarManager.request(this, queueIfClosed) + + companion object { + var requestCount = 0 + } } diff --git a/src/main/kotlin/com/lambda/interaction/request/interacting/InteractRequest.kt b/src/main/kotlin/com/lambda/interaction/request/interacting/InteractRequest.kt index d544c1aa9..d7f612e32 100644 --- a/src/main/kotlin/com/lambda/interaction/request/interacting/InteractRequest.kt +++ b/src/main/kotlin/com/lambda/interaction/request/interacting/InteractRequest.kt @@ -36,9 +36,15 @@ data class InteractRequest( val hotbar: HotbarConfig, val rotation: RotationConfig ) : Request(), InteractConfig by config { + override val requestID = ++requestCount + override val done: Boolean get() = contexts.all { mc.world?.getBlockState(it.blockPos)?.matches(it.expectedState) == true } override fun submit(queueIfClosed: Boolean) = InteractionManager.request(this, queueIfClosed) + + companion object { + var requestCount = 0 + } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/interaction/request/inventory/InventoryRequest.kt b/src/main/kotlin/com/lambda/interaction/request/inventory/InventoryRequest.kt index 9b073b726..670f421b7 100644 --- a/src/main/kotlin/com/lambda/interaction/request/inventory/InventoryRequest.kt +++ b/src/main/kotlin/com/lambda/interaction/request/inventory/InventoryRequest.kt @@ -22,9 +22,15 @@ import com.lambda.interaction.request.Request class InventoryRequest( override val config: InventoryConfig ) : Request(), InventoryConfig by config { + override val requestID = ++requestCount + override val done: Boolean get() = TODO("Not yet implemented") override fun submit(queueIfClosed: Boolean) = InventoryManager.request(this, queueIfClosed) + + companion object { + var requestCount = 0 + } } diff --git a/src/main/kotlin/com/lambda/interaction/request/placing/PlaceRequest.kt b/src/main/kotlin/com/lambda/interaction/request/placing/PlaceRequest.kt index 65e1efccd..b7cc7af73 100644 --- a/src/main/kotlin/com/lambda/interaction/request/placing/PlaceRequest.kt +++ b/src/main/kotlin/com/lambda/interaction/request/placing/PlaceRequest.kt @@ -36,6 +36,8 @@ data class PlaceRequest( val pendingInteractions: MutableCollection, val onPlace: ((BlockPos) -> Unit)? = null ) : Request(), PlaceConfig by build.placing { + override val requestID = ++requestCount + override val config = build.placing override val done: Boolean get() = runSafe { @@ -44,4 +46,8 @@ data class PlaceRequest( override fun submit(queueIfClosed: Boolean) = PlaceManager.request(this, queueIfClosed) + + companion object { + var requestCount = 0 + } } diff --git a/src/main/kotlin/com/lambda/interaction/request/rotating/RotationRequest.kt b/src/main/kotlin/com/lambda/interaction/request/rotating/RotationRequest.kt index 9e9579843..272e202e2 100644 --- a/src/main/kotlin/com/lambda/interaction/request/rotating/RotationRequest.kt +++ b/src/main/kotlin/com/lambda/interaction/request/rotating/RotationRequest.kt @@ -30,6 +30,8 @@ data class RotationRequest( override var decayTicks: Int = config.decayTicks, val speedMultiplier: Double = 1.0 ) : Request(), RotationConfig by config { + override val requestID = ++requestCount + var age = 0 override val done: Boolean get() = @@ -37,4 +39,8 @@ data class RotationRequest( override fun submit(queueIfClosed: Boolean): RotationRequest = RotationManager.request(this, queueIfClosed) + + companion object { + var requestCount = 0 + } } \ No newline at end of file From 52f3af1d20fe0c1f0e18996920db421d97da92bb Mon Sep 17 00:00:00 2001 From: beanbag44 Date: Thu, 21 Aug 2025 14:57:44 +0100 Subject: [PATCH 03/38] settings in the module --- .../lambda/interaction/request/DebugLogger.kt | 54 ++++++++----------- .../interaction/request/ManagerUtils.kt | 1 - .../request/breaking/BreakManager.kt | 4 +- .../lambda/module/hud/BreakManagerDebug.kt | 15 ++---- 4 files changed, 28 insertions(+), 46 deletions(-) diff --git a/src/main/kotlin/com/lambda/interaction/request/DebugLogger.kt b/src/main/kotlin/com/lambda/interaction/request/DebugLogger.kt index 1e4a62ed7..8e53a92fc 100644 --- a/src/main/kotlin/com/lambda/interaction/request/DebugLogger.kt +++ b/src/main/kotlin/com/lambda/interaction/request/DebugLogger.kt @@ -21,22 +21,26 @@ import com.lambda.gui.dsl.ImGuiBuilder import com.lambda.module.HudModule import com.lambda.module.tag.ModuleTag import imgui.ImGui -import imgui.type.ImBoolean import java.awt.Color import java.util.* -class DebugLogger(name: String, description: String) : HudModule( - name, description, ModuleTag.HUD -) { +abstract class DebugLogger(name: String, description: String) : HudModule(name, description, ModuleTag.HUD) { private val logs = LinkedList() - private var maxLogEntries: Int = 100 - private val autoScroll = ImBoolean(true) - private val wrapText = ImBoolean(false) - private val showDebug = ImBoolean(true) - private val showSuccess = ImBoolean(true) - private val showWarning = ImBoolean(true) - private val showError = ImBoolean(true) + private val autoScroll by setting("Auto-Scroll", true, "Automatically scrolls to the bottom of the log") + private val wrapText by setting("Wrap Text", false, "Wraps the text to the next line if it gets too long") + private val showDebug by setting("Show Debug", true, "Shows debug logs") + private val showSuccess by setting("Show Success", true, "Shows success logs") + private val showWarning by setting("Show Warning", true, "Shows warning logs") + private val showError by setting("Show Errors", true, "Shows error logs") + private val maxLogEntries by setting("Max Log Entries", 100, 1..1000, 1, "Maximum amount of entries in the log") + .onValueChange { from, to -> + if (to < from) { + while(logs.size > to) { + logs.removeFirst() + } + } + } private fun log(message: String, logColor: LogType) { logs.add(LogEntry(message, logColor)) @@ -51,22 +55,8 @@ class DebugLogger(name: String, description: String) : HudModule( fun error(message: String) = log(message, LogType.Error) override fun ImGuiBuilder.buildLayout() { - checkbox("Auto-scroll", autoScroll) - sameLine() - checkbox("Wrap Text", wrapText) - sameLine() - checkbox("Debug", showDebug) - sameLine() - checkbox("Info", showSuccess) - sameLine() - checkbox("Warn", showWarning) - sameLine() - checkbox("Error", showError) - - separator() - child("Log Content") { - if (wrapText.get()) ImGui.pushTextWrapPos() + if (wrapText) ImGui.pushTextWrapPos() logs.forEach { logEntry -> if (shouldDisplay(logEntry)) { @@ -82,9 +72,9 @@ class DebugLogger(name: String, description: String) : HudModule( } } - if (wrapText.get()) ImGui.popTextWrapPos() + if (wrapText) ImGui.popTextWrapPos() - if (autoScroll.get()) { + if (autoScroll) { ImGui.setScrollHereY(1f) } } @@ -94,10 +84,10 @@ class DebugLogger(name: String, description: String) : HudModule( fun shouldDisplay(logEntry: LogEntry) = when (logEntry.type) { - LogType.Debug -> showDebug.get() - LogType.Success -> showSuccess.get() - LogType.Warning -> showWarning.get() - LogType.Error -> showError.get() + LogType.Debug -> showDebug + LogType.Success -> showSuccess + LogType.Warning -> showWarning + LogType.Error -> showError } fun clear() = logs.clear() diff --git a/src/main/kotlin/com/lambda/interaction/request/ManagerUtils.kt b/src/main/kotlin/com/lambda/interaction/request/ManagerUtils.kt index 605d171b0..805f18e91 100644 --- a/src/main/kotlin/com/lambda/interaction/request/ManagerUtils.kt +++ b/src/main/kotlin/com/lambda/interaction/request/ManagerUtils.kt @@ -24,7 +24,6 @@ object ManagerUtils { val managers = getInstances>() val accumulatedManagerPriority = managers.map { it.stagePriority }.reduce { acc, priority -> acc + priority } val positionBlockingManagers = getInstances() - val loggingManagers = getInstances() fun isPosBlocked(pos: BlockPos) = positionBlockingManagers.any { manager -> manager.blockedPositions.any { blocked -> blocked == pos } } diff --git a/src/main/kotlin/com/lambda/interaction/request/breaking/BreakManager.kt b/src/main/kotlin/com/lambda/interaction/request/breaking/BreakManager.kt index 8fd6ca902..daf1305c2 100644 --- a/src/main/kotlin/com/lambda/interaction/request/breaking/BreakManager.kt +++ b/src/main/kotlin/com/lambda/interaction/request/breaking/BreakManager.kt @@ -105,7 +105,7 @@ object BreakManager : RequestHandler( TickEvent.Player.Post, onOpen = { processRequest(activeRequest); simulateAbandoned() }, onClose = { checkForCancels() } -), PositionBlocking, Logger by BreakManagerDebug { +), PositionBlocking, Logger { private val breakInfos = arrayOfNulls(2) private val activeInfos @@ -165,6 +165,8 @@ object BreakManager : RequestHandler( field = value } + override val logger = BreakManagerDebug + fun Any.onBreak( alwaysListen: Boolean = false, priority: Int = 0, diff --git a/src/main/kotlin/com/lambda/module/hud/BreakManagerDebug.kt b/src/main/kotlin/com/lambda/module/hud/BreakManagerDebug.kt index a7b64defc..d32030d83 100644 --- a/src/main/kotlin/com/lambda/module/hud/BreakManagerDebug.kt +++ b/src/main/kotlin/com/lambda/module/hud/BreakManagerDebug.kt @@ -17,18 +17,9 @@ package com.lambda.module.hud -import com.lambda.gui.dsl.ImGuiBuilder import com.lambda.interaction.request.DebugLogger -import com.lambda.interaction.request.Logger -import com.lambda.module.HudModule -import com.lambda.module.tag.ModuleTag -object BreakManagerDebug : HudModule( +object BreakManagerDebug : DebugLogger( "Break Manager Logger", - "Logs most of the actions performed in the break manager to aid in debugging", - ModuleTag.HUD -), Logger { - override val logger = DebugLogger(name, description) - - override fun ImGuiBuilder.buildLayout() = with(logger) { buildLayout() } -} \ No newline at end of file + "Logs most of the actions performed in the break manager to aid in debugging" +) \ No newline at end of file From 5e80a860f39ca54831a1e4dd658cd038718990a9 Mon Sep 17 00:00:00 2001 From: beanbag44 Date: Thu, 21 Aug 2025 15:33:22 +0100 Subject: [PATCH 04/38] background --- .../com/lambda/gui/components/HudGuiLayout.kt | 8 +-- .../lambda/interaction/request/DebugLogger.kt | 50 +++++++++++-------- .../kotlin/com/lambda/module/HudModule.kt | 1 + 3 files changed, 34 insertions(+), 25 deletions(-) diff --git a/src/main/kotlin/com/lambda/gui/components/HudGuiLayout.kt b/src/main/kotlin/com/lambda/gui/components/HudGuiLayout.kt index 87e1c1102..b81215574 100644 --- a/src/main/kotlin/com/lambda/gui/components/HudGuiLayout.kt +++ b/src/main/kotlin/com/lambda/gui/components/HudGuiLayout.kt @@ -38,9 +38,11 @@ object HudGuiLayout : Loadable { .filterIsInstance() .filter { it.isEnabled } .forEach { hud -> - window("##${hud.name}", flags = DEFAULT_HUD_FLAGS) { - with(hud) { buildLayout() } - } + if (!hud.customWindow) + window("##${hud.name}", flags = DEFAULT_HUD_FLAGS) { + with(hud) { buildLayout() } + } + else with(hud) { buildLayout() } } } } diff --git a/src/main/kotlin/com/lambda/interaction/request/DebugLogger.kt b/src/main/kotlin/com/lambda/interaction/request/DebugLogger.kt index 8e53a92fc..c6cd7d546 100644 --- a/src/main/kotlin/com/lambda/interaction/request/DebugLogger.kt +++ b/src/main/kotlin/com/lambda/interaction/request/DebugLogger.kt @@ -21,13 +21,21 @@ import com.lambda.gui.dsl.ImGuiBuilder import com.lambda.module.HudModule import com.lambda.module.tag.ModuleTag import imgui.ImGui +import imgui.flag.ImGuiWindowFlags import java.awt.Color import java.util.* -abstract class DebugLogger(name: String, description: String) : HudModule(name, description, ModuleTag.HUD) { +abstract class DebugLogger( + name: String, + description: String +) : HudModule( + name, + description, + ModuleTag.HUD, + customWindow = true +) { private val logs = LinkedList() - private val autoScroll by setting("Auto-Scroll", true, "Automatically scrolls to the bottom of the log") private val wrapText by setting("Wrap Text", false, "Wraps the text to the next line if it gets too long") private val showDebug by setting("Show Debug", true, "Shows debug logs") private val showSuccess by setting("Show Success", true, "Shows success logs") @@ -55,31 +63,29 @@ abstract class DebugLogger(name: String, description: String) : HudModule(name, fun error(message: String) = log(message, LogType.Error) override fun ImGuiBuilder.buildLayout() { - child("Log Content") { - if (wrapText) ImGui.pushTextWrapPos() - - logs.forEach { logEntry -> - if (shouldDisplay(logEntry)) { - when (val type = logEntry.type) { - LogType.Debug -> textColored("[DEBUG]", type.color) - LogType.Success -> textColored("[SUCCESS]", type.color) - LogType.Warning -> textColored("[WARNING]", type.color) - LogType.Error -> textColored("[ERROR]", type.color) + ImGui.setNextWindowSizeConstraints(300f, 400f, windowViewport.workSizeX, windowViewport.workSizeY) + window(name, flags = ImGuiWindowFlags.NoTitleBar) { + child("Log Content") { + if (wrapText) ImGui.pushTextWrapPos() + + logs.forEach { logEntry -> + if (shouldDisplay(logEntry)) { + when (val type = logEntry.type) { + LogType.Debug -> textColored("[DEBUG]", type.color) + LogType.Success -> textColored("[SUCCESS]", type.color) + LogType.Warning -> textColored("[WARNING]", type.color) + LogType.Error -> textColored("[ERROR]", type.color) + } + + sameLine() + textColored(logEntry.message, logEntry.type.color) } - - sameLine() - textColored(logEntry.message, logEntry.type.color) } - } - if (wrapText) ImGui.popTextWrapPos() - - if (autoScroll) { - ImGui.setScrollHereY(1f) + if (wrapText) ImGui.popTextWrapPos() } + button("Clear") { clear() } } - - button("Clear") { clear() } } fun shouldDisplay(logEntry: LogEntry) = diff --git a/src/main/kotlin/com/lambda/module/HudModule.kt b/src/main/kotlin/com/lambda/module/HudModule.kt index ba2324046..7ada317c1 100644 --- a/src/main/kotlin/com/lambda/module/HudModule.kt +++ b/src/main/kotlin/com/lambda/module/HudModule.kt @@ -25,6 +25,7 @@ abstract class HudModule( name: String, description: String = "", tag: ModuleTag, + val customWindow: Boolean = false, alwaysListening: Boolean = false, enabledByDefault: Boolean = false, defaultKeybind: KeyCode = KeyCode.UNBOUND, From fdd5c91e7987c4fcbd6e49468674090a7fee1cb8 Mon Sep 17 00:00:00 2001 From: beanbag44 Date: Thu, 21 Aug 2025 15:52:41 +0100 Subject: [PATCH 05/38] better auto scroll and background alpha setting --- .../com/lambda/interaction/request/DebugLogger.kt | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/com/lambda/interaction/request/DebugLogger.kt b/src/main/kotlin/com/lambda/interaction/request/DebugLogger.kt index c6cd7d546..d51611f5f 100644 --- a/src/main/kotlin/com/lambda/interaction/request/DebugLogger.kt +++ b/src/main/kotlin/com/lambda/interaction/request/DebugLogger.kt @@ -36,6 +36,7 @@ abstract class DebugLogger( ) { private val logs = LinkedList() + private val autoScroll by setting("Auto-Scroll", true, "Automatically scrolls to the bottom of the log") private val wrapText by setting("Wrap Text", false, "Wraps the text to the next line if it gets too long") private val showDebug by setting("Show Debug", true, "Shows debug logs") private val showSuccess by setting("Show Success", true, "Shows success logs") @@ -49,6 +50,7 @@ abstract class DebugLogger( } } } + private val backgroundAlpha by setting("Background Alpha", 0.3f, 0f..1f, 0.01f, "Sets the opacity for the elements background") private fun log(message: String, logColor: LogType) { logs.add(LogEntry(message, logColor)) @@ -64,8 +66,10 @@ abstract class DebugLogger( override fun ImGuiBuilder.buildLayout() { ImGui.setNextWindowSizeConstraints(300f, 400f, windowViewport.workSizeX, windowViewport.workSizeY) + ImGui.setNextWindowBgAlpha(backgroundAlpha) window(name, flags = ImGuiWindowFlags.NoTitleBar) { - child("Log Content") { + val noScroll = if (autoScroll) ImGuiWindowFlags.NoScrollbar or ImGuiWindowFlags.NoScrollWithMouse else 0 + child("Log Content", extraFlags = noScroll) { if (wrapText) ImGui.pushTextWrapPos() logs.forEach { logEntry -> @@ -83,6 +87,10 @@ abstract class DebugLogger( } if (wrapText) ImGui.popTextWrapPos() + + if (autoScroll) { + ImGui.setScrollHereY(1f) + } } button("Clear") { clear() } } From f35adad818587b61f09c5a1779c8e42c8d080582 Mon Sep 17 00:00:00 2001 From: beanbag44 Date: Thu, 21 Aug 2025 15:52:52 +0100 Subject: [PATCH 06/38] log chat warnings too --- .../request/breaking/BrokenBlockHandler.kt | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/com/lambda/interaction/request/breaking/BrokenBlockHandler.kt b/src/main/kotlin/com/lambda/interaction/request/breaking/BrokenBlockHandler.kt index 36f3fdefb..859195d6b 100644 --- a/src/main/kotlin/com/lambda/interaction/request/breaking/BrokenBlockHandler.kt +++ b/src/main/kotlin/com/lambda/interaction/request/breaking/BrokenBlockHandler.kt @@ -58,9 +58,13 @@ object BrokenBlockHandler : PostActionHandler() { if (!loaded) return@runSafe if (!info.broken) { - warn("${info.type} ${info::class.simpleName} at ${info.context.blockPos.toShortString()} timed out with cached state ${info.context.cachedState}") + val message = "${info.type} ${info::class.simpleName} at ${info.context.blockPos.toShortString()} timed out with cached state ${info.context.cachedState}" + BreakManager.logger.error(message) + warn(message) } else if (!TaskFlowModule.ignoreItemDropWarnings) { - warn("${info.type} ${info::class.simpleName}'s item drop at ${info.context.blockPos.toShortString()} timed out") + val message = "${info.type} ${info::class.simpleName}'s item drop at ${info.context.blockPos.toShortString()} timed out" + BreakManager.logger.warn(message) + warn(message) } if (!info.broken && info.breakConfig.breakConfirmation != BreakConfirmationMode.AwaitThenBreak) { @@ -90,7 +94,9 @@ object BrokenBlockHandler : PostActionHandler() { if (pending.type == BreakInfo.BreakType.Rebreak) { pending.context.cachedState = event.newState } else { - this@BrokenBlockHandler.warn("Broken block at ${event.pos.toShortString()} was rejected with ${event.newState} instead of ${pending.context.cachedState.emptyState}") + val message = "Broken block at ${event.pos.toShortString()} was rejected with ${event.newState} instead of ${pending.context.cachedState.emptyState}" + BreakManager.logger.error(message) + this@BrokenBlockHandler.warn(message) pending.stopPending() } return@listen From b4fb18a2d07a99e658ba1ff5846ac7599da86633 Mon Sep 17 00:00:00 2001 From: beanbag44 Date: Thu, 21 Aug 2025 15:59:12 +0100 Subject: [PATCH 07/38] lot type and state when starting and breaking block --- .../interaction/request/breaking/BreakManager.kt | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/kotlin/com/lambda/interaction/request/breaking/BreakManager.kt b/src/main/kotlin/com/lambda/interaction/request/breaking/BreakManager.kt index daf1305c2..2f71cf09b 100644 --- a/src/main/kotlin/com/lambda/interaction/request/breaking/BreakManager.kt +++ b/src/main/kotlin/com/lambda/interaction/request/breaking/BreakManager.kt @@ -745,7 +745,7 @@ object BreakManager : RequestHandler( ctx.blockPos, config ) * (info.breakingTicks - config.fudgeFactor) - logger.debug("${info.type} progress: $progress, breaking ticks: ${info.breakingTicks}") + logger.debug("${info.type} progress: $progress, breaking ticks: ${info.breakingTicks}, ${info.context.cachedState}") if (config.sounds) { if (info.soundsCooldown % 4.0f == 0.0f) { @@ -774,7 +774,7 @@ object BreakManager : RequestHandler( val swing = config.swing if (progress >= info.getBreakThreshold() && info.swapInfo.canCompleteBreak) { - logger.success("Breaking ${info.type}") + logger.success("Breaking ${info.type} ${info.context.cachedState}") if (info.type == Primary) { onBlockBreak(info) info.stopBreakPacket(world, interaction) @@ -804,7 +804,7 @@ object BreakManager : RequestHandler( logger.debug("Handling potential rebreak") when (val rebreakResult = RebreakHandler.handleUpdate(info.context, info.request)) { is RebreakResult.StillBreaking -> { - logger.debug("Rebreak not complete") + logger.debug("Rebreak not complete ${info.context.cachedState}") primaryBreak = rebreakResult.breakInfo.apply { type = Primary RebreakHandler.clearRebreak() @@ -818,7 +818,7 @@ object BreakManager : RequestHandler( return true } is RebreakResult.Rebroke -> { - logger.debug("Rebroke") + logger.debug("Rebroke ${info.context.cachedState}") info.type = Rebreak info.nullify() info.request.onReBreak?.invoke(ctx.blockPos) @@ -852,11 +852,11 @@ object BreakManager : RequestHandler( val progress = blockState.calcBreakDelta(player, world, ctx.blockPos, info.breakConfig) info.vanillaInstantBreakable = progress >= 1 && info.swapInfo.canCompleteBreak if (progress >= info.getBreakThreshold() && info.swapInfo.canCompleteBreak) { - logger.success("Instantly breaking") + logger.success("Instantly breaking ${info.type} $blockState") onBlockBreak(info) if (!info.vanillaInstantBreakable) breakCooldown = info.breakConfig.breakDelay } else { - logger.debug("Starting ${info.type}") + logger.debug("Starting ${info.type} $blockState") info.apply { breaking = true breakingTicks = 1 From 03adc96726fa8e4364b02c20bad6ea36a9d0b387 Mon Sep 17 00:00:00 2001 From: beanbag44 Date: Thu, 21 Aug 2025 16:20:52 +0100 Subject: [PATCH 08/38] logger gui improvements --- .../kotlin/com/lambda/interaction/request/DebugLogger.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/com/lambda/interaction/request/DebugLogger.kt b/src/main/kotlin/com/lambda/interaction/request/DebugLogger.kt index d51611f5f..e04d53e98 100644 --- a/src/main/kotlin/com/lambda/interaction/request/DebugLogger.kt +++ b/src/main/kotlin/com/lambda/interaction/request/DebugLogger.kt @@ -67,9 +67,10 @@ abstract class DebugLogger( override fun ImGuiBuilder.buildLayout() { ImGui.setNextWindowSizeConstraints(300f, 400f, windowViewport.workSizeX, windowViewport.workSizeY) ImGui.setNextWindowBgAlpha(backgroundAlpha) - window(name, flags = ImGuiWindowFlags.NoTitleBar) { + window(name, flags = ImGuiWindowFlags.NoCollapse) { val noScroll = if (autoScroll) ImGuiWindowFlags.NoScrollbar or ImGuiWindowFlags.NoScrollWithMouse else 0 - child("Log Content", extraFlags = noScroll) { + button("Clear") { clear() } + child("Log Content", extraFlags = noScroll) { if (wrapText) ImGui.pushTextWrapPos() logs.forEach { logEntry -> @@ -92,7 +93,6 @@ abstract class DebugLogger( ImGui.setScrollHereY(1f) } } - button("Clear") { clear() } } } From 859e0d2d85485b9256dc039f6e2e706246def5ab Mon Sep 17 00:00:00 2001 From: beanbag44 Date: Thu, 21 Aug 2025 18:43:51 +0100 Subject: [PATCH 09/38] BreakInfo toString and more debug statements / edits --- .../lambda/interaction/request/DebugLogger.kt | 13 ++++--- .../interaction/request/breaking/BreakInfo.kt | 2 ++ .../request/breaking/BreakManager.kt | 36 ++++++++++++------- 3 files changed, 34 insertions(+), 17 deletions(-) diff --git a/src/main/kotlin/com/lambda/interaction/request/DebugLogger.kt b/src/main/kotlin/com/lambda/interaction/request/DebugLogger.kt index e04d53e98..f13f31772 100644 --- a/src/main/kotlin/com/lambda/interaction/request/DebugLogger.kt +++ b/src/main/kotlin/com/lambda/interaction/request/DebugLogger.kt @@ -63,6 +63,7 @@ abstract class DebugLogger( fun success(message: String) = log(message, LogType.Success) fun warning(message: String) = log(message, LogType.Warning) fun error(message: String) = log(message, LogType.Error) + fun system(message: String) = log(message, LogType.System) override fun ImGuiBuilder.buildLayout() { ImGui.setNextWindowSizeConstraints(300f, 400f, windowViewport.workSizeX, windowViewport.workSizeY) @@ -80,6 +81,7 @@ abstract class DebugLogger( LogType.Success -> textColored("[SUCCESS]", type.color) LogType.Warning -> textColored("[WARNING]", type.color) LogType.Error -> textColored("[ERROR]", type.color) + LogType.System -> textColored("[SYSTEM]", type.color) } sameLine() @@ -102,20 +104,21 @@ abstract class DebugLogger( LogType.Success -> showSuccess LogType.Warning -> showWarning LogType.Error -> showError + LogType.System -> true } fun clear() = logs.clear() - data class LogEntry( val message: String, val type: LogType ) enum class LogType(val color: Color) { - Debug(Color.WHITE), - Success(Color.GREEN), - Warning(Color.YELLOW), - Error(Color.RED) + Debug(Color(255, 255, 255)), + Success(Color(70, 255, 70)), + Warning(Color(255, 255, 70)), + Error(Color(255, 70, 70)), + System(Color(70, 70, 255)) } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/interaction/request/breaking/BreakInfo.kt b/src/main/kotlin/com/lambda/interaction/request/breaking/BreakInfo.kt index 14198b7eb..e6949f225 100644 --- a/src/main/kotlin/com/lambda/interaction/request/breaking/BreakInfo.kt +++ b/src/main/kotlin/com/lambda/interaction/request/breaking/BreakInfo.kt @@ -147,4 +147,6 @@ data class BreakInfo( sequence ) } + + override fun toString() = "$type, ${context.cachedState}, ${context.blockPos}" } diff --git a/src/main/kotlin/com/lambda/interaction/request/breaking/BreakManager.kt b/src/main/kotlin/com/lambda/interaction/request/breaking/BreakManager.kt index 2f71cf09b..ab28eec9a 100644 --- a/src/main/kotlin/com/lambda/interaction/request/breaking/BreakManager.kt +++ b/src/main/kotlin/com/lambda/interaction/request/breaking/BreakManager.kt @@ -49,6 +49,7 @@ import com.lambda.interaction.request.breaking.BreakInfo.BreakType.Primary import com.lambda.interaction.request.breaking.BreakInfo.BreakType.Rebreak import com.lambda.interaction.request.breaking.BreakInfo.BreakType.RedundantSecondary import com.lambda.interaction.request.breaking.BreakInfo.BreakType.Secondary +import com.lambda.interaction.request.breaking.BreakManager.activeInfos import com.lambda.interaction.request.breaking.BreakManager.activeRequest import com.lambda.interaction.request.breaking.BreakManager.breakInfos import com.lambda.interaction.request.breaking.BreakManager.breaks @@ -103,7 +104,12 @@ object BreakManager : RequestHandler( TickEvent.Input.Pre, TickEvent.Input.Post, TickEvent.Player.Post, - onOpen = { processRequest(activeRequest); simulateAbandoned() }, + onOpen = { + if (activeInfos.isNotEmpty() || breaks.isNotEmpty() || instantBreaks.isNotEmpty()) + BreakManager.logger.system("Tick stage ${BreakManager.tickStage?.run { this::class.qualifiedName }}") + processRequest(activeRequest) + simulateAbandoned() + }, onClose = { checkForCancels() } ), PositionBlocking, Logger { private val breakInfos = arrayOfNulls(2) @@ -178,6 +184,11 @@ object BreakManager : RequestHandler( override fun load(): String { super.load() + listen(priority = Int.MAX_VALUE) { + if (activeInfos.isEmpty() && breaks.isEmpty() && instantBreaks.isEmpty()) return@listen + logger.system("------------- New Tick -------------") + } + listen(priority = Int.MIN_VALUE) { if (!swappedThisTick) { currentStack = player.mainHandStack @@ -377,7 +388,7 @@ object BreakManager : RequestHandler( .forEach { info -> newBreaks.find { ctx -> ctx.blockPos == info.context.blockPos && canAccept(ctx) }?.let { ctx -> if ((!info.updatedThisTick || info.type == RedundantSecondary) || info.abandoned) { - logger.debug("Updating info for ${info.type}") + logger.debug("Updating info for $info") if (info.type == RedundantSecondary) info.request.onStart?.invoke(info.context.blockPos) else if (info.abandoned) { @@ -403,7 +414,7 @@ object BreakManager : RequestHandler( .filter { !it.instantBreak } .toMutableList() - logger.debug("${breaks.size} unprocessed instant breaks") + logger.debug("${breaks.size} unprocessed breaks") val breakConfig = request.config val pendingLimit = (breakConfig.maxPendingBreaks - pendingBreakCount).coerceAtLeast(0) @@ -429,7 +440,6 @@ object BreakManager : RequestHandler( activeInfos .filter { it.updatedThisTick } .let { infos -> - if (infos.isNotEmpty()) logger.debug("Handling pre-processing") rotationRequest = infos.firstOrNull { info -> info.breakConfig.rotateForBreak } ?.let { info -> val rotation = info.context.rotation @@ -453,7 +463,7 @@ object BreakManager : RequestHandler( } logger.debug("Submitting request for hotbar index ${info.context.hotbarIndex} with min swap ticks $minSwapTicks (${hotbarRequest.requestID})") if (!hotbarRequest.done) { - logger.debug("hotbar request failed (${hotbarRequest.requestID})") + logger.warning("hotbar request failed (${hotbarRequest.requestID})") return false } if (minSwapTicks > 0) { @@ -474,7 +484,7 @@ object BreakManager : RequestHandler( * @return false if a break could not be performed. */ private fun SafeContext.performInstantBreaks(request: BreakRequest): Boolean { - if (instantBreaks.isNotEmpty()) logger.debug("Processing instant breaks") + if (instantBreaks.isNotEmpty()) logger.debug("Processing instant breaks ${instantBreaks.size}") val iterator = instantBreaks.iterator() while (iterator.hasNext()) { if (breaksThisTick + 1 > maxBreaksThisTick) return false @@ -503,7 +513,7 @@ object BreakManager : RequestHandler( * @see initNewBreak */ private fun SafeContext.processNewBreaks(request: BreakRequest): Boolean { - if (breaks.isNotEmpty()) logger.debug("Processing new breaks") + if (breaks.isNotEmpty()) logger.debug("Processing new breaks ${breaks.size}") val iterator = breaks.iterator() while (iterator.hasNext()) { val ctx = iterator.next() @@ -538,6 +548,7 @@ object BreakManager : RequestHandler( if (!primaryInfo.breaking) { secondaryBreak = breakInfo.apply { type = Secondary } + logger.success("Initialized $secondaryBreak") return secondaryBreak } @@ -549,6 +560,7 @@ object BreakManager : RequestHandler( primaryBreak = breakInfo setPendingConfigs(request.build) + logger.success("Initialized $primaryBreak") return primaryBreak } @@ -632,7 +644,7 @@ object BreakManager : RequestHandler( } private fun BreakInfo.updatePreProcessing(player: ClientPlayerEntity, world: BlockView) { - logger.debug("Updating pre-processing for $type") + logger.debug("Updating pre-processing for $this") shouldProgress = !progressedThisTick && tickStage in breakConfig.breakStageMask @@ -661,7 +673,7 @@ object BreakManager : RequestHandler( if (type == RedundantSecondary || abandoned) return@runSafe when (type) { Primary -> { - logger.debug("Cancelling $type") + logger.warning("Cancelling ${this@cancelBreak}") nullify() setBreakingTextureStage(player, world, -1) abortBreakPacket(world, interaction) @@ -669,12 +681,12 @@ object BreakManager : RequestHandler( } Secondary -> { if (breakConfig.unsafeCancels) { - logger.warning("Making $type redundant") + logger.warning("Making ${this@cancelBreak} redundant") type = RedundantSecondary setBreakingTextureStage(player, world, -1) request.onCancel?.invoke(context.blockPos) } else { - logger.debug("Abandoning $type") + logger.warning("Abandoning ${this@cancelBreak}") abandoned = true } } @@ -774,7 +786,7 @@ object BreakManager : RequestHandler( val swing = config.swing if (progress >= info.getBreakThreshold() && info.swapInfo.canCompleteBreak) { - logger.success("Breaking ${info.type} ${info.context.cachedState}") + logger.success("Breaking $info") if (info.type == Primary) { onBlockBreak(info) info.stopBreakPacket(world, interaction) From b4afde9a5bac0824713ba0887e118e7f6b06b686 Mon Sep 17 00:00:00 2001 From: beanbag44 Date: Sun, 31 Aug 2025 22:08:39 +0100 Subject: [PATCH 10/38] place manager logs and other manager debug logger hud elements --- .../kotlin/com/lambda/gui/dsl/ImGuiBuilder.kt | 13 +++ .../interaction/request/ManagerUtils.kt | 3 + .../request/breaking/BreakManager.kt | 3 +- .../request/placing/PlaceManager.kt | 84 +++++++++++++++---- ...ManagerDebug.kt => ManagerDebugLoggers.kt} | 27 +++++- 5 files changed, 114 insertions(+), 16 deletions(-) rename src/main/kotlin/com/lambda/module/hud/{BreakManagerDebug.kt => ManagerDebugLoggers.kt} (50%) diff --git a/src/main/kotlin/com/lambda/gui/dsl/ImGuiBuilder.kt b/src/main/kotlin/com/lambda/gui/dsl/ImGuiBuilder.kt index eb49e0a67..92036014a 100644 --- a/src/main/kotlin/com/lambda/gui/dsl/ImGuiBuilder.kt +++ b/src/main/kotlin/com/lambda/gui/dsl/ImGuiBuilder.kt @@ -81,13 +81,24 @@ import imgui.ImGui.endTabItem import imgui.ImGui.endTooltip import imgui.ImGui.getBackgroundDrawList import imgui.ImGui.getColorU32 +import imgui.ImGui.getContentRegionAvail +import imgui.ImGui.getCursorPosX +import imgui.ImGui.getCursorPosY import imgui.ImGui.getFont import imgui.ImGui.getFontSize import imgui.ImGui.getForegroundDrawList +import imgui.ImGui.getFrameHeight +import imgui.ImGui.getFrameHeightWithSpacing import imgui.ImGui.getIO import imgui.ImGui.getItemID +import imgui.ImGui.getItemRectMaxX +import imgui.ImGui.getItemRectMaxY +import imgui.ImGui.getItemRectMinX +import imgui.ImGui.getItemRectMinY import imgui.ImGui.getStyle import imgui.ImGui.getVersion +import imgui.ImGui.getWindowContentRegionMaxX +import imgui.ImGui.getWindowContentRegionMaxY import imgui.ImGui.getWindowDrawList import imgui.ImGui.getWindowHeight import imgui.ImGui.getWindowPos @@ -96,6 +107,7 @@ import imgui.ImGui.getWindowPosY import imgui.ImGui.getWindowSize import imgui.ImGui.getWindowViewport import imgui.ImGui.getWindowWidth +import imgui.ImGui.image import imgui.ImGui.inputDouble import imgui.ImGui.inputFloat import imgui.ImGui.inputFloat2 @@ -131,6 +143,7 @@ import imgui.ImGui.pushStyleVar import imgui.ImGui.pushTextWrapPos import imgui.ImGui.setClipboardText import imgui.ImGui.setCursorPosX +import imgui.ImGui.setCursorPosY import imgui.ImGui.sliderFloat import imgui.ImGui.sliderInt import imgui.ImGui.textColored diff --git a/src/main/kotlin/com/lambda/interaction/request/ManagerUtils.kt b/src/main/kotlin/com/lambda/interaction/request/ManagerUtils.kt index 805f18e91..2080018c1 100644 --- a/src/main/kotlin/com/lambda/interaction/request/ManagerUtils.kt +++ b/src/main/kotlin/com/lambda/interaction/request/ManagerUtils.kt @@ -25,6 +25,9 @@ object ManagerUtils { val accumulatedManagerPriority = managers.map { it.stagePriority }.reduce { acc, priority -> acc + priority } val positionBlockingManagers = getInstances() + fun DebugLogger.newTick() = + system("------------- New Tick -------------") + fun isPosBlocked(pos: BlockPos) = positionBlockingManagers.any { manager -> manager.blockedPositions.any { blocked -> blocked == pos } } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/interaction/request/breaking/BreakManager.kt b/src/main/kotlin/com/lambda/interaction/request/breaking/BreakManager.kt index 3e4ad22e0..cdc91ab81 100644 --- a/src/main/kotlin/com/lambda/interaction/request/breaking/BreakManager.kt +++ b/src/main/kotlin/com/lambda/interaction/request/breaking/BreakManager.kt @@ -41,6 +41,7 @@ import com.lambda.interaction.material.StackSelection import com.lambda.interaction.material.StackSelection.Companion.select import com.lambda.interaction.request.Logger import com.lambda.interaction.request.ManagerUtils.isPosBlocked +import com.lambda.interaction.request.ManagerUtils.newTick import com.lambda.interaction.request.PositionBlocking import com.lambda.interaction.request.RequestHandler import com.lambda.interaction.request.breaking.BreakConfig.BreakConfirmationMode @@ -106,7 +107,7 @@ object BreakManager : RequestHandler( TickEvent.Player.Post, onOpen = { if (activeInfos.isNotEmpty() || breaks.isNotEmpty() || instantBreaks.isNotEmpty()) - BreakManager.logger.system("Tick stage ${BreakManager.tickStage?.run { this::class.qualifiedName }}") + BreakManager.logger.newTick() processRequest(activeRequest) simulateAbandoned() }, diff --git a/src/main/kotlin/com/lambda/interaction/request/placing/PlaceManager.kt b/src/main/kotlin/com/lambda/interaction/request/placing/PlaceManager.kt index 731f442bf..edde563a4 100644 --- a/src/main/kotlin/com/lambda/interaction/request/placing/PlaceManager.kt +++ b/src/main/kotlin/com/lambda/interaction/request/placing/PlaceManager.kt @@ -25,7 +25,9 @@ import com.lambda.event.events.TickEvent import com.lambda.event.events.UpdateManagerEvent import com.lambda.event.listener.SafeListener.Companion.listen import com.lambda.interaction.construction.context.PlaceContext +import com.lambda.interaction.request.Logger import com.lambda.interaction.request.ManagerUtils.isPosBlocked +import com.lambda.interaction.request.ManagerUtils.newTick import com.lambda.interaction.request.PositionBlocking import com.lambda.interaction.request.RequestHandler import com.lambda.interaction.request.breaking.BreakManager @@ -39,6 +41,7 @@ import com.lambda.interaction.request.placing.PlaceManager.processRequest import com.lambda.interaction.request.placing.PlacedBlockHandler.pendingActions import com.lambda.interaction.request.placing.PlacedBlockHandler.setPendingConfigs import com.lambda.interaction.request.placing.PlacedBlockHandler.startPending +import com.lambda.module.hud.PlaceManagerDebug import com.lambda.util.BlockUtils.blockState import com.lambda.util.Communication.warn import com.lambda.util.player.MovementUtils.sneaking @@ -68,8 +71,12 @@ object PlaceManager : RequestHandler( TickEvent.Input.Pre, TickEvent.Input.Post, TickEvent.Player.Post, - onOpen = { activeRequest?.let { processRequest(it) } } -), PositionBlocking { + onOpen = { + activeRequest?.let { processRequest(it) } + if (potentialPlacements.isNotEmpty()) + PlaceManager.logger.system("Tick stage ${PlaceManager.tickStage?.run { this::class.qualifiedName }}") + } +), PositionBlocking, Logger { private var activeRequest: PlaceRequest? = null private var potentialPlacements = mutableListOf() @@ -83,6 +90,8 @@ object PlaceManager : RequestHandler( override val blockedPositions get() = pendingActions.map { it.context.blockPos } + override val logger = PlaceManagerDebug + fun Any.onPlace( alwaysListen: Boolean = false, priority: Int = 0, @@ -94,6 +103,11 @@ object PlaceManager : RequestHandler( override fun load(): String { super.load() + listen(priority = Int.MAX_VALUE) { + if (potentialPlacements.isNotEmpty()) + logger.newTick() + } + listen(priority = Int.MIN_VALUE) { activeRequest = null placementsThisTick = 0 @@ -135,6 +149,8 @@ object PlaceManager : RequestHandler( * @see placeBlock */ fun SafeContext.processRequest(request: PlaceRequest) { + logger.debug("Processing request (${request.requestID}) at tick stage ${tickStage?.run { this::class.qualifiedName }}") + if (request.fresh) populateFrom(request) val iterator = potentialPlacements.iterator() @@ -143,15 +159,22 @@ object PlaceManager : RequestHandler( val ctx = iterator.next() if (ctx.sneak) shouldSneak = true - if (!ctx.requestDependencies(request) || !validSneak(player)) return -// if (tickStage !in request.build.placing.placeStageMask) return + if (!ctx.requestDependencies(request)) { + logger.warning("Dependencies failed for ${request.requestID}") + return + } + if (!validSneak(player)) return + // if (tickStage !in request.build.placing.placeStageMask) return val actionResult = placeBlock(ctx, request, Hand.MAIN_HAND) if (!actionResult.isAccepted) warn("Placement interaction failed with $actionResult") placementsThisTick++ iterator.remove() } - if (potentialPlacements.isEmpty()) activeRequest = null + if (potentialPlacements.isEmpty()) { + if (activeRequest != null) logger.debug("Clearing active request") + activeRequest = null + } } /** @@ -161,10 +184,12 @@ object PlaceManager : RequestHandler( * @see isPosBlocked */ private fun populateFrom(request: PlaceRequest) { + logger.debug("Populating from request (${request.requestID})") setPendingConfigs(request.build) potentialPlacements = request.contexts .filter { !isPosBlocked(it.blockPos) } .toMutableList() + logger.debug("${potentialPlacements.size} potential placements") val pendingLimit = (request.maxPendingPlacements - pendingActions.size).coerceAtLeast(0) maxPlacementsThisTick = (request.placementsPerTick.coerceAtMost(pendingLimit)) @@ -178,8 +203,14 @@ object PlaceManager : RequestHandler( private fun SafeContext.placeBlock(placeContext: PlaceContext, request: PlaceRequest, hand: Hand): ActionResult { interaction.syncSelectedSlot() val hitResult = placeContext.result - if (!world.worldBorder.contains(hitResult.blockPos)) return ActionResult.FAIL - if (gamemode == GameMode.SPECTATOR) return ActionResult.PASS + if (!world.worldBorder.contains(hitResult.blockPos)) { + logger.error("Placement position outside the world border at ${placeContext.blockPos.toShortString()}") + return ActionResult.FAIL + } + if (gamemode == GameMode.SPECTATOR) { + logger.error("Player is in spectator mode") + return ActionResult.PASS + } return interactBlockInternal(placeContext, request, request.build.placing, hand, hitResult) } @@ -200,11 +231,13 @@ object PlaceManager : RequestHandler( if (!cantInteract) { val blockState = blockState(hitResult.blockPos) if (!connection.hasFeature(blockState.block.requiredFeatures)) { + logger.error("Required features not met for $blockState") return ActionResult.FAIL } val actionResult = blockState.onUse(world, player, hitResult) if (actionResult.isAccepted) { + logger.error("Block state ($blockState) onUse not accepted") return actionResult } } @@ -243,9 +276,15 @@ object PlaceManager : RequestHandler( val cantModifyWorld = !player.abilities.allowModifyWorld val cantPlaceOn = !itemStack.canPlaceOn(cachedBlockPosition) - if (cantModifyWorld && cantPlaceOn) return ActionResult.PASS + if (cantModifyWorld && cantPlaceOn) { + logger.error("Cannot modify world") + return ActionResult.PASS + } - val item = (itemStack.item as? BlockItem) ?: return ActionResult.PASS + val item = (itemStack.item as? BlockItem) ?: run { + logger.error("Item ${itemStack.item.name} is not a block item") + return ActionResult.PASS + } return place(placeContext, request, hand, hitResult, placeConfig, item, ItemPlacementContext(context)) } @@ -264,11 +303,23 @@ object PlaceManager : RequestHandler( item: BlockItem, context: ItemPlacementContext ): ActionResult { - if (!item.block.isEnabled(world.enabledFeatures)) return ActionResult.FAIL - if (!context.canPlace()) return ActionResult.FAIL + if (!item.block.isEnabled(world.enabledFeatures)) { + logger.error("Block ${item.block.name} is not enabled") + return ActionResult.FAIL + } + if (!context.canPlace()) { + logger.error("Cannot place at ${placeContext.blockPos} with current state ${placeContext.cachedState}") + return ActionResult.FAIL + } - val itemPlacementContext = item.getPlacementContext(context) ?: return ActionResult.FAIL - val blockState = item.getPlacementState(itemPlacementContext) ?: return ActionResult.FAIL + val itemPlacementContext = item.getPlacementContext(context) ?: run { + logger.error("Could not retrieve item placement context") + return ActionResult.FAIL + } + val blockState = item.getPlacementState(itemPlacementContext) ?: run { + logger.error("Could not retrieve placement state") + return ActionResult.FAIL + } val stackInHand = player.getStackInHand(hand) val stackCountPre = stackInHand.count @@ -302,7 +353,10 @@ object PlaceManager : RequestHandler( // TODO: Implement restriction checks (e.g., world height) to prevent unnecessary server requests when the // "AwaitThenPlace" confirmation setting is enabled, as the block state setting methods that validate these // rules are not called. - if (!item.place(itemPlacementContext, blockState)) return ActionResult.FAIL + if (!item.place(itemPlacementContext, blockState)) { + logger.error("Could not place block client side at ${placeContext.blockPos} with placement state ${placeContext.expectedState}") + return ActionResult.FAIL + } val blockPos = itemPlacementContext.blockPos var state = world.getBlockState(blockPos) @@ -318,6 +372,8 @@ object PlaceManager : RequestHandler( request.onPlace?.invoke(placeContext.blockPos) } + logger.success("Placed ${placeContext.expectedState} at ${placeContext.blockPos}") + return ActionResult.SUCCESS } diff --git a/src/main/kotlin/com/lambda/module/hud/BreakManagerDebug.kt b/src/main/kotlin/com/lambda/module/hud/ManagerDebugLoggers.kt similarity index 50% rename from src/main/kotlin/com/lambda/module/hud/BreakManagerDebug.kt rename to src/main/kotlin/com/lambda/module/hud/ManagerDebugLoggers.kt index d32030d83..c15a342a0 100644 --- a/src/main/kotlin/com/lambda/module/hud/BreakManagerDebug.kt +++ b/src/main/kotlin/com/lambda/module/hud/ManagerDebugLoggers.kt @@ -21,5 +21,30 @@ import com.lambda.interaction.request.DebugLogger object BreakManagerDebug : DebugLogger( "Break Manager Logger", - "Logs most of the actions performed in the break manager to aid in debugging" + "Logs actions performed in the break manager to aid in debugging" +) + +object PlaceManagerDebug : DebugLogger( + "Place Manager Logger", + "Logs actions performed in the place manager to aid in debugging" +) + +object InteractManagerDebug : DebugLogger( + "Interact Manager Logger", + "Logs actions performed in the interact manager to aid in debugging" +) + +object RotationManagerDebug : DebugLogger( + "Rotation Manager Logger", + "Logs actions performed in the rotation manager to aid in debugging" +) + +object HotbarManagerDebug : DebugLogger( + "Hotbar Manager Logger", + "Logs actions performed in the hotbar manager to aid in debugging" +) + +object InventoryManagerDebug : DebugLogger( + "Inventory Manager Logger", + "Logs actions performed in the inventory manager to aid in debugging" ) \ No newline at end of file From 61ebb81a32974c6aa67a39d800791d92337a2f66 Mon Sep 17 00:00:00 2001 From: beanbag44 Date: Mon, 1 Sep 2025 03:07:54 +0100 Subject: [PATCH 11/38] all individual manager debug logger toggles inside one hud module --- .../lambda/interaction/request/DebugLogger.kt | 80 ++++++++-------- .../request/breaking/BreakManager.kt | 8 +- .../request/hotbar/HotbarManager.kt | 6 +- .../request/interacting/InteractionManager.kt | 6 +- .../request/inventory/InventoryManager.kt | 6 +- .../request/placing/PlaceManager.kt | 4 +- .../request/rotating/RotationManager.kt | 6 +- .../lambda/module/hud/ManagerDebugLoggers.kt | 92 +++++++++++++------ 8 files changed, 131 insertions(+), 77 deletions(-) diff --git a/src/main/kotlin/com/lambda/interaction/request/DebugLogger.kt b/src/main/kotlin/com/lambda/interaction/request/DebugLogger.kt index f13f31772..f7d79d144 100644 --- a/src/main/kotlin/com/lambda/interaction/request/DebugLogger.kt +++ b/src/main/kotlin/com/lambda/interaction/request/DebugLogger.kt @@ -17,40 +17,30 @@ package com.lambda.interaction.request +import com.lambda.Lambda.mc +import com.lambda.gui.LambdaScreen import com.lambda.gui.dsl.ImGuiBuilder -import com.lambda.module.HudModule -import com.lambda.module.tag.ModuleTag +import com.lambda.module.hud.ManagerDebugLoggers.maxLogEntries import imgui.ImGui import imgui.flag.ImGuiWindowFlags +import imgui.type.ImBoolean +import imgui.type.ImFloat import java.awt.Color import java.util.* -abstract class DebugLogger( - name: String, - description: String -) : HudModule( - name, - description, - ModuleTag.HUD, - customWindow = true +class DebugLogger( + val name: String ) { - private val logs = LinkedList() + private val autoScroll = ImBoolean(true) + private val wrapText = ImBoolean(true) + private val showDebug = ImBoolean(true) + private val showSuccess = ImBoolean(true) + private val showWarning = ImBoolean(true) + private val showError = ImBoolean(true) + private val showSystem = ImBoolean(true) + private val backgroundAlpha = ImFloat(0.3f) - private val autoScroll by setting("Auto-Scroll", true, "Automatically scrolls to the bottom of the log") - private val wrapText by setting("Wrap Text", false, "Wraps the text to the next line if it gets too long") - private val showDebug by setting("Show Debug", true, "Shows debug logs") - private val showSuccess by setting("Show Success", true, "Shows success logs") - private val showWarning by setting("Show Warning", true, "Shows warning logs") - private val showError by setting("Show Errors", true, "Shows error logs") - private val maxLogEntries by setting("Max Log Entries", 100, 1..1000, 1, "Maximum amount of entries in the log") - .onValueChange { from, to -> - if (to < from) { - while(logs.size > to) { - logs.removeFirst() - } - } - } - private val backgroundAlpha by setting("Background Alpha", 0.3f, 0f..1f, 0.01f, "Sets the opacity for the elements background") + val logs = LinkedList() private fun log(message: String, logColor: LogType) { logs.add(LogEntry(message, logColor)) @@ -65,14 +55,28 @@ abstract class DebugLogger( fun error(message: String) = log(message, LogType.Error) fun system(message: String) = log(message, LogType.System) - override fun ImGuiBuilder.buildLayout() { + fun ImGuiBuilder.buildLayout() { ImGui.setNextWindowSizeConstraints(300f, 400f, windowViewport.workSizeX, windowViewport.workSizeY) - ImGui.setNextWindowBgAlpha(backgroundAlpha) + ImGui.setNextWindowBgAlpha(backgroundAlpha.get()) window(name, flags = ImGuiWindowFlags.NoCollapse) { - val noScroll = if (autoScroll) ImGuiWindowFlags.NoScrollbar or ImGuiWindowFlags.NoScrollWithMouse else 0 - button("Clear") { clear() } + val noScroll = if (autoScroll.get()) ImGuiWindowFlags.NoScrollbar or ImGuiWindowFlags.NoScrollWithMouse else 0 + if (mc.currentScreen == LambdaScreen) { + checkbox("Auto-Scroll", autoScroll) + sameLine() + checkbox("Warp Text", wrapText) + sameLine() + checkbox("Show Debug", showDebug) + checkbox("Show Success", showSuccess) + sameLine() + checkbox("Show Warning", showWarning) + sameLine() + checkbox("Show Error", showError) + checkbox("Show System", showSystem) + slider("Background Alpha", backgroundAlpha, 0.0f, 1.0f) + button("Clear") { clear() } + } child("Log Content", extraFlags = noScroll) { - if (wrapText) ImGui.pushTextWrapPos() + if (wrapText.get()) ImGui.pushTextWrapPos() logs.forEach { logEntry -> if (shouldDisplay(logEntry)) { @@ -89,9 +93,9 @@ abstract class DebugLogger( } } - if (wrapText) ImGui.popTextWrapPos() + if (wrapText.get()) ImGui.popTextWrapPos() - if (autoScroll) { + if (autoScroll.get()) { ImGui.setScrollHereY(1f) } } @@ -100,11 +104,11 @@ abstract class DebugLogger( fun shouldDisplay(logEntry: LogEntry) = when (logEntry.type) { - LogType.Debug -> showDebug - LogType.Success -> showSuccess - LogType.Warning -> showWarning - LogType.Error -> showError - LogType.System -> true + LogType.Debug -> showDebug.get() + LogType.Success -> showSuccess.get() + LogType.Warning -> showWarning.get() + LogType.Error -> showError.get() + LogType.System -> showSystem.get() } fun clear() = logs.clear() diff --git a/src/main/kotlin/com/lambda/interaction/request/breaking/BreakManager.kt b/src/main/kotlin/com/lambda/interaction/request/breaking/BreakManager.kt index cdc91ab81..ab8597a55 100644 --- a/src/main/kotlin/com/lambda/interaction/request/breaking/BreakManager.kt +++ b/src/main/kotlin/com/lambda/interaction/request/breaking/BreakManager.kt @@ -73,7 +73,7 @@ import com.lambda.interaction.request.hotbar.HotbarRequest import com.lambda.interaction.request.interacting.InteractionManager import com.lambda.interaction.request.placing.PlaceManager import com.lambda.interaction.request.rotating.RotationRequest -import com.lambda.module.hud.BreakManagerDebug +import com.lambda.module.hud.ManagerDebugLoggers.breakManagerLogger import com.lambda.threading.runSafe import com.lambda.util.BlockUtils.blockState import com.lambda.util.BlockUtils.calcItemBlockBreakingDelta @@ -107,7 +107,7 @@ object BreakManager : RequestHandler( TickEvent.Player.Post, onOpen = { if (activeInfos.isNotEmpty() || breaks.isNotEmpty() || instantBreaks.isNotEmpty()) - BreakManager.logger.newTick() + BreakManager.logger.system("Tick stage ${BreakManager.tickStage?.run { this::class.qualifiedName }}") processRequest(activeRequest) simulateAbandoned() }, @@ -172,7 +172,7 @@ object BreakManager : RequestHandler( field = value } - override val logger = BreakManagerDebug + override val logger = breakManagerLogger fun Any.onBreak( alwaysListen: Boolean = false, @@ -187,7 +187,7 @@ object BreakManager : RequestHandler( listen(priority = Int.MAX_VALUE) { if (activeInfos.isEmpty() && breaks.isEmpty() && instantBreaks.isEmpty()) return@listen - logger.system("------------- New Tick -------------") + logger.newTick() } listen(priority = Int.MIN_VALUE) { diff --git a/src/main/kotlin/com/lambda/interaction/request/hotbar/HotbarManager.kt b/src/main/kotlin/com/lambda/interaction/request/hotbar/HotbarManager.kt index d27f73bd5..34774d6e0 100644 --- a/src/main/kotlin/com/lambda/interaction/request/hotbar/HotbarManager.kt +++ b/src/main/kotlin/com/lambda/interaction/request/hotbar/HotbarManager.kt @@ -23,8 +23,10 @@ import com.lambda.event.EventFlow.post import com.lambda.event.events.TickEvent import com.lambda.event.events.UpdateManagerEvent import com.lambda.event.listener.SafeListener.Companion.listen +import com.lambda.interaction.request.Logger import com.lambda.interaction.request.RequestHandler import com.lambda.interaction.request.hotbar.HotbarManager.checkResetSwap +import com.lambda.module.hud.ManagerDebugLoggers.hotbarManagerLogger import com.lambda.threading.runSafe object HotbarManager : RequestHandler( @@ -34,7 +36,7 @@ object HotbarManager : RequestHandler( TickEvent.Input.Post, TickEvent.Player.Post, onClose = { checkResetSwap() } -) { +), Logger { val serverSlot get() = runSafe { interaction.lastSelectedSlot } ?: 0 @@ -45,6 +47,8 @@ object HotbarManager : RequestHandler( var activeRequest: HotbarRequest? = null + override val logger = hotbarManagerLogger + override fun load(): String { super.load() diff --git a/src/main/kotlin/com/lambda/interaction/request/interacting/InteractionManager.kt b/src/main/kotlin/com/lambda/interaction/request/interacting/InteractionManager.kt index c83fc99e5..f9769fcf5 100644 --- a/src/main/kotlin/com/lambda/interaction/request/interacting/InteractionManager.kt +++ b/src/main/kotlin/com/lambda/interaction/request/interacting/InteractionManager.kt @@ -25,6 +25,7 @@ import com.lambda.event.events.TickEvent import com.lambda.event.events.UpdateManagerEvent import com.lambda.event.listener.SafeListener.Companion.listen import com.lambda.interaction.construction.context.InteractionContext +import com.lambda.interaction.request.Logger import com.lambda.interaction.request.ManagerUtils.isPosBlocked import com.lambda.interaction.request.PositionBlocking import com.lambda.interaction.request.RequestHandler @@ -35,6 +36,7 @@ import com.lambda.interaction.request.interacting.InteractedBlockHandler.startPe import com.lambda.interaction.request.interacting.InteractionManager.activeRequest import com.lambda.interaction.request.interacting.InteractionManager.processRequest import com.lambda.interaction.request.placing.PlaceManager +import com.lambda.module.hud.ManagerDebugLoggers.interactionManagerLogger import com.lambda.util.player.MovementUtils.sneaking import com.lambda.util.player.swingHand import net.minecraft.network.packet.c2s.play.PlayerInteractBlockC2SPacket @@ -47,7 +49,7 @@ object InteractionManager : RequestHandler( TickEvent.Input.Post, TickEvent.Player.Post, onOpen = { activeRequest?.let { processRequest(it) } } -), PositionBlocking { +), PositionBlocking, Logger { private var activeRequest: InteractRequest? = null private var potentialInteractions = mutableListOf() @@ -57,6 +59,8 @@ object InteractionManager : RequestHandler( override val blockedPositions get() = pendingActions.map { it.context.blockPos } + override val logger = interactionManagerLogger + override fun load(): String { super.load() diff --git a/src/main/kotlin/com/lambda/interaction/request/inventory/InventoryManager.kt b/src/main/kotlin/com/lambda/interaction/request/inventory/InventoryManager.kt index 4c86403e9..ba2e21133 100644 --- a/src/main/kotlin/com/lambda/interaction/request/inventory/InventoryManager.kt +++ b/src/main/kotlin/com/lambda/interaction/request/inventory/InventoryManager.kt @@ -21,10 +21,12 @@ import com.lambda.context.SafeContext import com.lambda.event.EventFlow.post import com.lambda.event.events.TickEvent import com.lambda.event.events.UpdateManagerEvent +import com.lambda.interaction.request.Logger import com.lambda.interaction.request.RequestHandler import com.lambda.interaction.request.inventory.InventoryManager.activeRequest import com.lambda.interaction.request.inventory.InventoryManager.processRequest +import com.lambda.module.hud.ManagerDebugLoggers.inventoryManagerLogger object InventoryManager : RequestHandler( 1, @@ -33,9 +35,11 @@ object InventoryManager : RequestHandler( TickEvent.Input.Post, TickEvent.Player.Post, onOpen = { activeRequest?.let { processRequest(it) } } -) { +), Logger { var activeRequest: InventoryRequest? = null + override val logger = inventoryManagerLogger + override fun load(): String { super.load() diff --git a/src/main/kotlin/com/lambda/interaction/request/placing/PlaceManager.kt b/src/main/kotlin/com/lambda/interaction/request/placing/PlaceManager.kt index edde563a4..a81b1568b 100644 --- a/src/main/kotlin/com/lambda/interaction/request/placing/PlaceManager.kt +++ b/src/main/kotlin/com/lambda/interaction/request/placing/PlaceManager.kt @@ -41,7 +41,7 @@ import com.lambda.interaction.request.placing.PlaceManager.processRequest import com.lambda.interaction.request.placing.PlacedBlockHandler.pendingActions import com.lambda.interaction.request.placing.PlacedBlockHandler.setPendingConfigs import com.lambda.interaction.request.placing.PlacedBlockHandler.startPending -import com.lambda.module.hud.PlaceManagerDebug +import com.lambda.module.hud.ManagerDebugLoggers.placeManagerLogger import com.lambda.util.BlockUtils.blockState import com.lambda.util.Communication.warn import com.lambda.util.player.MovementUtils.sneaking @@ -90,7 +90,7 @@ object PlaceManager : RequestHandler( override val blockedPositions get() = pendingActions.map { it.context.blockPos } - override val logger = PlaceManagerDebug + override val logger = placeManagerLogger fun Any.onPlace( alwaysListen: Boolean = false, diff --git a/src/main/kotlin/com/lambda/interaction/request/rotating/RotationManager.kt b/src/main/kotlin/com/lambda/interaction/request/rotating/RotationManager.kt index dbc0d474c..5d4bfb371 100644 --- a/src/main/kotlin/com/lambda/interaction/request/rotating/RotationManager.kt +++ b/src/main/kotlin/com/lambda/interaction/request/rotating/RotationManager.kt @@ -27,10 +27,12 @@ import com.lambda.event.events.TickEvent import com.lambda.event.events.UpdateManagerEvent import com.lambda.event.listener.SafeListener.Companion.listen import com.lambda.event.listener.UnsafeListener.Companion.listenUnsafe +import com.lambda.interaction.request.Logger import com.lambda.interaction.request.RequestHandler import com.lambda.interaction.request.rotating.Rotation.Companion.slerp import com.lambda.interaction.request.rotating.Rotation.Companion.wrap import com.lambda.interaction.request.rotating.visibilty.lookAt +import com.lambda.module.hud.ManagerDebugLoggers.rotationManagerLogger import com.lambda.module.modules.client.Baritone import com.lambda.threading.runGameScheduled import com.lambda.threading.runSafe @@ -53,7 +55,7 @@ object RotationManager : RequestHandler( TickEvent.Input.Pre, TickEvent.Input.Post, TickEvent.Player.Post, -) { +), Logger { var activeRotation = Rotation.ZERO var serverRotation = Rotation.ZERO var prevServerRotation = Rotation.ZERO @@ -61,6 +63,8 @@ object RotationManager : RequestHandler( var activeRequest: RotationRequest? = null private var changedThisTick = false + override val logger = rotationManagerLogger + override fun load(): String { super.load() diff --git a/src/main/kotlin/com/lambda/module/hud/ManagerDebugLoggers.kt b/src/main/kotlin/com/lambda/module/hud/ManagerDebugLoggers.kt index c15a342a0..702323aab 100644 --- a/src/main/kotlin/com/lambda/module/hud/ManagerDebugLoggers.kt +++ b/src/main/kotlin/com/lambda/module/hud/ManagerDebugLoggers.kt @@ -17,34 +17,68 @@ package com.lambda.module.hud +import com.lambda.gui.dsl.ImGuiBuilder import com.lambda.interaction.request.DebugLogger +import com.lambda.module.HudModule +import com.lambda.module.tag.ModuleTag +import com.lambda.util.NamedEnum -object BreakManagerDebug : DebugLogger( - "Break Manager Logger", - "Logs actions performed in the break manager to aid in debugging" -) - -object PlaceManagerDebug : DebugLogger( - "Place Manager Logger", - "Logs actions performed in the place manager to aid in debugging" -) - -object InteractManagerDebug : DebugLogger( - "Interact Manager Logger", - "Logs actions performed in the interact manager to aid in debugging" -) - -object RotationManagerDebug : DebugLogger( - "Rotation Manager Logger", - "Logs actions performed in the rotation manager to aid in debugging" -) - -object HotbarManagerDebug : DebugLogger( - "Hotbar Manager Logger", - "Logs actions performed in the hotbar manager to aid in debugging" -) - -object InventoryManagerDebug : DebugLogger( - "Inventory Manager Logger", - "Logs actions performed in the inventory manager to aid in debugging" -) \ No newline at end of file +@Suppress("Unused") +object ManagerDebugLoggers : HudModule( + "Manager Debug Loggers", + "debug loggers for all action managers in lambda", + ModuleTag.HUD, + customWindow = true +) { + enum class Group(override val displayName: String) : NamedEnum { + General("General"), + Break("Break"), + Place("Place"), + Interact("Interact"), + Rotation("Rotation"), + Hotbar("Hotbar"), + Inventory("Inventory") + } + + private val loggers = mutableMapOf<() -> Boolean, DebugLogger>() + + val maxLogEntries by setting("Max Log Entries", 100, 1..1000, 1, "Maximum amount of entries in the log").group(Group.General) + .onValueChange { from, to -> + if (to < from) { + loggers.values.forEach { logger -> + while(logger.logs.size > to) { + logger.logs.removeFirst() + } + } + } + } + + private val showBreakManager by setting("Show Break Manager Logger", false).group(Group.Break) + val breakManagerLogger = DebugLogger("Break Manager Logger").store { showBreakManager } + + private val showPlaceManager by setting("Show Place Manager Logger", false).group(Group.Place) + val placeManagerLogger = DebugLogger("Place Manager Logger").store { showPlaceManager } + + private val showInteractionManager by setting("Show Interaction Manager Logger", false).group(Group.Interact) + val interactionManagerLogger = DebugLogger("Interaction Manager Logger").store { showInteractionManager } + + private val showRotationManager by setting("Show Rotation Manager Logger", false).group(Group.Rotation) + val rotationManagerLogger = DebugLogger("Rotation Manager Logger").store { showRotationManager } + + private val showHotbarManager by setting("Show Hotbar Manager Logger", false).group(Group.Hotbar) + val hotbarManagerLogger = DebugLogger("Hotbar Manager Logger").store { showHotbarManager } + + private val showInventoryManager by setting("Show Inventory Manager Logger", false).group(Group.Inventory) + val inventoryManagerLogger = DebugLogger("Inventory Manager Logger").store { showInventoryManager } + + private fun DebugLogger.store(show: () -> Boolean) = + also { loggers.put(show, this) } + + override fun ImGuiBuilder.buildLayout() { + loggers.entries.forEach { entry -> + if (entry.key()) with(entry.value) { + buildLayout() + } + } + } +} \ No newline at end of file From a988f1ef5cb4903a3b275b20915219a66af38f6b Mon Sep 17 00:00:00 2001 From: beanbag44 Date: Mon, 1 Sep 2025 16:31:07 +0100 Subject: [PATCH 12/38] hotbar manager debug logs --- .../com/lambda/interaction/request/ManagerUtils.kt | 4 ++++ .../interaction/request/breaking/BreakManager.kt | 3 ++- .../interaction/request/hotbar/HotbarManager.kt | 13 +++++++++++++ .../interaction/request/placing/PlaceManager.kt | 3 ++- 4 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/com/lambda/interaction/request/ManagerUtils.kt b/src/main/kotlin/com/lambda/interaction/request/ManagerUtils.kt index 2080018c1..552b1ebd2 100644 --- a/src/main/kotlin/com/lambda/interaction/request/ManagerUtils.kt +++ b/src/main/kotlin/com/lambda/interaction/request/ManagerUtils.kt @@ -17,6 +17,7 @@ package com.lambda.interaction.request +import com.lambda.event.Event import com.lambda.util.reflections.getInstances import net.minecraft.util.math.BlockPos @@ -28,6 +29,9 @@ object ManagerUtils { fun DebugLogger.newTick() = system("------------- New Tick -------------") + fun DebugLogger.newStage(tickStage: Event?) = + system("Tick stage ${tickStage?.run { this::class.qualifiedName }}") + fun isPosBlocked(pos: BlockPos) = positionBlockingManagers.any { manager -> manager.blockedPositions.any { blocked -> blocked == pos } } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/interaction/request/breaking/BreakManager.kt b/src/main/kotlin/com/lambda/interaction/request/breaking/BreakManager.kt index ab8597a55..38e8b1477 100644 --- a/src/main/kotlin/com/lambda/interaction/request/breaking/BreakManager.kt +++ b/src/main/kotlin/com/lambda/interaction/request/breaking/BreakManager.kt @@ -41,6 +41,7 @@ import com.lambda.interaction.material.StackSelection import com.lambda.interaction.material.StackSelection.Companion.select import com.lambda.interaction.request.Logger import com.lambda.interaction.request.ManagerUtils.isPosBlocked +import com.lambda.interaction.request.ManagerUtils.newStage import com.lambda.interaction.request.ManagerUtils.newTick import com.lambda.interaction.request.PositionBlocking import com.lambda.interaction.request.RequestHandler @@ -107,7 +108,7 @@ object BreakManager : RequestHandler( TickEvent.Player.Post, onOpen = { if (activeInfos.isNotEmpty() || breaks.isNotEmpty() || instantBreaks.isNotEmpty()) - BreakManager.logger.system("Tick stage ${BreakManager.tickStage?.run { this::class.qualifiedName }}") + BreakManager.logger.newStage(BreakManager.tickStage) processRequest(activeRequest) simulateAbandoned() }, diff --git a/src/main/kotlin/com/lambda/interaction/request/hotbar/HotbarManager.kt b/src/main/kotlin/com/lambda/interaction/request/hotbar/HotbarManager.kt index 34774d6e0..2bc0db084 100644 --- a/src/main/kotlin/com/lambda/interaction/request/hotbar/HotbarManager.kt +++ b/src/main/kotlin/com/lambda/interaction/request/hotbar/HotbarManager.kt @@ -24,6 +24,8 @@ import com.lambda.event.events.TickEvent import com.lambda.event.events.UpdateManagerEvent import com.lambda.event.listener.SafeListener.Companion.listen import com.lambda.interaction.request.Logger +import com.lambda.interaction.request.ManagerUtils.newStage +import com.lambda.interaction.request.ManagerUtils.newTick import com.lambda.interaction.request.RequestHandler import com.lambda.interaction.request.hotbar.HotbarManager.checkResetSwap import com.lambda.module.hud.ManagerDebugLoggers.hotbarManagerLogger @@ -35,6 +37,7 @@ object HotbarManager : RequestHandler( TickEvent.Input.Pre, TickEvent.Input.Post, TickEvent.Player.Post, + onOpen = { if (HotbarManager.activeRequest != null) HotbarManager.logger.newStage(HotbarManager.tickStage) }, onClose = { checkResetSwap() } ), Logger { val serverSlot get() = runSafe { @@ -52,6 +55,11 @@ object HotbarManager : RequestHandler( override fun load(): String { super.load() + listen(priority = Int.MAX_VALUE) { + if (activeRequest != null) + logger.newTick() + } + listen(priority = Int.MIN_VALUE) { swapsThisTick = 0 if (swapDelay > 0) swapDelay-- @@ -66,6 +74,8 @@ object HotbarManager : RequestHandler( } override fun SafeContext.handleRequest(request: HotbarRequest) { + logger.debug("Handling request ${request.requestID}") + maxSwapsThisTick = request.swapsPerTick swapDelay = swapDelay.coerceAtMost(request.swapDelay) @@ -76,6 +86,7 @@ object HotbarManager : RequestHandler( } == true if (sameButLonger) activeRequest?.let { current -> + logger.debug("Request is the same as current, but longer or the same keep time") request.swapPauseAge = current.swapPauseAge } else run swap@{ if (request.slot != activeRequest?.slot) { @@ -97,6 +108,7 @@ object HotbarManager : RequestHandler( } activeRequest = request + logger.success("Set active request to ${request.requestID}") interaction.syncSelectedSlot() return } @@ -105,6 +117,7 @@ object HotbarManager : RequestHandler( activeRequest?.let { active -> val canStopSwap = swapsThisTick < maxSwapsThisTick if (active.keepTicks <= 0 && tickStage in active.sequenceStageMask && canStopSwap) { + logger.debug("Clearing request and syncing slot") activeRequest = null interaction.syncSelectedSlot() } diff --git a/src/main/kotlin/com/lambda/interaction/request/placing/PlaceManager.kt b/src/main/kotlin/com/lambda/interaction/request/placing/PlaceManager.kt index a81b1568b..0ccbb0d83 100644 --- a/src/main/kotlin/com/lambda/interaction/request/placing/PlaceManager.kt +++ b/src/main/kotlin/com/lambda/interaction/request/placing/PlaceManager.kt @@ -27,6 +27,7 @@ import com.lambda.event.listener.SafeListener.Companion.listen import com.lambda.interaction.construction.context.PlaceContext import com.lambda.interaction.request.Logger import com.lambda.interaction.request.ManagerUtils.isPosBlocked +import com.lambda.interaction.request.ManagerUtils.newStage import com.lambda.interaction.request.ManagerUtils.newTick import com.lambda.interaction.request.PositionBlocking import com.lambda.interaction.request.RequestHandler @@ -74,7 +75,7 @@ object PlaceManager : RequestHandler( onOpen = { activeRequest?.let { processRequest(it) } if (potentialPlacements.isNotEmpty()) - PlaceManager.logger.system("Tick stage ${PlaceManager.tickStage?.run { this::class.qualifiedName }}") + PlaceManager.logger.newStage(PlaceManager.tickStage) } ), PositionBlocking, Logger { private var activeRequest: PlaceRequest? = null From 98f9f87570ebd39e1de6099a431af58c64d9d287 Mon Sep 17 00:00:00 2001 From: beanbag44 Date: Mon, 1 Sep 2025 16:32:55 +0100 Subject: [PATCH 13/38] log new stage before processing request --- .../com/lambda/interaction/request/placing/PlaceManager.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/com/lambda/interaction/request/placing/PlaceManager.kt b/src/main/kotlin/com/lambda/interaction/request/placing/PlaceManager.kt index 0ccbb0d83..d06b6e27e 100644 --- a/src/main/kotlin/com/lambda/interaction/request/placing/PlaceManager.kt +++ b/src/main/kotlin/com/lambda/interaction/request/placing/PlaceManager.kt @@ -73,9 +73,9 @@ object PlaceManager : RequestHandler( TickEvent.Input.Post, TickEvent.Player.Post, onOpen = { - activeRequest?.let { processRequest(it) } if (potentialPlacements.isNotEmpty()) PlaceManager.logger.newStage(PlaceManager.tickStage) + activeRequest?.let { processRequest(it) } } ), PositionBlocking, Logger { private var activeRequest: PlaceRequest? = null From e6f20763d83918410777703471df470ed9a3a32e Mon Sep 17 00:00:00 2001 From: beanbag44 Date: Mon, 1 Sep 2025 16:43:51 +0100 Subject: [PATCH 14/38] interaction manager logs --- .../request/interacting/InteractionManager.kt | 25 ++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/com/lambda/interaction/request/interacting/InteractionManager.kt b/src/main/kotlin/com/lambda/interaction/request/interacting/InteractionManager.kt index f9769fcf5..8a02136db 100644 --- a/src/main/kotlin/com/lambda/interaction/request/interacting/InteractionManager.kt +++ b/src/main/kotlin/com/lambda/interaction/request/interacting/InteractionManager.kt @@ -27,13 +27,14 @@ import com.lambda.event.listener.SafeListener.Companion.listen import com.lambda.interaction.construction.context.InteractionContext import com.lambda.interaction.request.Logger import com.lambda.interaction.request.ManagerUtils.isPosBlocked +import com.lambda.interaction.request.ManagerUtils.newStage +import com.lambda.interaction.request.ManagerUtils.newTick import com.lambda.interaction.request.PositionBlocking import com.lambda.interaction.request.RequestHandler import com.lambda.interaction.request.breaking.BreakManager import com.lambda.interaction.request.interacting.InteractedBlockHandler.pendingActions import com.lambda.interaction.request.interacting.InteractedBlockHandler.setPendingConfigs import com.lambda.interaction.request.interacting.InteractedBlockHandler.startPending -import com.lambda.interaction.request.interacting.InteractionManager.activeRequest import com.lambda.interaction.request.interacting.InteractionManager.processRequest import com.lambda.interaction.request.placing.PlaceManager import com.lambda.module.hud.ManagerDebugLoggers.interactionManagerLogger @@ -48,7 +49,11 @@ object InteractionManager : RequestHandler( TickEvent.Input.Pre, TickEvent.Input.Post, TickEvent.Player.Post, - onOpen = { activeRequest?.let { processRequest(it) } } + onOpen = { + if (InteractionManager.potentialInteractions.isNotEmpty()) + InteractionManager.logger.newStage(InteractionManager.tickStage) + InteractionManager.activeRequest?.let { processRequest(it) } + } ), PositionBlocking, Logger { private var activeRequest: InteractRequest? = null private var potentialInteractions = mutableListOf() @@ -64,6 +69,11 @@ object InteractionManager : RequestHandler( override fun load(): String { super.load() + listen(priority = Int.MAX_VALUE) { + if (potentialInteractions.isNotEmpty()) + logger.newTick() + } + listen(priority = Int.MIN_VALUE) { activeRequest = null interactionsThisTick = 0 @@ -88,6 +98,8 @@ object InteractionManager : RequestHandler( } fun SafeContext.processRequest(request: InteractRequest) { + logger.debug("Processing request ${request.requestID}") + if (request.fresh) populateFrom(request) if (player.isSneaking) return @@ -97,7 +109,10 @@ object InteractionManager : RequestHandler( if (interactionsThisTick + 1 > maxInteractionsThisTick) break val ctx = iterator.next() - if (!ctx.requestDependencies(request)) return + if (!ctx.requestDependencies(request)) { + logger.warning("Dependencies failed for ${request.requestID}") + return + } if (request.interactConfirmationMode != InteractionConfig.InteractConfirmationMode.None) { InteractionInfo(ctx, request.pendingInteractionsList, request).startPending() @@ -115,15 +130,19 @@ object InteractionManager : RequestHandler( request.onInteract?.invoke(ctx.blockPos) interactionsThisTick++ iterator.remove() + logger.success("Placed ${ctx.expectedState} at ${ctx.blockPos}") } } private fun populateFrom(request: InteractRequest) { + logger.debug("Populating from request ${request.requestID}") setPendingConfigs(request.build) potentialInteractions = request.contexts .filter { !isPosBlocked(it.blockPos) } .toMutableList() + logger.debug("${potentialInteractions.size} potential interactions") + val pendingLimit = (request.build.maxPendingInteractions - pendingActions.size).coerceAtLeast(0) maxInteractionsThisTick = (request.build.interactionsPerTick.coerceAtMost(pendingLimit)) } From b16b2487cb1b432e3d86ac95381a24571ff49b15 Mon Sep 17 00:00:00 2001 From: beanbag44 Date: Tue, 2 Sep 2025 18:52:43 +0100 Subject: [PATCH 15/38] rotation manager logs --- .../lambda/interaction/request/rotating/RotationManager.kt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/kotlin/com/lambda/interaction/request/rotating/RotationManager.kt b/src/main/kotlin/com/lambda/interaction/request/rotating/RotationManager.kt index 5d4bfb371..9c8b005f5 100644 --- a/src/main/kotlin/com/lambda/interaction/request/rotating/RotationManager.kt +++ b/src/main/kotlin/com/lambda/interaction/request/rotating/RotationManager.kt @@ -71,6 +71,7 @@ object RotationManager : RequestHandler( listen(priority = Int.MAX_VALUE) { activeRequest?.let { if (it.keepTicks <= 0 && it.decayTicks <= 0) { + logger.debug("Clearing active request ${it.requestID}") activeRequest = null } } @@ -102,6 +103,7 @@ object RotationManager : RequestHandler( override fun SafeContext.handleRequest(request: RotationRequest) { activeRequest?.let { if (it.age <= 0) return } if (request.target.targetRotation.value != null) { + logger.debug("Accepting request ${request.requestID}") activeRequest = request updateActiveRotation() changedThisTick = true @@ -147,9 +149,12 @@ object RotationManager : RequestHandler( serverRotation.slerp(rotationTo, turnSpeed).wrap() } ?: player.rotation + + logger.debug("Active rotation set to $activeRotation") } private fun reset(rotation: Rotation) { + logger.debug("Resetting values") prevServerRotation = rotation serverRotation = rotation activeRotation = rotation From 1f2a1a43c194f62e5cb66c04cb8fcd9b3764de6f Mon Sep 17 00:00:00 2001 From: beanbag44 Date: Fri, 5 Sep 2025 01:23:51 +0100 Subject: [PATCH 16/38] fix treeNode label / id argument order and inline textColored logic with the way it's done in the rest of the class --- .../kotlin/com/lambda/gui/dsl/ImGuiBuilder.kt | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/main/kotlin/com/lambda/gui/dsl/ImGuiBuilder.kt b/src/main/kotlin/com/lambda/gui/dsl/ImGuiBuilder.kt index 92036014a..6ab287b87 100644 --- a/src/main/kotlin/com/lambda/gui/dsl/ImGuiBuilder.kt +++ b/src/main/kotlin/com/lambda/gui/dsl/ImGuiBuilder.kt @@ -448,15 +448,11 @@ object ImGuiBuilder { * @param text The text to display */ @ImGuiDsl - fun textColored(text: String, color: Color) = textColored( - getColorU32( - color.red / 255f, - color.green / 255f, - color.blue / 255f, - color.alpha / 255f - ), - text - ) + fun textColored(text: String, color: Color) { + val floats = floatArrayOf(0f, 0f, 0f, 0f) + val (r, g, b, a) = color.getColorComponents(floats) + textColored(r, g, b, a, text) + } /** * Text with disabled coloring. @@ -1317,7 +1313,7 @@ object ImGuiBuilder { */ @ImGuiDsl inline fun treeNode(label: String, id: String, block: ProcedureBlock) { - if (treeNode(label, id)) { + if (treeNode(id, label)) { block() treePop() } From f8beaff5097fcd70e863ab42e9dbc71c7fe0c0ea Mon Sep 17 00:00:00 2001 From: beanbag44 Date: Fri, 5 Sep 2025 03:31:23 +0100 Subject: [PATCH 17/38] a start to log contexts --- .../lambda/interaction/request/DebugLogger.kt | 74 +++++++++++++------ .../lambda/interaction/request/LogContext.kt | 61 +++++++++++++++ .../interaction/request/ManagerUtils.kt | 4 +- .../request/breaking/BreakManager.kt | 2 +- .../request/hotbar/HotbarManager.kt | 8 +- .../request/hotbar/HotbarRequest.kt | 16 +++- 6 files changed, 134 insertions(+), 31 deletions(-) create mode 100644 src/main/kotlin/com/lambda/interaction/request/LogContext.kt diff --git a/src/main/kotlin/com/lambda/interaction/request/DebugLogger.kt b/src/main/kotlin/com/lambda/interaction/request/DebugLogger.kt index f7d79d144..331d92207 100644 --- a/src/main/kotlin/com/lambda/interaction/request/DebugLogger.kt +++ b/src/main/kotlin/com/lambda/interaction/request/DebugLogger.kt @@ -21,10 +21,13 @@ import com.lambda.Lambda.mc import com.lambda.gui.LambdaScreen import com.lambda.gui.dsl.ImGuiBuilder import com.lambda.module.hud.ManagerDebugLoggers.maxLogEntries +import com.lambda.util.math.a import imgui.ImGui +import imgui.flag.ImGuiCol import imgui.flag.ImGuiWindowFlags import imgui.type.ImBoolean import imgui.type.ImFloat +import net.minecraft.util.math.BlockPos import java.awt.Color import java.util.* @@ -42,18 +45,18 @@ class DebugLogger( val logs = LinkedList() - private fun log(message: String, logColor: LogType) { - logs.add(LogEntry(message, logColor)) - if (logs.size > maxLogEntries) { + private fun log(message: String, logColor: LogType, vararg extraContext: String?) { + if (logs.size + 1 > maxLogEntries) { logs.removeFirst() } + logs.add(LogEntry(message, logColor, *extraContext)) } - fun debug(message: String) = log(message, LogType.Debug) - fun success(message: String) = log(message, LogType.Success) - fun warning(message: String) = log(message, LogType.Warning) - fun error(message: String) = log(message, LogType.Error) - fun system(message: String) = log(message, LogType.System) + fun debug(message: String, vararg extraContext: String?) = log(message, LogType.Debug, *extraContext) + fun success(message: String, vararg extraContext: String?) = log(message, LogType.Success, *extraContext) + fun warning(message: String, vararg extraContext: String?) = log(message, LogType.Warning, *extraContext) + fun error(message: String, vararg extraContext: String?) = log(message, LogType.Error, *extraContext) + fun system(message: String, vararg extraContext: String?) = log(message, LogType.System, *extraContext) fun ImGuiBuilder.buildLayout() { ImGui.setNextWindowSizeConstraints(300f, 400f, windowViewport.workSizeX, windowViewport.workSizeY) @@ -80,16 +83,30 @@ class DebugLogger( logs.forEach { logEntry -> if (shouldDisplay(logEntry)) { - when (val type = logEntry.type) { - LogType.Debug -> textColored("[DEBUG]", type.color) - LogType.Success -> textColored("[SUCCESS]", type.color) - LogType.Warning -> textColored("[WARNING]", type.color) - LogType.Error -> textColored("[ERROR]", type.color) - LogType.System -> textColored("[SYSTEM]", type.color) + val type = logEntry.type + val (logTypeStr, color) = when (type) { + LogType.Debug -> Pair("[DEBUG]", type.color) + LogType.Success -> Pair("[SUCCESS]", type.color) + LogType.Warning -> Pair("[WARNING]", type.color) + LogType.Error -> Pair("[ERROR]", type.color) + LogType.System -> Pair("[SYSTEM]", type.color) } - sameLine() - textColored(logEntry.message, logEntry.type.color) + val floats = floatArrayOf(0f, 0f, 0f) + val (r, g, b) = color.getColorComponents(floats) + ImGui.pushStyleColor(ImGuiCol.Text, r, g, b, color.a.toFloat()) + if (logEntry.type == LogType.System) { + text("$logTypeStr ${logEntry.message}") + } else { + treeNode("$logTypeStr ${logEntry.message}", logEntry.uuid) { + logEntry.extraContext + .filterNotNull() + .forEach { + text(it) + } + } + } + ImGui.popStyleColor() } } @@ -113,16 +130,25 @@ class DebugLogger( fun clear() = logs.clear() - data class LogEntry( + class LogEntry( val message: String, - val type: LogType - ) + val type: LogType, + vararg val extraContext: String? + ) { + val uuid = UUID.randomUUID().toString() + companion object { + fun BlockPos.toLogContext(): String { + val pos = if (this is BlockPos.Mutable) toImmutable() else this + return "Pos: ${pos.toShortString()}" + } + } + } enum class LogType(val color: Color) { - Debug(Color(255, 255, 255)), - Success(Color(70, 255, 70)), - Warning(Color(255, 255, 70)), - Error(Color(255, 70, 70)), - System(Color(70, 70, 255)) + Debug(Color(1.0f, 1.0f, 1.0f, 1f)), + Success(Color(0.28f, 1.0f, 0.28f, 1f)), + Warning(Color(1.0f, 1.0f, 0.28f, 1f)), + Error(Color(1.0f, 0.28f, 0.28f, 1f)), + System(Color(0.28f, 0.28f, 1.0f, 1f)) } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/interaction/request/LogContext.kt b/src/main/kotlin/com/lambda/interaction/request/LogContext.kt new file mode 100644 index 000000000..8c6f6efe0 --- /dev/null +++ b/src/main/kotlin/com/lambda/interaction/request/LogContext.kt @@ -0,0 +1,61 @@ +/* + * Copyright 2025 Lambda + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.lambda.interaction.request + +interface LogContext { + fun toLogContext(): String + + companion object { + @DslMarker + private annotation class LogContextDsl + + @LogContextDsl + fun buildLogContext(builder: LogContextBuilder.() -> Unit): String = + LogContextBuilder().apply(builder).build() + + private fun LogContextBuilder.build() = logContext + + class LogContextBuilder { + var logContext = "" + + private var tabs = 0 + + @LogContextDsl + fun sameLine() = + logContext.replace("\n", " ") + + @LogContextDsl + fun text(text: String) { + repeat(tabs) { + logContext += "\t" + } + logContext += "$text\n" + } + + @LogContextDsl + fun pushTab() { + tabs++ + } + + @LogContextDsl + fun popTab() { + tabs-- + } + } + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/interaction/request/ManagerUtils.kt b/src/main/kotlin/com/lambda/interaction/request/ManagerUtils.kt index 552b1ebd2..a66048e28 100644 --- a/src/main/kotlin/com/lambda/interaction/request/ManagerUtils.kt +++ b/src/main/kotlin/com/lambda/interaction/request/ManagerUtils.kt @@ -30,7 +30,9 @@ object ManagerUtils { system("------------- New Tick -------------") fun DebugLogger.newStage(tickStage: Event?) = - system("Tick stage ${tickStage?.run { this::class.qualifiedName }}") + system("Tick stage ${tickStage?.run { this.toLogContext() }}") + + fun Event.toLogContext() = this::class.qualifiedName?.substringAfter("com.lambda.event.events.") fun isPosBlocked(pos: BlockPos) = positionBlockingManagers.any { manager -> manager.blockedPositions.any { blocked -> blocked == pos } } diff --git a/src/main/kotlin/com/lambda/interaction/request/breaking/BreakManager.kt b/src/main/kotlin/com/lambda/interaction/request/breaking/BreakManager.kt index 38e8b1477..7c78de51c 100644 --- a/src/main/kotlin/com/lambda/interaction/request/breaking/BreakManager.kt +++ b/src/main/kotlin/com/lambda/interaction/request/breaking/BreakManager.kt @@ -465,7 +465,7 @@ object BreakManager : RequestHandler( } logger.debug("Submitting request for hotbar index ${info.context.hotbarIndex} with min swap ticks $minSwapTicks (${hotbarRequest.requestID})") if (!hotbarRequest.done) { - logger.warning("hotbar request failed (${hotbarRequest.requestID})") + logger.warning("Hotbar request failed (${hotbarRequest.requestID})") return false } if (minSwapTicks > 0) { diff --git a/src/main/kotlin/com/lambda/interaction/request/hotbar/HotbarManager.kt b/src/main/kotlin/com/lambda/interaction/request/hotbar/HotbarManager.kt index 2bc0db084..715684da1 100644 --- a/src/main/kotlin/com/lambda/interaction/request/hotbar/HotbarManager.kt +++ b/src/main/kotlin/com/lambda/interaction/request/hotbar/HotbarManager.kt @@ -74,7 +74,7 @@ object HotbarManager : RequestHandler( } override fun SafeContext.handleRequest(request: HotbarRequest) { - logger.debug("Handling request ${request.requestID}") + logger.debug("Handling request:", request.toLogContext()) maxSwapsThisTick = request.swapsPerTick swapDelay = swapDelay.coerceAtMost(request.swapDelay) @@ -86,8 +86,8 @@ object HotbarManager : RequestHandler( } == true if (sameButLonger) activeRequest?.let { current -> - logger.debug("Request is the same as current, but longer or the same keep time") request.swapPauseAge = current.swapPauseAge + logger.debug("Request is the same as current, but longer or the same keep time", request.toLogContext()) } else run swap@{ if (request.slot != activeRequest?.slot) { if (swapsThisTick + 1 > maxSwapsThisTick || swapDelay > 0) return @@ -108,7 +108,7 @@ object HotbarManager : RequestHandler( } activeRequest = request - logger.success("Set active request to ${request.requestID}") + logger.success("Set active request", request.toLogContext()) interaction.syncSelectedSlot() return } @@ -117,7 +117,7 @@ object HotbarManager : RequestHandler( activeRequest?.let { active -> val canStopSwap = swapsThisTick < maxSwapsThisTick if (active.keepTicks <= 0 && tickStage in active.sequenceStageMask && canStopSwap) { - logger.debug("Clearing request and syncing slot") + logger.debug("Clearing request and syncing slot", activeRequest?.toLogContext()) activeRequest = null interaction.syncSelectedSlot() } diff --git a/src/main/kotlin/com/lambda/interaction/request/hotbar/HotbarRequest.kt b/src/main/kotlin/com/lambda/interaction/request/hotbar/HotbarRequest.kt index a5820e074..8cd9a5ae5 100644 --- a/src/main/kotlin/com/lambda/interaction/request/hotbar/HotbarRequest.kt +++ b/src/main/kotlin/com/lambda/interaction/request/hotbar/HotbarRequest.kt @@ -17,6 +17,8 @@ package com.lambda.interaction.request.hotbar +import com.lambda.interaction.request.LogContext +import com.lambda.interaction.request.LogContext.Companion.buildLogContext import com.lambda.interaction.request.Request class HotbarRequest( @@ -24,7 +26,7 @@ class HotbarRequest( override val config: HotbarConfig, override var keepTicks: Int = config.keepTicks, override var swapPause: Int = config.swapPause -) : Request(), HotbarConfig by config { +) : Request(), HotbarConfig by config, LogContext { override val requestID = ++requestCount var activeRequestAge = 0 @@ -40,6 +42,18 @@ class HotbarRequest( override fun submit(queueIfClosed: Boolean) = HotbarManager.request(this, queueIfClosed) + override fun toLogContext() = + buildLogContext { + text("Hotbar Request") + pushTab() + text("Request ID: $requestID") + text("Slot: $slot") + text("Keep Ticks: $keepTicks") + text("Swap Pause: $swapPause") + text("Swap Pause Age: $swapPauseAge") + text("Active Request Age: $activeRequestAge") + } + companion object { var requestCount = 0 } From ee5a026ad0eb2041c9d502d73e301cf293e3067f Mon Sep 17 00:00:00 2001 From: beanbag44 Date: Tue, 9 Sep 2025 00:41:55 +0100 Subject: [PATCH 18/38] compile fixes --- src/main/kotlin/com/lambda/gui/dsl/ImGuiBuilder.kt | 2 ++ .../com/lambda/interaction/request/breaking/BreakManager.kt | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/com/lambda/gui/dsl/ImGuiBuilder.kt b/src/main/kotlin/com/lambda/gui/dsl/ImGuiBuilder.kt index 58b33f3e9..bf4e6fc19 100644 --- a/src/main/kotlin/com/lambda/gui/dsl/ImGuiBuilder.kt +++ b/src/main/kotlin/com/lambda/gui/dsl/ImGuiBuilder.kt @@ -129,6 +129,7 @@ import imgui.ImGui.isMouseClicked import imgui.ImGui.isWindowAppearing import imgui.ImGui.isWindowCollapsed import imgui.ImGui.isWindowHovered +import imgui.ImGui.plotHistogram import imgui.ImGui.popFont import imgui.ImGui.popID import imgui.ImGui.popItemWidth @@ -178,6 +179,7 @@ import net.minecraft.util.math.Vec3d import net.minecraft.util.math.Vec3i import java.awt.Color import kotlin.reflect.KMutableProperty0 +import imgui.ImGui.plotLines typealias ProcedureBlock = ImGuiBuilder.() -> Unit typealias WrappedBlock = ImGuiBuilder.(In) -> Out diff --git a/src/main/kotlin/com/lambda/interaction/request/breaking/BreakManager.kt b/src/main/kotlin/com/lambda/interaction/request/breaking/BreakManager.kt index 50343e3a2..bb3978087 100644 --- a/src/main/kotlin/com/lambda/interaction/request/breaking/BreakManager.kt +++ b/src/main/kotlin/com/lambda/interaction/request/breaking/BreakManager.kt @@ -101,7 +101,7 @@ object BreakManager : RequestHandler( TickEvent.Input.Post, TickEvent.Player.Post, onOpen = { - if (activeInfos.isNotEmpty() || breaks.isNotEmpty() || instantBreaks.isNotEmpty()) + if (activeInfos.isNotEmpty() || breaks.isNotEmpty()) BreakManager.logger.newStage(BreakManager.tickStage) processRequest(activeRequest) simulateAbandoned() @@ -172,7 +172,7 @@ object BreakManager : RequestHandler( super.load() listen(priority = Int.MAX_VALUE) { - if (activeInfos.isEmpty() && breaks.isEmpty() && instantBreaks.isEmpty()) return@listen + if (activeInfos.isEmpty() && breaks.isEmpty()) return@listen logger.newTick() } From a9c13ea723495efc3b462a04012aa4c99d995a32 Mon Sep 17 00:00:00 2001 From: beanbag44 Date: Tue, 9 Sep 2025 01:57:58 +0100 Subject: [PATCH 19/38] empty replace for sameLine calls --- src/main/kotlin/com/lambda/interaction/request/LogContext.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/com/lambda/interaction/request/LogContext.kt b/src/main/kotlin/com/lambda/interaction/request/LogContext.kt index 8c6f6efe0..cb8dc5296 100644 --- a/src/main/kotlin/com/lambda/interaction/request/LogContext.kt +++ b/src/main/kotlin/com/lambda/interaction/request/LogContext.kt @@ -37,7 +37,7 @@ interface LogContext { @LogContextDsl fun sameLine() = - logContext.replace("\n", " ") + logContext.replace("\n", "") @LogContextDsl fun text(text: String) { From e86389e8f5f0e4a02a7476b38e3dab75b52d5277 Mon Sep 17 00:00:00 2001 From: beanbag44 Date: Tue, 9 Sep 2025 01:58:31 +0100 Subject: [PATCH 20/38] BreakRequest toLogContext --- .../request/breaking/BreakRequest.kt | 21 ++++++++++++++++++- .../request/hotbar/HotbarRequest.kt | 2 +- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/com/lambda/interaction/request/breaking/BreakRequest.kt b/src/main/kotlin/com/lambda/interaction/request/breaking/BreakRequest.kt index 0c23c8200..7ae42f58e 100644 --- a/src/main/kotlin/com/lambda/interaction/request/breaking/BreakRequest.kt +++ b/src/main/kotlin/com/lambda/interaction/request/breaking/BreakRequest.kt @@ -21,6 +21,8 @@ import com.lambda.config.groups.BuildConfig import com.lambda.config.groups.InteractionConfig import com.lambda.interaction.construction.context.BreakContext import com.lambda.interaction.construction.context.BuildContext +import com.lambda.interaction.request.LogContext +import com.lambda.interaction.request.LogContext.Companion.buildLogContext import com.lambda.interaction.request.Request import com.lambda.interaction.request.hotbar.HotbarConfig import com.lambda.interaction.request.inventory.InventoryConfig @@ -40,7 +42,7 @@ data class BreakRequest( val rotation: RotationConfig = TaskFlowModule.rotation, val inventory: InventoryConfig = TaskFlowModule.inventory, val interact: InteractionConfig = TaskFlowModule.interaction -) : Request() { +) : Request(), LogContext { override val requestID = ++requestCount override val config = build.breaking @@ -58,6 +60,23 @@ data class BreakRequest( override fun submit(queueIfClosed: Boolean) = BreakManager.request(this, queueIfClosed) + override fun toLogContext() = + buildLogContext { + text("Break Request") + pushTab() + text("Request ID: $requestID") + text("Contexts: ${contexts.size}") + text("Callbacks:") + pushTab() + text("onStart: ${onStart != null}") + text("onUpdate: ${onUpdate != null}") + text("onStop: ${onStop != null}") + text("onCancel: ${onCancel != null}") + text("onItemDrop: ${onItemDrop != null}") + text("onReBreakStart: ${onReBreakStart != null}") + text("onReBreak: ${onReBreak != null}") + } + @DslMarker annotation class BreakRequestBuilder diff --git a/src/main/kotlin/com/lambda/interaction/request/hotbar/HotbarRequest.kt b/src/main/kotlin/com/lambda/interaction/request/hotbar/HotbarRequest.kt index 8cd9a5ae5..e3a7ccb0e 100644 --- a/src/main/kotlin/com/lambda/interaction/request/hotbar/HotbarRequest.kt +++ b/src/main/kotlin/com/lambda/interaction/request/hotbar/HotbarRequest.kt @@ -44,7 +44,7 @@ class HotbarRequest( override fun toLogContext() = buildLogContext { - text("Hotbar Request") + text("Hotbar Request:") pushTab() text("Request ID: $requestID") text("Slot: $slot") From d77d2e19abd9bba4399f4f607046acba28b41e0d Mon Sep 17 00:00:00 2001 From: beanbag44 Date: Tue, 9 Sep 2025 02:00:23 +0100 Subject: [PATCH 21/38] InteractRequest toLogContext --- .../request/interacting/InteractRequest.kt | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/com/lambda/interaction/request/interacting/InteractRequest.kt b/src/main/kotlin/com/lambda/interaction/request/interacting/InteractRequest.kt index d7f612e32..e2ca8c7c7 100644 --- a/src/main/kotlin/com/lambda/interaction/request/interacting/InteractRequest.kt +++ b/src/main/kotlin/com/lambda/interaction/request/interacting/InteractRequest.kt @@ -21,6 +21,8 @@ import com.lambda.Lambda.mc import com.lambda.config.groups.BuildConfig import com.lambda.interaction.construction.context.BuildContext import com.lambda.interaction.construction.context.InteractionContext +import com.lambda.interaction.request.LogContext +import com.lambda.interaction.request.LogContext.Companion.buildLogContext import com.lambda.interaction.request.Request import com.lambda.interaction.request.hotbar.HotbarConfig import com.lambda.interaction.request.rotating.RotationConfig @@ -35,7 +37,7 @@ data class InteractRequest( val build: BuildConfig, val hotbar: HotbarConfig, val rotation: RotationConfig -) : Request(), InteractConfig by config { +) : Request(), InteractConfig by config, LogContext { override val requestID = ++requestCount override val done: Boolean @@ -44,6 +46,14 @@ data class InteractRequest( override fun submit(queueIfClosed: Boolean) = InteractionManager.request(this, queueIfClosed) + override fun toLogContext() = + buildLogContext { + text("Interact Request:") + pushTab() + text("Request ID: $requestID") + text("Contexts: ${contexts.size}") + } + companion object { var requestCount = 0 } From 8f850123a5fd4f82f37cb0bba1b5416d4393b9f1 Mon Sep 17 00:00:00 2001 From: beanbag44 Date: Tue, 9 Sep 2025 02:01:46 +0100 Subject: [PATCH 22/38] InventoryRequest toLogContext --- .../interaction/request/inventory/InventoryRequest.kt | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/com/lambda/interaction/request/inventory/InventoryRequest.kt b/src/main/kotlin/com/lambda/interaction/request/inventory/InventoryRequest.kt index 670f421b7..de21a4e6d 100644 --- a/src/main/kotlin/com/lambda/interaction/request/inventory/InventoryRequest.kt +++ b/src/main/kotlin/com/lambda/interaction/request/inventory/InventoryRequest.kt @@ -17,11 +17,13 @@ package com.lambda.interaction.request.inventory +import com.lambda.interaction.request.LogContext +import com.lambda.interaction.request.LogContext.Companion.buildLogContext import com.lambda.interaction.request.Request class InventoryRequest( override val config: InventoryConfig -) : Request(), InventoryConfig by config { +) : Request(), InventoryConfig by config, LogContext { override val requestID = ++requestCount override val done: Boolean @@ -30,6 +32,13 @@ class InventoryRequest( override fun submit(queueIfClosed: Boolean) = InventoryManager.request(this, queueIfClosed) + override fun toLogContext() = + buildLogContext { + text("Inventory Request:") + pushTab() + text("Request ID: $requestID") + } + companion object { var requestCount = 0 } From 3804abb8f99ba4085fadcc738909fd9cb6d3eaa2 Mon Sep 17 00:00:00 2001 From: beanbag44 Date: Tue, 9 Sep 2025 02:03:29 +0100 Subject: [PATCH 23/38] PlaceRequest toLogContext --- .../interaction/request/placing/PlaceRequest.kt | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/com/lambda/interaction/request/placing/PlaceRequest.kt b/src/main/kotlin/com/lambda/interaction/request/placing/PlaceRequest.kt index e1094c56b..dc30ab3c8 100644 --- a/src/main/kotlin/com/lambda/interaction/request/placing/PlaceRequest.kt +++ b/src/main/kotlin/com/lambda/interaction/request/placing/PlaceRequest.kt @@ -20,6 +20,8 @@ package com.lambda.interaction.request.placing import com.lambda.config.groups.BuildConfig import com.lambda.interaction.construction.context.BuildContext import com.lambda.interaction.construction.context.PlaceContext +import com.lambda.interaction.request.LogContext +import com.lambda.interaction.request.LogContext.Companion.buildLogContext import com.lambda.interaction.request.Request import com.lambda.interaction.request.hotbar.HotbarConfig import com.lambda.interaction.request.rotating.RotationConfig @@ -35,7 +37,7 @@ data class PlaceRequest( val hotbar: HotbarConfig, val rotation: RotationConfig, val onPlace: ((BlockPos) -> Unit)? = null -) : Request(), PlaceConfig by build.placing { +) : Request(), PlaceConfig by build.placing, LogContext { override val requestID = ++requestCount override val config = build.placing @@ -48,6 +50,14 @@ data class PlaceRequest( override fun submit(queueIfClosed: Boolean) = PlaceManager.request(this, queueIfClosed) + override fun toLogContext() = + buildLogContext { + text("PlaceRequest:") + pushTab() + text("Request ID: $requestID") + text("Contexts: ${contexts.size}") + } + companion object { var requestCount = 0 } From 10df72de1baa23fa34c1760691e7fb7079c0a06c Mon Sep 17 00:00:00 2001 From: beanbag44 Date: Tue, 9 Sep 2025 02:06:09 +0100 Subject: [PATCH 24/38] RotationRequest toLogContext --- .../request/rotating/RotationRequest.kt | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/com/lambda/interaction/request/rotating/RotationRequest.kt b/src/main/kotlin/com/lambda/interaction/request/rotating/RotationRequest.kt index 272e202e2..44e6b30c1 100644 --- a/src/main/kotlin/com/lambda/interaction/request/rotating/RotationRequest.kt +++ b/src/main/kotlin/com/lambda/interaction/request/rotating/RotationRequest.kt @@ -17,6 +17,8 @@ package com.lambda.interaction.request.rotating +import com.lambda.interaction.request.LogContext +import com.lambda.interaction.request.LogContext.Companion.buildLogContext import com.lambda.interaction.request.Request import com.lambda.interaction.request.rotating.visibilty.RotationTarget import com.lambda.threading.runSafe @@ -29,7 +31,7 @@ data class RotationRequest( override var keepTicks: Int = config.keepTicks, override var decayTicks: Int = config.decayTicks, val speedMultiplier: Double = 1.0 -) : Request(), RotationConfig by config { +) : Request(), RotationConfig by config, LogContext { override val requestID = ++requestCount var age = 0 @@ -40,6 +42,19 @@ data class RotationRequest( override fun submit(queueIfClosed: Boolean): RotationRequest = RotationManager.request(this, queueIfClosed) + override fun toLogContext() = + buildLogContext { + text("Rotation Request:") + pushTab() + text("Request ID: $requestID") + text("Rotation Mode: $rotationMode") + text("Turn Speed: $turnSpeed") + text("Keep Ticks: $keepTicks") + text("Decay Ticks: $decayTicks") + text("Speed Multiplier: $speedMultiplier") + text("Age: $age") + } + companion object { var requestCount = 0 } From b6299415ae72ea14bf500391164b45d543739682 Mon Sep 17 00:00:00 2001 From: beanbag44 Date: Tue, 9 Sep 2025 02:19:53 +0100 Subject: [PATCH 25/38] BreakInfo and SwapInfo toLogContext --- .../interaction/request/breaking/BreakInfo.kt | 28 ++++++++++++++++++- .../interaction/request/breaking/SwapInfo.kt | 14 +++++++++- 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/com/lambda/interaction/request/breaking/BreakInfo.kt b/src/main/kotlin/com/lambda/interaction/request/breaking/BreakInfo.kt index e6949f225..fd578f7c6 100644 --- a/src/main/kotlin/com/lambda/interaction/request/breaking/BreakInfo.kt +++ b/src/main/kotlin/com/lambda/interaction/request/breaking/BreakInfo.kt @@ -19,6 +19,9 @@ package com.lambda.interaction.request.breaking import com.lambda.interaction.construction.context.BreakContext import com.lambda.interaction.request.ActionInfo +import com.lambda.interaction.request.DebugLogger.LogEntry.Companion.toLogContext +import com.lambda.interaction.request.LogContext +import com.lambda.interaction.request.LogContext.Companion.buildLogContext import com.lambda.interaction.request.breaking.BreakInfo.BreakType.Primary import com.lambda.interaction.request.breaking.BreakInfo.BreakType.Rebreak import com.lambda.interaction.request.breaking.BreakInfo.BreakType.RedundantSecondary @@ -39,7 +42,7 @@ data class BreakInfo( override var context: BreakContext, var type: BreakType, var request: BreakRequest -) : ActionInfo { +) : ActionInfo, LogContext { // Delegates val breakConfig get() = request.build.breaking override val pendingInteractionsList get() = request.pendingInteractions @@ -148,5 +151,28 @@ data class BreakInfo( ) } + override fun toLogContext() = + buildLogContext { + text("Break Info:") + pushTab() + text("Type: $type") + text("Pos: ${context.blockPos.toLogContext()}") + text("Details:") + pushTab() + text("Should Progress: $shouldProgress") + text("Rebreak Potential: $rebreakPotential") + text(swapInfo.toLogContext()) + text("Swap Stack: $swapStack") + text("Updated This Tick: $updatedThisTick") + text("Updated Pre-Processing This Tick: $updatedPreProcessingThisTick") + text("Progressed This Tick: $progressedThisTick") + text("Breaking: $breaking") + text("Abandoned: $abandoned") + text("Breaking Ticks: $breakingTicks") + text("Sounds Cooldown: $soundsCooldown") + text("Vanilla Instant Breakable: $vanillaInstantBreakable") + text("Rebreakable: $rebreakable") + } + override fun toString() = "$type, ${context.cachedState}, ${context.blockPos}" } diff --git a/src/main/kotlin/com/lambda/interaction/request/breaking/SwapInfo.kt b/src/main/kotlin/com/lambda/interaction/request/breaking/SwapInfo.kt index 3c686d47b..887bd83f5 100644 --- a/src/main/kotlin/com/lambda/interaction/request/breaking/SwapInfo.kt +++ b/src/main/kotlin/com/lambda/interaction/request/breaking/SwapInfo.kt @@ -18,6 +18,8 @@ package com.lambda.interaction.request.breaking import com.lambda.Lambda.mc +import com.lambda.interaction.request.LogContext +import com.lambda.interaction.request.LogContext.Companion.buildLogContext import com.lambda.interaction.request.breaking.BreakInfo.BreakType.Primary import com.lambda.interaction.request.breaking.BreakInfo.BreakType.Rebreak import com.lambda.interaction.request.breaking.BreakManager.calcBreakDelta @@ -32,7 +34,7 @@ data class SwapInfo( private val breakConfig: BreakConfig = TaskFlowModule.build.breaking, val swap: Boolean = false, val minKeepTicks: Int = 0, -) { +) : LogContext { val validSwap get() = run { val serverSwapTicks = if (type == Primary || type == Rebreak) breakConfig.serverSwapTicks @@ -41,6 +43,16 @@ data class SwapInfo( (mc.player?.mainHandStack?.heldTicks ?: return false) >= serverSwapTicks } + override fun toLogContext() = + buildLogContext { + text("Swap Info:") + pushTab() + text("Type: $type") + text("Swap: $swap") + text("Min Keep Ticks: $minKeepTicks") + text("Valid Swap: $validSwap") + } + companion object { val EMPTY = SwapInfo(Primary) From ca437faf1c8378a21ff61daf000ec1deb97c8dfe Mon Sep 17 00:00:00 2001 From: beanbag44 Date: Tue, 9 Sep 2025 02:20:59 +0100 Subject: [PATCH 26/38] InteractionInfo toLogContext --- .../interaction/request/interacting/InteractionInfo.kt | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/com/lambda/interaction/request/interacting/InteractionInfo.kt b/src/main/kotlin/com/lambda/interaction/request/interacting/InteractionInfo.kt index da14884a7..38670327c 100644 --- a/src/main/kotlin/com/lambda/interaction/request/interacting/InteractionInfo.kt +++ b/src/main/kotlin/com/lambda/interaction/request/interacting/InteractionInfo.kt @@ -20,9 +20,17 @@ package com.lambda.interaction.request.interacting import com.lambda.interaction.construction.context.BuildContext import com.lambda.interaction.construction.context.InteractionContext import com.lambda.interaction.request.ActionInfo +import com.lambda.interaction.request.LogContext +import com.lambda.interaction.request.LogContext.Companion.buildLogContext data class InteractionInfo( override val context: InteractionContext, override val pendingInteractionsList: MutableCollection, private val config: InteractConfig -) : ActionInfo, InteractConfig by config \ No newline at end of file +) : ActionInfo, InteractConfig by config, LogContext { + override fun toLogContext() = + buildLogContext { + text("Interaction Info:") + pushTab() + } +} \ No newline at end of file From dbdab885fbd750e49824afc6524490ddfed0fbf7 Mon Sep 17 00:00:00 2001 From: beanbag44 Date: Tue, 9 Sep 2025 02:22:22 +0100 Subject: [PATCH 27/38] PlaceInfo toLogContext --- .../lambda/interaction/request/placing/PlaceInfo.kt | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/com/lambda/interaction/request/placing/PlaceInfo.kt b/src/main/kotlin/com/lambda/interaction/request/placing/PlaceInfo.kt index dbb51800e..83d9a667c 100644 --- a/src/main/kotlin/com/lambda/interaction/request/placing/PlaceInfo.kt +++ b/src/main/kotlin/com/lambda/interaction/request/placing/PlaceInfo.kt @@ -20,6 +20,8 @@ package com.lambda.interaction.request.placing import com.lambda.interaction.construction.context.BuildContext import com.lambda.interaction.construction.context.PlaceContext import com.lambda.interaction.request.ActionInfo +import com.lambda.interaction.request.LogContext +import com.lambda.interaction.request.LogContext.Companion.buildLogContext import net.minecraft.util.math.BlockPos data class PlaceInfo( @@ -27,4 +29,13 @@ data class PlaceInfo( override val pendingInteractionsList: MutableCollection, val onPlace: ((BlockPos) -> Unit)?, val placeConfig: PlaceConfig -) : ActionInfo \ No newline at end of file +) : ActionInfo, LogContext { + override fun toLogContext() = + buildLogContext { + text("Place Info:") + pushTab() + text("Callbacks:") + pushTab() + text("onPlace: ${onPlace != null}") + } +} \ No newline at end of file From a5d4eb42a6b08e162f0866177c4e21a3f0b40bf8 Mon Sep 17 00:00:00 2001 From: beanbag44 Date: Tue, 9 Sep 2025 02:41:04 +0100 Subject: [PATCH 28/38] toLogContext for all manager contexts --- .../construction/context/BreakContext.kt | 21 +++++++++++++--- .../context/InteractionContext.kt | 17 ++++++++++++- .../construction/context/PlaceContext.kt | 24 +++++++++++++++---- .../lambda/interaction/request/DebugLogger.kt | 11 +++++++++ .../interaction/request/breaking/BreakInfo.kt | 1 + .../request/interacting/InteractionInfo.kt | 1 + .../interaction/request/placing/PlaceInfo.kt | 1 + 7 files changed, 67 insertions(+), 9 deletions(-) diff --git a/src/main/kotlin/com/lambda/interaction/construction/context/BreakContext.kt b/src/main/kotlin/com/lambda/interaction/construction/context/BreakContext.kt index 4f8b81806..ce9dd7ee9 100644 --- a/src/main/kotlin/com/lambda/interaction/construction/context/BreakContext.kt +++ b/src/main/kotlin/com/lambda/interaction/construction/context/BreakContext.kt @@ -21,10 +21,11 @@ import com.lambda.graphics.renderer.esp.DirectionMask import com.lambda.graphics.renderer.esp.DirectionMask.exclude import com.lambda.graphics.renderer.esp.ShapeBuilder import com.lambda.interaction.material.StackSelection +import com.lambda.interaction.request.DebugLogger.LogEntry.Companion.toLogContext +import com.lambda.interaction.request.LogContext +import com.lambda.interaction.request.LogContext.Companion.buildLogContext import com.lambda.interaction.request.breaking.BreakConfig -import com.lambda.interaction.request.breaking.BreakRequest import com.lambda.interaction.request.hotbar.HotbarManager -import com.lambda.interaction.request.hotbar.HotbarRequest import com.lambda.interaction.request.rotating.RotationRequest import com.lambda.util.BlockUtils.emptyState import net.minecraft.block.BlockState @@ -42,7 +43,7 @@ data class BreakContext( var instantBreak: Boolean, override var cachedState: BlockState, val sortMode: BreakConfig.SortMode -) : BuildContext() { +) : BuildContext(), LogContext { private val baseColor = Color(222, 0, 0, 25) private val sideColor = Color(222, 0, 0, 100) @@ -75,4 +76,18 @@ data class BreakContext( override fun ShapeBuilder.buildRenderer() { box(blockPos, cachedState, baseColor, sideColor, DirectionMask.ALL.exclude(result.side)) } + + override fun toLogContext() = + buildLogContext { + text("Break Context:") + pushTab() + text("Block Pos: ${blockPos.toLogContext()}") + text(result.toLogContext()) + text(rotation.toLogContext()) + text("Hotbar Index: $hotbarIndex") + text("Instant Break: $instantBreak") + text("Cached State: $cachedState") + text("Expected State: $expectedState") + text("Sort Mode: $sortMode") + } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/interaction/construction/context/InteractionContext.kt b/src/main/kotlin/com/lambda/interaction/construction/context/InteractionContext.kt index e61351a32..6ebfc83fb 100644 --- a/src/main/kotlin/com/lambda/interaction/construction/context/InteractionContext.kt +++ b/src/main/kotlin/com/lambda/interaction/construction/context/InteractionContext.kt @@ -19,6 +19,9 @@ package com.lambda.interaction.construction.context import com.lambda.graphics.renderer.esp.DirectionMask.mask import com.lambda.graphics.renderer.esp.ShapeBuilder +import com.lambda.interaction.request.DebugLogger.LogEntry.Companion.toLogContext +import com.lambda.interaction.request.LogContext +import com.lambda.interaction.request.LogContext.Companion.buildLogContext import com.lambda.interaction.request.Request.Companion.submit import com.lambda.interaction.request.hotbar.HotbarManager import com.lambda.interaction.request.hotbar.HotbarRequest @@ -36,7 +39,7 @@ class InteractionContext( override var hotbarIndex: Int, override var cachedState: BlockState, override val expectedState: BlockState, -) : BuildContext() { +) : BuildContext(), LogContext { private val baseColor = Color(35, 254, 79, 25) private val sideColor = Color(35, 254, 79, 100) @@ -68,4 +71,16 @@ class InteractionContext( val validRotation = if (request.rotate) submit(rotation, false).done else true return hotbarRequest.done && validRotation } + + override fun toLogContext() = + buildLogContext { + text("Interaction Context:") + pushTab() + text("Block Pos: ${blockPos.toLogContext()}") + text(result.toLogContext()) + text(rotation.toLogContext()) + text("Hotbar Index: $hotbarIndex") + text("Cached State: $cachedState") + text("Expected State: $expectedState") + } } diff --git a/src/main/kotlin/com/lambda/interaction/construction/context/PlaceContext.kt b/src/main/kotlin/com/lambda/interaction/construction/context/PlaceContext.kt index 76689dab2..d12a78f05 100644 --- a/src/main/kotlin/com/lambda/interaction/construction/context/PlaceContext.kt +++ b/src/main/kotlin/com/lambda/interaction/construction/context/PlaceContext.kt @@ -18,18 +18,17 @@ package com.lambda.interaction.construction.context import com.lambda.Lambda.mc -import com.lambda.context.SafeContext -import com.lambda.graphics.renderer.esp.DirectionMask -import com.lambda.graphics.renderer.esp.DirectionMask.exclude import com.lambda.graphics.renderer.esp.DirectionMask.mask import com.lambda.graphics.renderer.esp.ShapeBuilder +import com.lambda.interaction.request.DebugLogger.LogEntry.Companion.toLogContext +import com.lambda.interaction.request.LogContext +import com.lambda.interaction.request.LogContext.Companion.buildLogContext import com.lambda.interaction.request.Request.Companion.submit import com.lambda.interaction.request.hotbar.HotbarManager import com.lambda.interaction.request.hotbar.HotbarRequest import com.lambda.interaction.request.placing.PlaceRequest import com.lambda.interaction.request.rotating.RotationRequest import com.lambda.util.BlockUtils -import com.lambda.util.BlockUtils.blockState import net.minecraft.block.BlockState import net.minecraft.util.hit.BlockHitResult import net.minecraft.util.math.BlockPos @@ -45,7 +44,7 @@ data class PlaceContext( val sneak: Boolean, val insideBlock: Boolean, val currentDirIsValid: Boolean = false -) : BuildContext() { +) : BuildContext(), LogContext { private val baseColor = Color(35, 188, 254, 25) private val sideColor = Color(35, 188, 254, 100) @@ -83,4 +82,19 @@ data class PlaceContext( } else true return hotbarRequest.done && validRotation } + + override fun toLogContext() = + buildLogContext { + text("Place Context:") + pushTab() + text("Block Pos: ${blockPos.toLogContext()}") + text(result.toLogContext()) + text(rotation.toLogContext()) + text("Hotbar Index: $hotbarIndex") + text("Cached State: $cachedState") + text("Expected State: $expectedState") + text("Sneak: $sneak") + text("Inside Block: $insideBlock") + text("Current Dir Is Invalid: $currentDirIsValid") + } } diff --git a/src/main/kotlin/com/lambda/interaction/request/DebugLogger.kt b/src/main/kotlin/com/lambda/interaction/request/DebugLogger.kt index 331d92207..faf505297 100644 --- a/src/main/kotlin/com/lambda/interaction/request/DebugLogger.kt +++ b/src/main/kotlin/com/lambda/interaction/request/DebugLogger.kt @@ -20,6 +20,7 @@ package com.lambda.interaction.request import com.lambda.Lambda.mc import com.lambda.gui.LambdaScreen import com.lambda.gui.dsl.ImGuiBuilder +import com.lambda.interaction.request.LogContext.Companion.buildLogContext import com.lambda.module.hud.ManagerDebugLoggers.maxLogEntries import com.lambda.util.math.a import imgui.ImGui @@ -27,6 +28,7 @@ import imgui.flag.ImGuiCol import imgui.flag.ImGuiWindowFlags import imgui.type.ImBoolean import imgui.type.ImFloat +import net.minecraft.util.hit.BlockHitResult import net.minecraft.util.math.BlockPos import java.awt.Color import java.util.* @@ -141,6 +143,15 @@ class DebugLogger( val pos = if (this is BlockPos.Mutable) toImmutable() else this return "Pos: ${pos.toShortString()}" } + + fun BlockHitResult.toLogContext() = + buildLogContext { + text("Block Hit Result:") + pushTab() + text("Side: $side") + text("Block Pos: $blockPos") + text("Pos: $pos") + } } } diff --git a/src/main/kotlin/com/lambda/interaction/request/breaking/BreakInfo.kt b/src/main/kotlin/com/lambda/interaction/request/breaking/BreakInfo.kt index fd578f7c6..d5c94f0f7 100644 --- a/src/main/kotlin/com/lambda/interaction/request/breaking/BreakInfo.kt +++ b/src/main/kotlin/com/lambda/interaction/request/breaking/BreakInfo.kt @@ -157,6 +157,7 @@ data class BreakInfo( pushTab() text("Type: $type") text("Pos: ${context.blockPos.toLogContext()}") + text(context.toLogContext()) text("Details:") pushTab() text("Should Progress: $shouldProgress") diff --git a/src/main/kotlin/com/lambda/interaction/request/interacting/InteractionInfo.kt b/src/main/kotlin/com/lambda/interaction/request/interacting/InteractionInfo.kt index 38670327c..76f92b662 100644 --- a/src/main/kotlin/com/lambda/interaction/request/interacting/InteractionInfo.kt +++ b/src/main/kotlin/com/lambda/interaction/request/interacting/InteractionInfo.kt @@ -32,5 +32,6 @@ data class InteractionInfo( buildLogContext { text("Interaction Info:") pushTab() + text(context.toLogContext()) } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/interaction/request/placing/PlaceInfo.kt b/src/main/kotlin/com/lambda/interaction/request/placing/PlaceInfo.kt index 83d9a667c..ba7c6b67a 100644 --- a/src/main/kotlin/com/lambda/interaction/request/placing/PlaceInfo.kt +++ b/src/main/kotlin/com/lambda/interaction/request/placing/PlaceInfo.kt @@ -34,6 +34,7 @@ data class PlaceInfo( buildLogContext { text("Place Info:") pushTab() + text(context.toLogContext()) text("Callbacks:") pushTab() text("onPlace: ${onPlace != null}") From 582f1b3b263366cef3cf65ee7eb10ecde512352e Mon Sep 17 00:00:00 2001 From: beanbag44 Date: Tue, 9 Sep 2025 03:00:21 +0100 Subject: [PATCH 29/38] value builder function --- .../construction/context/BreakContext.kt | 12 ++++---- .../context/InteractionContext.kt | 8 +++--- .../construction/context/PlaceContext.kt | 14 +++++----- .../lambda/interaction/request/DebugLogger.kt | 10 ++++--- .../lambda/interaction/request/LogContext.kt | 8 ++++++ .../interaction/request/breaking/BreakInfo.kt | 28 +++++++++---------- .../request/breaking/BreakRequest.kt | 18 ++++++------ .../interaction/request/breaking/SwapInfo.kt | 8 +++--- .../request/hotbar/HotbarRequest.kt | 12 ++++---- .../request/interacting/InteractRequest.kt | 4 +-- .../request/inventory/InventoryRequest.kt | 2 +- .../interaction/request/placing/PlaceInfo.kt | 2 +- .../request/placing/PlaceRequest.kt | 4 +-- .../request/rotating/RotationRequest.kt | 14 +++++----- 14 files changed, 77 insertions(+), 67 deletions(-) diff --git a/src/main/kotlin/com/lambda/interaction/construction/context/BreakContext.kt b/src/main/kotlin/com/lambda/interaction/construction/context/BreakContext.kt index ce9dd7ee9..980eb74b8 100644 --- a/src/main/kotlin/com/lambda/interaction/construction/context/BreakContext.kt +++ b/src/main/kotlin/com/lambda/interaction/construction/context/BreakContext.kt @@ -81,13 +81,13 @@ data class BreakContext( buildLogContext { text("Break Context:") pushTab() - text("Block Pos: ${blockPos.toLogContext()}") + text(blockPos.toLogContext()) text(result.toLogContext()) text(rotation.toLogContext()) - text("Hotbar Index: $hotbarIndex") - text("Instant Break: $instantBreak") - text("Cached State: $cachedState") - text("Expected State: $expectedState") - text("Sort Mode: $sortMode") + value("Hotbar Index", hotbarIndex) + value("Instant Break", instantBreak) + value("Cached State", cachedState) + value("Expected State", expectedState) + value("Sort Mode", sortMode) } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/interaction/construction/context/InteractionContext.kt b/src/main/kotlin/com/lambda/interaction/construction/context/InteractionContext.kt index 6ebfc83fb..4123b048c 100644 --- a/src/main/kotlin/com/lambda/interaction/construction/context/InteractionContext.kt +++ b/src/main/kotlin/com/lambda/interaction/construction/context/InteractionContext.kt @@ -76,11 +76,11 @@ class InteractionContext( buildLogContext { text("Interaction Context:") pushTab() - text("Block Pos: ${blockPos.toLogContext()}") + text(blockPos.toLogContext()) text(result.toLogContext()) text(rotation.toLogContext()) - text("Hotbar Index: $hotbarIndex") - text("Cached State: $cachedState") - text("Expected State: $expectedState") + value("Hotbar Index", hotbarIndex) + value("Cached State", cachedState) + value("Expected State", expectedState) } } diff --git a/src/main/kotlin/com/lambda/interaction/construction/context/PlaceContext.kt b/src/main/kotlin/com/lambda/interaction/construction/context/PlaceContext.kt index d12a78f05..8027dc35f 100644 --- a/src/main/kotlin/com/lambda/interaction/construction/context/PlaceContext.kt +++ b/src/main/kotlin/com/lambda/interaction/construction/context/PlaceContext.kt @@ -87,14 +87,14 @@ data class PlaceContext( buildLogContext { text("Place Context:") pushTab() - text("Block Pos: ${blockPos.toLogContext()}") + text(blockPos.toLogContext()) text(result.toLogContext()) text(rotation.toLogContext()) - text("Hotbar Index: $hotbarIndex") - text("Cached State: $cachedState") - text("Expected State: $expectedState") - text("Sneak: $sneak") - text("Inside Block: $insideBlock") - text("Current Dir Is Invalid: $currentDirIsValid") + value("Hotbar Index", hotbarIndex) + value("Cached State", cachedState) + value("Expected State", expectedState) + value("Sneak", sneak) + value("Inside Block", insideBlock) + value("Current Dir Is Invalid", currentDirIsValid) } } diff --git a/src/main/kotlin/com/lambda/interaction/request/DebugLogger.kt b/src/main/kotlin/com/lambda/interaction/request/DebugLogger.kt index faf505297..904a2d179 100644 --- a/src/main/kotlin/com/lambda/interaction/request/DebugLogger.kt +++ b/src/main/kotlin/com/lambda/interaction/request/DebugLogger.kt @@ -141,16 +141,18 @@ class DebugLogger( companion object { fun BlockPos.toLogContext(): String { val pos = if (this is BlockPos.Mutable) toImmutable() else this - return "Pos: ${pos.toShortString()}" + return buildLogContext { + value("Block Pos", pos.toShortString()) + } } fun BlockHitResult.toLogContext() = buildLogContext { text("Block Hit Result:") pushTab() - text("Side: $side") - text("Block Pos: $blockPos") - text("Pos: $pos") + value("Side", side) + value("Block Pos", blockPos) + value("Pos", pos) } } } diff --git a/src/main/kotlin/com/lambda/interaction/request/LogContext.kt b/src/main/kotlin/com/lambda/interaction/request/LogContext.kt index cb8dc5296..7a6f66650 100644 --- a/src/main/kotlin/com/lambda/interaction/request/LogContext.kt +++ b/src/main/kotlin/com/lambda/interaction/request/LogContext.kt @@ -47,6 +47,14 @@ interface LogContext { logContext += "$text\n" } + fun value(name: String, value: Any) { + text("$name: $value") + } + + fun value(name: String, value: String) { + text("$name: $value") + } + @LogContextDsl fun pushTab() { tabs++ diff --git a/src/main/kotlin/com/lambda/interaction/request/breaking/BreakInfo.kt b/src/main/kotlin/com/lambda/interaction/request/breaking/BreakInfo.kt index d5c94f0f7..caf1183ff 100644 --- a/src/main/kotlin/com/lambda/interaction/request/breaking/BreakInfo.kt +++ b/src/main/kotlin/com/lambda/interaction/request/breaking/BreakInfo.kt @@ -155,24 +155,24 @@ data class BreakInfo( buildLogContext { text("Break Info:") pushTab() - text("Type: $type") - text("Pos: ${context.blockPos.toLogContext()}") + value("Type", type) + text(context.blockPos.toLogContext()) text(context.toLogContext()) text("Details:") pushTab() - text("Should Progress: $shouldProgress") - text("Rebreak Potential: $rebreakPotential") + value("Should Progress", shouldProgress) + value("Rebreak Potential", rebreakPotential) text(swapInfo.toLogContext()) - text("Swap Stack: $swapStack") - text("Updated This Tick: $updatedThisTick") - text("Updated Pre-Processing This Tick: $updatedPreProcessingThisTick") - text("Progressed This Tick: $progressedThisTick") - text("Breaking: $breaking") - text("Abandoned: $abandoned") - text("Breaking Ticks: $breakingTicks") - text("Sounds Cooldown: $soundsCooldown") - text("Vanilla Instant Breakable: $vanillaInstantBreakable") - text("Rebreakable: $rebreakable") + value("Swap Stack", swapStack) + value("Updated This Tick", updatedThisTick) + value("Updated Pre-Processing This Tick", updatedPreProcessingThisTick) + value("Progressed This Tick", progressedThisTick) + value("Breaking", breaking) + value("Abandoned", abandoned) + value("Breaking Ticks", breakingTicks) + value("Sounds Cooldown", soundsCooldown) + value("Vanilla Instant Breakable", vanillaInstantBreakable) + value("Rebreakable", rebreakable) } override fun toString() = "$type, ${context.cachedState}, ${context.blockPos}" diff --git a/src/main/kotlin/com/lambda/interaction/request/breaking/BreakRequest.kt b/src/main/kotlin/com/lambda/interaction/request/breaking/BreakRequest.kt index 7ae42f58e..f79a3b5f2 100644 --- a/src/main/kotlin/com/lambda/interaction/request/breaking/BreakRequest.kt +++ b/src/main/kotlin/com/lambda/interaction/request/breaking/BreakRequest.kt @@ -64,17 +64,17 @@ data class BreakRequest( buildLogContext { text("Break Request") pushTab() - text("Request ID: $requestID") - text("Contexts: ${contexts.size}") + value("Request ID", requestID) + value("Contexts", contexts.size) text("Callbacks:") pushTab() - text("onStart: ${onStart != null}") - text("onUpdate: ${onUpdate != null}") - text("onStop: ${onStop != null}") - text("onCancel: ${onCancel != null}") - text("onItemDrop: ${onItemDrop != null}") - text("onReBreakStart: ${onReBreakStart != null}") - text("onReBreak: ${onReBreak != null}") + value("onStart", onStart != null) + value("onUpdate", onUpdate != null) + value("onStop", onStop != null) + value("onCancel", onCancel != null) + value("onItemDrop", onItemDrop != null) + value("onReBreakStart", onReBreakStart != null) + value("onReBreak", onReBreak != null) } @DslMarker diff --git a/src/main/kotlin/com/lambda/interaction/request/breaking/SwapInfo.kt b/src/main/kotlin/com/lambda/interaction/request/breaking/SwapInfo.kt index 887bd83f5..bd1a4f009 100644 --- a/src/main/kotlin/com/lambda/interaction/request/breaking/SwapInfo.kt +++ b/src/main/kotlin/com/lambda/interaction/request/breaking/SwapInfo.kt @@ -47,10 +47,10 @@ data class SwapInfo( buildLogContext { text("Swap Info:") pushTab() - text("Type: $type") - text("Swap: $swap") - text("Min Keep Ticks: $minKeepTicks") - text("Valid Swap: $validSwap") + value("Type", type) + value("Swap", swap) + value("Min Keep Ticks", minKeepTicks) + value("Valid Swap", validSwap) } companion object { diff --git a/src/main/kotlin/com/lambda/interaction/request/hotbar/HotbarRequest.kt b/src/main/kotlin/com/lambda/interaction/request/hotbar/HotbarRequest.kt index e3a7ccb0e..e26741165 100644 --- a/src/main/kotlin/com/lambda/interaction/request/hotbar/HotbarRequest.kt +++ b/src/main/kotlin/com/lambda/interaction/request/hotbar/HotbarRequest.kt @@ -46,12 +46,12 @@ class HotbarRequest( buildLogContext { text("Hotbar Request:") pushTab() - text("Request ID: $requestID") - text("Slot: $slot") - text("Keep Ticks: $keepTicks") - text("Swap Pause: $swapPause") - text("Swap Pause Age: $swapPauseAge") - text("Active Request Age: $activeRequestAge") + value("Request ID", requestID) + value("Slot", slot) + value("Keep Ticks", keepTicks) + value("Swap Pause", swapPause) + value("Swap Pause Age", swapPauseAge) + value("Active Request Age", activeRequestAge) } companion object { diff --git a/src/main/kotlin/com/lambda/interaction/request/interacting/InteractRequest.kt b/src/main/kotlin/com/lambda/interaction/request/interacting/InteractRequest.kt index e2ca8c7c7..4319a26c9 100644 --- a/src/main/kotlin/com/lambda/interaction/request/interacting/InteractRequest.kt +++ b/src/main/kotlin/com/lambda/interaction/request/interacting/InteractRequest.kt @@ -50,8 +50,8 @@ data class InteractRequest( buildLogContext { text("Interact Request:") pushTab() - text("Request ID: $requestID") - text("Contexts: ${contexts.size}") + value("Request ID", requestID) + value("Contexts", contexts.size) } companion object { diff --git a/src/main/kotlin/com/lambda/interaction/request/inventory/InventoryRequest.kt b/src/main/kotlin/com/lambda/interaction/request/inventory/InventoryRequest.kt index de21a4e6d..59a2ee38e 100644 --- a/src/main/kotlin/com/lambda/interaction/request/inventory/InventoryRequest.kt +++ b/src/main/kotlin/com/lambda/interaction/request/inventory/InventoryRequest.kt @@ -36,7 +36,7 @@ class InventoryRequest( buildLogContext { text("Inventory Request:") pushTab() - text("Request ID: $requestID") + value("Request ID", requestID) } companion object { diff --git a/src/main/kotlin/com/lambda/interaction/request/placing/PlaceInfo.kt b/src/main/kotlin/com/lambda/interaction/request/placing/PlaceInfo.kt index ba7c6b67a..3edf966ec 100644 --- a/src/main/kotlin/com/lambda/interaction/request/placing/PlaceInfo.kt +++ b/src/main/kotlin/com/lambda/interaction/request/placing/PlaceInfo.kt @@ -37,6 +37,6 @@ data class PlaceInfo( text(context.toLogContext()) text("Callbacks:") pushTab() - text("onPlace: ${onPlace != null}") + value("onPlace", onPlace != null) } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/interaction/request/placing/PlaceRequest.kt b/src/main/kotlin/com/lambda/interaction/request/placing/PlaceRequest.kt index dc30ab3c8..7fd5f4723 100644 --- a/src/main/kotlin/com/lambda/interaction/request/placing/PlaceRequest.kt +++ b/src/main/kotlin/com/lambda/interaction/request/placing/PlaceRequest.kt @@ -54,8 +54,8 @@ data class PlaceRequest( buildLogContext { text("PlaceRequest:") pushTab() - text("Request ID: $requestID") - text("Contexts: ${contexts.size}") + value("Request ID", requestID) + value("Contexts", contexts.size) } companion object { diff --git a/src/main/kotlin/com/lambda/interaction/request/rotating/RotationRequest.kt b/src/main/kotlin/com/lambda/interaction/request/rotating/RotationRequest.kt index 44e6b30c1..fef047257 100644 --- a/src/main/kotlin/com/lambda/interaction/request/rotating/RotationRequest.kt +++ b/src/main/kotlin/com/lambda/interaction/request/rotating/RotationRequest.kt @@ -46,13 +46,13 @@ data class RotationRequest( buildLogContext { text("Rotation Request:") pushTab() - text("Request ID: $requestID") - text("Rotation Mode: $rotationMode") - text("Turn Speed: $turnSpeed") - text("Keep Ticks: $keepTicks") - text("Decay Ticks: $decayTicks") - text("Speed Multiplier: $speedMultiplier") - text("Age: $age") + value("Request ID", requestID) + value("Rotation Mode", rotationMode) + value("Turn Speed", turnSpeed) + value("Keep Ticks", keepTicks) + value("Decay Ticks", decayTicks) + value("Speed Multiplier", speedMultiplier) + value("Age", age) } companion object { From 9a45a506d90b541ed319f6d3dbe003e9af8bcdf8 Mon Sep 17 00:00:00 2001 From: beanbag44 Date: Tue, 9 Sep 2025 03:44:32 +0100 Subject: [PATCH 30/38] group build function --- .../construction/context/BreakContext.kt | 22 +++++----- .../context/InteractionContext.kt | 18 ++++----- .../construction/context/PlaceContext.kt | 24 +++++------ .../lambda/interaction/request/DebugLogger.kt | 17 -------- .../lambda/interaction/request/LogContext.kt | 34 ++++++++++++++-- .../interaction/request/breaking/BreakInfo.kt | 40 +++++++++---------- .../request/breaking/BreakRequest.kt | 26 ++++++------ .../interaction/request/breaking/SwapInfo.kt | 12 +++--- .../request/hotbar/HotbarRequest.kt | 16 ++++---- .../request/interacting/InteractRequest.kt | 8 ++-- .../request/interacting/InteractionInfo.kt | 6 +-- .../request/inventory/InventoryRequest.kt | 6 +-- .../interaction/request/placing/PlaceInfo.kt | 12 +++--- .../request/placing/PlaceRequest.kt | 8 ++-- .../request/rotating/RotationRequest.kt | 18 ++++----- 15 files changed, 137 insertions(+), 130 deletions(-) diff --git a/src/main/kotlin/com/lambda/interaction/construction/context/BreakContext.kt b/src/main/kotlin/com/lambda/interaction/construction/context/BreakContext.kt index 980eb74b8..6bdeb1b23 100644 --- a/src/main/kotlin/com/lambda/interaction/construction/context/BreakContext.kt +++ b/src/main/kotlin/com/lambda/interaction/construction/context/BreakContext.kt @@ -21,9 +21,9 @@ import com.lambda.graphics.renderer.esp.DirectionMask import com.lambda.graphics.renderer.esp.DirectionMask.exclude import com.lambda.graphics.renderer.esp.ShapeBuilder import com.lambda.interaction.material.StackSelection -import com.lambda.interaction.request.DebugLogger.LogEntry.Companion.toLogContext import com.lambda.interaction.request.LogContext import com.lambda.interaction.request.LogContext.Companion.buildLogContext +import com.lambda.interaction.request.LogContext.Companion.toLogContext import com.lambda.interaction.request.breaking.BreakConfig import com.lambda.interaction.request.hotbar.HotbarManager import com.lambda.interaction.request.rotating.RotationRequest @@ -79,15 +79,15 @@ data class BreakContext( override fun toLogContext() = buildLogContext { - text("Break Context:") - pushTab() - text(blockPos.toLogContext()) - text(result.toLogContext()) - text(rotation.toLogContext()) - value("Hotbar Index", hotbarIndex) - value("Instant Break", instantBreak) - value("Cached State", cachedState) - value("Expected State", expectedState) - value("Sort Mode", sortMode) + group("Break Context") { + text(blockPos.toLogContext()) + text(result.toLogContext()) + text(rotation.toLogContext()) + value("Hotbar Index", hotbarIndex) + value("Instant Break", instantBreak) + value("Cached State", cachedState) + value("Expected State", expectedState) + value("Sort Mode", sortMode) + } } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/interaction/construction/context/InteractionContext.kt b/src/main/kotlin/com/lambda/interaction/construction/context/InteractionContext.kt index 4123b048c..a085ea34b 100644 --- a/src/main/kotlin/com/lambda/interaction/construction/context/InteractionContext.kt +++ b/src/main/kotlin/com/lambda/interaction/construction/context/InteractionContext.kt @@ -19,9 +19,9 @@ package com.lambda.interaction.construction.context import com.lambda.graphics.renderer.esp.DirectionMask.mask import com.lambda.graphics.renderer.esp.ShapeBuilder -import com.lambda.interaction.request.DebugLogger.LogEntry.Companion.toLogContext import com.lambda.interaction.request.LogContext import com.lambda.interaction.request.LogContext.Companion.buildLogContext +import com.lambda.interaction.request.LogContext.Companion.toLogContext import com.lambda.interaction.request.Request.Companion.submit import com.lambda.interaction.request.hotbar.HotbarManager import com.lambda.interaction.request.hotbar.HotbarRequest @@ -74,13 +74,13 @@ class InteractionContext( override fun toLogContext() = buildLogContext { - text("Interaction Context:") - pushTab() - text(blockPos.toLogContext()) - text(result.toLogContext()) - text(rotation.toLogContext()) - value("Hotbar Index", hotbarIndex) - value("Cached State", cachedState) - value("Expected State", expectedState) + group("Interaction Context") { + text(blockPos.toLogContext()) + text(result.toLogContext()) + text(rotation.toLogContext()) + value("Hotbar Index", hotbarIndex) + value("Cached State", cachedState) + value("Expected State", expectedState) + } } } diff --git a/src/main/kotlin/com/lambda/interaction/construction/context/PlaceContext.kt b/src/main/kotlin/com/lambda/interaction/construction/context/PlaceContext.kt index 8027dc35f..fcbb049c5 100644 --- a/src/main/kotlin/com/lambda/interaction/construction/context/PlaceContext.kt +++ b/src/main/kotlin/com/lambda/interaction/construction/context/PlaceContext.kt @@ -20,9 +20,9 @@ package com.lambda.interaction.construction.context import com.lambda.Lambda.mc import com.lambda.graphics.renderer.esp.DirectionMask.mask import com.lambda.graphics.renderer.esp.ShapeBuilder -import com.lambda.interaction.request.DebugLogger.LogEntry.Companion.toLogContext import com.lambda.interaction.request.LogContext import com.lambda.interaction.request.LogContext.Companion.buildLogContext +import com.lambda.interaction.request.LogContext.Companion.toLogContext import com.lambda.interaction.request.Request.Companion.submit import com.lambda.interaction.request.hotbar.HotbarManager import com.lambda.interaction.request.hotbar.HotbarRequest @@ -85,16 +85,16 @@ data class PlaceContext( override fun toLogContext() = buildLogContext { - text("Place Context:") - pushTab() - text(blockPos.toLogContext()) - text(result.toLogContext()) - text(rotation.toLogContext()) - value("Hotbar Index", hotbarIndex) - value("Cached State", cachedState) - value("Expected State", expectedState) - value("Sneak", sneak) - value("Inside Block", insideBlock) - value("Current Dir Is Invalid", currentDirIsValid) + group("Place Context") { + text(blockPos.toLogContext()) + text(result.toLogContext()) + text(rotation.toLogContext()) + value("Hotbar Index", hotbarIndex) + value("Cached State", cachedState) + value("Expected State", expectedState) + value("Sneak", sneak) + value("Inside Block", insideBlock) + value("Current Dir Is Invalid", currentDirIsValid) + } } } diff --git a/src/main/kotlin/com/lambda/interaction/request/DebugLogger.kt b/src/main/kotlin/com/lambda/interaction/request/DebugLogger.kt index 904a2d179..17062e81a 100644 --- a/src/main/kotlin/com/lambda/interaction/request/DebugLogger.kt +++ b/src/main/kotlin/com/lambda/interaction/request/DebugLogger.kt @@ -138,23 +138,6 @@ class DebugLogger( vararg val extraContext: String? ) { val uuid = UUID.randomUUID().toString() - companion object { - fun BlockPos.toLogContext(): String { - val pos = if (this is BlockPos.Mutable) toImmutable() else this - return buildLogContext { - value("Block Pos", pos.toShortString()) - } - } - - fun BlockHitResult.toLogContext() = - buildLogContext { - text("Block Hit Result:") - pushTab() - value("Side", side) - value("Block Pos", blockPos) - value("Pos", pos) - } - } } enum class LogType(val color: Color) { diff --git a/src/main/kotlin/com/lambda/interaction/request/LogContext.kt b/src/main/kotlin/com/lambda/interaction/request/LogContext.kt index 7a6f66650..fb11a2328 100644 --- a/src/main/kotlin/com/lambda/interaction/request/LogContext.kt +++ b/src/main/kotlin/com/lambda/interaction/request/LogContext.kt @@ -17,6 +17,9 @@ package com.lambda.interaction.request +import net.minecraft.util.hit.BlockHitResult +import net.minecraft.util.math.BlockPos + interface LogContext { fun toLogContext(): String @@ -24,16 +27,32 @@ interface LogContext { @DslMarker private annotation class LogContextDsl + fun BlockPos.toLogContext(): String { + val pos = if (this is BlockPos.Mutable) toImmutable() else this + return buildLogContext { + value("Block Pos", pos.toShortString()) + } + } + + fun BlockHitResult.toLogContext() = + buildLogContext { + group("Block Hit Result") { + value("Side", side) + value("Block Pos", blockPos) + value("Pos", pos) + } + } + @LogContextDsl - fun buildLogContext(builder: LogContextBuilder.() -> Unit): String = - LogContextBuilder().apply(builder).build() + fun buildLogContext(tabMin: Int = 0, builder: LogContextBuilder.() -> Unit): String = + LogContextBuilder(tabMin).apply(builder).build() private fun LogContextBuilder.build() = logContext - class LogContextBuilder { + class LogContextBuilder(val tabMin: Int = 0) { var logContext = "" - private var tabs = 0 + private var tabs = tabMin @LogContextDsl fun sameLine() = @@ -55,6 +74,12 @@ interface LogContext { text("$name: $value") } + @LogContextDsl + fun group(name: String, builder: LogContextBuilder.() -> Unit) { + text("$name:") + text(LogContextBuilder(tabs + 1).apply(builder).build()) + } + @LogContextDsl fun pushTab() { tabs++ @@ -63,6 +88,7 @@ interface LogContext { @LogContextDsl fun popTab() { tabs-- + if (tabs < tabMin) throw IllegalStateException("Cannot reduce tabs beneath the minimum tab count") } } } diff --git a/src/main/kotlin/com/lambda/interaction/request/breaking/BreakInfo.kt b/src/main/kotlin/com/lambda/interaction/request/breaking/BreakInfo.kt index caf1183ff..b47f00e67 100644 --- a/src/main/kotlin/com/lambda/interaction/request/breaking/BreakInfo.kt +++ b/src/main/kotlin/com/lambda/interaction/request/breaking/BreakInfo.kt @@ -19,7 +19,6 @@ package com.lambda.interaction.request.breaking import com.lambda.interaction.construction.context.BreakContext import com.lambda.interaction.request.ActionInfo -import com.lambda.interaction.request.DebugLogger.LogEntry.Companion.toLogContext import com.lambda.interaction.request.LogContext import com.lambda.interaction.request.LogContext.Companion.buildLogContext import com.lambda.interaction.request.breaking.BreakInfo.BreakType.Primary @@ -153,26 +152,25 @@ data class BreakInfo( override fun toLogContext() = buildLogContext { - text("Break Info:") - pushTab() - value("Type", type) - text(context.blockPos.toLogContext()) - text(context.toLogContext()) - text("Details:") - pushTab() - value("Should Progress", shouldProgress) - value("Rebreak Potential", rebreakPotential) - text(swapInfo.toLogContext()) - value("Swap Stack", swapStack) - value("Updated This Tick", updatedThisTick) - value("Updated Pre-Processing This Tick", updatedPreProcessingThisTick) - value("Progressed This Tick", progressedThisTick) - value("Breaking", breaking) - value("Abandoned", abandoned) - value("Breaking Ticks", breakingTicks) - value("Sounds Cooldown", soundsCooldown) - value("Vanilla Instant Breakable", vanillaInstantBreakable) - value("Rebreakable", rebreakable) + group("Break Info") { + value("Type", type) + text(context.toLogContext()) + group("Details") { + value("Should Progress", shouldProgress) + value("Rebreak Potential", rebreakPotential) + text(swapInfo.toLogContext()) + value("Swap Stack", swapStack) + value("Updated This Tick", updatedThisTick) + value("Updated Pre-Processing This Tick", updatedPreProcessingThisTick) + value("Progressed This Tick", progressedThisTick) + value("Breaking", breaking) + value("Abandoned", abandoned) + value("Breaking Ticks", breakingTicks) + value("Sounds Cooldown", soundsCooldown) + value("Vanilla Instant Breakable", vanillaInstantBreakable) + value("Rebreakable", rebreakable) + } + } } override fun toString() = "$type, ${context.cachedState}, ${context.blockPos}" diff --git a/src/main/kotlin/com/lambda/interaction/request/breaking/BreakRequest.kt b/src/main/kotlin/com/lambda/interaction/request/breaking/BreakRequest.kt index f79a3b5f2..255ef788c 100644 --- a/src/main/kotlin/com/lambda/interaction/request/breaking/BreakRequest.kt +++ b/src/main/kotlin/com/lambda/interaction/request/breaking/BreakRequest.kt @@ -62,19 +62,19 @@ data class BreakRequest( override fun toLogContext() = buildLogContext { - text("Break Request") - pushTab() - value("Request ID", requestID) - value("Contexts", contexts.size) - text("Callbacks:") - pushTab() - value("onStart", onStart != null) - value("onUpdate", onUpdate != null) - value("onStop", onStop != null) - value("onCancel", onCancel != null) - value("onItemDrop", onItemDrop != null) - value("onReBreakStart", onReBreakStart != null) - value("onReBreak", onReBreak != null) + group("Break Request") { + value("Request ID", requestID) + value("Contexts", contexts.size) + group("Callbacks") { + value("onStart", onStart != null) + value("onUpdate", onUpdate != null) + value("onStop", onStop != null) + value("onCancel", onCancel != null) + value("onItemDrop", onItemDrop != null) + value("onReBreakStart", onReBreakStart != null) + value("onReBreak", onReBreak != null) + } + } } @DslMarker diff --git a/src/main/kotlin/com/lambda/interaction/request/breaking/SwapInfo.kt b/src/main/kotlin/com/lambda/interaction/request/breaking/SwapInfo.kt index bd1a4f009..57f02512b 100644 --- a/src/main/kotlin/com/lambda/interaction/request/breaking/SwapInfo.kt +++ b/src/main/kotlin/com/lambda/interaction/request/breaking/SwapInfo.kt @@ -45,12 +45,12 @@ data class SwapInfo( override fun toLogContext() = buildLogContext { - text("Swap Info:") - pushTab() - value("Type", type) - value("Swap", swap) - value("Min Keep Ticks", minKeepTicks) - value("Valid Swap", validSwap) + group("Swap Info") { + value("Type", type) + value("Swap", swap) + value("Min Keep Ticks", minKeepTicks) + value("Valid Swap", validSwap) + } } companion object { diff --git a/src/main/kotlin/com/lambda/interaction/request/hotbar/HotbarRequest.kt b/src/main/kotlin/com/lambda/interaction/request/hotbar/HotbarRequest.kt index e26741165..9d2c4c31d 100644 --- a/src/main/kotlin/com/lambda/interaction/request/hotbar/HotbarRequest.kt +++ b/src/main/kotlin/com/lambda/interaction/request/hotbar/HotbarRequest.kt @@ -44,14 +44,14 @@ class HotbarRequest( override fun toLogContext() = buildLogContext { - text("Hotbar Request:") - pushTab() - value("Request ID", requestID) - value("Slot", slot) - value("Keep Ticks", keepTicks) - value("Swap Pause", swapPause) - value("Swap Pause Age", swapPauseAge) - value("Active Request Age", activeRequestAge) + group("Hotbar Request") { + value("Request ID", requestID) + value("Slot", slot) + value("Keep Ticks", keepTicks) + value("Swap Pause", swapPause) + value("Swap Pause Age", swapPauseAge) + value("Active Request Age", activeRequestAge) + } } companion object { diff --git a/src/main/kotlin/com/lambda/interaction/request/interacting/InteractRequest.kt b/src/main/kotlin/com/lambda/interaction/request/interacting/InteractRequest.kt index 4319a26c9..06bc1b448 100644 --- a/src/main/kotlin/com/lambda/interaction/request/interacting/InteractRequest.kt +++ b/src/main/kotlin/com/lambda/interaction/request/interacting/InteractRequest.kt @@ -48,10 +48,10 @@ data class InteractRequest( override fun toLogContext() = buildLogContext { - text("Interact Request:") - pushTab() - value("Request ID", requestID) - value("Contexts", contexts.size) + group("Interact Request") { + value("Request ID", requestID) + value("Contexts", contexts.size) + } } companion object { diff --git a/src/main/kotlin/com/lambda/interaction/request/interacting/InteractionInfo.kt b/src/main/kotlin/com/lambda/interaction/request/interacting/InteractionInfo.kt index 76f92b662..56fd3ba7f 100644 --- a/src/main/kotlin/com/lambda/interaction/request/interacting/InteractionInfo.kt +++ b/src/main/kotlin/com/lambda/interaction/request/interacting/InteractionInfo.kt @@ -30,8 +30,8 @@ data class InteractionInfo( ) : ActionInfo, InteractConfig by config, LogContext { override fun toLogContext() = buildLogContext { - text("Interaction Info:") - pushTab() - text(context.toLogContext()) + group("Interaction Info") { + text(context.toLogContext()) + } } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/interaction/request/inventory/InventoryRequest.kt b/src/main/kotlin/com/lambda/interaction/request/inventory/InventoryRequest.kt index 59a2ee38e..8c38b8782 100644 --- a/src/main/kotlin/com/lambda/interaction/request/inventory/InventoryRequest.kt +++ b/src/main/kotlin/com/lambda/interaction/request/inventory/InventoryRequest.kt @@ -34,9 +34,9 @@ class InventoryRequest( override fun toLogContext() = buildLogContext { - text("Inventory Request:") - pushTab() - value("Request ID", requestID) + group("Inventory Request") { + value("Request ID", requestID) + } } companion object { diff --git a/src/main/kotlin/com/lambda/interaction/request/placing/PlaceInfo.kt b/src/main/kotlin/com/lambda/interaction/request/placing/PlaceInfo.kt index 3edf966ec..c826b27cf 100644 --- a/src/main/kotlin/com/lambda/interaction/request/placing/PlaceInfo.kt +++ b/src/main/kotlin/com/lambda/interaction/request/placing/PlaceInfo.kt @@ -32,11 +32,11 @@ data class PlaceInfo( ) : ActionInfo, LogContext { override fun toLogContext() = buildLogContext { - text("Place Info:") - pushTab() - text(context.toLogContext()) - text("Callbacks:") - pushTab() - value("onPlace", onPlace != null) + group("Place Info") { + text(context.toLogContext()) + group("Callbacks") { + value("onPlace", onPlace != null) + } + } } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/interaction/request/placing/PlaceRequest.kt b/src/main/kotlin/com/lambda/interaction/request/placing/PlaceRequest.kt index 7fd5f4723..af497a07e 100644 --- a/src/main/kotlin/com/lambda/interaction/request/placing/PlaceRequest.kt +++ b/src/main/kotlin/com/lambda/interaction/request/placing/PlaceRequest.kt @@ -52,10 +52,10 @@ data class PlaceRequest( override fun toLogContext() = buildLogContext { - text("PlaceRequest:") - pushTab() - value("Request ID", requestID) - value("Contexts", contexts.size) + group("PlaceRequest") { + value("Request ID", requestID) + value("Contexts", contexts.size) + } } companion object { diff --git a/src/main/kotlin/com/lambda/interaction/request/rotating/RotationRequest.kt b/src/main/kotlin/com/lambda/interaction/request/rotating/RotationRequest.kt index fef047257..89240c490 100644 --- a/src/main/kotlin/com/lambda/interaction/request/rotating/RotationRequest.kt +++ b/src/main/kotlin/com/lambda/interaction/request/rotating/RotationRequest.kt @@ -44,15 +44,15 @@ data class RotationRequest( override fun toLogContext() = buildLogContext { - text("Rotation Request:") - pushTab() - value("Request ID", requestID) - value("Rotation Mode", rotationMode) - value("Turn Speed", turnSpeed) - value("Keep Ticks", keepTicks) - value("Decay Ticks", decayTicks) - value("Speed Multiplier", speedMultiplier) - value("Age", age) + group("Rotation Request") { + value("Request ID", requestID) + value("Rotation Mode", rotationMode) + value("Turn Speed", turnSpeed) + value("Keep Ticks", keepTicks) + value("Decay Ticks", decayTicks) + value("Speed Multiplier", speedMultiplier) + value("Age", age) + } } companion object { From 42eef99f59846c9076e18e8b0e0783dd8e2b751a Mon Sep 17 00:00:00 2001 From: beanbag44 Date: Tue, 9 Sep 2025 17:36:46 +0100 Subject: [PATCH 31/38] annotation correction --- src/main/kotlin/com/lambda/interaction/request/LogContext.kt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/kotlin/com/lambda/interaction/request/LogContext.kt b/src/main/kotlin/com/lambda/interaction/request/LogContext.kt index fb11a2328..2627bd38f 100644 --- a/src/main/kotlin/com/lambda/interaction/request/LogContext.kt +++ b/src/main/kotlin/com/lambda/interaction/request/LogContext.kt @@ -66,10 +66,12 @@ interface LogContext { logContext += "$text\n" } + @LogContextDsl fun value(name: String, value: Any) { text("$name: $value") } + @LogContextDsl fun value(name: String, value: String) { text("$name: $value") } From aa6966c32fdbb128455d2dee9283843e849304cf Mon Sep 17 00:00:00 2001 From: beanbag44 Date: Wed, 10 Sep 2025 02:21:05 +0100 Subject: [PATCH 32/38] better break manager logs and fancy styling --- .../construction/context/BreakContext.kt | 27 ++++++------ .../context/InteractionContext.kt | 23 +++++------ .../construction/context/PlaceContext.kt | 31 +++++++------- .../lambda/interaction/request/DebugLogger.kt | 33 ++++++++++----- .../lambda/interaction/request/LogContext.kt | 32 ++++++++------- .../interaction/request/breaking/BreakInfo.kt | 41 +++++++++---------- .../request/breaking/BreakManager.kt | 40 +++++++++--------- .../request/breaking/BreakRequest.kt | 29 +++++++------ .../interaction/request/breaking/SwapInfo.kt | 17 ++++---- .../request/hotbar/HotbarManager.kt | 8 ++-- .../request/hotbar/HotbarRequest.kt | 21 +++++----- .../request/interacting/InteractRequest.kt | 13 +++--- .../request/interacting/InteractionInfo.kt | 11 +++-- .../request/inventory/InventoryRequest.kt | 11 +++-- .../interaction/request/placing/PlaceInfo.kt | 15 ++++--- .../request/placing/PlaceRequest.kt | 13 +++--- .../request/rotating/RotationRequest.kt | 23 +++++------ 17 files changed, 195 insertions(+), 193 deletions(-) diff --git a/src/main/kotlin/com/lambda/interaction/construction/context/BreakContext.kt b/src/main/kotlin/com/lambda/interaction/construction/context/BreakContext.kt index 6bdeb1b23..7c4e32e2f 100644 --- a/src/main/kotlin/com/lambda/interaction/construction/context/BreakContext.kt +++ b/src/main/kotlin/com/lambda/interaction/construction/context/BreakContext.kt @@ -22,8 +22,8 @@ import com.lambda.graphics.renderer.esp.DirectionMask.exclude import com.lambda.graphics.renderer.esp.ShapeBuilder import com.lambda.interaction.material.StackSelection import com.lambda.interaction.request.LogContext -import com.lambda.interaction.request.LogContext.Companion.buildLogContext -import com.lambda.interaction.request.LogContext.Companion.toLogContext +import com.lambda.interaction.request.LogContext.Companion.LogContextBuilder +import com.lambda.interaction.request.LogContext.Companion.getLogContextBuilder import com.lambda.interaction.request.breaking.BreakConfig import com.lambda.interaction.request.hotbar.HotbarManager import com.lambda.interaction.request.rotating.RotationRequest @@ -77,17 +77,16 @@ data class BreakContext( box(blockPos, cachedState, baseColor, sideColor, DirectionMask.ALL.exclude(result.side)) } - override fun toLogContext() = - buildLogContext { - group("Break Context") { - text(blockPos.toLogContext()) - text(result.toLogContext()) - text(rotation.toLogContext()) - value("Hotbar Index", hotbarIndex) - value("Instant Break", instantBreak) - value("Cached State", cachedState) - value("Expected State", expectedState) - value("Sort Mode", sortMode) - } + override fun getLogContextBuilder(): LogContextBuilder.() -> Unit = { + group("Break Context") { + text(blockPos.getLogContextBuilder()) + text(result.getLogContextBuilder()) + text(rotation.getLogContextBuilder()) + value("Hotbar Index", hotbarIndex) + value("Instant Break", instantBreak) + value("Cached State", cachedState) + value("Expected State", expectedState) + value("Sort Mode", sortMode) } + } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/interaction/construction/context/InteractionContext.kt b/src/main/kotlin/com/lambda/interaction/construction/context/InteractionContext.kt index a085ea34b..cce1f76a3 100644 --- a/src/main/kotlin/com/lambda/interaction/construction/context/InteractionContext.kt +++ b/src/main/kotlin/com/lambda/interaction/construction/context/InteractionContext.kt @@ -20,8 +20,8 @@ package com.lambda.interaction.construction.context import com.lambda.graphics.renderer.esp.DirectionMask.mask import com.lambda.graphics.renderer.esp.ShapeBuilder import com.lambda.interaction.request.LogContext -import com.lambda.interaction.request.LogContext.Companion.buildLogContext -import com.lambda.interaction.request.LogContext.Companion.toLogContext +import com.lambda.interaction.request.LogContext.Companion.LogContextBuilder +import com.lambda.interaction.request.LogContext.Companion.getLogContextBuilder import com.lambda.interaction.request.Request.Companion.submit import com.lambda.interaction.request.hotbar.HotbarManager import com.lambda.interaction.request.hotbar.HotbarRequest @@ -72,15 +72,14 @@ class InteractionContext( return hotbarRequest.done && validRotation } - override fun toLogContext() = - buildLogContext { - group("Interaction Context") { - text(blockPos.toLogContext()) - text(result.toLogContext()) - text(rotation.toLogContext()) - value("Hotbar Index", hotbarIndex) - value("Cached State", cachedState) - value("Expected State", expectedState) - } + override fun getLogContextBuilder(): LogContextBuilder.() -> Unit = { + group("Interaction Context") { + text(blockPos.getLogContextBuilder()) + text(result.getLogContextBuilder()) + text(rotation.getLogContextBuilder()) + value("Hotbar Index", hotbarIndex) + value("Cached State", cachedState) + value("Expected State", expectedState) } + } } diff --git a/src/main/kotlin/com/lambda/interaction/construction/context/PlaceContext.kt b/src/main/kotlin/com/lambda/interaction/construction/context/PlaceContext.kt index fcbb049c5..93a2bc185 100644 --- a/src/main/kotlin/com/lambda/interaction/construction/context/PlaceContext.kt +++ b/src/main/kotlin/com/lambda/interaction/construction/context/PlaceContext.kt @@ -21,8 +21,8 @@ import com.lambda.Lambda.mc import com.lambda.graphics.renderer.esp.DirectionMask.mask import com.lambda.graphics.renderer.esp.ShapeBuilder import com.lambda.interaction.request.LogContext -import com.lambda.interaction.request.LogContext.Companion.buildLogContext -import com.lambda.interaction.request.LogContext.Companion.toLogContext +import com.lambda.interaction.request.LogContext.Companion.LogContextBuilder +import com.lambda.interaction.request.LogContext.Companion.getLogContextBuilder import com.lambda.interaction.request.Request.Companion.submit import com.lambda.interaction.request.hotbar.HotbarManager import com.lambda.interaction.request.hotbar.HotbarRequest @@ -83,18 +83,17 @@ data class PlaceContext( return hotbarRequest.done && validRotation } - override fun toLogContext() = - buildLogContext { - group("Place Context") { - text(blockPos.toLogContext()) - text(result.toLogContext()) - text(rotation.toLogContext()) - value("Hotbar Index", hotbarIndex) - value("Cached State", cachedState) - value("Expected State", expectedState) - value("Sneak", sneak) - value("Inside Block", insideBlock) - value("Current Dir Is Invalid", currentDirIsValid) - } + override fun getLogContextBuilder(): LogContextBuilder.() -> Unit = { + group("Place Context") { + text(blockPos.getLogContextBuilder()) + text(result.getLogContextBuilder()) + text(rotation.getLogContextBuilder()) + value("Hotbar Index", hotbarIndex) + value("Cached State", cachedState) + value("Expected State", expectedState) + value("Sneak", sneak) + value("Inside Block", insideBlock) + value("Current Dir Is Invalid", currentDirIsValid) } -} + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/interaction/request/DebugLogger.kt b/src/main/kotlin/com/lambda/interaction/request/DebugLogger.kt index 17062e81a..a9d47c4d0 100644 --- a/src/main/kotlin/com/lambda/interaction/request/DebugLogger.kt +++ b/src/main/kotlin/com/lambda/interaction/request/DebugLogger.kt @@ -28,8 +28,6 @@ import imgui.flag.ImGuiCol import imgui.flag.ImGuiWindowFlags import imgui.type.ImBoolean import imgui.type.ImFloat -import net.minecraft.util.hit.BlockHitResult -import net.minecraft.util.math.BlockPos import java.awt.Color import java.util.* @@ -47,18 +45,33 @@ class DebugLogger( val logs = LinkedList() - private fun log(message: String, logColor: LogType, vararg extraContext: String?) { + private fun log(message: String, logColor: LogType, extraContext: List) { if (logs.size + 1 > maxLogEntries) { logs.removeFirst() } - logs.add(LogEntry(message, logColor, *extraContext)) + logs.add(LogEntry(message, logColor, extraContext.filterNotNull())) } - fun debug(message: String, vararg extraContext: String?) = log(message, LogType.Debug, *extraContext) - fun success(message: String, vararg extraContext: String?) = log(message, LogType.Success, *extraContext) - fun warning(message: String, vararg extraContext: String?) = log(message, LogType.Warning, *extraContext) - fun error(message: String, vararg extraContext: String?) = log(message, LogType.Error, *extraContext) - fun system(message: String, vararg extraContext: String?) = log(message, LogType.System, *extraContext) + fun debug(message: String) = log(message, LogType.Debug, emptyList()) + fun debug(message: String, vararg extraContext: String?) = log(message, LogType.Debug, extraContext.toList()) + fun debug(message: String, vararg extraContext: LogContext?) = + log(message, LogType.Debug, extraContext.filterNotNull().map { buildLogContext(builder = it.getLogContextBuilder()) }) + fun success(message: String) = log(message, LogType.Success, emptyList()) + fun success(message: String, vararg extraContext: String?) = log(message, LogType.Success, extraContext.toList()) + fun success(message: String, vararg extraContext: LogContext?) = + log(message, LogType.Success, extraContext.filterNotNull().map { buildLogContext(builder = it.getLogContextBuilder()) }) + fun warning(message: String) = log(message, LogType.Warning, emptyList()) + fun warning(message: String, vararg extraContext: String?) = log(message, LogType.Warning, extraContext.toList()) + fun warning(message: String, vararg extraContext: LogContext?) = + log(message, LogType.Warning, extraContext.filterNotNull().map { buildLogContext(builder = it.getLogContextBuilder()) }) + fun error(message: String) = log(message, LogType.Error, emptyList()) + fun error(message: String, vararg extraContext: String?) = log(message, LogType.Error, extraContext.toList()) + fun error(message: String, vararg extraContext: LogContext?) = + log(message, LogType.Error, extraContext.filterNotNull().map { buildLogContext(builder = it.getLogContextBuilder()) }) + fun system(message: String) = log(message, LogType.System, emptyList()) + fun system(message: String, vararg extraContext: String?) = log(message, LogType.System, extraContext.toList()) + fun system(message: String, vararg extraContext: LogContext?) = + log(message, LogType.System, extraContext.filterNotNull().map { buildLogContext(builder = it.getLogContextBuilder()) }) fun ImGuiBuilder.buildLayout() { ImGui.setNextWindowSizeConstraints(300f, 400f, windowViewport.workSizeX, windowViewport.workSizeY) @@ -135,7 +148,7 @@ class DebugLogger( class LogEntry( val message: String, val type: LogType, - vararg val extraContext: String? + val extraContext: Collection ) { val uuid = UUID.randomUUID().toString() } diff --git a/src/main/kotlin/com/lambda/interaction/request/LogContext.kt b/src/main/kotlin/com/lambda/interaction/request/LogContext.kt index 2627bd38f..ba65c2ccf 100644 --- a/src/main/kotlin/com/lambda/interaction/request/LogContext.kt +++ b/src/main/kotlin/com/lambda/interaction/request/LogContext.kt @@ -21,27 +21,24 @@ import net.minecraft.util.hit.BlockHitResult import net.minecraft.util.math.BlockPos interface LogContext { - fun toLogContext(): String + fun getLogContextBuilder(): LogContextBuilder.() -> Unit companion object { @DslMarker private annotation class LogContextDsl - fun BlockPos.toLogContext(): String { + fun BlockPos.getLogContextBuilder(): LogContextBuilder.() -> Unit { val pos = if (this is BlockPos.Mutable) toImmutable() else this - return buildLogContext { - value("Block Pos", pos.toShortString()) - } + return { value("Block Pos", pos.toShortString()) } } - fun BlockHitResult.toLogContext() = - buildLogContext { - group("Block Hit Result") { - value("Side", side) - value("Block Pos", blockPos) - value("Pos", pos) - } + fun BlockHitResult.getLogContextBuilder(): LogContextBuilder.() -> Unit = { + group("Block Hit Result") { + value("Side", side) + value("Block Pos", blockPos) + value("Pos", pos) } + } @LogContextDsl fun buildLogContext(tabMin: Int = 0, builder: LogContextBuilder.() -> Unit): String = @@ -61,11 +58,15 @@ interface LogContext { @LogContextDsl fun text(text: String) { repeat(tabs) { - logContext += "\t" + logContext += "----" } logContext += "$text\n" } + fun text(builder: LogContextBuilder.() -> Unit) { + logContext += LogContextBuilder(tabs).apply(builder).build() + } + @LogContextDsl fun value(name: String, value: Any) { text("$name: $value") @@ -78,8 +79,9 @@ interface LogContext { @LogContextDsl fun group(name: String, builder: LogContextBuilder.() -> Unit) { - text("$name:") - text(LogContextBuilder(tabs + 1).apply(builder).build()) + text("$name {") + logContext += LogContextBuilder(tabs + 1).apply(builder).build() + text("}") } @LogContextDsl diff --git a/src/main/kotlin/com/lambda/interaction/request/breaking/BreakInfo.kt b/src/main/kotlin/com/lambda/interaction/request/breaking/BreakInfo.kt index b47f00e67..edd719096 100644 --- a/src/main/kotlin/com/lambda/interaction/request/breaking/BreakInfo.kt +++ b/src/main/kotlin/com/lambda/interaction/request/breaking/BreakInfo.kt @@ -20,7 +20,7 @@ package com.lambda.interaction.request.breaking import com.lambda.interaction.construction.context.BreakContext import com.lambda.interaction.request.ActionInfo import com.lambda.interaction.request.LogContext -import com.lambda.interaction.request.LogContext.Companion.buildLogContext +import com.lambda.interaction.request.LogContext.Companion.LogContextBuilder import com.lambda.interaction.request.breaking.BreakInfo.BreakType.Primary import com.lambda.interaction.request.breaking.BreakInfo.BreakType.Rebreak import com.lambda.interaction.request.breaking.BreakInfo.BreakType.RedundantSecondary @@ -150,28 +150,27 @@ data class BreakInfo( ) } - override fun toLogContext() = - buildLogContext { - group("Break Info") { - value("Type", type) - text(context.toLogContext()) - group("Details") { - value("Should Progress", shouldProgress) - value("Rebreak Potential", rebreakPotential) - text(swapInfo.toLogContext()) - value("Swap Stack", swapStack) - value("Updated This Tick", updatedThisTick) - value("Updated Pre-Processing This Tick", updatedPreProcessingThisTick) - value("Progressed This Tick", progressedThisTick) - value("Breaking", breaking) - value("Abandoned", abandoned) - value("Breaking Ticks", breakingTicks) - value("Sounds Cooldown", soundsCooldown) - value("Vanilla Instant Breakable", vanillaInstantBreakable) - value("Rebreakable", rebreakable) - } + override fun getLogContextBuilder(): LogContextBuilder.() -> Unit = { + group("Break Info") { + value("Type", type) + text(context.getLogContextBuilder()) + group("Details") { + value("Should Progress", shouldProgress) + value("Rebreak Potential", rebreakPotential) + text(swapInfo.getLogContextBuilder()) + value("Swap Stack", swapStack) + value("Updated This Tick", updatedThisTick) + value("Updated Pre-Processing This Tick", updatedPreProcessingThisTick) + value("Progressed This Tick", progressedThisTick) + value("Breaking", breaking) + value("Abandoned", abandoned) + value("Breaking Ticks", breakingTicks) + value("Sounds Cooldown", soundsCooldown) + value("Vanilla Instant Breakable", vanillaInstantBreakable) + value("Rebreakable", rebreakable) } } + } override fun toString() = "$type, ${context.cachedState}, ${context.blockPos}" } diff --git a/src/main/kotlin/com/lambda/interaction/request/breaking/BreakManager.kt b/src/main/kotlin/com/lambda/interaction/request/breaking/BreakManager.kt index bf8ce273c..d48949213 100644 --- a/src/main/kotlin/com/lambda/interaction/request/breaking/BreakManager.kt +++ b/src/main/kotlin/com/lambda/interaction/request/breaking/BreakManager.kt @@ -317,7 +317,7 @@ object BreakManager : RequestHandler( */ private fun SafeContext.processRequest(breakRequest: BreakRequest?) { breakRequest?.let { request -> - logger.debug("Processing request (${request.requestID}) at tick stage ${tickStage?.run { this::class.qualifiedName }}") + logger.debug("Processing request", breakRequest) if (request.fresh) populateFrom(request) } @@ -351,7 +351,7 @@ object BreakManager : RequestHandler( } if (breaks.isEmpty()) { - if (activeRequest != null) logger.debug("Clearing active request") + if (activeRequest != null) logger.debug("Clearing active request", activeRequest) activeRequest = null } if (breaksThisTick > 0 || activeInfos.isNotEmpty()) { @@ -368,7 +368,7 @@ object BreakManager : RequestHandler( * @see canAccept */ private fun SafeContext.populateFrom(request: BreakRequest) { - logger.debug("Populating from request (${request.requestID})") + logger.debug("Populating from request", request) // Sanitize the new breaks val newBreaks = request.contexts @@ -381,7 +381,7 @@ object BreakManager : RequestHandler( .forEach { info -> newBreaks.find { ctx -> ctx.blockPos == info.context.blockPos && canAccept(ctx) }?.let { ctx -> if ((!info.updatedThisTick || info.type == RedundantSecondary) || info.abandoned) { - logger.debug("Updating info for $info") + logger.debug("Updating info", info, ctx) if (info.type == RedundantSecondary) info.request.onStart?.invoke(info.context.blockPos) else if (info.abandoned) { @@ -430,7 +430,7 @@ object BreakManager : RequestHandler( rotationRequest = infos.firstOrNull { info -> info.breakConfig.rotateForBreak } ?.let { info -> val rotation = info.context.rotation - logger.debug("Requesting rotation (${rotation.requestID})") + logger.debug("Requesting rotation", rotation) rotation.submit(false) } @@ -448,9 +448,9 @@ object BreakManager : RequestHandler( request.hotbar.keepTicks.coerceAtLeast(minSwapTicks) ).submit(false) } - logger.debug("Submitting request for hotbar index ${info.context.hotbarIndex} with min swap ticks $minSwapTicks (${hotbarRequest.requestID})") + logger.debug("Submitted hotbar request", hotbarRequest) if (!hotbarRequest.done) { - logger.warning("Hotbar request failed (${hotbarRequest.requestID})") + logger.warning("Hotbar request failed", hotbarRequest) return false } if (minSwapTicks > 0) { @@ -507,7 +507,7 @@ object BreakManager : RequestHandler( if (!primaryInfo.breaking) return null - logger.debug("Transforming ${primaryInfo.type} to $Secondary") + logger.debug("Transforming primary to secondary", primaryInfo) secondaryBreak = primaryInfo.apply { type = Secondary } secondaryBreak?.stopBreakPacket(world, interaction) return@let @@ -515,7 +515,7 @@ object BreakManager : RequestHandler( primaryBreak = breakInfo setPendingConfigs(request.build) - logger.success("Initialized $primaryBreak") + logger.success("Initialized break info", breakInfo) return primaryBreak } @@ -599,7 +599,7 @@ object BreakManager : RequestHandler( } private fun BreakInfo.updatePreProcessing(player: ClientPlayerEntity, world: BlockView) { - logger.debug("Updating pre-processing for $this") + logger.debug("Updating pre-processing", this) shouldProgress = !progressedThisTick && tickStage in breakConfig.breakStageMask @@ -628,7 +628,7 @@ object BreakManager : RequestHandler( if (type == RedundantSecondary || abandoned) return@runSafe when (type) { Primary -> { - logger.warning("Cancelling ${this@cancelBreak}") + logger.warning("Cancelling break", this@cancelBreak) nullify() setBreakingTextureStage(player, world, -1) abortBreakPacket(world, interaction) @@ -636,12 +636,12 @@ object BreakManager : RequestHandler( } Secondary -> { if (breakConfig.unsafeCancels) { - logger.warning("Making ${this@cancelBreak} redundant") + logger.warning("Making break redundant", this@cancelBreak) type = RedundantSecondary setBreakingTextureStage(player, world, -1) request.onCancel?.invoke(context.blockPos) } else { - logger.warning("Abandoning ${this@cancelBreak}") + logger.warning("Abandoning break", this@cancelBreak) abandoned = true } } @@ -701,14 +701,14 @@ object BreakManager : RequestHandler( if (blockState.isEmpty) { info.nullify() info.request.onCancel?.invoke(ctx.blockPos) - logger.warning("Block state was unexpectedly empty") + logger.warning("Block state was unexpectedly empty", info) return false } info.breakingTicks++ val breakDelta = blockState.calcBreakDelta(player, world, ctx.blockPos, config) val progress = breakDelta * (info.breakingTicks - config.fudgeFactor) - logger.debug("${info.type} progress: $progress, breaking ticks: ${info.breakingTicks}, ${info.context.cachedState}") + logger.debug("${info.type} progress: $progress, breaking ticks: ${info.breakingTicks}", info) if (config.sounds) { if (info.soundsCooldown % 4.0f == 0.0f) { @@ -737,7 +737,7 @@ object BreakManager : RequestHandler( val swing = config.swing if (progress >= info.getBreakThreshold() && info.swapInfo.validSwap) { - logger.success("Breaking $info") + logger.success("Breaking", info) if (info.type == Primary) { onBlockBreak(info) info.stopBreakPacket(world, interaction) @@ -767,7 +767,7 @@ object BreakManager : RequestHandler( logger.debug("Handling potential rebreak") when (val rebreakResult = RebreakHandler.handleUpdate(info.context, info.request)) { is RebreakResult.StillBreaking -> { - logger.debug("Rebreak not complete ${info.context.cachedState}") + logger.debug("Rebreak not complete", info) primaryBreak = rebreakResult.breakInfo.apply { type = Primary RebreakHandler.clearRebreak() @@ -781,7 +781,7 @@ object BreakManager : RequestHandler( return true } is RebreakResult.Rebroke -> { - logger.debug("Rebroke ${info.context.cachedState}") + logger.debug("Rebroke", info) info.type = Rebreak info.nullify() info.request.onReBreak?.invoke(ctx.blockPos) @@ -818,11 +818,11 @@ object BreakManager : RequestHandler( info.vanillaInstantBreakable = progress >= 1 && info.swapInfo.validSwap if (instantBreakable) { - logger.success("Instantly breaking ${info.type} $blockState") + logger.success("Instant breaking", info) onBlockBreak(info) if (!info.vanillaInstantBreakable) breakCooldown = info.breakConfig.breakDelay } else { - logger.debug("Starting ${info.type} $blockState") + logger.debug("Starting break", info) info.apply { breaking = true breakingTicks = 1 diff --git a/src/main/kotlin/com/lambda/interaction/request/breaking/BreakRequest.kt b/src/main/kotlin/com/lambda/interaction/request/breaking/BreakRequest.kt index 255ef788c..4c07843c6 100644 --- a/src/main/kotlin/com/lambda/interaction/request/breaking/BreakRequest.kt +++ b/src/main/kotlin/com/lambda/interaction/request/breaking/BreakRequest.kt @@ -22,7 +22,7 @@ import com.lambda.config.groups.InteractionConfig import com.lambda.interaction.construction.context.BreakContext import com.lambda.interaction.construction.context.BuildContext import com.lambda.interaction.request.LogContext -import com.lambda.interaction.request.LogContext.Companion.buildLogContext +import com.lambda.interaction.request.LogContext.Companion.LogContextBuilder import com.lambda.interaction.request.Request import com.lambda.interaction.request.hotbar.HotbarConfig import com.lambda.interaction.request.inventory.InventoryConfig @@ -60,22 +60,21 @@ data class BreakRequest( override fun submit(queueIfClosed: Boolean) = BreakManager.request(this, queueIfClosed) - override fun toLogContext() = - buildLogContext { - group("Break Request") { - value("Request ID", requestID) - value("Contexts", contexts.size) - group("Callbacks") { - value("onStart", onStart != null) - value("onUpdate", onUpdate != null) - value("onStop", onStop != null) - value("onCancel", onCancel != null) - value("onItemDrop", onItemDrop != null) - value("onReBreakStart", onReBreakStart != null) - value("onReBreak", onReBreak != null) - } + override fun getLogContextBuilder(): LogContextBuilder.() -> Unit = { + group("Break Request") { + value("Request ID", requestID) + value("Contexts", contexts.size) + group("Callbacks") { + value("onStart", onStart != null) + value("onUpdate", onUpdate != null) + value("onStop", onStop != null) + value("onCancel", onCancel != null) + value("onItemDrop", onItemDrop != null) + value("onReBreakStart", onReBreakStart != null) + value("onReBreak", onReBreak != null) } } + } @DslMarker annotation class BreakRequestBuilder diff --git a/src/main/kotlin/com/lambda/interaction/request/breaking/SwapInfo.kt b/src/main/kotlin/com/lambda/interaction/request/breaking/SwapInfo.kt index 57f02512b..5a3236fa7 100644 --- a/src/main/kotlin/com/lambda/interaction/request/breaking/SwapInfo.kt +++ b/src/main/kotlin/com/lambda/interaction/request/breaking/SwapInfo.kt @@ -19,7 +19,7 @@ package com.lambda.interaction.request.breaking import com.lambda.Lambda.mc import com.lambda.interaction.request.LogContext -import com.lambda.interaction.request.LogContext.Companion.buildLogContext +import com.lambda.interaction.request.LogContext.Companion.LogContextBuilder import com.lambda.interaction.request.breaking.BreakInfo.BreakType.Primary import com.lambda.interaction.request.breaking.BreakInfo.BreakType.Rebreak import com.lambda.interaction.request.breaking.BreakManager.calcBreakDelta @@ -43,15 +43,14 @@ data class SwapInfo( (mc.player?.mainHandStack?.heldTicks ?: return false) >= serverSwapTicks } - override fun toLogContext() = - buildLogContext { - group("Swap Info") { - value("Type", type) - value("Swap", swap) - value("Min Keep Ticks", minKeepTicks) - value("Valid Swap", validSwap) - } + override fun getLogContextBuilder(): LogContextBuilder.() -> Unit = { + group("Swap Info") { + value("Type", type) + value("Swap", swap) + value("Min Keep Ticks", minKeepTicks) + value("Valid Swap", validSwap) } + } companion object { val EMPTY = SwapInfo(Primary) diff --git a/src/main/kotlin/com/lambda/interaction/request/hotbar/HotbarManager.kt b/src/main/kotlin/com/lambda/interaction/request/hotbar/HotbarManager.kt index 715684da1..b1b14446e 100644 --- a/src/main/kotlin/com/lambda/interaction/request/hotbar/HotbarManager.kt +++ b/src/main/kotlin/com/lambda/interaction/request/hotbar/HotbarManager.kt @@ -74,7 +74,7 @@ object HotbarManager : RequestHandler( } override fun SafeContext.handleRequest(request: HotbarRequest) { - logger.debug("Handling request:", request.toLogContext()) + logger.debug("Handling request:", request) maxSwapsThisTick = request.swapsPerTick swapDelay = swapDelay.coerceAtMost(request.swapDelay) @@ -87,7 +87,7 @@ object HotbarManager : RequestHandler( if (sameButLonger) activeRequest?.let { current -> request.swapPauseAge = current.swapPauseAge - logger.debug("Request is the same as current, but longer or the same keep time", request.toLogContext()) + logger.debug("Request is the same as current, but longer or the same keep time", request) } else run swap@{ if (request.slot != activeRequest?.slot) { if (swapsThisTick + 1 > maxSwapsThisTick || swapDelay > 0) return @@ -108,7 +108,7 @@ object HotbarManager : RequestHandler( } activeRequest = request - logger.success("Set active request", request.toLogContext()) + logger.success("Set active request", request) interaction.syncSelectedSlot() return } @@ -117,7 +117,7 @@ object HotbarManager : RequestHandler( activeRequest?.let { active -> val canStopSwap = swapsThisTick < maxSwapsThisTick if (active.keepTicks <= 0 && tickStage in active.sequenceStageMask && canStopSwap) { - logger.debug("Clearing request and syncing slot", activeRequest?.toLogContext()) + logger.debug("Clearing request and syncing slot", activeRequest) activeRequest = null interaction.syncSelectedSlot() } diff --git a/src/main/kotlin/com/lambda/interaction/request/hotbar/HotbarRequest.kt b/src/main/kotlin/com/lambda/interaction/request/hotbar/HotbarRequest.kt index 9d2c4c31d..e17cc6e7f 100644 --- a/src/main/kotlin/com/lambda/interaction/request/hotbar/HotbarRequest.kt +++ b/src/main/kotlin/com/lambda/interaction/request/hotbar/HotbarRequest.kt @@ -18,7 +18,7 @@ package com.lambda.interaction.request.hotbar import com.lambda.interaction.request.LogContext -import com.lambda.interaction.request.LogContext.Companion.buildLogContext +import com.lambda.interaction.request.LogContext.Companion.LogContextBuilder import com.lambda.interaction.request.Request class HotbarRequest( @@ -42,17 +42,16 @@ class HotbarRequest( override fun submit(queueIfClosed: Boolean) = HotbarManager.request(this, queueIfClosed) - override fun toLogContext() = - buildLogContext { - group("Hotbar Request") { - value("Request ID", requestID) - value("Slot", slot) - value("Keep Ticks", keepTicks) - value("Swap Pause", swapPause) - value("Swap Pause Age", swapPauseAge) - value("Active Request Age", activeRequestAge) - } + override fun getLogContextBuilder(): LogContextBuilder.() -> Unit = { + group("Hotbar Request") { + value("Request ID", requestID) + value("Slot", slot) + value("Keep Ticks", keepTicks) + value("Swap Pause", swapPause) + value("Swap Pause Age", swapPauseAge) + value("Active Request Age", activeRequestAge) } + } companion object { var requestCount = 0 diff --git a/src/main/kotlin/com/lambda/interaction/request/interacting/InteractRequest.kt b/src/main/kotlin/com/lambda/interaction/request/interacting/InteractRequest.kt index 06bc1b448..cf8b6796f 100644 --- a/src/main/kotlin/com/lambda/interaction/request/interacting/InteractRequest.kt +++ b/src/main/kotlin/com/lambda/interaction/request/interacting/InteractRequest.kt @@ -22,7 +22,7 @@ import com.lambda.config.groups.BuildConfig import com.lambda.interaction.construction.context.BuildContext import com.lambda.interaction.construction.context.InteractionContext import com.lambda.interaction.request.LogContext -import com.lambda.interaction.request.LogContext.Companion.buildLogContext +import com.lambda.interaction.request.LogContext.Companion.LogContextBuilder import com.lambda.interaction.request.Request import com.lambda.interaction.request.hotbar.HotbarConfig import com.lambda.interaction.request.rotating.RotationConfig @@ -46,13 +46,12 @@ data class InteractRequest( override fun submit(queueIfClosed: Boolean) = InteractionManager.request(this, queueIfClosed) - override fun toLogContext() = - buildLogContext { - group("Interact Request") { - value("Request ID", requestID) - value("Contexts", contexts.size) - } + override fun getLogContextBuilder(): LogContextBuilder.() -> Unit = { + group("Interact Request") { + value("Request ID", requestID) + value("Contexts", contexts.size) } + } companion object { var requestCount = 0 diff --git a/src/main/kotlin/com/lambda/interaction/request/interacting/InteractionInfo.kt b/src/main/kotlin/com/lambda/interaction/request/interacting/InteractionInfo.kt index 56fd3ba7f..9c84fae7b 100644 --- a/src/main/kotlin/com/lambda/interaction/request/interacting/InteractionInfo.kt +++ b/src/main/kotlin/com/lambda/interaction/request/interacting/InteractionInfo.kt @@ -21,17 +21,16 @@ import com.lambda.interaction.construction.context.BuildContext import com.lambda.interaction.construction.context.InteractionContext import com.lambda.interaction.request.ActionInfo import com.lambda.interaction.request.LogContext -import com.lambda.interaction.request.LogContext.Companion.buildLogContext +import com.lambda.interaction.request.LogContext.Companion.LogContextBuilder data class InteractionInfo( override val context: InteractionContext, override val pendingInteractionsList: MutableCollection, private val config: InteractConfig ) : ActionInfo, InteractConfig by config, LogContext { - override fun toLogContext() = - buildLogContext { - group("Interaction Info") { - text(context.toLogContext()) - } + override fun getLogContextBuilder(): LogContextBuilder.() -> Unit = { + group("Interaction Info") { + text(context.getLogContextBuilder()) } + } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/interaction/request/inventory/InventoryRequest.kt b/src/main/kotlin/com/lambda/interaction/request/inventory/InventoryRequest.kt index 8c38b8782..a8589b1e2 100644 --- a/src/main/kotlin/com/lambda/interaction/request/inventory/InventoryRequest.kt +++ b/src/main/kotlin/com/lambda/interaction/request/inventory/InventoryRequest.kt @@ -18,7 +18,7 @@ package com.lambda.interaction.request.inventory import com.lambda.interaction.request.LogContext -import com.lambda.interaction.request.LogContext.Companion.buildLogContext +import com.lambda.interaction.request.LogContext.Companion.LogContextBuilder import com.lambda.interaction.request.Request class InventoryRequest( @@ -32,12 +32,11 @@ class InventoryRequest( override fun submit(queueIfClosed: Boolean) = InventoryManager.request(this, queueIfClosed) - override fun toLogContext() = - buildLogContext { - group("Inventory Request") { - value("Request ID", requestID) - } + override fun getLogContextBuilder(): LogContextBuilder.() -> Unit = { + group("Inventory Request") { + value("Request ID", requestID) } + } companion object { var requestCount = 0 diff --git a/src/main/kotlin/com/lambda/interaction/request/placing/PlaceInfo.kt b/src/main/kotlin/com/lambda/interaction/request/placing/PlaceInfo.kt index c826b27cf..1335e2a59 100644 --- a/src/main/kotlin/com/lambda/interaction/request/placing/PlaceInfo.kt +++ b/src/main/kotlin/com/lambda/interaction/request/placing/PlaceInfo.kt @@ -21,7 +21,7 @@ import com.lambda.interaction.construction.context.BuildContext import com.lambda.interaction.construction.context.PlaceContext import com.lambda.interaction.request.ActionInfo import com.lambda.interaction.request.LogContext -import com.lambda.interaction.request.LogContext.Companion.buildLogContext +import com.lambda.interaction.request.LogContext.Companion.LogContextBuilder import net.minecraft.util.math.BlockPos data class PlaceInfo( @@ -30,13 +30,12 @@ data class PlaceInfo( val onPlace: ((BlockPos) -> Unit)?, val placeConfig: PlaceConfig ) : ActionInfo, LogContext { - override fun toLogContext() = - buildLogContext { - group("Place Info") { - text(context.toLogContext()) - group("Callbacks") { - value("onPlace", onPlace != null) - } + override fun getLogContextBuilder(): LogContextBuilder.() -> Unit = { + group("Place Info") { + text(context.getLogContextBuilder()) + group("Callbacks") { + value("onPlace", onPlace != null) } } + } } \ No newline at end of file diff --git a/src/main/kotlin/com/lambda/interaction/request/placing/PlaceRequest.kt b/src/main/kotlin/com/lambda/interaction/request/placing/PlaceRequest.kt index af497a07e..f38ecfcf3 100644 --- a/src/main/kotlin/com/lambda/interaction/request/placing/PlaceRequest.kt +++ b/src/main/kotlin/com/lambda/interaction/request/placing/PlaceRequest.kt @@ -21,7 +21,7 @@ import com.lambda.config.groups.BuildConfig import com.lambda.interaction.construction.context.BuildContext import com.lambda.interaction.construction.context.PlaceContext import com.lambda.interaction.request.LogContext -import com.lambda.interaction.request.LogContext.Companion.buildLogContext +import com.lambda.interaction.request.LogContext.Companion.LogContextBuilder import com.lambda.interaction.request.Request import com.lambda.interaction.request.hotbar.HotbarConfig import com.lambda.interaction.request.rotating.RotationConfig @@ -50,13 +50,12 @@ data class PlaceRequest( override fun submit(queueIfClosed: Boolean) = PlaceManager.request(this, queueIfClosed) - override fun toLogContext() = - buildLogContext { - group("PlaceRequest") { - value("Request ID", requestID) - value("Contexts", contexts.size) - } + override fun getLogContextBuilder(): LogContextBuilder.() -> Unit = { + group("PlaceRequest") { + value("Request ID", requestID) + value("Contexts", contexts.size) } + } companion object { var requestCount = 0 diff --git a/src/main/kotlin/com/lambda/interaction/request/rotating/RotationRequest.kt b/src/main/kotlin/com/lambda/interaction/request/rotating/RotationRequest.kt index 89240c490..c38bfcd11 100644 --- a/src/main/kotlin/com/lambda/interaction/request/rotating/RotationRequest.kt +++ b/src/main/kotlin/com/lambda/interaction/request/rotating/RotationRequest.kt @@ -18,7 +18,7 @@ package com.lambda.interaction.request.rotating import com.lambda.interaction.request.LogContext -import com.lambda.interaction.request.LogContext.Companion.buildLogContext +import com.lambda.interaction.request.LogContext.Companion.LogContextBuilder import com.lambda.interaction.request.Request import com.lambda.interaction.request.rotating.visibilty.RotationTarget import com.lambda.threading.runSafe @@ -42,18 +42,17 @@ data class RotationRequest( override fun submit(queueIfClosed: Boolean): RotationRequest = RotationManager.request(this, queueIfClosed) - override fun toLogContext() = - buildLogContext { - group("Rotation Request") { - value("Request ID", requestID) - value("Rotation Mode", rotationMode) - value("Turn Speed", turnSpeed) - value("Keep Ticks", keepTicks) - value("Decay Ticks", decayTicks) - value("Speed Multiplier", speedMultiplier) - value("Age", age) - } + override fun getLogContextBuilder(): LogContextBuilder.() -> Unit = { + group("Rotation Request") { + value("Request ID", requestID) + value("Rotation Mode", rotationMode) + value("Turn Speed", turnSpeed) + value("Keep Ticks", keepTicks) + value("Decay Ticks", decayTicks) + value("Speed Multiplier", speedMultiplier) + value("Age", age) } + } companion object { var requestCount = 0 From 276dea24af33712462a8cf8ff2f85e51ce1de89f Mon Sep 17 00:00:00 2001 From: beanbag44 Date: Wed, 10 Sep 2025 02:42:45 +0100 Subject: [PATCH 33/38] hopefully better sameLine builder function --- .../kotlin/com/lambda/interaction/request/LogContext.kt | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/com/lambda/interaction/request/LogContext.kt b/src/main/kotlin/com/lambda/interaction/request/LogContext.kt index ba65c2ccf..53d90db3a 100644 --- a/src/main/kotlin/com/lambda/interaction/request/LogContext.kt +++ b/src/main/kotlin/com/lambda/interaction/request/LogContext.kt @@ -52,8 +52,13 @@ interface LogContext { private var tabs = tabMin @LogContextDsl - fun sameLine() = - logContext.replace("\n", "") + fun sameLine() { + val length = logContext.length + val first = logContext[length - 2] + val second = logContext[length - 1] + if (first != '\\' || second != 'n') throw IllegalStateException("String does not end in a new line") + logContext = logContext.removeRange(length - 2, length - 1) + } @LogContextDsl fun text(text: String) { From 77fecd754651af99538b6edfdf05118c42844e01 Mon Sep 17 00:00:00 2001 From: beanbag44 Date: Sun, 14 Sep 2025 11:42:34 +0100 Subject: [PATCH 34/38] use hud window --- .../lambda/interaction/request/DebugLogger.kt | 92 +++++++++---------- .../lambda/interaction/request/LogContext.kt | 2 +- .../request/rotating/RotationManager.kt | 1 - 3 files changed, 46 insertions(+), 49 deletions(-) diff --git a/src/main/kotlin/com/lambda/interaction/request/DebugLogger.kt b/src/main/kotlin/com/lambda/interaction/request/DebugLogger.kt index a9d47c4d0..d0c6cd18c 100644 --- a/src/main/kotlin/com/lambda/interaction/request/DebugLogger.kt +++ b/src/main/kotlin/com/lambda/interaction/request/DebugLogger.kt @@ -76,60 +76,58 @@ class DebugLogger( fun ImGuiBuilder.buildLayout() { ImGui.setNextWindowSizeConstraints(300f, 400f, windowViewport.workSizeX, windowViewport.workSizeY) ImGui.setNextWindowBgAlpha(backgroundAlpha.get()) - window(name, flags = ImGuiWindowFlags.NoCollapse) { - val noScroll = if (autoScroll.get()) ImGuiWindowFlags.NoScrollbar or ImGuiWindowFlags.NoScrollWithMouse else 0 - if (mc.currentScreen == LambdaScreen) { - checkbox("Auto-Scroll", autoScroll) - sameLine() - checkbox("Warp Text", wrapText) - sameLine() - checkbox("Show Debug", showDebug) - checkbox("Show Success", showSuccess) - sameLine() - checkbox("Show Warning", showWarning) - sameLine() - checkbox("Show Error", showError) - checkbox("Show System", showSystem) - slider("Background Alpha", backgroundAlpha, 0.0f, 1.0f) - button("Clear") { clear() } - } - child("Log Content", extraFlags = noScroll) { - if (wrapText.get()) ImGui.pushTextWrapPos() + val noScroll = if (autoScroll.get()) ImGuiWindowFlags.NoScrollbar or ImGuiWindowFlags.NoScrollWithMouse else 0 + if (mc.currentScreen == LambdaScreen) { + checkbox("Auto-Scroll", autoScroll) + sameLine() + checkbox("Warp Text", wrapText) + sameLine() + checkbox("Show Debug", showDebug) + checkbox("Show Success", showSuccess) + sameLine() + checkbox("Show Warning", showWarning) + sameLine() + checkbox("Show Error", showError) + checkbox("Show System", showSystem) + slider("Background Alpha", backgroundAlpha, 0.0f, 1.0f) + button("Clear") { clear() } + } + child("Log Content", extraFlags = noScroll) { + if (wrapText.get()) ImGui.pushTextWrapPos() - logs.forEach { logEntry -> - if (shouldDisplay(logEntry)) { - val type = logEntry.type - val (logTypeStr, color) = when (type) { - LogType.Debug -> Pair("[DEBUG]", type.color) - LogType.Success -> Pair("[SUCCESS]", type.color) - LogType.Warning -> Pair("[WARNING]", type.color) - LogType.Error -> Pair("[ERROR]", type.color) - LogType.System -> Pair("[SYSTEM]", type.color) - } + logs.forEach { logEntry -> + if (shouldDisplay(logEntry)) { + val type = logEntry.type + val (logTypeStr, color) = when (type) { + LogType.Debug -> Pair("[DEBUG]", type.color) + LogType.Success -> Pair("[SUCCESS]", type.color) + LogType.Warning -> Pair("[WARNING]", type.color) + LogType.Error -> Pair("[ERROR]", type.color) + LogType.System -> Pair("[SYSTEM]", type.color) + } - val floats = floatArrayOf(0f, 0f, 0f) - val (r, g, b) = color.getColorComponents(floats) - ImGui.pushStyleColor(ImGuiCol.Text, r, g, b, color.a.toFloat()) - if (logEntry.type == LogType.System) { - text("$logTypeStr ${logEntry.message}") - } else { - treeNode("$logTypeStr ${logEntry.message}", logEntry.uuid) { - logEntry.extraContext - .filterNotNull() - .forEach { - text(it) - } - } + val floats = floatArrayOf(0f, 0f, 0f) + val (r, g, b) = color.getColorComponents(floats) + ImGui.pushStyleColor(ImGuiCol.Text, r, g, b, color.a.toFloat()) + if (logEntry.type == LogType.System) { + text("$logTypeStr ${logEntry.message}") + } else { + treeNode("$logTypeStr ${logEntry.message}", logEntry.uuid) { + logEntry.extraContext + .filterNotNull() + .forEach { + text(it) + } } - ImGui.popStyleColor() } + ImGui.popStyleColor() } + } - if (wrapText.get()) ImGui.popTextWrapPos() + if (wrapText.get()) ImGui.popTextWrapPos() - if (autoScroll.get()) { - ImGui.setScrollHereY(1f) - } + if (autoScroll.get()) { + ImGui.setScrollHereY(1f) } } } diff --git a/src/main/kotlin/com/lambda/interaction/request/LogContext.kt b/src/main/kotlin/com/lambda/interaction/request/LogContext.kt index 53d90db3a..8e16e0d0a 100644 --- a/src/main/kotlin/com/lambda/interaction/request/LogContext.kt +++ b/src/main/kotlin/com/lambda/interaction/request/LogContext.kt @@ -35,7 +35,7 @@ interface LogContext { fun BlockHitResult.getLogContextBuilder(): LogContextBuilder.() -> Unit = { group("Block Hit Result") { value("Side", side) - value("Block Pos", blockPos) + text(blockPos.getLogContextBuilder()) value("Pos", pos) } } diff --git a/src/main/kotlin/com/lambda/interaction/request/rotating/RotationManager.kt b/src/main/kotlin/com/lambda/interaction/request/rotating/RotationManager.kt index 15cb20288..b1827fc30 100644 --- a/src/main/kotlin/com/lambda/interaction/request/rotating/RotationManager.kt +++ b/src/main/kotlin/com/lambda/interaction/request/rotating/RotationManager.kt @@ -34,7 +34,6 @@ import com.lambda.interaction.request.RequestHandler import com.lambda.interaction.request.rotating.Rotation.Companion.slerp import com.lambda.interaction.request.rotating.visibilty.lookAt import com.lambda.module.hud.ManagerDebugLoggers.rotationManagerLogger -import com.lambda.module.modules.client.Baritone import com.lambda.threading.runGameScheduled import com.lambda.threading.runSafe import com.lambda.util.extension.partialTicks From e409a2e55d4673967a2922934f3d959d8ee94d70 Mon Sep 17 00:00:00 2001 From: beanbag44 Date: Sun, 14 Sep 2025 20:20:43 +0100 Subject: [PATCH 35/38] improved interaction manager logs --- .../interaction/request/interacting/InteractionManager.kt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/kotlin/com/lambda/interaction/request/interacting/InteractionManager.kt b/src/main/kotlin/com/lambda/interaction/request/interacting/InteractionManager.kt index 8a02136db..973623569 100644 --- a/src/main/kotlin/com/lambda/interaction/request/interacting/InteractionManager.kt +++ b/src/main/kotlin/com/lambda/interaction/request/interacting/InteractionManager.kt @@ -98,7 +98,7 @@ object InteractionManager : RequestHandler( } fun SafeContext.processRequest(request: InteractRequest) { - logger.debug("Processing request ${request.requestID}") + logger.debug("Processing request", request) if (request.fresh) populateFrom(request) @@ -110,7 +110,7 @@ object InteractionManager : RequestHandler( val ctx = iterator.next() if (!ctx.requestDependencies(request)) { - logger.warning("Dependencies failed for ${request.requestID}") + logger.warning("Dependencies failed for interaction", ctx, request) return } @@ -130,12 +130,12 @@ object InteractionManager : RequestHandler( request.onInteract?.invoke(ctx.blockPos) interactionsThisTick++ iterator.remove() - logger.success("Placed ${ctx.expectedState} at ${ctx.blockPos}") + logger.success("interacted with ${ctx.cachedState} at ${ctx.blockPos}, changing to ${ctx.expectedState}", ctx, request) } } private fun populateFrom(request: InteractRequest) { - logger.debug("Populating from request ${request.requestID}") + logger.debug("Populating from request", request) setPendingConfigs(request.build) potentialInteractions = request.contexts .filter { !isPosBlocked(it.blockPos) } From 6ec157b70a20189633f5864627e4e124b079d273 Mon Sep 17 00:00:00 2001 From: beanbag44 Date: Sun, 14 Sep 2025 20:29:54 +0100 Subject: [PATCH 36/38] improved place manager logs --- .../request/placing/PlaceManager.kt | 41 +++++++++++-------- 1 file changed, 23 insertions(+), 18 deletions(-) diff --git a/src/main/kotlin/com/lambda/interaction/request/placing/PlaceManager.kt b/src/main/kotlin/com/lambda/interaction/request/placing/PlaceManager.kt index f84619922..967439b8f 100644 --- a/src/main/kotlin/com/lambda/interaction/request/placing/PlaceManager.kt +++ b/src/main/kotlin/com/lambda/interaction/request/placing/PlaceManager.kt @@ -142,7 +142,7 @@ object PlaceManager : RequestHandler( * @see placeBlock */ fun SafeContext.processRequest(request: PlaceRequest) { - logger.debug("Processing request (${request.requestID}) at tick stage ${tickStage?.run { this::class.qualifiedName }}") + logger.debug("Processing request", request) if (request.fresh) populateFrom(request) @@ -153,20 +153,25 @@ object PlaceManager : RequestHandler( if (ctx.sneak) shouldSneak = true if (!ctx.requestDependencies(request)) { - logger.warning("Dependencies failed for ${request.requestID}") + logger.warning("Dependencies failed for context", ctx, request) return } if (!validSneak(player)) return // if (tickStage !in request.build.placing.placeStageMask) return val actionResult = placeBlock(ctx, request, Hand.MAIN_HAND) - if (!actionResult.isAccepted) warn("Placement interaction failed with $actionResult") + if (!actionResult.isAccepted) { + logger.warning("Placement interaction failed with $actionResult", ctx, request) + warn("Placement interaction failed with $actionResult") + } placementsThisTick++ iterator.remove() } if (potentialPlacements.isEmpty()) { - if (activeRequest != null) logger.debug("Clearing active request") - activeRequest = null + if (activeRequest != null) { + logger.debug("Clearing active request", activeRequest) + activeRequest = null + } } } @@ -177,7 +182,7 @@ object PlaceManager : RequestHandler( * @see isPosBlocked */ private fun populateFrom(request: PlaceRequest) { - logger.debug("Populating from request (${request.requestID})") + logger.debug("Populating from request", request) setPendingConfigs(request.build) potentialPlacements = request.contexts .filter { !isPosBlocked(it.blockPos) } @@ -197,11 +202,11 @@ object PlaceManager : RequestHandler( interaction.syncSelectedSlot() val hitResult = placeContext.result if (!world.worldBorder.contains(hitResult.blockPos)) { - logger.error("Placement position outside the world border at ${placeContext.blockPos.toShortString()}") + logger.error("Placement position outside the world border", placeContext, request) return ActionResult.FAIL } if (gamemode == GameMode.SPECTATOR) { - logger.error("Player is in spectator mode") + logger.error("Player is in spectator mode", placeContext, request) return ActionResult.PASS } return interactBlockInternal(placeContext, request, request.build.placing, hand, hitResult) @@ -224,13 +229,13 @@ object PlaceManager : RequestHandler( if (!cantInteract) { val blockState = blockState(hitResult.blockPos) if (!connection.hasFeature(blockState.block.requiredFeatures)) { - logger.error("Required features not met for $blockState") + logger.error("Required features not met for $blockState", placeContext, request) return ActionResult.FAIL } val actionResult = blockState.onUse(world, player, hitResult) if (actionResult.isAccepted) { - logger.error("Block state ($blockState) onUse not accepted") + logger.error("Block state ($blockState) onUse not accepted", placeContext, request) return actionResult } } @@ -270,12 +275,12 @@ object PlaceManager : RequestHandler( val cantModifyWorld = !player.abilities.allowModifyWorld val cantPlaceOn = !itemStack.canPlaceOn(cachedBlockPosition) if (cantModifyWorld && cantPlaceOn) { - logger.error("Cannot modify world") + logger.error("Cannot modify world", placeContext, request) return ActionResult.PASS } val item = (itemStack.item as? BlockItem) ?: run { - logger.error("Item ${itemStack.item.name} is not a block item") + logger.error("Item ${itemStack.item.name} is not a block item", placeContext, request) return ActionResult.PASS } @@ -297,20 +302,20 @@ object PlaceManager : RequestHandler( context: ItemPlacementContext ): ActionResult { if (!item.block.isEnabled(world.enabledFeatures)) { - logger.error("Block ${item.block.name} is not enabled") + logger.error("Block ${item.block.name} is not enabled", placeContext, request) return ActionResult.FAIL } if (!context.canPlace()) { - logger.error("Cannot place at ${placeContext.blockPos} with current state ${placeContext.cachedState}") + logger.error("Cannot place at ${placeContext.blockPos} with current state ${placeContext.cachedState}", placeContext, request) return ActionResult.FAIL } val itemPlacementContext = item.getPlacementContext(context) ?: run { - logger.error("Could not retrieve item placement context") + logger.error("Could not retrieve item placement context", placeContext, request) return ActionResult.FAIL } val blockState = item.getPlacementState(itemPlacementContext) ?: run { - logger.error("Could not retrieve placement state") + logger.error("Could not retrieve placement state", placeContext, request) return ActionResult.FAIL } @@ -347,7 +352,7 @@ object PlaceManager : RequestHandler( // "AwaitThenPlace" confirmation setting is enabled, as the block state setting methods that validate these // rules are not called. if (!item.place(itemPlacementContext, blockState)) { - logger.error("Could not place block client side at ${placeContext.blockPos} with placement state ${placeContext.expectedState}") + logger.error("Could not place block client side at ${placeContext.blockPos} with placement state ${placeContext.expectedState}", placeContext, request) return ActionResult.FAIL } @@ -365,7 +370,7 @@ object PlaceManager : RequestHandler( request.onPlace?.invoke(placeContext.blockPos) } - logger.success("Placed ${placeContext.expectedState} at ${placeContext.blockPos}") + logger.success("Placed ${placeContext.expectedState} at ${placeContext.blockPos}", placeContext, request) return ActionResult.SUCCESS } From 54d5c15657020ac63e21192e0ec0ec9ff7f80332 Mon Sep 17 00:00:00 2001 From: beanbag44 Date: Sun, 14 Sep 2025 20:33:40 +0100 Subject: [PATCH 37/38] improved rotation manager logs --- .../interaction/request/rotating/RotationManager.kt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/main/kotlin/com/lambda/interaction/request/rotating/RotationManager.kt b/src/main/kotlin/com/lambda/interaction/request/rotating/RotationManager.kt index b1827fc30..7052a54e3 100644 --- a/src/main/kotlin/com/lambda/interaction/request/rotating/RotationManager.kt +++ b/src/main/kotlin/com/lambda/interaction/request/rotating/RotationManager.kt @@ -28,8 +28,8 @@ import com.lambda.event.events.TickEvent import com.lambda.event.events.UpdateManagerEvent import com.lambda.event.listener.SafeListener.Companion.listen import com.lambda.event.listener.UnsafeListener.Companion.listenUnsafe -import com.lambda.interaction.request.Logger import com.lambda.interaction.BaritoneManager +import com.lambda.interaction.request.Logger import com.lambda.interaction.request.RequestHandler import com.lambda.interaction.request.rotating.Rotation.Companion.slerp import com.lambda.interaction.request.rotating.visibilty.lookAt @@ -75,7 +75,7 @@ object RotationManager : RequestHandler( listen(priority = Int.MAX_VALUE) { activeRequest?.let { if (it.keepTicks <= 0 && it.decayTicks <= 0) { - logger.debug("Clearing active request ${it.requestID}") + logger.debug("Clearing active request", it) activeRequest = null } } @@ -139,7 +139,7 @@ object RotationManager : RequestHandler( override fun SafeContext.handleRequest(request: RotationRequest) { activeRequest?.let { if (it.age <= 0) return } if (request.target.targetRotation.value != null) { - logger.debug("Accepting request ${request.requestID}") + logger.debug("Accepting request", request) activeRequest = request updateActiveRotation() changedThisTick = true @@ -271,11 +271,11 @@ object RotationManager : RequestHandler( serverRotation.slerp(rotationTo, turnSpeed) } ?: player.rotation - logger.debug("Active rotation set to $activeRotation") + logger.debug("Active rotation set to $activeRotation", activeRequest) } private fun reset(rotation: Rotation) { - logger.debug("Resetting values") + logger.debug("Resetting values with rotation $rotation") prevServerRotation = rotation serverRotation = rotation activeRotation = rotation From b93e0600e9120117805eff0075145b4f0790f5b7 Mon Sep 17 00:00:00 2001 From: beanbag44 Date: Sun, 14 Sep 2025 21:20:42 +0100 Subject: [PATCH 38/38] move logger settings to hud module settings. This also saves the settings in the config --- .../lambda/interaction/request/DebugLogger.kt | 57 ++++++------------- .../lambda/module/hud/ManagerDebugLoggers.kt | 7 +++ 2 files changed, 25 insertions(+), 39 deletions(-) diff --git a/src/main/kotlin/com/lambda/interaction/request/DebugLogger.kt b/src/main/kotlin/com/lambda/interaction/request/DebugLogger.kt index d0c6cd18c..a745822a2 100644 --- a/src/main/kotlin/com/lambda/interaction/request/DebugLogger.kt +++ b/src/main/kotlin/com/lambda/interaction/request/DebugLogger.kt @@ -17,32 +17,26 @@ package com.lambda.interaction.request -import com.lambda.Lambda.mc -import com.lambda.gui.LambdaScreen import com.lambda.gui.dsl.ImGuiBuilder import com.lambda.interaction.request.LogContext.Companion.buildLogContext +import com.lambda.module.hud.ManagerDebugLoggers.autoScroll import com.lambda.module.hud.ManagerDebugLoggers.maxLogEntries +import com.lambda.module.hud.ManagerDebugLoggers.showDebug +import com.lambda.module.hud.ManagerDebugLoggers.showError +import com.lambda.module.hud.ManagerDebugLoggers.showSuccess +import com.lambda.module.hud.ManagerDebugLoggers.showSystem +import com.lambda.module.hud.ManagerDebugLoggers.showWarning +import com.lambda.module.hud.ManagerDebugLoggers.wrapText import com.lambda.util.math.a import imgui.ImGui import imgui.flag.ImGuiCol import imgui.flag.ImGuiWindowFlags -import imgui.type.ImBoolean -import imgui.type.ImFloat import java.awt.Color import java.util.* class DebugLogger( val name: String ) { - private val autoScroll = ImBoolean(true) - private val wrapText = ImBoolean(true) - private val showDebug = ImBoolean(true) - private val showSuccess = ImBoolean(true) - private val showWarning = ImBoolean(true) - private val showError = ImBoolean(true) - private val showSystem = ImBoolean(true) - private val backgroundAlpha = ImFloat(0.3f) - val logs = LinkedList() private fun log(message: String, logColor: LogType, extraContext: List) { @@ -75,25 +69,10 @@ class DebugLogger( fun ImGuiBuilder.buildLayout() { ImGui.setNextWindowSizeConstraints(300f, 400f, windowViewport.workSizeX, windowViewport.workSizeY) - ImGui.setNextWindowBgAlpha(backgroundAlpha.get()) - val noScroll = if (autoScroll.get()) ImGuiWindowFlags.NoScrollbar or ImGuiWindowFlags.NoScrollWithMouse else 0 - if (mc.currentScreen == LambdaScreen) { - checkbox("Auto-Scroll", autoScroll) - sameLine() - checkbox("Warp Text", wrapText) - sameLine() - checkbox("Show Debug", showDebug) - checkbox("Show Success", showSuccess) - sameLine() - checkbox("Show Warning", showWarning) - sameLine() - checkbox("Show Error", showError) - checkbox("Show System", showSystem) - slider("Background Alpha", backgroundAlpha, 0.0f, 1.0f) - button("Clear") { clear() } - } - child("Log Content", extraFlags = noScroll) { - if (wrapText.get()) ImGui.pushTextWrapPos() + var flags = if (autoScroll) ImGuiWindowFlags.NoScrollbar or ImGuiWindowFlags.NoScrollWithMouse else 0 + flags = flags or ImGuiWindowFlags.NoBackground + child("Log Content", extraFlags = flags) { + if (wrapText) ImGui.pushTextWrapPos() logs.forEach { logEntry -> if (shouldDisplay(logEntry)) { @@ -124,9 +103,9 @@ class DebugLogger( } } - if (wrapText.get()) ImGui.popTextWrapPos() + if (wrapText) ImGui.popTextWrapPos() - if (autoScroll.get()) { + if (autoScroll) { ImGui.setScrollHereY(1f) } } @@ -134,11 +113,11 @@ class DebugLogger( fun shouldDisplay(logEntry: LogEntry) = when (logEntry.type) { - LogType.Debug -> showDebug.get() - LogType.Success -> showSuccess.get() - LogType.Warning -> showWarning.get() - LogType.Error -> showError.get() - LogType.System -> showSystem.get() + LogType.Debug -> showDebug + LogType.Success -> showSuccess + LogType.Warning -> showWarning + LogType.Error -> showError + LogType.System -> showSystem } fun clear() = logs.clear() diff --git a/src/main/kotlin/com/lambda/module/hud/ManagerDebugLoggers.kt b/src/main/kotlin/com/lambda/module/hud/ManagerDebugLoggers.kt index 702323aab..70173c704 100644 --- a/src/main/kotlin/com/lambda/module/hud/ManagerDebugLoggers.kt +++ b/src/main/kotlin/com/lambda/module/hud/ManagerDebugLoggers.kt @@ -42,6 +42,13 @@ object ManagerDebugLoggers : HudModule( private val loggers = mutableMapOf<() -> Boolean, DebugLogger>() + val autoScroll by setting("Auto-Scroll", true, "Locks the page at the bottom of the logs").group(Group.General) + val wrapText by setting("Wrap Text", true, "Wraps the logs to new lines if they go off the panel").group(Group.General) + val showDebug by setting("Show Debug", true, "Shows debug logs").group(Group.General) + val showSuccess by setting("Show Success", true, "Shows success logs").group(Group.General) + val showWarning by setting("Show Warning", true, "Shows warning logs").group(Group.General) + val showError by setting("Show Error", true, "Shows error logs").group(Group.General) + val showSystem by setting("Show System", true, "Shows system logs").group(Group.General) val maxLogEntries by setting("Max Log Entries", 100, 1..1000, 1, "Maximum amount of entries in the log").group(Group.General) .onValueChange { from, to -> if (to < from) {