CoolFace
Modelpublic

hwding/forge-coder-v1.21.11

sourceHugging Faceotherupdated 9mo agoView on Hugging Face
2likes19downloads
Model Card

<div align="center"> <h1>๐Ÿ”จ Forge Coder v1.21.11</h1> <p><strong>A Specialized Code Generation Model for Minecraft Forge Mod Development</strong></p> <p> <a href="#quickstart">Quick Start</a> โ€ข <a href="#capabilities">Capabilities</a> โ€ข <a href="#examples">Examples</a> โ€ข <a href="#training">Training Details</a> </p> </div>


Overview

Forge Coder is a fine-tuned large language model specifically designed to assist developers in creating Minecraft Forge mods. Built on top of DeepSeek Coder 6.7B, this model has been trained on extensive Forge mod source code and documentation to provide accurate, idiomatic, and up-to-date code generation for Minecraft modding.

Key Features

  • โ€”๐ŸŽฏ Specialized Knowledge: Deep understanding of Forge API, registry systems, and modding patterns
  • โ€”๐Ÿ”„ Version-Aligned: Trained specifically for Minecraft 1.21.11 and Forge 1.21.11
  • โ€”๐Ÿ’ก Code Completion: Generate complete mod components from natural language descriptions
  • โ€”๐Ÿ“š Best Practices: Follows modern Forge modding conventions and patterns

Model Details

PropertyValue
Base Modeldeepseek-ai/deepseek-coder-6.7b-instruct
Fine-tuning MethodQLoRA (4-bit quantization + LoRA)
LoRA Rank64
LoRA Alpha128
Trainable Parameters159.9M (2.3% of 6.7B)
Target Forge Version1.21.11
Target Minecraft Version1.21.11
MCP Mappings20251209.095502

Quickstart

Installation

bash
pip install transformers peft accelerate bitsandbytes torch

Basic Usage

python
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
from peft import PeftModel

# Quantization config for efficient inference
bnb_config = BitsAndBytesConfig(
    load_in_4bit=True,
    bnb_4bit_quant_type="nf4",
    bnb_4bit_compute_dtype=torch.bfloat16,
    bnb_4bit_use_double_quant=True,
)

# Load model
base_model_id = "deepseek-ai/deepseek-coder-6.7b-instruct"
adapter_id = "hwding/forge-coder-v1.21.11"

tokenizer = AutoTokenizer.from_pretrained(adapter_id)
model = AutoModelForCausalLM.from_pretrained(
    base_model_id,
    quantization_config=bnb_config,
    device_map="auto",
)
model = PeftModel.from_pretrained(model, adapter_id)

# Generate code
def generate_forge_code(prompt: str, max_tokens: int = 1024) -> str:
    messages = f"""### System:
You are an expert Minecraft Forge mod developer for version 1.21.11. Write clean, efficient, and well-structured Java code.

### User:
{prompt}

### Assistant:
"""
    inputs = tokenizer(messages, return_tensors="pt").to(model.device)
    outputs = model.generate(
        **inputs,
        max_new_tokens=max_tokens,
        temperature=0.7,
        top_p=0.95,
        do_sample=True,
        pad_token_id=tokenizer.eos_token_id,
    )
    return tokenizer.decode(outputs[0], skip_special_tokens=True)

# Example
code = generate_forge_code("Create a custom ore block that drops experience when mined")
print(code)

Capabilities

The model excels at generating code for various Forge mod components:

CategoryExamples
BlocksCustom blocks, ore blocks, machine blocks, multi-blocks
ItemsTools, weapons, armor, food items, custom items
EntitiesMobs, projectiles, vehicles, tile entities
GUI/ScreensContainer menus, custom screens, HUD elements
NetworkingPacket handling, client-server sync
World GenerationOre generation, structures, biomes, features
EventsForge event handlers, lifecycle events
RegistriesDeferredRegister patterns, registry objects
CapabilitiesCustom capabilities, capability providers
RecipesCustom recipe types, recipe serializers
Data GenerationDatagen for models, blockstates, loot tables, tags
RenderingBlock/item/entity renderers, shaders

Examples

Creating a Custom Block

Prompt: "Create a copper lamp block that emits light when powered by redstone"

java
public class CopperLampBlock extends Block {
    public static final BooleanProperty LIT = BlockStateProperties.LIT;
    
    public CopperLampBlock(Properties properties) {
        super(properties);
        this.registerDefaultState(this.stateDefinition.any().setValue(LIT, false));
    }
    
    @Override
    protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
        builder.add(LIT);
    }
    
    @Override
    public void neighborChanged(BlockState state, Level level, BlockPos pos, 
                                Block block, BlockPos fromPos, boolean isMoving) {
        if (!level.isClientSide) {
            boolean powered = level.hasNeighborSignal(pos);
            if (powered != state.getValue(LIT)) {
                level.setBlock(pos, state.setValue(LIT, powered), 2);
            }
        }
    }
    
    @Override
    public int getLightEmission(BlockState state, BlockGetter level, BlockPos pos) {
        return state.getValue(LIT) ? 15 : 0;
    }
}

Creating a Custom Item

Prompt: "Create a magic wand item that shoots fireballs on right click"

java
public class MagicWandItem extends Item {
    public MagicWandItem(Properties properties) {
        super(properties.stacksTo(1).durability(100));
    }
    
    @Override
    public InteractionResultHolder<ItemStack> use(Level level, Player player, InteractionHand hand) {
        ItemStack stack = player.getItemInHand(hand);
        
        if (!level.isClientSide) {
            Vec3 look = player.getLookAngle();
            SmallFireball fireball = new SmallFireball(level, player, look.x, look.y, look.z);
            fireball.setPos(player.getX(), player.getEyeY() - 0.1, player.getZ());
            level.addFreshEntity(fireball);
            
            stack.hurtAndBreak(1, player, (p) -> p.broadcastBreakEvent(hand));
            player.getCooldowns().addCooldown(this, 20);
        }
        
        level.playSound(player, player.blockPosition(), SoundEvents.BLAZE_SHOOT, 
                        SoundSource.PLAYERS, 1.0F, 1.0F);
        
        return InteractionResultHolder.sidedSuccess(stack, level.isClientSide);
    }
}

Training Data

Data Sources

SourceDescriptionFiles
Forge SourceMinecraftForge core, ForgeGradle, EventBus, ModLauncher~1,200
Popular Mods27 well-maintained open-source mod repositories~21,700
DocumentationOfficial Forge docs and tutorials74

Featured Mod Repositories

Training data includes code from highly-regarded mods:

  • โ€”Applied Energistics 2 - Storage & automation
  • โ€”Mekanism - Tech & machinery
  • โ€”Create - Mechanical contraptions
  • โ€”Botania - Nature magic
  • โ€”Thermal Series - Energy systems
  • โ€”Tinkers' Construct - Tool crafting
  • โ€”Immersive Engineering - Industrial machines
  • โ€”JustEnoughItems (JEI) - Recipe viewing
  • โ€”TerraFirmaCraft - Survival overhaul
  • โ€”The Twilight Forest - Dimension mod
  • โ€”Quark - Vanilla enhancements
  • โ€”RFTools - RF-powered utilities
  • โ€”And 15 more...

Dataset Statistics

MetricValue
Total Java Files Processed22,916
Training Samples13,936
Validation Samples734
Sample TypesCode completion, explanation, Q&A

Training

Configuration

ParameterValue
Epochs3
Batch Size2 (per device)
Gradient Accumulation8 steps
Effective Batch Size128
Learning Rate2e-4
LR SchedulerCosine
Warmup Ratio3%
Max Sequence Length2,048 tokens
PrecisionBF16
Hardware8ร— NVIDIA H20 (96GB each)

Training Metrics

MetricValue
Training Duration9h 12m
Total Steps1,848
Final Training Loss0.27
Final Validation Loss0.325
Token Accuracy92.5%
Eval Accuracy91.2%

Loss Curve

Epoch 1: 0.89 โ†’ 0.42
Epoch 2: 0.38 โ†’ 0.31
Epoch 3: 0.29 โ†’ 0.27

Framework Versions

  • โ€”PEFT: 0.18.0
  • โ€”TRL: 0.26.1
  • โ€”Transformers: 4.57.3
  • โ€”PyTorch: 2.5.1+cu121
  • โ€”Datasets: 4.4.1
  • โ€”Tokenizers: 0.22.1

Limitations

  • โ€”Version Specific: Optimized for Forge 1.21.11; may produce outdated patterns for older versions
  • โ€”Java Only: Does not generate Kotlin, Gradle scripts, or JSON resources
  • โ€”No Runtime Testing: Generated code should be tested before use in production
  • โ€”Context Window: Limited to 2,048 tokens; very large classes may need to be split

Intended Use

โœ… Recommended Uses:

  • โ€”Learning Forge modding patterns and best practices
  • โ€”Rapid prototyping of mod components
  • โ€”Code completion and suggestions
  • โ€”Understanding Forge API usage

โš ๏ธ Not Recommended For:

  • โ€”Production code without review
  • โ€”Security-critical applications
  • โ€”Forge versions significantly different from 1.21.11

Citation

If you use this model in your research or projects, please cite:

bibtex
@misc{forge-coder-2024,
  author = {hwding},
  title = {Forge Coder: A Specialized Code Generation Model for Minecraft Forge Mod Development},
  year = {2024},
  publisher = {Hugging Face},
  url = {https://huggingface.co/hwding/forge-coder-v1.21.11}
}

Cite TRL as:

bibtex
@misc{vonwerra2022trl,
    title        = {{TRL: Transformer Reinforcement Learning}},
    author       = {Leandro von Werra and Younes Belkada and Lewis Tunstall and Edward Beeching and Tristan Thrush and Nathan Lambert and Shengyi Huang and Kashif Rasul and Quentin Gallou{\'e}dec},
    year         = 2020,
    journal      = {GitHub repository},
    publisher    = {GitHub},
    howpublished = {\url{https://github.com/huggingface/trl}}
}

License

This model is released under the DeepSeek License, consistent with the base model.

Training data was sourced from open-source repositories under various permissive licenses (MIT, Apache 2.0, LGPL, etc.).

Acknowledgments

  • โ€”DeepSeek for the excellent base model
  • โ€”MinecraftForge team for the modding framework
  • โ€”All open-source mod developers whose code made this training possible

<div align="center"> <p><strong>Happy Modding! ๐ŸŽฎโ›๏ธ</strong></p> </div>