Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions src/main/kotlin/com/lambda/module/Module.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,18 @@ import com.lambda.event.listener.Listener
import com.lambda.event.listener.SafeListener
import com.lambda.event.listener.SafeListener.Companion.listen
import com.lambda.event.listener.UnsafeListener
import com.lambda.module.modules.client.ModuleNotifier
import com.lambda.module.modules.client.ModuleNotifier.NotifyTarget
import com.lambda.module.modules.client.ModuleNotifier.notifyTarget
import com.lambda.module.tag.ModuleTag
import com.lambda.sound.LambdaSound
import com.lambda.sound.SoundManager.play
import com.lambda.threading.runSafe
import com.lambda.util.Communication.log
import com.lambda.util.KeyCode
import com.lambda.util.Nameable
import net.minecraft.text.Text
import net.minecraft.util.Colors

/**
* A [Module] is a feature or tool for the utility mod.
Expand Down Expand Up @@ -171,6 +178,22 @@ abstract class Module(

fun toggle() {
isEnabled = !isEnabled

if (ModuleNotifier.isEnabled) {
runSafe {
val message = if (isEnabled) {
Text.literal("on").withColor(Colors.GREEN)
} else {
Text.literal("off").withColor(Colors.RED)
}
if (notifyTarget.contains(NotifyTarget.Chat)) {
log(message, source = name)
}
if (notifyTarget.contains(NotifyTarget.ActionBar)) {
log(message, source = name, inGameOverlay = true)
}
}
}
}

fun onEnable(block: SafeContext.() -> Unit) {
Expand Down
36 changes: 36 additions & 0 deletions src/main/kotlin/com/lambda/module/modules/client/ModuleNotifier.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright 2026 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 <http://www.gnu.org/licenses/>.
*/

package com.lambda.module.modules.client

import com.lambda.module.Module
import com.lambda.util.Describable
import com.lambda.util.NamedEnum

@Suppress("unused")
object ModuleNotifier : Module(
name = "ModuleNotifier",
description = "Notifies you when a module is enabled or disabled",
tag = com.lambda.module.tag.ModuleTag.CLIENT
) {
var notifyTarget by setting("Notify Target", setOf<NotifyTarget>(NotifyTarget.ActionBar), NotifyTarget.entries.toSet(), description = "Where to send notifications when modules are toggled")

enum class NotifyTarget(override val displayName: String, override val description: String) : Describable, NamedEnum {
Chat("Chat", "Sends a message to chat when a module is toggled"),
ActionBar("Action Bar", "Sends a message to the action bar when a module is toggled"),;
}
}
27 changes: 26 additions & 1 deletion src/main/kotlin/com/lambda/util/Communication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import com.lambda.util.text.literal
import com.lambda.util.text.styled
import com.lambda.util.text.text
import net.minecraft.client.toast.SystemToast
import net.minecraft.text.MutableText
import net.minecraft.text.Text
import java.awt.Color
import java.time.LocalDateTime
Expand Down Expand Up @@ -96,18 +97,42 @@ object Communication {
}
}

/**
* Logs messages to the in game chat if available while stripping the message styles
*/
fun Any.log(
message: Text,
logLevel: LogLevel = LogLevel.Info,
source: String = "",
textSource: Text = Text.empty(),
inGameOverlay: Boolean = false
) {
buildText {
text(this@log.source(logLevel, source, textSource))
text(message)
}.let { log ->
runSafeGameScheduled {
player.sendMessage(log, false)
player.sendMessage(log, inGameOverlay)
}
}
}

/**
* Logs messages to the in game chat if available while keeping the message styles
*/
fun Any.log(
message: MutableText,
logLevel: LogLevel = LogLevel.Info,
source: String = "",
textSource: Text = Text.empty(),
inGameOverlay: Boolean = false
) {
buildText {
text(this@log.source(logLevel, source, textSource))
literal(message)
}.let { log ->
runSafeGameScheduled {
player.sendMessage(log, inGameOverlay)
}
}
}
Expand Down
16 changes: 16 additions & 0 deletions src/main/kotlin/com/lambda/util/text/TextDsl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ class TextBuilder {
this.text.append(style.applyTo(text))
}

@TextDsl
fun append(text: MutableText) {
this.text.append(text)
}

/**
* Returns the [Text] result of this builder.
*/
Expand Down Expand Up @@ -120,6 +125,17 @@ fun TextBuilder.literal(value: String) {
styleAndAppend(Text.literal(value))
}

/**
* Adds a literal text that is not re-styled by the builder's current style.
*
* @param value The text.
* @see StyleBuilder for action
*/
@TextDsl
fun TextBuilder.literal(value: MutableText) {
append(value)
}

/**
* Adds a literal text.
*
Expand Down