Creating Chat Responses
Setup
The chat responses API lets you easily create your own chat responses by inheriting from the ChatResponse class.
package com.example.mymod.responses
import dev.wendigodrip.thebrokenscript.api.responses.ChatResponseimport net.minecraft.world.entity.player.Playerimport 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... }}
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;import java.util.List;
public class MyResponse extends ChatResponse { @Override public List<String> getTriggers() { // 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. return List.of("My Trigger 1", "My Trigger 2"); }
// level: The level the sender was in. // sender: The player who sent the message. @Override public void respond(Level level, Player sender) { // 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:
package com.example.mymod
import net.neoforged.fml.common.Modimport thedarkcolour.kotlinforforge.neoforge.forge.MOD_BUSimport dev.wendigodrip.thebrokenscript.api.registry.RegistryWrapperimport 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()! }}
package com.example.mymod;
import net.neoforged.fml.ModContainer;import net.neoforged.fml.common.Mod;import net.neoforged.bus.api.IEventBus;import dev.wendigodrip.thebrokenscript.api.registry.RegistryWrapper;import com.example.mymod.responses.MyResponse;
@Mod(MyMod.MOD_ID)public class MyMod { public static final String MOD_ID = "my_mod"; public static final RegistryWrapper REGISTRAR = new RegistryWrapper(MOD_ID);
public MyMod(IEventBus bus, ModContainer mod) { // Your code here...
// [ ID ] [Constructor] REGISTRAR.chatResponse("my_response", MyResponse::new); REGISTRAR.setup(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
package com.example.mymod.responses
// ...
class MyResponse : ChatResponse() { override val delay: Int = 100 // set your own number here
// ...}
package com.example.mymod.responses;
// ...
public class MyResponse extends ChatResponse { @Override public int getDelay() { return 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
package com.example.mymod.responses
// ...
class MyResponse : ChatResponse() { override val caseSensitive: Boolean = true
// ...}
package com.example.mymod.responses;
// ...
public class MyResponse extends ChatResponse { @Override public boolean getCaseSensitive() { return 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
package com.example.mymod.responses
// ...
class MyResponse : ChatResponse() { override val isFullMessage: Boolean = true
// ...}
package com.example.mymod.responses;
// ...
public class MyResponse extends ChatResponse { @Override public boolean isFullMessage() { return true; }
// ...}