This README explains how to use the generate.py script to generate Minecraft structures from a trained flow matching model.
Make sure you have the following dependencies installed:
pip install torch torchvision torchdyn nbtlib scikit-learn tqdmThe script supports two modes of operation:
- Generation Mode: Generate new Minecraft structures from scratch
- Reconstruction Mode: Take existing structures, partially destroy them, and reconstruct them
To generate Minecraft structures from scratch, run:
python generate.py --model_path /path/to/your/model_checkpoint.ptTo reconstruct partially destroyed structures, run:
python generate.py --model_path /path/to/your/model_checkpoint.pt --reconstruction --destruction_percentage 0.3--model_path: Path to the model checkpoint (required)--cache_file: Path to the block mappings cache file (default: "cache/block_mappings.pkl")--embedding_cache: Path to the block embeddings cache file (default: "cache/block_embeddings.pt")--output_dir: Directory to save generated samples (default: "generated_samples")--embedding_dim: Dimension of block embeddings (default: 32)--save_npy: Save raw numpy arrays of block indices--save_schematic: Save as Minecraft schematic files (requires nbtlib)
--num_samples: Number of samples to generate (default: 8)--chunk_size: Size of the generated chunks (default: 16)
--reconstruction: Enable reconstruction mode--destruction_percentage: Percentage of blocks to destroy (0-1, default: 0.3)--schematics_dir: Directory containing schematic files for reconstruction (default: "minecraft-schematics-raw")--num_structures: Number of structures to reconstruct (default: 4)
# Generate 16 samples from scratch and save as schematic files
python generate.py --model_path output/unet/unet_minecraft_epoch_160_checkpoint.pt --num_samples 16 --save_schematic
# Reconstruct 4 structures with 50% destruction
python generate.py --model_path output/unet/unet_minecraft_epoch_160_checkpoint.pt --reconstruction --destruction_percentage 0.5 --num_structures 4 --save_schematicThe script generates:
- Optionally, numpy arrays of block indices (if
--save_npyis specified) - Optionally, Minecraft schematic files that can be imported into Minecraft (if
--save_schematicis specified)
The script generates three sets of files in separate directories:
- original/ - The original structures before destruction
- destroyed/ - The partially destroyed structures
- reconstructed/ - The structures after reconstruction by the model
Each directory contains:
- Optionally, numpy arrays of block indices (if
--save_npyis specified) - Optionally, Minecraft schematic files (if
--save_schematicis specified)
This allows you to compare the original, destroyed, and reconstructed versions side by side.
- The script loads the trained flow matching model
- It generates continuous embeddings using Neural ODE with the correct dimensions (embedding_dim × 16 × 16 × 16)
- It maps these continuous embeddings back to discrete Minecraft blocks using cosine similarity
- It saves the results in the specified formats
- The script loads the trained flow matching model
- It loads real Minecraft structures from the dataset
- It partially destroys the structures by replacing a percentage of blocks with random noise
- It uses the model to reconstruct the original structures
- It saves the original, destroyed, and reconstructed versions for comparison
The reconstruction process demonstrates the model's ability to understand and repair Minecraft structures, which is useful for:
- Repairing damaged structures in-game
- Completing partially built structures
- Understanding the structural patterns the model has learned
If you've generated schematic files (with the --save_schematic option), you can import them into Minecraft using tools like:
Simply load the .schem file in your preferred tool and place it in your Minecraft world.