Skip to content

Creating Chat Responses

Setup

The chat responses API lets you easily create your own chat responses by inheriting from the ChatResponse class.

MyResponse.kt
package com.example.mymod.responses
import dev.wendigodrip.thebrokenscript.api.responses.ChatResponse
import net.minecraft.world.entity.player.Player
import net.minecraft.world.level.Level
class MyResponse : ChatResponse() {
// These are the pieces of text that will trigger the response.
// If any of these, not all of them, are found in the player's message,
// it will trigger.
override val triggers: List<String> = listOf("My Trigger 1", "My Trigger 2")
// level: The level the sender was in.
// sender: The player who sent the message.
override fun respond(level: Level, sender: Player) {
// Your code here...
}
}

There are a LOT of utilities in the base class, so I’d recommend taking a good look at the docs!

Registration

Don’t forget to register the response:

MyMod.kt
package com.example.mymod
import net.neoforged.fml.common.Mod
import thedarkcolour.kotlinforforge.neoforge.forge.MOD_BUS
import dev.wendigodrip.thebrokenscript.api.registry.RegistryWrapper
import com.example.mymod.responses.MyResponse
@Mod(MyMod.MOD_ID)
object MyMod {
const val MOD_ID: String = "my_mod"
val REGISTRAR = RegistryWrapper(MOD_ID)
init {
// Your code here...
// [ ID ] [Constructor]
REGISTRAR.chatResponse("my_response", ::MyResponse)
REGISTRAR.setup(MOD_BUS) // <- Make sure you register everything before calling setup()!
}
}

After registering, you can test your response by triggering it!

Customization

There’s a few variables you can modify in your chat responses that impact if, and how, it triggers.

Delay

You can customize how many ticks it will take for your response to be triggered.

Default: 0

MyResponse.kt
package com.example.mymod.responses
// ...
class MyResponse : ChatResponse() {
override val delay: Int = 100 // set your own number here
// ...
}

Case Sensitivity

You can customize whether the triggers should be case-sensitive or not. If this is set to true, the player must type your trigger with the correct capitalization to trigger it.

Default: false

MyResponse.kt
package com.example.mymod.responses
// ...
class MyResponse : ChatResponse() {
override val caseSensitive: Boolean = true
// ...
}

Full Message

Chat responses will by default assume that if any trigger is anywhere in a message, it will trigger. This can be turned off by setting isFullMessage to true, which means that any of the triggers must be same as the entire message the player typed for it to trigger.

Default: false

MyResponse.kt
package com.example.mymod.responses
// ...
class MyResponse : ChatResponse() {
override val isFullMessage: Boolean = true
// ...
}