Skip to content

Instantly share code, notes, and snippets.

@Norbiros
Created May 24, 2022 07:18
Show Gist options
  • Save Norbiros/ba30e0575c3a0123ae56a668a666952a to your computer and use it in GitHub Desktop.
Save Norbiros/ba30e0575c3a0123ae56a668a666952a to your computer and use it in GitHub Desktop.
This is simple example, that shows how to create auto reply bot in Minecraft Forge 1.18.2
import net.minecraftforge.client.event.ClientChatReceivedEvent;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import net.minecraftforge.event.entity.player.AttackEntityEvent;
import net.minecraftforge.eventbus.api.EventPriority;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraft.client.Minecraft;
import net.minecraft.client.player.LocalPlayer;
@Mod.EventBusSubscriber(modid = SkytopAutomizer.MOD_ID, bus = Mod.EventBusSubscriber.Bus.FORGE, value = Dist.CLIENT)
public class FastMath {
@SubscribeEvent
public static void onClientChat(ClientChatReceivedEvent event) {
String keyword = "msg";
// In newest version you need to use getString() method
if (event.getMessage().getString().contains(keyword)) {
Minecraft.getInstance().player.chat("/reply hi");
// You need to use chat method, not sendMessage (or addMessage)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment