MinecraftScripterAI
Discord ↗
Link Copied to Clipboard
×
"create a lava block when the player says "im spongebob" in chat"
/* To create a lava block when a player says "im spongebob" in chat, you need to listen for the ServerChatEvent and check the message. If it matches, place a lava block at the player's position. */ import net.minecraft.block.Blocks; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import net.minecraftforge.event.ServerChatEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod; @Mod.EventBusSubscriber public class ChatListener { @SubscribeEvent public static void onPlayerChat(ServerChatEvent event) { /* Check if the message is "im spongebob" */ if (event.getMessage().equalsIgnoreCase("im spongebob")) { /* Get the player's position and world */ BlockPos playerPos = event.getPlayer().blockPosition(); World world = event.getPlayer().level; /* Set the block at the player's position to lava */ world.setBlock(playerPos, Blocks.LAVA.defaultBlockState(), 2); } } }