Learn Java inside Minecraft
A Fabric mod that puts a real code editor in the game window — no alt-tabbing to a browser. It compiles what you type at runtime and runs it against the world you are standing in. Write a loop, press Run, watch a tower go up in front of you.
Why it is built this way
4 NOTESThe editor is a game screen
Not a localhost page sitting next to the game. You never leave the window, so the gap between writing a line and seeing it happen is one keypress wide.
- Open with
- G / /codecraft
- Panes
- List · Code · Console
Real Java, really compiled
Not a block editor and not a scripting DSL. Source goes through
javax.tools.JavaCompiler exactly as javac would, so the
compiler errors you learn to read are the real ones.
- Needs
- JDK, not JRE
- Timeout
- 5 s daemon
The whole language
Not limited to the parts that touch Minecraft. Exceptions, generics, lambdas, streams and recursion are all in there — the world is just what makes them visible.
- Lessons
- 18
- Levels
- 3
Verified by playing itself
A marker file arms an in-game self-test: it opens the screens, exercises the command, scrolls the list, saves screenshots, then compiles and runs every lesson against a live world, timing each.
- Coverage
- 18 / 18
- Slowest
- 930 ms
The editor
FIG. 05What it teaches
18 UNITSOn first open it asks how much Java you already know. Your answer only sets where the lesson list starts — nothing is deleted, and the Track button switches at any time.
| Track | Starts at | Units |
|---|---|---|
| New to code | Fundamentals — what a variable is | 18 |
| Coded before | Core Java — methods, arrays, classes | 13 |
| Know Java | Advanced — maps, generics, streams | 7 |
F — FUNDAMENTALS · C — CORE JAVA · A — ADVANCED
Playground API
12 CALLSLesson code calls Playground to
touch the world. Every position is a relative offset from where you are standing, so
(0, 1, 0) is the block above your head.
| Call | Effect |
|---|---|
| say(text) | Chat message to yourself |
| showTitle(text) | Flash text above the hotbar |
| placeBlock(dx, dy, dz, id) | Place a block, e.g. "stone" |
| breakBlock(dx, dy, dz) | Replace a block with air |
| getBlock(dx, dy, dz) | Read a block id back out of the world |
| spawnEntity(dx, dy, dz, id) | Spawn a mob, e.g. "cow" |
| teleportPlayer(dx, dy, dz) | Move yourself |
| particles(dx, dy, dz, id, n) | Spray particles |
| giveItem(id, count) | Put an item in your inventory |
| playSound(id) | Play a sound at your feet |
| playerX() / playerY() / playerZ() | Your current world coordinates |
| isDay() | Whether it is daytime |
How it works
NOTESSource is compiled in memory: a ForwardingJavaFileManager captures the
.class bytes, a small classloader picks them up, and the program runs on a
timeboxed daemon thread.
A Fabric mod's classes are loaded by Knot, not from java.class.path
— so javac cannot find Playground on a normal classpath. The file
manager hands those classes to the compiler straight out of the mod's own loader.
The whole Playground surface is deliberately free of Minecraft types, for
the same reason. The Minecraft-aware implementation sits behind an interface, and calls
are marshalled onto the server thread before they touch a block.
Lessons are data, not code: a .json of explanation paragraphs beside a
real .java starter file. Adding one is two files and an index entry —
the level field decides which tracks show it.
Run it yourself
SETUPREQUIREMENTS
- Minecraft Java Edition 1.21.1
- Fabric Loader 0.19.3+ and Fabric API
- A JDK 21 — not just a JRE. CodeCraft compiles at runtime and needs a real compiler on hand.
- Join a singleplayer world, then press G or run
/codecraft.
FROM SOURCE
$ git clone https://github.com/vanshxnar/codecraft $ cd codecraft $ ./gradlew build # jar in build/libs $ ./gradlew runClient # dev client, mod loaded
Scope and limits
READ THIS- Singleplayer only. World calls run against the integrated server.
- Not sandboxed. Submitted code runs with the game's permissions, guarded only by a timeout. Built for one learner running their own code locally — not a public server accepting code from strangers.
- A tight infinite loop cannot be force-killed. It is abandoned as a daemon thread, and you are told so.
LICENCE & TRADEMARKS
MIT. Not affiliated with or endorsed by Mojang or Microsoft. CodeCraft ships no Minecraft assets — it uses only the public Fabric modding API, against a copy of the game you already own.