Skip to main content

Voxel color format

This tutorial uses the following encoding for painted ground cells on chunkZ=0, voxelZ=0.

Fields

FieldTypePurpose
voxelTypeintPalette index (1–255). 0 = empty/unpainted
voxelStatebase64 string4 bytes: [R, G, B, A]

Encode (TypeScript)

function rgbaToVoxelState(r: number, g: number, b: number, a: number): string {
const bytes = new Uint8Array([r, g, b, a]);
let binary = '';
for (let i = 0; i < bytes.length; i++) {
binary += String.fromCharCode(bytes[i]!);
}
return btoa(binary);
}

Decode

function voxelStateToRgba(voxelState: string): { r: number; g: number; b: number; a: number } {
const binary = atob(voxelState);
return {
r: binary.charCodeAt(0),
g: binary.charCodeAt(1),
b: binary.charCodeAt(2),
a: binary.charCodeAt(3),
};
}

Default palette

voxelTypeColor
1Red #e74c3c
2Blue #3498db
3Green #2ecc71
4Yellow #f1c40f
5Purple #9b59b6

See VoxelUpdateRequestInput and sendVoxelUpdate.