Lucas Lopez

An NPC mod featuring: NPCs that move within a designated area (e.g., specifying via chat that "Jorge" should walk between coordinates x, y, and z). NPCs that respond to commands and conversations (e.g., telling "Jorge" to "come here" makes him approach you, or instructing him to "place [block] at [coordinates]" causes him to do so). NPCs that interact with one another (e.g., if "Jorge" is near "Maria," they can find topics to discuss, greet each other, and say goodbye when they part ways). NPCs capable of trading, including compatibility with other mods (e.g., if "Jorge" is a cook from the "Farmer's Delight" mod, he can trade items from the base game as well as cooking-related items and dishes from that mod). NPCs that can take poses (e.g., telling "Jorge" to "sit on the ground at [coordinates]," or—if a furniture mod is present—to "sit on the oak chair at [coordinates]"). Fully customizable NPCs (including skin, size, behavior, spontaneous actions, gender, etc.). Individual AI for each NPC (e.g., NPCs can engage in real-time conversational responses and perform autonomous actions, such as going fishing). NPCs that can be configured to either spawn naturally or not.

Kodari AI
KodariOct 30 at 6:55 pm 2
LivingNPCFramework
Adds fully customizable NPCs with individual AI, movement control, conversational responses, and autonomous behaviors. NPCs can be directed via chat commands to walk between coordinates, approach players, place blocks, sit in poses, and trade items including modded content. NPCs interact with each other through greetings, discussions, and farewells, and can spawn naturally or be manually placed.
  1. Set up the Fabric 1.20.4 project and an in-game /npc command system for creating named villagers, directing them, and making them speak.

  2. Add configurable player-created trades using registry item IDs, including items from installed mods.

  3. Keep natural spawning disabled by default; deliver a clear survival/usage summary and identify what this initial implementation does not provide, such as external real-time AI.

Created the Fabric 1.20.4 project with persistent, named villager NPCs. NPCs are created with /npc create <name> and don’t spawn naturally.

Commands include /npc come, /npc goto, /npc stop, /npc say, and /npc talk. Add trades with /npc trade <name> <buy-item-id> <buy-count> <sell-item-id> <sell-count>; item IDs can come from other installed mods.

This is a starter implementation, not the full feature set described: it doesn’t include custom skins, sizes or gender, sit poses, block placement, patrol routes, NPC-to-NPC conversations, natural-spawn controls, or real-time AI. The dialogue responses are scripted.

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

import com.mojang.brigadier.arguments.StringArgumentType;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.passive.VillagerEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.registry.Registries;
import net.minecraft.server.command.CommandManager;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
import net.minecraft.village.TradeOffer;

public class NpcAtelier implements ModInitializer {
    private static final String NPC_TAG = "npcatelier_npc";

    @Override
    public void onInitialize() {
        CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> dispatcher.register(
                CommandManager.literal("npc")
                        .executes(context -> {
                            feedback(context.getSource(), "NPC commands: create, come, goto, stop, say, talk, trade.");
                            return 1;
                        })
                        .then(CommandManager.literal("create")
                                .then(CommandManager.argument("name", StringArgumentType.word())
                                        .executes(context -> {
                                            ServerCommandSource source = context.getSource();
                                            ServerPlayerEntity player = source.getPlayerOrThrow();
                                            String name = StringArgumentType.getString(context, "name");
                                            VillagerEntity npc = EntityType.VILLAGER.create(source.getWorld());
                                            if (npc == null) {
                                                feedback(source, "Could not create that NPC.");
                                                return 0;
                                            }

                                            npc.refreshPositionAndAngles(player.getX(), player.getY(), player.getZ(), player.getYaw(), player.getPitch());
                                            npc.setCustomName(Text.literal(name));
                                            npc.setCustomNameVisible(true);
                                            npc.addCommandTag(NPC_TAG);
                                            npc.setPersistent();
                                            source.getWorld().spawnEntity(npc);
                                            feedback(source, "Created NPC " + name + ".");
                                            return 1;
                                        })))
                        .then(CommandManager.literal("come")
                                .then(CommandManager.argument("name", StringArgumentType.word())
                                        .executes(context -> {
                                            ServerCommandSource source = context.getSource();
                                            ServerPlayerEntity player = source.getPlayerOrThrow();
                                            VillagerEntity npc = findNpc(source.getWorld(), player, StringArgumentType.getString(context, "name"));
                                            if (npc == null) {
                                                feedback(source, "No matching NPC within 64 blocks.");
                                                return 0;
                                            }
                                            npc.getNavigation().startMovingTo(player, 1.0);
                                            feedback(source, npc.getCustomName().getString() + " is coming to you.");
                                            return 1;
                                        })))
                        .then(CommandManager.literal("goto")
                                .then(CommandManager.argument("name", StringArgumentType.word())
                                        .then(CommandManager.argument("x", StringArgumentType.word())
                                                .then(CommandManager.argument("y", StringArgumentType.word())
                                                        .then(CommandManager.argument("z", StringArgumentType.word())
                                                                .executes(context -> {
                                                                    ServerCommandSource source = context.getSource();
                                                                    ServerPlayerEntity player = source.getPlayerOrThrow();
                                                                    VillagerEntity npc = findNpc(source.getWorld(), player, StringArgumentType.getString(context, "name"));
                                                                    if (npc == null) {
                                                                        feedback(source, "No matching NPC within 64 blocks.");
                                                                        return 0;
                                                                    }
                                                                    try {
                                                                        double x = parseCoordinate(StringArgumentType.getString(context, "x"));
                                                                        double y = parseCoordinate(StringArgumentType.getString(context, "y"));
                                                                        double z = parseCoordinate(StringArgumentType.getString(context, "z"));
                                                                        npc.getNavigation().startMovingTo(x, y, z, 1.0);
                                                                        feedback(source, npc.getCustomName().getString() + " is heading to " + x + ", " + y + ", " + z + ".");
                                                                        return 1;
                                                                    } catch (IllegalArgumentException exception) {
                                                                        feedback(source, "Coordinates must be finite numbers within 30,000,000 blocks.");
                                                                        return 0;
                                                                    }
                                                                }))))))
                        .then(CommandManager.literal("stop")
                                .then(CommandManager.argument("name", StringArgumentType.word())
                                        .executes(context -> {
                                            ServerCommandSource source = context.getSource();
                                            ServerPlayerEntity player = source.getPlayerOrThrow();
                                            VillagerEntity npc = findNpc(source.getWorld(), player, StringArgumentType.getString(context, "name"));
                                            if (npc == null) {
                                                feedback(source, "No matching NPC within 64 blocks.");
                                                return 0;
                                            }
                                            npc.getNavigation().stop();
                                            feedback(source, npc.getCustomName().getString() + " stopped.");
                                            return 1;
                                        })))
                        .then(CommandManager.literal("say")
                                .then(CommandManager.argument("name", StringArgumentType.word())
                                        .then(CommandManager.argument("message", StringArgumentType.greedyString())
                                                .executes(context -> {
                                                    ServerCommandSource source = context.getSource();
                                                    ServerPlayerEntity player = source.getPlayerOrThrow();
                                                    VillagerEntity npc = findNpc(source.getWorld(), player, StringArgumentType.getString(context, "name"));
                                                    if (npc == null) {
                                                        feedback(source, "No matching NPC within 64 blocks.");
                                                        return 0;
                                                    }
                                                    feedback(source, "<" + npc.getCustomName().getString() + "> " + StringArgumentType.getString(context, "message"));
                                                    return 1;
                                                }))))
                        .then(CommandManager.literal("talk")
                                .then(CommandManager.argument("name", StringArgumentType.word())
                                        .then(CommandManager.argument("message", StringArgumentType.greedyString())
                                                .executes(context -> {
                                                    ServerCommandSource source = context.getSource();
                                                    ServerPlayerEntity player = source.getPlayerOrThrow();
                                                    VillagerEntity npc = findNpc(source.getWorld(), player, StringArgumentType.getString(context, "name"));
                                                    if (npc == null) {
                                                        feedback(source, "No matching NPC within 64 blocks.");
                                                        return 0;
                                                    }
                                                    String response = replyTo(StringArgumentType.getString(context, "message"));
                                                    feedback(source, "<" + npc.getCustomName().getString() + "> " + response);
                                                    return 1;
                                                }))))
                        .then(CommandManager.literal("trade")
                                .then(CommandManager.argument("name", StringArgumentType.word())
                                        .then(CommandManager.argument("buy_item", StringArgumentType.word())
                                                .then(CommandManager.argument("buy_count", StringArgumentType.word())
                                                        .then(CommandManager.argument("sell_item", StringArgumentType.word())
                                                                .then(CommandManager.argument("sell_count", StringArgumentType.word())
                                                                        .executes(context -> {
                                                                            ServerCommandSource source = context.getSource();
                                                                            ServerPlayerEntity player = source.getPlayerOrThrow();
                                                                            VillagerEntity npc = findNpc(source.getWorld(), player, StringArgumentType.getString(context, "name"));
                                                                            if (npc == null) {
                                                                                feedback(source, "No matching NPC within 64 blocks.");
                                                                                return 0;
                                                                            }

                                                                            Item buyItem = resolveItem(StringArgumentType.getString(context, "buy_item"));
                                                                            Item sellItem = resolveItem(StringArgumentType.getString(context, "sell_item"));
                                                                            int buyCount;
                                                                            int sellCount;
                                                                            try {
                                                                                buyCount = Integer.parseInt(StringArgumentType.getString(context, "buy_count"));
                                                                                sellCount = Integer.parseInt(StringArgumentType.getString(context, "sell_count"));
                                                                            } catch (NumberFormatException exception) {
                                                                                feedback(source, "Trade counts must be whole numbers from 1 to 64.");
                                                                                return 0;
                                                                            }

                                                                            if (buyItem == null || sellItem == null) {
                                                                                feedback(source, "Unknown item ID. Use a registry ID such as minecraft:emerald.");
                                                                                return 0;
                                                                            }
                                                                            if (buyCount < 1 || buyCount > 64 || sellCount < 1 || sellCount > 64) {
                                                                                feedback(source, "Trade counts must be from 1 to 64.");
                                                                                return 0;
                                                                            }

                                                                            npc.getOffers().add(new TradeOffer(
                                                                                    new ItemStack(buyItem, buyCount),
                                                                                    new ItemStack(sellItem, sellCount),
                                                                                    12,
                                                                                    0,
                                                                                    0.05f));
                                                                            feedback(source, "Added trade to " + npc.getCustomName().getString() + ".");
                                                                            return 1;
                                                                        })))))))
        ));
    }

    private static VillagerEntity findNpc(ServerWorld world, ServerPlayerEntity player, String name) {
        return world.getEntitiesByClass(
                        VillagerEntity.class,
                        player.getBoundingBox().expand(64.0),
                        npc -> npc.getCommandTags().contains(NPC_TAG)
                                && npc.getCustomName() != null
                                && npc.getCustomName().getString().equalsIgnoreCase(name))
                .stream()
                .findFirst()
                .orElse(null);
    }

    private static Item resolveItem(String itemId) {
        try {
            Item item = Registries.ITEM.get(new Identifier(itemId));
            return item == Items.AIR ? null : item;
        } catch (IllegalArgumentException exception) {
            return null;
        }