Note: Most of this article was written by AI.

Introduction

For the purpose of learning Minecraft Mod development, I created a Mod that generates a castle with a single command.

Development Environment

The technology stack used:

  • Minecraft: 1.21
  • Modding Framework: Fabric Mod
  • Java: 21
  • Development Environment: Cursor (AI-integrated editor)
  • AI Assistance: Claude 4 Sonnet

Environment Setup

Java 21 installation was needed, so I installed it with Homebrew:

brew install openjdk@21

Project initialization was done by cloning Fabric’s official template:

git clone https://github.com/FabricMC/fabric-example-mod.git castle-mod
Cloning into 'castle-mod'...
remote: Enumerating objects: 930, done.
remote: Counting objects: 100% (47/47), done.
remote: Compressing objects: 100% (30/30), done.
remote: Total 930 (delta 33), reused 17 (delta 17), pack-reused 883 (from 3)
Receiving objects: 100% (930/930), 588.77 KiB | 10.51 MiB/s, done.
Resolving deltas: 100% (404/404), done.

Then, I launched the development environment with Cursor:

cd castle-mod
cursor .

Castle Design

I asked claude-4-sonnet with the following instructions:

I want to add a command to create a Western-style castle

  • Thick stone walls
  • Towers
  • Castle walls
  • Drawbridge and gate
  • Small windows
  • Battlements (crenellations on castle walls)
  • More rectangular structure

Implementation

Creating a Blueprint with Arrays

Rather than manually placing blocks, I created a blueprint using arrays:

// 0=空気, 1=石垣, 2=木材, 3=白い壁, 4=金装飾, 5=瓦屋根, 6=窓, 7=入口...
private static final int[][][] CASTLE_BLUEPRINT = {
    createLayer1(), // 29x29の基礎
    createLayer2(), // 27x27の2層目
    // ...
};

Placing Blocks

Actual blocks are placed according to the numbers:

switch (blockType) {
    case 1: // 石垣
        world.setBlockState(pos, Blocks.COBBLESTONE.getDefaultState());
        break;
    case 6: // 窓
        world.setBlockState(pos, Blocks.GLASS_PANE.getDefaultState());
        break;
    // ...
}

Usage

  1. Install the Mod
./gradlew runClient
  1. Execute the /western-castle command in-game

  1. A castle is generated at the player’s position

When I launched Minecraft in the development environment and executed the command…

[Server thread/INFO] [Player:城が生成されました!]

The castle was successfully generated!

Summary

By combining with AI tools, I was able to easily verify the implementation.

Building on this experience, I would like to try creating other structures and Mods with more advanced features in the future!