Skip to main content
The VmfWriter class is responsible for writing formatted VMF (Valve Map Format) files during the decompilation process. It handles proper indentation, section nesting, and value formatting. Source: VmfWriter.java:34

Overview

VmfWriter provides a structured API for writing VMF files with correct formatting. It manages nested sections, handles different data types, and ensures proper precision for coordinate values.

Constructor

VmfWriter
constructor
Creates a new VMF writer instance.
VmfWriter(
    PrintWriter pw,
    int doubleScale,
    int doubleScaleTextureAxes,
    int doubleScaleTextureScale
)

Methods

Section Management

start
void
Start a new VMF section.
void start(String name)
Opens a new named section with proper indentation and braces.
end
void
End the current VMF section.
void end(String name)
Closes the current section. The name must match the currently open section.

Value Writing

put
void
Write a key-value pair.
void put(String key, String value)
void put(String key, int value)
void put(String key, int... values)
void put(String key, long value)
void put(String key, float value)
void put(String key, double value)
void put(String key, Vector3f value)
void put(String key, Vector3d value)
Writes a property with proper quoting and formatting. Supports various data types including primitives, vectors, and arrays.

Usage Example

import info.ata4.bspsrc.decompiler.VmfWriter;
import java.io.PrintWriter;
import java.io.FileWriter;

// Create writer
PrintWriter pw = new PrintWriter(new FileWriter("output.vmf"));
VmfWriter writer = new VmfWriter(pw, 8, 4, 4);

// Write VMF structure
writer.start("world");
writer.put("id", 1);
writer.put("mapversion", 1);
writer.put("classname", "worldspawn");

writer.start("solid");
writer.put("id", 2);
writer.end("solid");

writer.end("world");

// Close when done
writer.close();

Precision Scaling

The scale parameters control decimal precision for different value types:
  • doubleScale: Used for world coordinates and vertex positions
  • doubleScaleTextureAxes: Used for texture axis vectors
  • doubleScaleTextureScale: Used for texture scale values
Higher values provide more precision but increase file size. Default values (8, 4, 4) provide good balance.

Build docs developers (and LLMs) love