Player 2 AI NPC: What It Is and How to Build Your Own

By Arron R.10 min read
Player 2 AI NPC refers to Player2NPC, a Minecraft companion mod that uses the Player2 API to read your chat and turn it into real in-game actions, like gatherin

What is Player 2 AI NPC?

Player 2 AI NPC is the name most players use for Player2NPC, a Minecraft mod by the developer Goodbird that lets you summon AI companions you talk to in ordinary chat, and who then go and do what you asked. An NPC, or non-player character, is any character the game controls rather than a human. What makes this one interesting is that you do not pick from a dialogue menu: you type “can you grab me some wood?” and the companion walks off, chops trees and fills its inventory.

According to the Player2NPC repository on GitHub, the mod was built for the Player2 AI Game Jam as a showcase of a framework called PlayerEngine. The “thinking” comes from the Player2 API, which runs a large language model (LLM, the same kind of AI behind chat assistants) to interpret your message. The “doing” comes from PlayerEngine, which gives an ordinary mob the abilities of a player: an inventory, block breaking and placing, item use and pathfinding.

That split matters, and it is the reason the Player 2 AI NPC mod gets attention. Game AI has traditionally meant hand-built systems. The Wikipedia overview of artificial intelligence in video games describes how most NPC behaviour has historically been scripted patterns and finite-state machines (a set of modes such as “chase” and “flee” with rules for switching between them), from Pac-Man’s ghosts with their distinct personalities to strategy-game units. Player2NPC keeps that dependable game logic and puts a language model on top of it as the decision-maker.

How the Player2NPC mod works under the hood

You do not need to read Java to understand the design, but it helps to know the moving parts, because the same structure is how you would build an AI NPC in any engine.

The body: a mob that behaves like a player

The companion is a custom entity that implements a handful of PlayerEngine interfaces. One marks it as a controllable agent, one grants a persistent player-style inventory, one lets it break and place blocks and use items, and one adds a hunger system. Those abilities are attached as modular components using a library called Cardinal Components, so a modder can make their own mob player-like by registering the same components on their entity class.

The legs: pathfinding

Movement and navigation come from Automatone, a version of the Baritone pathfinding system. Pathfinding is the code that works out a route from A to B around obstacles. Because of that, the companion does not teleport to a tree: it walks there like a player would.

The brain: the language-to-action loop

When you type a message, the repository describes a loop that looks like this:

  1. You write something in chat, for example “hey, can you get me some logs?”
  2. The Player2 API (the LLM) turns that into a short command, such as get oak_log 10.
  3. A controller called AltoClefController receives the command.
  4. Its task system creates the matching task, in this case a mine-and-collect task.
  5. The entity carries the task out in the world, guided by the pathfinder.

The key design choice: the LLM never moves the character directly. It only produces a goal. Deterministic code (code that gives the same result every time for the same input) decides how to reach that goal. The project calls this layer a guardrail, and it is why the companion does not glitch through walls or invent items it does not have.

One more detail worth knowing for servers: the companions are independent server-side entities, not bots running on separate copies of the game client. That keeps them lighter and easier to manage on a multiplayer world.

Diagram of the AI NPC loop from player chat to language model command to task to in-game action
The language model picks the goal; ordinary game code carries it out.

How to install and use Player 2 AI NPC in Minecraft

The repository describes how to use the mod once it is running; it does not lay out a full install walkthrough. Here is what you can count on, and what to check.

What you need

  • Minecraft: Java Edition. Player2NPC is written in Java and built with Gradle, the standard setup for Java Edition mods. Install the Minecraft version and mod loader that the project’s releases specify, then place the mod file in your mods folder.
  • Access to the Player2 API. The companions’ understanding of your messages comes from Player2, so Player2 needs to be set up alongside the mod. Without it, the body still exists but nothing is thinking.

Using it in game

  1. Press H to open the character selection menu.
  2. Pick a companion; each has its own personality and appearance.
  3. Summon it, then talk to it in chat in plain language.
  4. Give it jobs: gather a set number of a resource, deal with a nearby mob, or stay by your side.

Bedrock, Pocket Edition and APK files

Bedrock Edition, including the mobile version long known as Pocket Edition, uses a different add-on system from Java Edition, so a Java mod like this one will not load there. The repository does not offer an Android build either. If you find an APK file advertising itself as Player 2 AI NPC, be cautious: unofficial installers are a classic malware route. Stick to the developer’s repository or the official Player2 platform.

Player2 also hosts AI mods for other games beyond Minecraft. If you are after AI companions in a different title, check its current catalogue rather than trusting reposted downloads.

Player 2 AI NPC compared with traditional NPC AI

It helps to see where an LLM-driven companion fits next to the two other common approaches: classic scripted AI, and a “chatbot in a box” NPC that can talk but cannot act.

Scripted NPC AI (state machines, behaviour trees)Chatbot-only NPCLLM plus action layer (Player 2 AI NPC style)
Understands free-text requestsNo, only menu choices or triggersYesYes
Changes the game worldYes, in pre-planned waysNo, it only repliesYes, through approved actions
PredictabilityHighLow: may promise things the game cannot doMedium to high: the action layer enforces rules
Response speedInstantWaits on the modelWaits on the model for decisions, then runs at game speed
Running costNone beyond your gameModel callsModel calls
Effort to buildGrows with every behaviourLowModerate: you write the actions once, the model chooses among them

Language-model characters are not brand new. AI Dungeon is a text adventure where AI generates the story as you play. What the Player 2 AI NPC approach adds is a body: the model’s output drives real systems with real constraints, so the character participates in the game instead of narrating it.

How to build your own AI NPC (with JavaScript code)

You can copy the Player2NPC pattern in any engine, no Minecraft required. The recipe has four parts:

  1. A whitelist of actions. Write each thing the NPC can do as normal game code: follow, gather, attack, wait.
  2. A prompt that asks for structure. Tell the model the available actions and ask it to reply with JSON only, for example {"action":"gather","item":"wood","count":10}.
  3. Validation. Parse the reply, reject unknown actions, clamp numbers and fall back to something safe.
  4. Execution. Run the matching function and show the NPC’s reply.

Here is a complete, runnable example in plain JavaScript. The askModel function is a stand-in so the file runs without a key; in a real game you would replace its body with a call to your LLM, sent from your own server so the API key stays private.

const world = {
  player: { x: 0, y: 0 },
  resources: { wood: 25, stone: 8 },
  enemies: [{ id: "zombie-1", hp: 3 }]
};

const npc = { name: "Bram", mode: "idle", inventory: {} };

// The guardrail: the only things the NPC is allowed to do.
const ACTIONS = {
  follow(npc) {
    npc.mode = "follow";
    return "Right behind you.";
  },
  gather(npc, { item, count }) {
    const available = world.resources[item];
    const taken = Math.min(available, count);
    world.resources[item] = available - taken;
    npc.inventory[item] = (npc.inventory[item] || 0) + taken;
    return taken > 0 ? `Got ${taken} ${item}.` : `There's no ${item} left.`;
  },
  attack() {
    const enemy = world.enemies.find((e) => e.hp > 0);
    if (!enemy) return "Nothing to fight.";
    enemy.hp = 0;
    return `Took care of ${enemy.id}.`;
  },
  idle(npc) {
    npc.mode = "idle";
    return "Okay, I'll wait here.";
  }
};

const SYSTEM_PROMPT =
  "You control a companion NPC. Reply with JSON only. " +
  'Allowed: {"action":"follow"}, {"action":"attack"}, {"action":"idle"}, ' +
  '{"action":"gather","item":"wood|stone","count":number}, ' +
  '{"action":"chat","reply":"text"}';

// Stand-in for a real LLM call that would send SYSTEM_PROMPT + message.
async function askModel(message) {
  const m = message.toLowerCase();
  if (m.includes("wood") || m.includes("log")) {
    const n = parseInt((m.match(/\d+/) || ["5"])[0], 10);
    return JSON.stringify({ action: "gather", item: "wood", count: n });
  }
  if (m.includes("zombie") || m.includes("attack")) return '{"action":"attack"}';
  if (m.includes("follow") || m.includes("stick with me")) return '{"action":"follow"}';
  return '{"action":"chat","reply":"Not sure what you mean."}';
}

function validate(raw) {
  let cmd;
  try {
    cmd = JSON.parse(raw);
  } catch {
    return { action: "idle" };
  }
  if (cmd.action === "chat") return { action: "chat", reply: String(cmd.reply || "...") };
  if (!(cmd.action in ACTIONS)) return { action: "idle" };
  if (cmd.action === "gather") {
    if (!(cmd.item in world.resources)) return { action: "chat", reply: "I can't find that." };
    cmd.count = Math.max(1, Math.min(Number(cmd.count) || 1, 64));
  }
  return cmd;
}

async function talkToNpc(message) {
  const cmd = validate(await askModel(message));
  const reply = cmd.action === "chat" ? cmd.reply : ACTIONS[cmd.action](npc, cmd);
  console.log(`You: ${message}\n${npc.name}: ${reply}`);
}

(async () => {
  await talkToNpc("can you get me 10 wood?");
  await talkToNpc("take care of that zombie!");
  await talkToNpc("stick with me");
  console.log(npc.inventory, world.resources);
})();

Notice that the model never edits world directly. Even if it hallucinates (makes up) an item called “diamonds” or asks for a million logs, validation catches it. That is the same principle the Player2NPC guardrail uses, scaled down to a page of code.

JavaScript code for an AI NPC action whitelist next to a 2D game where the NPC follows the player
A whitelist of actions plus validation is the guardrail that keeps an AI NPC inside the rules.

Building an AI NPC game in WizardGenie

If you would rather describe the game than hand-write the plumbing, WizardGenie is the AI game engine inside Sorceress: you describe the game you want, and it writes, runs and iterates on the code with you. It runs in the browser with nothing to install, and as a Windows desktop app with an auto-updater that gives native file access and longer agent sessions, which helps on bigger projects like an NPC system with several actions.

A practical way to use it for this job:

  1. Describe the loop, not just the character. For example: “Top-down 2D game. A companion NPC follows the player. When the player types in a chat box, send the message to a language model, expect JSON with one of follow, gather, attack or idle, validate it against a whitelist and run the action. Show a ‘thinking’ bubble while waiting.”
  2. Iterate on behaviour. Ask for one change at a time: add a new action, cap gather counts, make the NPC refuse to leave a safe zone at night. Run it after each step.
  3. Pick your model. WizardGenie works with the leading AI coding models, and you can switch models with your own API key.

Then give the companion a look and a voice. Auto-Sprite v2 (Pro) creates game-ready 2D sprites of any character in any art style, including the animations a follower needs. For a 3D game, 3D Studio goes from a typed idea to a fully rigged, fully animated 3D character. Sound Studio covers AI music, sound effects and text-to-speech with voice cloning, so your companion can have a voice that matches its personality. If you prefer another coding agent, the Sorceress API gives it one key to generate those same assets. For writing the NPC’s lines and personality notes, see our guide to AI game script generators, and browse every Sorceress tool in one guide for the rest of the pipeline.

Common mistakes when making AI NPCs

  • Letting the model touch game state. If raw model text can spawn items or move characters, players will break it within minutes. Always route through a whitelist, like the Player2NPC action layer.
  • No fallback. Models sometimes return malformed JSON or nothing at all. Default to a safe action such as idle and a short canned line.
  • Ignoring latency. Model replies are not instant. Show a thinking animation or have the NPC say “one sec” so the pause reads as character, not lag.
  • Shipping your API key. A key embedded in browser code can be copied by anyone. Proxy calls through your own server.
  • Personality drift. Long conversations wander. Keep a short, fixed character description in every request and trim old messages.
  • Using AI as the whole game. A talking NPC with nothing meaningful to do feels like a gimmick, the kind of low-effort output people call AI slop. The NPC should change the game: gather, guard, trade, refuse. Design the actions first, then let the model choose among them.

The workflow at a glance

Player 2 AI NPC is a good model to study even if you never install it: a language model for understanding, and plain game code for acting. To get the same result in your own project:

  1. Try Player2NPC in Minecraft: Java Edition to feel how chat-driven companions play.
  2. List the four to six actions your NPC truly needs.
  3. Write a prompt that forces structured JSON, then validate every reply.
  4. Build the loop in WizardGenie, or start from the JavaScript above.
  5. Generate the NPC’s sprites, model and voice with Auto-Sprite v2, 3D Studio and Sound Studio.
  6. Playtest for broken requests, slow replies and personality drift, then export your build and host it wherever you like.

Get the guardrail right and the rest is creative work: deciding who your companion is and what it will, and will not, do for the player.

Frequently Asked Questions

What is Player 2 AI NPC?

Player 2 AI NPC usually means Player2NPC, a Minecraft mod by Goodbird built for the Player2 AI Game Jam. It lets you summon AI companions, talk to them in normal chat, and give them tasks such as gathering resources, attacking mobs or following you. The Player2 API interprets your message, and the PlayerEngine framework turns that interpretation into actual actions in the world.

Does Player 2 AI NPC work on Minecraft Bedrock or Pocket Edition?

The Player2NPC project is written in Java and built with Gradle, which is how Minecraft: Java Edition mods are made. Bedrock Edition, including the mobile version once called Pocket Edition, uses a different add-on system, so a Java mod will not load there. If you want this kind of companion on Bedrock, you would need a separate project built for that platform.

Is there an official Player 2 AI NPC APK for Android?

The mod’s public repository is a Java Edition Minecraft mod, not an Android app, and it does not point to an APK. Treat any APK file that claims to be Player 2 AI NPC with suspicion, because unofficial installers are a common way to spread malware. Get mods only from the developer’s repository or the official Player2 platform.

How do AI NPCs actually perform actions instead of just chatting?

The reliable pattern is to split the job in two. A language model reads the player’s message and outputs a short, structured command, such as “get oak_log 10”. Ordinary game code then checks that command and executes it with normal systems like pathfinding, inventory and combat. The model decides what to do; deterministic code decides how, which keeps the NPC from breaking game rules.

Can I make my own game with AI NPCs without being a modder?

Yes. You do not need Minecraft or Java to use the same idea. Any game can send player chat to a language model, ask for a JSON command, validate it and run it. An AI game engine like WizardGenie can write that loop for you from a plain-language description, and you can generate the NPC’s sprites, 3D model and voice with other Sorceress tools.

What are some games with AI NPCs?

AI-driven characters go back decades: Pac-Man gave each ghost its own chase behaviour, and Façade (2005) built a drama around open-ended conversation. AI Dungeon is a text adventure where a language model generates the story as you play. Mods like Player2NPC bring language-model companions into existing games such as Minecraft, where they can act on what you say.

Sources

  1. Player2NPC. This is not just another companion ...
  2. Artificial intelligence in video games — Wikipedia
  3. AI Dungeon — Wikipedia
  4. AI slop — Wikipedia
Written by Arron R.·2,300 words·10 min read

Related posts