zayromc

create a fabric mod for Minecraft 1.21.11 that adds a command /show-title and when it is executed it runs give {player} apple 64

Kodari AI
KodariOct 14 at 3:43 pm 1
TitleCommandMod
Adds a custom /show-title command to Minecraft Fabric 1.21.11. When executed, the command grants the executing player 64 apples. The mod registers a server-side command handler, validates player context, and applies the item stack to the player's inventory. Includes proper command registration, permission checks, and feedback messages for successful execution or invalid usage scenarios.
  1. Register /show-title with Fabric’s server command callback.

  2. Have it run give <executing player> minecraft:apple 64 and add the minimal mod metadata.

Created the Fabric 1.21.11 mod. Players can run /show-title to receive 64 apples; the command runs vanilla give with server permissions.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
gradle.properties
settings.gradle
Code
5 98
src/main/java/com/kodari/showtitle/ShowTitleMod.java
package com.kodari.showtitle;

import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
import net.minecraft.server.command.CommandManager;
import net.minecraft.server.command.ServerCommandSource;

public class ShowTitleMod implements ModInitializer {
    @Override
    public void onInitialize() {
        CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) ->
                dispatcher.register(CommandManager.literal("show-title")
                        .executes(context -> {
                            ServerCommandSource playerSource = context.getSource();
                            playerSource.getPlayerOrThrow();
                            playerSource.getServer().getCommandManager().parseAndExecute(
                                    playerSource.getServer().getCommandSource(),
                                    "give " + playerSource.getName() + " minecraft:apple 64"
                            );
                            return 1;
                        }))
        );
    }
}