VANSH.CC
SYS / CODECRAFT · FABRIC 1.21.1 · JDK 21
Source
SHEET 01 — MINECRAFT MOD REV 1.0 · MIT

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.

JAVA 21 FABRIC 1.21.1 LESSONS 18 TRACKS 3 GRADLE + LOOM
FIG. A — EXECUTION PATH SCALE 1:1
01 Editor In-game screen
02 javac In memory
03 Loader Knot-aware
invoke
04 Playground No MC types
05 Server thread Marshalled
06 The world Blocks move
Compile 5 s timeout Run
BUILT ON Fabric Loader Fabric API javax.tools Gradle Loom Gson
02

Why it is built this way

4 NOTES
FIG. 01NO ALT-TAB

The 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
FIG. 02REAL COMPILER

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
FIG. 03CURRICULUM

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
FIG. 04SELF-TEST

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
03

The editor

FIG. 05
CODECRAFT — IN-GAME SCREEN TRACK: CODED BEFORE
Core Java
✓Methods
✓Arrays
✓Nested Loops
●Lists
●Classes
●Inheritance
Advanced
●Maps
●Exceptions
●Generics
●Lambdas
public class Lesson { public static void main(String[] args) { int size = 7; int placed = 0; // A loop inside a loop sweeps a 2D area: // every x, and for each x, every z. for (int x = 0; x < size; x++) { for (int z = 0; z < size; z++) { Playground.placeBlock(x, 0, z, "polished_andesite"); placed++; } } System.out.println("placed " + placed + " blocks"); Playground.say("Platform built."); } }
> NESTED LOOPS — CONTROL FLOW Put a loop inside a loop and you sweep a whole 2D area. A 7 by 7 area means the inner body runs 49 times. ▸ compiled in 210 ms placed 49 blocks ✓ finished — lesson complete
Run ▶ Reset 49 blocks placed in front of you
04

What it teaches

18 UNITS

On 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.

TABLE 01 — EXPERIENCE TRACKS
TrackStarts atUnits
New to codeFundamentals — what a variable is18
Coded beforeCore Java — methods, arrays, classes13
Know JavaAdvanced — maps, generics, streams7
01Hello WorldF
02VariablesF
03MathF
04ConditionalsF
05LoopsF
06Nested LoopsC
07MethodsC
08ArraysC
09ListsC
10ClassesC
11InheritanceC
12Maps & CountingA
13ExceptionsA
14GenericsA
15LambdasA
16StreamsA
17RecursionA
18Capstone — a baseA

F — FUNDAMENTALS  ·  C — CORE JAVA  ·  A — ADVANCED

05

Playground API

12 CALLS

Lesson 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.

TABLE 02 — WORLD CALLS
CallEffect
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
06

How it works

NOTES
NOTE ACOMPILE

Source 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.

NOTE BCLASSPATH

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.

NOTE CBOUNDARY

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.

NOTE DDATA

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.

07

Run it yourself

SETUP

REQUIREMENTS

  • 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
08

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.

+ · + · + · + · + · + · + · + · + · + · + · + · + · + · + · +