MCSKIN for AIs

Back to MCSKIN. An AI can paint a skin three ways: drive the page through window.MCSkin, paste a spec into the page's spec box, or run the offline command. All three take the same JSON paint spec and give the same PNG bytes.

The paint spec

{"model": "classic", "start": "blank", "ops": [
  {"op": "fill", "part": "head", "face": "front", "color": "#e0ac84"},
  {"op": "px",   "part": "head", "face": "front", "x": 2, "y": 4, "color": "#3b6fd8", "mirror": true},
  {"op": "rect", "part": "body", "face": "front", "x": 0, "y": 0, "w": 8, "h": 3, "color": "#7a1f1f80", "layer": "overlay"}
]}
FieldMeaning
modelRequired. "classic" (4-pixel arms) or "slim" (3-pixel arms). The PNG does not record this; players choose it in the launcher.
start"blank" (default): a white player. "keep": paint on top of the current skin (re-fitted first if the model changes).
opfill a whole face, px one pixel at x, y, or rect x, y, w, h.
parthead, body, right_arm, left_arm, right_leg, left_leg. Right and left are the character's own: right_arm is on your left when the character faces you.
facefront, back, top, bottom, right, left (the character's right and left sides).
layerbase (default; always opaque, as in the game) or overlay (hat, jacket, sleeves, trousers; may be see-through).
x, yWhole numbers inside the face, in the PNG's own directions: x to the right and y downwards within that face's rectangle of the skin file. On the 3D player that is: front, left to right as you face it, top to bottom; top face, y 0 is the back edge; bottom face, y 0 is the front edge.
color#rrggbb, #rrggbbaa (alpha only counts on the overlay) or "clear" (clears the overlay; paints white on the base).
mirrorOptional true: also paint the same spot on the other side (right arm to left arm, x reversed).

Face sizes: head 8×8 on every face; body front/back 8×12, sides 4×12, top/bottom 8×4; each limb front/back 4×12 (slim arms 3×12), sides 4×12, top/bottom 4×4 (slim arms 3×4). A spec is checked whole before anything is painted, and up to 20000 ops are taken.

In the page

MCSkin.apply(spec)        // {ok: true, model} or {ok: false, error}; one undo step
MCSkin.validate(spec)     // {ok: true} or {ok: false, error}, paints nothing
MCSkin.exportPNG()        // "data:image/png;base64,..." of the skin
MCSkin.pngBytes()         // the same as a Uint8Array
MCSkin.loadPNG(input, model)  // Promise: a data URL, ArrayBuffer or Uint8Array of a 64x64 or 64x32 skin;
                              // model "classic"/"slim" reads it as that, or leave it out to guess
MCSkin.getPixel(x, y)     // [r, g, b, a] at that spot of the 64x64 file
MCSkin.setModel("slim"); MCSkin.reset(); MCSkin.download();

Offline

python -I -X utf8 mcskin/paint.py spec.json -o skin.png
python -I -X utf8 mcskin/paint.py spec.json -o skin.png --base old.png   (with "start": "keep")
python -I -X utf8 mcskin/paint.py spec.json -o skin.png --base old.png --base-model classic

Python 3 standard library only. --base is read as the spec's model unless --base-model says which model the file was made for. Exit 0 when written; 2 when the spec or a file is wrong, with the reason on stderr.