Repository navigation
Expand file tree
/
Copy pathsave-format.html
More file actions
1666 lines (1607 loc) · 97.2 KB
/
Copy pathsave-format.html
File metadata and controls
1666 lines (1607 loc) · 97.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Vintage Story Save Format</title>
<!-- Inline favicon so opening the file makes zero network requests. -->
<link rel="icon" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Crect x='1' y='1' width='6' height='6' fill='%238a8f98'/%3E%3Crect x='9' y='1' width='6' height='6' fill='%236aae55'/%3E%3Crect x='1' y='9' width='6' height='6' fill='%239a6a3c'/%3E%3Crect x='9' y='9' width='6' height='6' fill='%232563eb'/%3E%3C/svg%3E">
<link rel="stylesheet" href="../style/fonts.css">
<link rel="stylesheet" href="../style/base.css">
<style>
:root {
/* Data colours: x, y and z of a position, used nowhere else. */
--x: #c2410c;
--x-soft: #fde4d6;
--z: #237a36;
--z-soft: #d9f2de;
--y: #6741d9;
--y-soft: #e7defd;
--one: #1d1f23;
--one-fg: #fbfaf7;
--zero: #ebe8e0;
--zero-fg: #8d929a;
--changed: #eab308;
--solid: #9a8f80;
--top: #4f9a43;
}
.diagram { width: 100%; max-width: 22.5rem; height: auto; overflow: visible; }
.diagram .face-side { fill: var(--zero); stroke: var(--panel); }
.diagram .face-side.needed { fill: var(--accent-soft); stroke: var(--accent); }
.diagram .face-top { fill: var(--soft); stroke: var(--border); }
.diagram .chunk { fill: var(--panel); }
.diagram .chunk.needed { fill: var(--accent-soft); }
.diagram .terrain { fill: var(--solid); opacity: 0.55; }
.diagram .surface { fill: none; stroke: var(--top); stroke-width: 2; }
.diagram .chunk-line { fill: none; stroke: var(--border); }
.diagram .chunk-line.needed { stroke: var(--accent); stroke-width: 1.5; }
.diagram .layer { fill: var(--soft); stroke: var(--muted); }
.diagram .layer-line { stroke: var(--border); }
.diagram .cell { fill: var(--accent); }
.diagram .arrow { stroke: var(--accent); stroke-width: 1.5; stroke-dasharray: 4 3; }
.diagram .arrow-head { fill: var(--accent); }
.diagram .picked { fill: var(--accent); }
.diagram .label { font: 500 0.75rem var(--mono); fill: var(--muted); }
.diagram .label.strong, .diagram .label.needed { fill: var(--fg); font-weight: 600; }
.key-needed { background: var(--accent-soft); color: var(--accent); border-radius: 0.2rem; padding: 0 0.25rem; }
.bit {
display: inline-grid;
place-items: center;
width: 1.375rem;
height: 1.375rem;
border-radius: 0.25rem;
font: 600 var(--t-micro)/1 var(--mono);
background: var(--zero);
color: var(--zero-fg);
}
.bit.on { background: var(--one); color: var(--one-fg); }
/* Changed bits keep their marker until the next action instead of flashing. */
.chg { outline: 2px solid var(--changed); outline-offset: 1px; }
/* position */
.pos-inputs { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--s3); }
.pos-inputs label:nth-child(1) { color: var(--x); }
.pos-inputs label:nth-child(2) { color: var(--y); }
.pos-inputs label:nth-child(3) { color: var(--z); }
.pos-inputs label:nth-child(4) { color: var(--accent); }
.pos-value { margin-top: var(--s3); }
.climate-inputs { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--s3); }
.climate-inputs label:nth-child(1) { color: var(--x); }
.climate-inputs label:nth-child(2) { color: var(--z); }
.climate-inputs label:nth-child(3) { color: var(--y); }
.bitbar { margin-top: var(--s5); }
.bitbar-labels, .bitbar-cells { display: grid; grid-template-columns: repeat(64, minmax(0, 1fr)); gap: 1px; }
.bitbar.bits32 .bitbar-labels, .bitbar.bits32 .bitbar-cells { grid-template-columns: repeat(32, minmax(0, 1fr)); }
.bitbar-labels span {
font: 600 var(--t-micro)/1 var(--mono);
padding-bottom: var(--s2);
border-bottom: 2px solid currentColor;
margin-bottom: var(--s1);
white-space: nowrap;
overflow: hidden;
}
.bitbar-cells span { height: 1.375rem; border-radius: 2px; display: grid; place-items: center; font: 600 0.5625rem/1 var(--mono); }
.seg-y { color: var(--y); }
.seg-z { color: var(--z); }
.seg-x { color: var(--x); }
.seg-d { color: var(--accent); }
.seg-pad { color: var(--zero-fg); }
.bitbar-cells .seg-y { background: var(--y-soft); }
.bitbar-cells .seg-z { background: var(--z-soft); }
.bitbar-cells .seg-x { background: var(--x-soft); }
.bitbar-cells .seg-d { background: var(--accent-soft); }
.bitbar-cells .seg-pad { background: var(--zero); }
.bitbar-cells .seg-y.on { background: var(--y); color: var(--panel); }
.bitbar-cells .seg-z.on { background: var(--z); color: var(--panel); }
.bitbar-cells .seg-x.on { background: var(--x); color: var(--panel); }
.bitbar-cells .seg-d.on { background: var(--accent); color: var(--panel); }
.bitbar-cells .seg-pad.on { background: var(--error); color: var(--panel); }
.bitbar-ends { display: flex; justify-content: space-between; font: var(--t-micro)/1 var(--mono); color: var(--muted); margin-top: var(--s2); }
#fields tr[id] { scroll-margin-top: var(--s5); }
#fields tbody tr:target, #fields tbody tr:target td { background: var(--accent-soft); }
.strip { display: flex; gap: 3px; margin: var(--s5) 0 var(--s4); height: 2.875rem; }
.strip > div {
border-radius: var(--radius-sm);
display: grid;
place-items: center;
font: 600 var(--t-micro)/1.15 var(--mono);
text-align: center;
padding: 0 var(--s2);
min-width: 4rem;
transition: flex-grow 0.18s var(--ease);
}
.strip .s-len { background: var(--y-soft); color: var(--y); flex: 0 0 4rem; }
.strip .s-pal { background: var(--z-soft); color: var(--z); }
.strip .s-dat { background: var(--x-soft); color: var(--x); }
.parts { display: grid; gap: var(--s3); }
.part { display: grid; grid-template-columns: 0.875rem 1fr; gap: var(--s3); align-items: start; }
.part .dot { width: 0.625rem; height: 0.625rem; border-radius: 0.2rem; margin-top: 0.45rem; }
.part p { margin: 0; }
.entries { display: flex; flex-wrap: wrap; gap: var(--s1); margin-top: var(--s2); }
.entries span { font: var(--t-small)/1 var(--mono); font-variant-numeric: tabular-nums; background: var(--soft); border-radius: 0.25rem; padding: var(--s1) 0.4rem; }
/* palette */
.slider { display: grid; grid-template-columns: auto 1fr 2rem; gap: var(--s3); align-items: center; font: 600 var(--t-small)/1 var(--mono); }
.slider output { text-align: right; font-variant-numeric: tabular-nums; }
.slots { display: grid; grid-template-columns: repeat(auto-fill, minmax(2.75rem, 1fr)); gap: var(--s2); margin-top: var(--s4); }
.slot {
border-radius: var(--radius-sm);
padding: var(--s2) var(--s1);
text-align: center;
font: var(--t-micro)/1.3 var(--mono);
font-variant-numeric: tabular-nums;
background: var(--z-soft);
color: var(--z);
border: 1px solid transparent;
}
.slot b { display: block; font-size: var(--t-small); }
.slot.air { background: var(--soft); color: var(--muted); }
.slot.pad { background: repeating-linear-gradient(135deg, transparent 0 0.3rem, var(--soft) 0.3rem 0.6rem); border: 1px dashed var(--border); color: var(--muted); }
.sliders { display: grid; gap: var(--s3); }
.sliders .slider { grid-template-columns: 1.375rem 1fr 2rem; }
.grid32 {
display: grid;
grid-template-columns: repeat(32, minmax(0, 1fr));
gap: 1px;
aspect-ratio: 1;
width: 100%;
max-width: 20rem;
touch-action: manipulation;
border-radius: 2px;
}
.grid32 div { background: var(--zero); border-radius: 1px; cursor: pointer; }
.grid32 div.row-hl { background: var(--accent-soft); }
.grid32 div.cur { background: var(--accent); }
.axis { font: var(--t-micro)/1 var(--mono); color: var(--muted); display: flex; justify-content: space-between; max-width: 20rem; margin: var(--s2) 0 0; }
.word-strip { display: flex; flex-wrap: wrap; gap: 2px; }
.word-strip .bit { width: 1.125rem; height: 1.25rem; font-size: 0.5625rem; font-weight: 400; }
.word-strip .bit.cur { background: var(--accent); color: var(--accent-fg); }
/* planes */
.pg-top { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: var(--s5); align-items: start; }
.blocks4 { display: grid; grid-template-columns: repeat(4, 3.25rem); gap: var(--s2); }
.blk {
position: relative;
width: 3.25rem;
height: 3.25rem;
border-radius: 0.5rem;
border: 1px solid rgb(0 0 0 / 0.12);
cursor: pointer;
padding: 0;
transition: transform 0.12s var(--ease);
}
.blk:active { transform: scale(0.94); }
.blk .n, .blk .t { position: absolute; font: 600 0.625rem/1 var(--mono); color: rgb(0 0 0 / 0.6); }
.blk .n { top: var(--s1); left: 0.4rem; }
.blk .t { bottom: var(--s1); right: 0.4rem; }
.blk.air { background: repeating-linear-gradient(135deg, transparent 0 0.375rem, var(--soft) 0.375rem 0.75rem); border: 1px dashed var(--border); }
.blk.air .n, .blk.air .t { color: var(--muted); }
.blk.sel { box-shadow: 0 0 0 3px var(--panel), 0 0 0 5px var(--accent); }
.pal-list { display: grid; gap: var(--s2); }
.pal-item { display: grid; grid-template-columns: 1.125rem auto 1fr; gap: var(--s3); align-items: center; font: var(--t-small)/1.2 var(--mono); font-variant-numeric: tabular-nums; }
.pal-item i { width: 1.125rem; height: 1.125rem; border-radius: 0.3rem; border: 1px solid rgb(0 0 0 / 0.12); }
.pal-item.pad { color: var(--muted); }
.pal-item.pad i, .pal-item.air i { background: repeating-linear-gradient(135deg, transparent 0 0.25rem, var(--soft) 0.25rem 0.5rem); border: 1px dashed var(--border); }
.pal-item .idx { color: var(--muted); }
.planes { margin-top: var(--s5); }
.plane-row, .planes-head { display: grid; grid-template-columns: 5.25rem minmax(0, 1fr); align-items: center; gap: var(--s2); }
.plane-row { overflow: hidden; }
.plane-row + .plane-row { margin-top: var(--s1); }
.planes-head { margin-bottom: var(--s1); }
.plane-row .lbl { font: var(--t-micro)/1.2 var(--mono); font-variant-numeric: tabular-nums; color: var(--muted); white-space: nowrap; }
.plane-row .lbl b { color: var(--fg); }
.bits16 { display: grid; grid-template-columns: repeat(16, minmax(0, 1fr)); gap: 3px; max-width: 25rem; }
.bits16 .bit { width: auto; }
.bits16 span { font: var(--t-micro)/1 var(--mono); font-variant-numeric: tabular-nums; color: var(--muted); text-align: center; }
.bit.col { box-shadow: 0 0 0 2px var(--accent); }
.packed { margin-top: var(--s5); }
.packed-bits { display: flex; gap: var(--s2); flex-wrap: wrap; }
.packed-bits .grp { display: inline-flex; gap: 1px; padding: 2px; border-radius: 0.3rem; }
.packed-bits .grp.col { box-shadow: 0 0 0 2px var(--accent); }
.packed-bits .bit { width: 1rem; height: 1.25rem; font-size: 0.625rem; }
.readout { margin-top: var(--s5); display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2); font: var(--t-small)/1.3 var(--mono); font-variant-numeric: tabular-nums; }
.readout .arrow { color: var(--muted); }
.readout .pill { background: var(--soft); border-radius: var(--radius-sm); padding: var(--s2) 0.6rem; }
.diff { margin-top: var(--s3); font: var(--t-small)/1.5 var(--mono); font-variant-numeric: tabular-nums; min-height: 1.5em; color: var(--muted); }
.diff b { color: var(--fg); }
.diff .mark { display: inline-block; width: 0.7rem; height: 0.7rem; border-radius: 0.15rem; outline: 2px solid var(--changed); outline-offset: 1px; margin-right: var(--s2); vertical-align: -0.05rem; }
.empty-planes { font: var(--t-small)/1.4 var(--mono); color: var(--muted); padding: var(--s2) 0; }
/* map */
.toy { display: grid; gap: var(--s4); }
.toy-map, .toy-side { display: grid; grid-template-columns: repeat(16, minmax(0, 1fr)); gap: 2px; max-width: 30rem; }
.toy-map div { aspect-ratio: 1; border-radius: 0.2rem; }
.toy-side { border-radius: 0.3rem; }
.toy-side button {
aspect-ratio: 1;
border: 0;
border-radius: 0.2rem;
padding: 0;
cursor: pointer;
background: var(--zero);
transition: background-color 0.15s var(--ease);
}
.toy-side button:focus-visible { outline-offset: 0; position: relative; z-index: 1; }
.toy-side button.solid { background: var(--solid); }
.toy-side button.top { background: var(--top); }
.toy-side button.scan { box-shadow: inset 0 0 0 2px var(--accent); }
/* chiseled blocks */
.cuboid-wrap { display: grid; grid-template-columns: minmax(0, 18rem) minmax(0, 1fr); gap: var(--s5); align-items: center; }
.cuboid-3d { width: 100%; height: auto; max-width: 18rem; justify-self: center; }
.cuboid-3d [data-box] { cursor: pointer; }
.cuboid-3d .selected { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; pointer-events: none; }
.cub-sliders { display: grid; gap: var(--s2); }
.cub-sliders .slider { grid-template-columns: 4.5rem 1fr 2rem; }
.cub-table tbody tr { cursor: pointer; }
.cub-table tbody tr.selected td { background: var(--accent-soft); }
.cub-table .pick { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; display: inline-flex; align-items: center; }
.cuboid-3d .floor { fill: var(--soft); stroke: var(--border); }
.cuboid-3d .grid-line { stroke: var(--border); stroke-width: 0.5; }
.cuboid-3d .label { font: 500 0.75rem var(--mono); fill: var(--muted); }
.hex-anatomy { display: flex; flex-wrap: wrap; align-items: flex-start; gap: var(--s1); font-family: var(--mono); }
.hex-anatomy .prefix { font-size: 1.5rem; line-height: 2.5rem; color: var(--muted); padding-right: var(--s1); }
.hex-anatomy .hex-field { display: grid; justify-items: center; gap: var(--s1); }
.hex-anatomy .digits { display: flex; gap: 2px; }
.hex-anatomy .digit { font-size: 1.5rem; font-weight: 600; width: 1.75rem; height: 2.5rem; display: grid; place-items: center; border-radius: var(--radius-sm); background: var(--soft); }
.hex-anatomy .name { font-size: var(--t-micro); color: var(--muted); white-space: nowrap; }
.hex-anatomy .value { font-size: var(--t-small); font-weight: 600; }
.hex-anatomy .gap { width: var(--s3); }
.hex-anatomy .x .digit { background: var(--x-soft); color: var(--x); }
.hex-anatomy .y .digit { background: var(--y-soft); color: var(--y); }
.hex-anatomy .z .digit { background: var(--z-soft); color: var(--z); }
.hex-code .x { color: var(--x); }
.hex-code .y { color: var(--y); }
.hex-code .z { color: var(--z); }
.hex-code .mat { color: var(--muted); }
@media (max-width: 44rem) {
.pg-top, .cuboid-wrap { grid-template-columns: minmax(0, 1fr); }
.hex-anatomy .digit { font-size: 1.125rem; width: 1.25rem; height: 2rem; }
.hex-anatomy .prefix { font-size: 1.125rem; line-height: 2rem; }
.hex-anatomy .gap { width: var(--s1); }
.bitbar-cells span { font-size: 0; height: 1.125rem; }
.bits16 { gap: 2px; }
/* Field table: the status tag moves under the name, so names and tags never squeeze each other. */
#fields table, #fields thead, #fields tbody { display: block; }
#fields tr { display: grid; grid-template-columns: 3.5em minmax(0, 1fr); border-bottom: 1px solid var(--border); }
#fields th, #fields td { border-bottom: 0; }
#fields th:nth-child(3) { display: none; }
#fields td:nth-child(3) { grid-column: 2; padding-top: 0; }
#fields tr.key { background: var(--soft); }
#fields tr.key td { background: none; }
}
</style>
</head>
<body>
<main>
<header>
<h1>Vintage Story save format</h1>
<p class="lede">How a <code>.vcdbs</code> save stores the world's blocks, from a database row down to a single block. The full text reference, with sources for every claim, is <a href="../save-format/README.md">README.md</a>.</p>
<div class="versions"><span class="label">verified with</span><span class="version">1.19.1</span><span class="version">1.19.2</span><span class="version">1.22.7</span></div>
</header>
<nav class="toc" aria-label="Contents"><ol id="toc"></ol></nav>
<section id="save">
<div class="section-content">
<h2><span class="num">1</span><span>The save file</span></h2>
<p>A <code>.vcdbs</code> file is a plain SQLite database with five tables (plus SQLite's own <code>sqlite_sequence</code>):</p>
<div class="chips">
<a class="chip" href="#chunk">chunk</a>
<a class="chip" href="#mapchunk">mapchunk</a>
<a class="chip" href="#mapregion">mapregion</a>
<a class="chip" href="#gamedata">gamedata</a>
<a class="chip" href="#playerdata">playerdata</a>
</div>
<p>The world is cut into <b>chunks</b>: cubes of 32 × 32 × 32 blocks. Each chunk is one row of the <code>chunk</code> table, with two columns: <code>position</code> (where the cube is) and <code>data</code> (what's inside it). The tables store the world at three scales:</p>
<ul class="list">
<li><b><code>chunk</code> is 3D</b> (<a href="#chunk">3.1</a>). One row per cube, keyed by its x, z and y. The only table with blocks in it.</li>
<li><b><code>mapchunk</code> is a 2D layer on top</b> (<a href="#mapchunk">3.2</a>). One row per <b>chunk column</b>, the stack of chunks with the same x and z, keyed by just x and z. For each of its 32 × 32 block columns it keeps a few numbers, such as the height of the highest block rain can't fall through.</li>
<li><b><code>mapregion</code> is coarser still</b> (<a href="#mapregion">3.3</a>). One row per 16 × 16 chunk columns, with world generation data.</li>
</ul>
<p><code>gamedata</code> is a single row of world-wide data, such as block names and the clock (<a href="#gamedata">3.4</a>). <code>playerdata</code> has one row per player (<a href="#playerdata">3.5</a>).</p>
<p>So a block column's map chunk gives its surface height, and that height names the one chunk holding the surface block. A top-down map only needs those chunks: about a fifth of the chunks in the test saves.</p>
<figure class="panel figure">
<svg class="diagram" viewBox="0 0 360 430" role="img" aria-labelledby="column-diagram-title">
<title id="column-diagram-title">A chunk column: eight chunks stacked from y 0 to y 7, with the terrain surface crossing chunks 3 and 4. Above it floats the map chunk, a flat grid of 32 by 32 heights. An arrow drops from one cell of that grid to the surface block it names, in chunk 3.</title>
<polygon class="face-side" points="200,368 244,344 244,380 200,404"/>
<polygon class="face-side" points="200,332 244,308 244,344 200,368"/>
<polygon class="face-side" points="200,296 244,272 244,308 200,332"/>
<polygon class="face-side needed" points="200,260 244,236 244,272 200,296"/>
<polygon class="face-side needed" points="200,224 244,200 244,236 200,260"/>
<polygon class="face-side" points="200,188 244,164 244,200 200,224"/>
<polygon class="face-side" points="200,152 244,128 244,164 200,188"/>
<polygon class="face-side" points="200,116 244,92 244,128 200,152"/>
<polygon class="face-top" points="40,116 200,116 244,92 84,92"/>
<rect class="chunk" x="40" y="368" width="160" height="36"/>
<rect class="chunk" x="40" y="332" width="160" height="36"/>
<rect class="chunk" x="40" y="296" width="160" height="36"/>
<rect class="chunk needed" x="40" y="260" width="160" height="36"/>
<rect class="chunk needed" x="40" y="224" width="160" height="36"/>
<rect class="chunk" x="40" y="188" width="160" height="36"/>
<rect class="chunk" x="40" y="152" width="160" height="36"/>
<rect class="chunk" x="40" y="116" width="160" height="36"/>
<polygon class="terrain" points="40,404 40,271.25 45,271.25 45,267.875 50,267.875 50,263.375 55,263.375 55,258.875 60,258.875 60,253.25 65,253.25 65,247.625 70,247.625 70,243.125 75,243.125 75,239.75 80,239.75 80,238.625 85,238.625 85,238.625 90,238.625 90,240.875 95,240.875 95,245.375 100,245.375 100,251 105,251 105,257.75 110,257.75 110,264.5 115,264.5 115,271.25 120,271.25 120,276.875 125,276.875 125,281.375 130,281.375 130,284.75 135,284.75 135,287 140,287 140,288.125 145,288.125 145,288.125 150,288.125 150,287 155,287 155,284.75 160,284.75 160,281.375 165,281.375 165,276.875 170,276.875 170,271.25 175,271.25 175,265.625 180,265.625 180,260 185,260 185,254.375 190,254.375 190,249.875 195,249.875 195,246.5 200,246.5 200,404"/>
<polyline class="surface" points="40,271.25 45,271.25 45,267.875 50,267.875 50,263.375 55,263.375 55,258.875 60,258.875 60,253.25 65,253.25 65,247.625 70,247.625 70,243.125 75,243.125 75,239.75 80,239.75 80,238.625 85,238.625 85,238.625 90,238.625 90,240.875 95,240.875 95,245.375 100,245.375 100,251 105,251 105,257.75 110,257.75 110,264.5 115,264.5 115,271.25 120,271.25 120,276.875 125,276.875 125,281.375 130,281.375 130,284.75 135,284.75 135,287 140,287 140,288.125 145,288.125 145,288.125 150,288.125 150,287 155,287 155,284.75 160,284.75 160,281.375 165,281.375 165,276.875 170,276.875 170,271.25 175,271.25 175,265.625 180,265.625 180,260 185,260 185,254.375 190,254.375 190,249.875 195,249.875 195,246.5 200,246.5"/>
<rect class="chunk-line" x="40" y="368" width="160" height="36"/>
<text class="label" x="254" y="378">y 0</text>
<rect class="chunk-line" x="40" y="332" width="160" height="36"/>
<text class="label" x="254" y="342">y 1</text>
<rect class="chunk-line" x="40" y="296" width="160" height="36"/>
<text class="label" x="254" y="306">y 2</text>
<rect class="chunk-line needed" x="40" y="260" width="160" height="36"/>
<text class="label needed" x="254" y="270">y 3</text>
<rect class="chunk-line needed" x="40" y="224" width="160" height="36"/>
<text class="label needed" x="254" y="234">y 4</text>
<rect class="chunk-line" x="40" y="188" width="160" height="36"/>
<text class="label" x="254" y="198">y 5</text>
<rect class="chunk-line" x="40" y="152" width="160" height="36"/>
<text class="label" x="254" y="162">y 6</text>
<rect class="chunk-line" x="40" y="116" width="160" height="36"/>
<text class="label" x="254" y="126">y 7</text>
<polygon class="layer" points="40,52 200,52 244,28 84,28"/>
<line class="layer-line" x1="45.5" y1="49" x2="205.5" y2="49"/>
<line class="layer-line" x1="60" y1="52" x2="104" y2="28"/>
<line class="layer-line" x1="51" y1="46" x2="211" y2="46"/>
<line class="layer-line" x1="80" y1="52" x2="124" y2="28"/>
<line class="layer-line" x1="56.5" y1="43" x2="216.5" y2="43"/>
<line class="layer-line" x1="100" y1="52" x2="144" y2="28"/>
<line class="layer-line" x1="62" y1="40" x2="222" y2="40"/>
<line class="layer-line" x1="120" y1="52" x2="164" y2="28"/>
<line class="layer-line" x1="67.5" y1="37" x2="227.5" y2="37"/>
<line class="layer-line" x1="140" y1="52" x2="184" y2="28"/>
<line class="layer-line" x1="73" y1="34" x2="233" y2="34"/>
<line class="layer-line" x1="160" y1="52" x2="204" y2="28"/>
<line class="layer-line" x1="78.5" y1="31" x2="238.5" y2="31"/>
<line class="layer-line" x1="180" y1="52" x2="224" y2="28"/>
<polygon class="cell" points="140,52 160,52 165.5,49 145.5,49"/>
<text class="label strong" x="254" y="44">mapchunk</text>
<line class="arrow" x1="147.5" y1="53" x2="147.5" y2="282.125"/>
<polygon class="arrow-head" points="143.5,280.125 151.5,280.125 147.5,287.125"/>
<rect class="picked" x="145" y="288.125" width="5" height="1.625"/>
</svg>
<figcaption>One chunk column, seen from the front. Each cell of the map chunk is a block column; its height, here 103, falls in chunk y 3 (heights 96 to 127). The surface lies in the <span class="key-needed">highlighted chunks</span> only.</figcaption>
</figure>
<p>Saves use SQLite's write-ahead log, so even read-only access creates <code>-shm</code> and <code>-wal</code> files next to the save. Read a copy, or open it with SQLite's <code>immutable=1</code> option.</p>
<p class="source">Sources: table schema from 1.19 and 1.22.7 saves · <a href="https://www.sqlite.org/wal.html">SQLite: write-ahead log</a> · table descriptions from the <a href="https://wiki.vintagestory.at/index.php/Modding:WorldGen_Concept">wiki</a> · <a href="../save-format/README.md#1-the-save-file">README §1</a></p>
</div>
</section>
<section id="concepts">
<div class="section-content">
<h2><span class="num">2</span><span>Common formats</span></h2>
<p>Formats used by more than one table.</p>
</div>
<section id="position">
<div class="section-content">
<h3><span class="num">2.1</span><span>Positions</span></h3>
<p>The position is a single 64-bit integer: the chunk's <span class="seg-x">x</span> and <span class="seg-z">z</span> in 21 bits each, its <span class="seg-y">y</span> (height) in 9, and its <span class="seg-d">dimension</span> in 10, split in two. These are chunk coordinates: multiply by 32 to get block coordinates. Dimension 0 is the world itself; others hold separate block spaces, such as the time-switched alternate world.</p>
<div class="panel">
<div class="pos-inputs">
<label class="field">X<input id="pos-x" type="number" min="0" max="2097151" value="15995" inputmode="numeric"></label>
<label class="field">Y<input id="pos-y" type="number" min="0" max="511" value="4" inputmode="numeric"></label>
<label class="field">Z<input id="pos-z" type="number" min="0" max="2097151" value="15999" inputmode="numeric"></label>
<label class="field">DIM<input id="pos-d" type="number" min="0" max="1023" value="0" inputmode="numeric"></label>
</div>
<label class="field pos-value">POSITION<input id="pos-value" type="text" inputmode="numeric" spellcheck="false" autocomplete="off"></label>
<p class="error-line" id="pos-error" aria-live="polite"></p>
<div class="bitbar">
<div class="bitbar-labels" aria-hidden="true">
<span class="seg-pad"></span>
<span class="seg-y" style="grid-column: span 9">y · 9</span>
<span class="seg-d" style="grid-column: span 5">dim</span>
<span class="seg-pad"></span>
<span class="seg-z" style="grid-column: span 21">z · 21 bits</span>
<span class="seg-d" style="grid-column: span 5">dim</span>
<span class="seg-pad"></span>
<span class="seg-x" style="grid-column: span 21">x · 21 bits</span>
</div>
<div class="bitbar-cells" id="pos-bits" aria-hidden="true"></div>
<div class="bitbar-ends"><span>bit 63</span><span>bit 0</span></div>
</div>
<p class="stat" id="pos-range" style="margin: var(--s4) 0 0"></p>
<p class="stat" id="pos-game" style="margin: var(--s2) 0 0"></p>
</div>
<p class="muted">The grey bits are always 0, so positions are never negative. <code>mapchunk</code> and <code>mapregion</code> positions use the same packing with y = 0, a map region's x and z counting regions of 16 × 16 chunk columns.</p>
<p>These coordinates are absolute. The game shows x and z from the world's centre instead, half the world's size in <code>gamedata</code> (<a href="#sea-level">3.4.2</a>): in a default world of 1,024,000 × 1,024,000 blocks, block 512,000 is 0. It shows y as it is. That's checked against a player's position (<a href="#playerdata">3.5</a>).</p>
<p class="source">Sources: <a href="https://wiki.vintagestory.at/Modding:VCDBS_format#ChunkPos">wiki: VCDBS format</a> · verified against 1.19 and 1.22.7 saves · <a href="../save-format/README.md#2-positions">README §2</a></p>
</div>
</section>
<section id="protobuf">
<div class="section-content">
<h3><span class="num">2.2</span><span>Protobuf messages</span></h3>
<p>Every table's <code>data</code> column is a <a href="https://protobuf.dev/programming-guides/encoding/">Protobuf</a> message: like JSON where every key is a number and every value is raw bytes. Each field is its number and a wire type, then a varint, 4 or 8 bytes, or a length and that many bytes; a field can be another message. The names are the game's own, from a schema generated from its code.</p>
<p>A list of numbers comes either way Protobuf allows: as the same field repeated, one value each, as in map chunks, or packed into one field of varints, as in map regions. A reader should take both. The messages aren't compressed; only a chunk's blocks, liquids and light are, inside their fields.</p>
<p class="source">Sources: every row of every table in the test saves parses · names from <a href="https://github.com/bluelightning32/vs-proto/blob/80ff05afa98af324425ef6f3e5f12b4bea9e6a3f/schema-1.21.0.rc.3.proto">vs-proto's schema</a> · <a href="../../lib/protobuf/ProtoBuf.zig">lib/protobuf/ProtoBuf.zig</a> · <a href="../save-format/README.md#3-chunk-data-protobuf-fields">README §3</a></p>
</div>
</section>
<section id="tree-attributes">
<div class="section-content">
<h3><span class="num">2.3</span><span>Tree attributes</span></h3>
<p>Some data isn't Protobuf but the game's own binary format, a <b>tree attribute</b>: a chunk's block entities (<a href="#block-entities">3.1.7</a>) and the world's configuration (<a href="#world-config">3.4.4</a>). A tree is a list of entries, each a type byte, a string key and a value, ended by a single <code>0</code> byte. Numbers are little-endian, and strings are .NET <code>BinaryWriter</code> strings: a varint byte length, then UTF-8.</p>
<div class="table-wrap">
<table>
<thead><tr><th>id</th><th>type</th><th>encoding</th></tr></thead>
<tbody>
<tr><td>1</td><td>int</td><td><code>i32</code></td></tr>
<tr><td>2</td><td>long</td><td><code>i64</code></td></tr>
<tr><td>3</td><td>double</td><td><code>f64</code></td></tr>
<tr><td>4</td><td>float</td><td><code>f32</code></td></tr>
<tr><td>5</td><td>string</td><td>string</td></tr>
<tr><td>6</td><td>tree</td><td>nested tree, ends with <code>0</code></td></tr>
<tr><td>7</td><td>item stack</td><td><code>u8</code> is-null; if 0: <code>i32</code> class, <code>i32</code> id, <code>i32</code> stack size, tree</td></tr>
<tr><td>8</td><td>byte array</td><td><code>u16</code> length, bytes</td></tr>
<tr><td>9</td><td>bool</td><td><code>u8</code></td></tr>
<tr><td>10–16</td><td>arrays</td><td><code>i32</code> count, then values: string, int, float, double, tree, long, bool</td></tr>
</tbody>
</table>
</div>
<p class="source">Sources: every block entity and world configuration in the test saves parses with this format · 1.22.7 code: <a href="https://github.com/anegostudios/vsapi/blob/63d33f70018c606fb0f70ead900fe90625fbd7b2/Datastructures/AttributeTree/TreeAttribute.cs">vsapi TreeAttribute.cs</a> and <a href="https://github.com/anegostudios/vsapi/tree/63d33f70018c606fb0f70ead900fe90625fbd7b2/Datastructures/AttributeTree">attribute classes</a> · <a href="https://github.com/anegostudios/vsapi/blob/63d33f70018c606fb0f70ead900fe90625fbd7b2/Common/Collectible/ItemStack.cs">ItemStack.cs</a> · <a href="../save-format/README.md#tree-attribute-format">README §5</a></p>
</div>
</section>
</section>
<section id="tables">
<div class="section-content">
<h2><span class="num">3</span><span>Tables</span></h2>
</div>
<section id="chunk">
<div class="section-content">
<h3><span class="num">3.1</span><span><code>chunk</code></span></h3>
<p>One row per cube of 32 × 32 × 32 blocks: its position (<a href="#position">2.1</a>), and a message of its blocks, liquids, light and block entities.</p>
</div>
<section id="fields">
<div class="section-content">
<h4><span class="num">3.1.1</span><span>Fields</span></h4>
<p>A chunk's message, <code>ServerChunk</code>, has these fields:</p>
<div class="table-wrap">
<table>
<thead><tr><th>#</th><th>name</th><th>status</th></tr></thead>
<tbody>
<tr class="key" id="field-1"><td>1</td><td><code>blocksCompressed</code></td><td><span class="tag ok">decoded</span></td></tr>
<tr><td>2</td><td><code>lightCompressed</code></td><td><span class="tag ok">light, the planes</span></td></tr>
<tr><td>3</td><td><code>lightSatCompressed</code></td><td><span class="tag ok">light, the palette</span></td></tr>
<tr><td>5</td><td><code>EntitiesCount</code></td><td><span class="tag ok">count</span></td></tr>
<tr><td>6</td><td><code>EntitiesSerialized</code></td><td><span class="tag">class, version, data</span></td></tr>
<tr><td>7</td><td><code>BlockEntitiesCount</code></td><td><span class="tag ok">count</span></td></tr>
<tr class="key"><td>8</td><td><code>BlockEntitiesSerialized</code></td><td><a class="tag ok" href="#block-entities">decoded, see 3.1.7</a></td></tr>
<tr><td>10</td><td><code>lightPositions</code></td><td><span class="tag">unknown</span></td></tr>
<tr><td>12</td><td><code>GameVersionCreated</code></td><td><span class="tag ok">text, e.g. "1.19.1"</span></td></tr>
<tr><td>13</td><td><code>EmptyBeforeSave</code></td><td><span class="tag ok">bool</span></td></tr>
<tr><td>14</td><td><code>DecorsSerialized</code></td><td><span class="tag">not decoded</span></td></tr>
<tr><td>15</td><td><code>savedCompressionVersion</code></td><td><span class="tag ok">2</span></td></tr>
<tr><td>16</td><td><code>liquidsCompressed</code></td><td><a class="tag ok" href="#field-1">liquids, same as 1</a></td></tr>
<tr><td>17</td><td><code>BlocksPlaced</code></td><td><span class="tag ok">count</span></td></tr>
<tr><td>18</td><td><code>BlocksRemoved</code></td><td><span class="tag ok">count</span></td></tr>
</tbody>
</table>
</div>
<p>Field <b>1</b> holds the solid blocks, field <b>16</b> the liquids in the same format, and field <b>8</b> the block entities. Field 12 records the game version that created the chunk, so one save can mix versions. Not every field appears in every chunk.</p>
<p>Light is a layer of the same kind as blocks, split across two fields: field 3 is the palette and field 2 the bit planes. Each light value packs sunlight in bits 0–4, 22 under open sky, and light from blocks such as torches in bits 5–9; bits 10–19 are set only where block light is, probably its colour. A column gets light when world generation reaches stage 4 (<a href="#mapchunk">3.2</a>); most of its lowest chunks store none, presumably being dark all through.</p>
<p class="source">Sources: every chunk of the 1.19 and 1.22.7 saves scanned · names from <a href="https://github.com/bluelightning32/vs-proto/blob/80ff05afa98af324425ef6f3e5f12b4bea9e6a3f/schema-1.21.0.rc.3.proto">vs-proto's schema</a> · <a href="https://wiki.vintagestory.at/index.php/Modding:Chunk_Data_Storage">wiki: Chunk Data Storage</a> · <a href="../save-format/README.md#3-chunk-data-protobuf-fields">README §3</a></p>
</div>
</section>
<section id="blob">
<div class="section-content">
<h4><span class="num">3.1.2</span><span>Block data</span></h4>
<p>The first 4 bytes are a little-endian <code>i32</code>, <code>length</code>. Its sign says how the palette (<a href="#palette">3.1.3</a>) is stored: <b>negative</b> means the palette is stored as-is, <b>positive</b> means it's compressed with zstd, and <b>0</b> means the chunk is empty. Everything after the palette is one zstd-compressed block of <b>bit planes</b>.</p>
<div class="panel">
<div class="seg-control" role="group" aria-label="Example chunk">
<button type="button" data-ex="raw" aria-pressed="true">chunk y = 4</button>
<button type="button" data-ex="zstd" aria-pressed="false">chunk y = 3</button>
</div>
<div class="strip" id="blob-strip" aria-hidden="true">
<div class="s-len">length</div>
<div class="s-pal">palette</div>
<div class="s-dat">bit planes</div>
</div>
<div class="parts" id="blob-parts"></div>
</div>
<p class="muted">Both examples are real chunks from one column (x 15995, z 15999) of a 1.19.1 save.</p>
<p class="source">Sources: verified against a 1.19 save · <a href="../../src/vs/Compression.zig">src/vs/Compression.zig</a> · <a href="../save-format/README.md#4-blocks-fields-1-and-16">README §4</a></p>
</div>
</section>
<section id="palette">
<div class="section-content">
<h4><span class="num">3.1.3</span><span>Palette</span></h4>
<p>Instead of storing a full block ID for all 32,768 blocks, a chunk keeps a short list of the block types it uses: the <b>palette</b>, a list of <code>i32</code> block IDs. Each block then only stores its <b>position in that list</b>. Slot 0 is always air (ID 0).</p>
<p>Positions are stored in bits, and <i>b</i> bits can count 2<sup><i>b</i></sup> different positions. So the palette is treated as if it had the next power of two of slots. Only the real entries are stored; the extra slots are never referenced, and a reader should treat them as air rather than read past the stored entries.</p>
<div class="panel">
<label class="slider">
<span>block types</span>
<input id="pal-n" type="range" min="1" max="40" value="22">
<output id="pal-n-out">22</output>
</label>
<p class="stat" id="pal-stat" style="margin: var(--s4) 0 0"></p>
<div class="slots" id="pal-slots"></div>
<div class="legend">
<span><i style="background: var(--soft)"></i>air</span>
<span><i style="background: var(--z-soft)"></i>block type</span>
<span><i style="background: repeating-linear-gradient(135deg, transparent 0 0.2rem, var(--border) 0.2rem 0.4rem)"></i>padding</span>
</div>
</div>
</div>
</section>
<section id="order">
<div class="section-content">
<h4><span class="num">3.1.4</span><span>Block order</span></h4>
<p>The cube is flattened into one long list, like reading a book: across a row (<b>x</b>), then the next row (<b>z</b>), then the next page (<b>y</b>). Every block gets a number <i>n</i> from 0 to 32,767.</p>
<p>Bits for those blocks are packed 32 to a little-endian <code>i32</code>. Block <i>n</i> lives in <code>i32</code> number <code>n / 32</code> (rounded down), at bit <code>n % 32</code> counting from the least significant bit. That works out neatly: <b>each <code>i32</code> holds one row of 32 blocks along x</b>, and the bit index is the block's x.</p>
<div class="panel">
<div class="two-col">
<div>
<div class="grid32" id="order-grid" tabindex="0" role="img" aria-label="Layer of 32 by 32 blocks. Arrow keys move x and z, Page Up and Page Down change y."></div>
<div class="axis"><span>x 0 →</span><span id="order-layer" class="num-tab"></span><span>→ 31</span></div>
<div class="axis" style="margin-top: var(--s1)"><span>z 0 ↓</span></div>
</div>
<div>
<div class="sliders">
<label class="slider"><span class="seg-x">x</span><input id="o-x" type="range" min="0" max="31" value="5"><output id="o-x-out">5</output></label>
<label class="slider"><span class="seg-y">y</span><input id="o-y" type="range" min="0" max="31" value="7"><output id="o-y-out">7</output></label>
<label class="slider"><span class="seg-z">z</span><input id="o-z" type="range" min="0" max="31" value="18"><output id="o-z-out">18</output></label>
</div>
<div class="formula" id="order-formula"></div>
<p class="sub" style="margin-top: var(--s5)" id="order-word-label"></p>
<div class="word-strip" id="order-word" aria-hidden="true"></div>
</div>
</div>
</div>
</div>
</section>
<section id="planes">
<div class="section-content">
<h4><span class="num">3.1.5</span><span>Bit planes</span></h4>
<p>A block's palette position isn't stored as one number. With 3 bits per block, the chunk stores <b>every block's first bit together</b> (plane 0), then every block's second bit (plane 1), then every block's third bit (plane 2). To read a block, take its bit from each plane and add them up: plane 0 counts 1, plane 1 counts 2, plane 2 counts 4, and so on.</p>
<p>The number of planes is log₂ of the rounded-up palette size, and each plane is 32,768 bits: 1,024 <code>i32</code>s, 4,096 bytes. The toy chunk below has 16 blocks.</p>
<div class="panel">
<div class="pg-top">
<div>
<p class="sub">blocks n = 0–15</p>
<div class="blocks4" id="pg-blocks"></div>
</div>
<div>
<p class="sub">palette</p>
<div class="pal-list" id="pg-palette"></div>
<div class="buttons">
<button type="button" class="btn" id="pg-add">Add type</button>
<button type="button" class="btn" id="pg-remove">Remove type</button>
<button type="button" class="btn" id="pg-reset">Reset</button>
</div>
</div>
</div>
<div class="planes">
<p class="sub">stored as bit planes</p>
<div class="planes-head" aria-hidden="true"><span></span><div class="bits16" id="pg-head"></div></div>
<div id="pg-planes"></div>
</div>
<div class="packed">
<p class="sub">for comparison: bits side by side</p>
<div class="packed-bits" id="pg-packed"></div>
</div>
<div class="readout" id="pg-readout"></div>
<div class="diff" id="pg-diff" aria-live="polite"></div>
</div>
<p>The format doesn't say why it uses planes, but they have clear advantages. When a chunk needs one more bit, a new plane of zeros is added and every existing bit stays where it is, while side-by-side packing would move every block's bits. Every block also sits at the same bit in every plane whatever the palette size. And planes tend to be long runs of the same bit, which zstd compresses well.</p>
<p class="source">Sources: verified against a 1.19 save · <code>Chunk.getBlock</code> in <a href="../../src/vs/Chunk.zig">src/vs/Chunk.zig</a> · <a href="../save-format/README.md#block-order-and-bit-planes">README §4</a></p>
</div>
</section>
<section id="example">
<div class="section-content">
<h4><span class="num">3.1.6</span><span>Example: decoding a block</span></h4>
<p>A chunk from a 1.19.1 save containing a single placed block, start to finish.</p>
<ol class="steps">
<li><div><p>Find the chunk's row.</p><p class="calc" id="ex-pos"></p></div></li>
<li><div><p>Read field 1 (39 bytes). The first 4 bytes are <code>f8 ff ff ff</code>, which is <b>−8</b>: the palette is stored as-is and is 8 bytes long.</p><p class="calc">palette = [ <b>0</b>, <b>164</b> ] → 2 slots → <b>1 bit</b> per block → 1 plane</p></div></li>
<li><div><p>Decompress the remaining 27 bytes with zstd.</p><p class="calc">27 bytes → <b>4,096 bytes</b> = 1 plane × 1,024 <code>i32</code>s × 4 bytes</p></div></li>
<li><div><p>Exactly one bit in the whole plane is set.</p><p class="calc"><code>i32</code> <b>242</b>, bit <b>5</b> → n = 242 × 32 + 5 = <b>7,749</b></p></div></li>
<li><div><p>Turn <i>n</i> back into a position inside the chunk.</p><p class="calc">x = n % 32 = <b>5</b> · z = ⌊n / 32⌋ % 32 = <b>18</b> · y = ⌊n / 1024⌋ = <b>7</b></p></div></li>
<li><div><p>Look it up. The bit is 1, so the palette position is 1.</p><p class="calc">palette[1] = <b>164</b>, at world block (<b>511,845</b>, <b>135</b>, <b>511,986</b>)</p></div></li>
</ol>
<p class="source">Source: chunk (15995, 4, 15999) of a 1.19.1 save</p>
</div>
</section>
<section id="block-entities">
<div class="section-content">
<h4><span class="num">3.1.7</span><span>Block entities</span></h4>
<p>Blocks that need extra data, like chests, signs and chiseled blocks, have a <b>block entity</b>. Each one is a field 8 entry: the class name as a string, then a tree attribute (<a href="#tree-attributes">2.3</a>).</p>
<p>Every block entity starts with <code>posx</code>, <code>posy</code>, <code>posz</code> (absolute block coordinates) and <code>blockCode</code>. The most common classes in the sample 1.19 save are MicroBlock (8,343), Generic (4,364), BerryBush (632), GenericTypedContainer (370), Crate (274) and GroundStorage (184); the larger 1.22.7 world's ruins have most of the same, led by MicroBlock (40,528) and Generic (22,933). GroundStorage, items placed on the ground, keeps item stacks in its inventory; what their IDs refer to isn't decoded yet.</p>
<p class="source">Sources: every block entity of a 1.19 save (14,447) and of the 1.22.7 saves (77,462) parses · <a href="../save-format/README.md#5-block-entities-field-8">README §5</a></p>
</div>
</section>
<section id="chiseled">
<div class="section-content">
<h4><span class="num">3.1.8</span><span>Chiseled blocks</span></h4>
<p>A chiseled block is an ordinary block in the chunk with a <code>MicroBlock</code> block entity holding its shape: a 16 × 16 × 16 voxel grid stored as a list of boxes (<code>cuboids</code>), plus <code>materials</code>, a list of block IDs from the same ID space as the palettes.</p>
<p>Each box is one 32-bit number. Written in hexadecimal, every 4 bits are one digit, so the box reads off digit by digit: two digits of material (an index into <code>materials</code>), then the far corner, then the near corner, each as z, y, x. The far corner is stored minus 1, so a box reaching the edge fits in one digit (F = 15 means up to 16).</p>
<div class="panel">
<div class="cuboid-wrap">
<svg class="cuboid-3d" id="cub-3d" role="img" aria-label="The boxes drawn in 3D inside the 16 × 16 × 16 block. Click a box to edit it."></svg>
<div>
<p class="sub" id="cub-title">box 1</p>
<div class="cub-sliders">
<label class="slider"><span class="seg-x">x from</span><input id="cub-x1" type="range" min="0" max="15"><output id="cub-x1-out"></output></label>
<label class="slider"><span class="seg-x">x to</span><input id="cub-x2" type="range" min="1" max="16"><output id="cub-x2-out"></output></label>
<label class="slider"><span class="seg-y">y from</span><input id="cub-y1" type="range" min="0" max="15"><output id="cub-y1-out"></output></label>
<label class="slider"><span class="seg-y">y to</span><input id="cub-y2" type="range" min="1" max="16"><output id="cub-y2-out"></output></label>
<label class="slider"><span class="seg-z">z from</span><input id="cub-z1" type="range" min="0" max="15"><output id="cub-z1-out"></output></label>
<label class="slider"><span class="seg-z">z to</span><input id="cub-z2" type="range" min="1" max="16"><output id="cub-z2-out"></output></label>
<label class="slider"><span>material</span><input id="cub-material" type="range" min="0" max="255"><output id="cub-material-out"></output></label>
</div>
<div class="buttons">
<button type="button" class="btn" id="cub-add">Add box</button>
<button type="button" class="btn" id="cub-remove">Remove box</button>
<button type="button" class="btn" id="cub-reset">Reset</button>
</div>
</div>
</div>
<p class="sub" id="cub-anatomy-title" style="margin-top: var(--s5)">box 1, as stored</p>
<div class="hex-anatomy" id="cub-anatomy"></div>
<p class="stat" id="cub-number" style="margin: var(--s3) 0 0"></p>
<div class="table-wrap" style="margin-top: var(--s5)">
<table class="cub-table">
<thead><tr><th>box</th><th>hex</th><th>x</th><th>y</th><th>z</th><th>material</th></tr></thead>
<tbody id="cub-rows"></tbody>
</table>
</div>
<label class="field" style="margin-top: var(--s5)">CUBOIDS, AS STORED<input id="cub-input" type="text" spellcheck="false" autocomplete="off" value="15986688, 16757824, 4190336, 16774284"></label>
<p class="error-line" id="cub-error" aria-live="polite"></p>
</div>
<p class="muted">The block starts as a real chiseled block from the sample save, "Aged polished rock (Granite)": four boxes of one material. Each box has its own colour here; in the game all four are granite.</p>
<p class="source">Sources: all 20,407 boxes of a 1.19 save and 101,400 of a 1.22.7 save decode to boxes inside the block, with materials in the list · 1.22.7 code: <a href="https://github.com/anegostudios/vssurvivalmod/blob/849fa8cad9e392368566efc7474e73db6404a145/Systems/Microblock/BEMicroBlock.cs">vssurvivalmod BEMicroBlock.cs</a> · <a href="../save-format/README.md#chiseled-blocks-microblock-chisel">README §5</a></p>
</div>
</section>
</section>
<section id="mapchunk">
<div class="section-content">
<h3><span class="num">3.2</span><span><code>mapchunk</code></span></h3>
<p>One row per chunk column, keyed by its x and z (<a href="#position">2.1</a>, y 0). Its message, <code>ServerMapChunk</code>, is 10 to 17 KiB, and most of its fields are a value for each of the column's 1,024 block columns, at index z × 32 + x, written as one field each.</p>
<div class="table-wrap">
<table>
<thead><tr><th>#</th><th>name</th><th>contents</th></tr></thead>
<tbody>
<tr class="key"><td>3</td><td><code>RainHeightMap</code></td><td>per block column: the height of the highest block rain can't fall through</td></tr>
<tr><td>4</td><td><code>currentpass</code></td><td>the world generation stage, below</td></tr>
<tr><td>7</td><td><code>WorldGenTerrainHeightMap</code></td><td>per block column: the ground before plants and trees grew</td></tr>
<tr><td>10</td><td><code>YMax</code></td><td>the highest block that isn't air</td></tr>
<tr><td>13</td><td><code>TopRockIdMap</code></td><td>per block column: the block ID of the top rock layer</td></tr>
<tr><td>16</td><td><code>WorldGenVersion</code></td><td>as <code>gamedata</code>'s</td></tr>
<tr><td>…</td><td></td><td>fields 1, 8, 9, 11, 12, 15 and 17: mods' and the game's data by key, scheduled updates, new block entities, snow, cave shapes, and an unused map</td></tr>
<tr><td>18</td><td></td><td>newer than the schema; unknown</td></tr>
</tbody>
</table>
</div>
<p><b>The rain height</b> falls through plants and loose stones but stops at water, so it's the ground, or a water surface. The game's own map draws it. A column with no blocks has 0, and a few hold 65,531 to 65,535: the game keeps these heights as unsigned 16-bit numbers, so those are −5 to −1. A row stays when its blocks are removed, so a reader should check the block at the height it gives.</p>
<p><b>The terrain height</b> is set by world generation and never changed afterwards. For seas and lakes, it's their bed.</p>
<p><b>The stage</b> is the column's next world generation pass (<code>EnumWorldGenPass</code>), not the last one done. Passes 2 to 5 need the columns around, so everything finished is ringed by partly generated columns, one ring per stage, each one chunk column wide. Only stage 6 is finished; at stages 2 and 3 there are no trees or plants yet.</p>
<div class="table-wrap">
<table>
<thead><tr><th>value</th><th>next pass</th><th>generates</th></tr></thead>
<tbody>
<tr><td>1</td><td>Terrain</td><td>terrain, rock layers, caves</td></tr>
<tr><td>2</td><td>TerrainFeatures</td><td>deposits, structures, ponds</td></tr>
<tr><td>3</td><td>Vegetation</td><td>plants, shrubs, trees, rivulets</td></tr>
<tr><td>4</td><td>NeighbourSunLightFlood</td><td>snow, light across chunks</td></tr>
<tr><td>5</td><td>PreDone</td><td>creatures</td></tr>
<tr class="key"><td>6</td><td>Done</td><td>–</td></tr>
</tbody>
</table>
</div>
<p class="source">Sources: every row of the test saves parses; heights checked against the highest block of every column · names from <a href="https://github.com/bluelightning32/vs-proto/blob/80ff05afa98af324425ef6f3e5f12b4bea9e6a3f/schema-1.21.0.rc.3.proto">vs-proto's schema</a> and meanings from <a href="https://github.com/anegostudios/vsapi/blob/63d33f70018c606fb0f70ead900fe90625fbd7b2/Common/API/IMapChunk.cs">vsapi IMapChunk.cs</a> · stages from the <a href="https://wiki.vintagestory.at/index.php/Modding:WorldGen_Concept">wiki: WorldGen Concept</a> · <a href="../save-format/README.md#7-map-chunks">README §7</a></p>
</div>
</section>
<section id="mapregion">
<div class="section-content">
<h3><span class="num">3.3</span><span><code>mapregion</code></span></h3>
<p>One row per 16 × 16 chunk columns, 512 × 512 blocks, keyed by the region's x and z (<a href="#position">2.1</a>). Its message, <code>ServerMapRegion</code>, holds the maps world generation drew the region from. Each map is a square grid of numbers, packed, with a few rows and columns of padding copied from the regions around it so they blend at the edges; the grid inside the padding, its inner size, can be finer than one value per chunk column.</p>
<div class="table-wrap">
<table>
<thead><tr><th>#</th><th>map</th><th>inner size</th></tr></thead>
<tbody>
<tr><td>1</td><td><code>LandformMap</code></td><td>32 × 32</td></tr>
<tr><td>2</td><td><code>ForestMap</code></td><td>16 × 16</td></tr>
<tr class="key"><td>3</td><td><a href="#climate"><code>ClimateMap</code></a></td><td>16 × 16</td></tr>
<tr><td>4</td><td><code>GeologicProvinceMap</code></td><td>8 × 8</td></tr>
<tr><td>5, 6</td><td><code>BushMap</code>, <code>FlowerMap</code></td><td>32 × 32, 16 × 16</td></tr>
<tr><td>8</td><td><code>OreMaps</code></td><td>one per ore, by name: 31</td></tr>
<tr><td>12</td><td><code>RockStrata</code></td><td>one per rock layer: 16, each 32 × 32</td></tr>
<tr><td>15</td><td><code>BeachMap</code></td><td>32 × 32</td></tr>
<tr><td>16</td><td><code>BlockPatchMaps</code></td><td>one per kind of patch, such as mushrooms</td></tr>
<tr><td>17, 18</td><td><code>UpheavelMap</code>, <code>OceanMap</code></td><td>16 × 16</td></tr>
</tbody>
</table>
</div>
<p>Besides the maps, field 11 lists the structures world generation placed: lakes, ruins, villages, traders and more, each with a code such as <code>small5.json/lakes</code> and its box in absolute block coordinates, so a map could label them. Field 9 keeps the game's and mods' data by key, such as the weather.</p>
<p class="source">Sources: sizes and keys in every test save · names from <a href="https://github.com/bluelightning32/vs-proto/blob/80ff05afa98af324425ef6f3e5f12b4bea9e6a3f/schema-1.21.0.rc.3.proto">vs-proto's schema</a> · <a href="https://wiki.vintagestory.at/Modding:VCDBS_format#mapregion">wiki: VCDBS format</a> · <a href="../save-format/README.md#8-map-regions">README §8</a></p>
</div>
<section id="climate">
<div class="section-content">
<h4><span class="num">3.3.1</span><span>Climate map</span></h4>
<p>The climate map, field 3, has a value every 32 blocks: 16 × 16 inside 2 cells of padding. Each value packs the climate there at sea level: <span class="seg-x">temperature</span> and <span class="seg-z">rainfall</span>, a byte each, 0 to 255. Between the values, the game interpolates.</p>
<div class="panel">
<div class="climate-inputs">
<label class="field">TEMPERATURE<input id="cl-t" type="number" min="0" max="255" value="93" inputmode="numeric"></label>
<label class="field">RAINFALL<input id="cl-r" type="number" min="0" max="255" value="83" inputmode="numeric"></label>
<label class="field">OTHER<input id="cl-o" type="number" min="0" max="255" value="0" inputmode="numeric"></label>
</div>
<label class="field pos-value">VALUE<input id="cl-value" type="text" inputmode="numeric" spellcheck="false" autocomplete="off"></label>
<p class="error-line" id="cl-error" aria-live="polite"></p>
<div class="bitbar bits32">
<div class="bitbar-labels" aria-hidden="true">
<span class="seg-pad" style="grid-column: span 8">0</span>
<span class="seg-x" style="grid-column: span 8">temperature</span>
<span class="seg-z" style="grid-column: span 8">rainfall</span>
<span class="seg-y" style="grid-column: span 8">other</span>
</div>
<div class="bitbar-cells" id="cl-bits" aria-hidden="true"></div>
<div class="bitbar-ends"><span>bit 31</span><span>bit 0</span></div>
</div>
</div>
<p class="muted">The top byte is always 0. The lowest isn't the climate: it's set in about 30% of the values in the test saves, and what it means isn't known. The test saves' temperatures are 84 to 139 and their rainfalls 4 to 255.</p>
<p>Height changes both: it's colder higher up, by 1 for every 1.5 blocks above sea level, and the rainfall changes too. The game tints grass, leaves and water by the result, picking a colour from a climate colour map by temperature across and rainfall down. That's checked against the game's own map, whose water is that colour to within 1%.</p>
<p class="source">Sources: the grid's sizes in every test save · <a href="https://github.com/anegostudios/vsapi/blob/63d33f70018c606fb0f70ead900fe90625fbd7b2/Datastructures/IntDataMap2D.cs">vsapi IntDataMap2D.cs</a> and <a href="https://github.com/anegostudios/vsapi/blob/63d33f70018c606fb0f70ead900fe90625fbd7b2/Common/Climate.cs">Climate.cs</a> · <a href="../blocks.md#climate-and-season-tint">blocks.md: climate and season tint</a> · <a href="../save-format/README.md#8-map-regions">README §8</a></p>
</div>
</section>
</section>
<section id="gamedata">
<div class="section-content">
<h3><span class="num">3.4</span><span><code>gamedata</code></span></h3>
<p>A single row holding one <code>SaveGame</code> message: block and item IDs, the world's size, clock and settings, and more.</p>
</div>
<section id="block-names">
<div class="section-content">
<h4><span class="num">3.4.1</span><span>Block and item IDs</span></h4>
<p>Palettes and chiseled blocks only hold numeric block IDs. The names are in field 11, a list of named entries: <code>BlockIDs</code> lists every ID with its block code, and <code>ItemIDs</code> does the same for items. A mod's codes carry its name, such as <code>primitivesurvival:</code>, and its IDs follow the game's.</p>
<div class="table-wrap">
<table>
<thead><tr><th>ID</th><th>1.22.7 world</th><th>1.19 sample</th></tr></thead>
<tbody>
<tr><td>0</td><td><code>air</code></td><td><code>air</code></td></tr>
<tr><td>1</td><td><code>mantle</code></td><td><code>mantle</code></td></tr>
<tr><td>164</td><td><code>creativeblock-2</code></td><td><code>creativeblock-12</code></td></tr>
</tbody>
</table>
</div>
<p>The same number means different blocks in different saves: 2966 is <code>water-still-7</code> in the 1.22.7 world but a snowy fireclay roof corner in the 1.19 sample. So every save has to be read with its own list.</p>
<p class="source">Sources: every block ID in the test saves has a code · <a href="../../src/vs/GameData.zig">src/vs/GameData.zig</a> · <a href="../save-format/README.md#block-and-item-ids">README §6</a></p>
</div>
</section>
<section id="sea-level">
<div class="section-content">
<h4><span class="num">3.4.2</span><span>World size and sea level</span></h4>
<p>Fields 1, 2 and 3 are the world's size: 1,024,000 blocks east to west, 256 high and 1,024,000 north to south by default. The game shows positions from the middle, half of those across (<a href="#position">2.1</a>).</p>
<p>The sea level isn't stored; the game derives it from the height: × 110 / 255, rounded down, so 110 in a default world. Water fills the blocks below it, so the top water block of a sea or lake is at y 109.</p>
<p class="source">Sources: sea level from the <a href="https://wiki.vintagestory.at/Sea_level">wiki</a>, matching the water in the test saves · <a href="../save-format/README.md#sea-level">README §6</a></p>
</div>
</section>
<section id="date">
<div class="section-content">
<h4><span class="num">3.4.3</span><span>Date</span></h4>
<p><code>TotalGameSeconds</code>, field 12, counts game time from 00:00 on 1 January of the first year, which the calendar numbers 1386. Divide by 3,600 for hours and by <code>HoursPerDay</code>, field 25, 24, for days; a year is 12 months of the world's <code>daysPerMonth</code> (<a href="#world-config">3.4.4</a>), 9 by default. Field 38 is the time the world was created.</p>
<p>The 1.22.7 worlds were created at 3,139,200 seconds: 872 hours, so 36 days and 8 hours, which is 08:00 on 1 May 1386. A map coloured like the game's tints grass and leaves for the season on the save's date.</p>
<p class="source">Sources: the calendar from <a href="https://github.com/anegostudios/vsapi/blob/63d33f70018c606fb0f70ead900fe90625fbd7b2/Common/API/IGameCalendar.cs">vsapi IGameCalendar.cs</a> · <a href="../save-format/README.md#the-date">README §6</a></p>
</div>
</section>
<section id="world-config">
<div class="section-content">
<h4><span class="num">3.4.4</span><span>World configuration</span></h4>
<p>Field 31 is the world's settings, chosen when it was created, as a tree attribute (<a href="#tree-attributes">2.3</a>). The values are mostly strings, such as <code>gameMode: "survival"</code>, <code>startingClimate: "temperate"</code>, <code>seasons: "enabled"</code>, <code>daysPerMonth: "9"</code> and <code>spawnRadius: "5000"</code>, how far from the centre new players appear. A world with the colour-accurate map has <code>colorAccurateWorldmap</code> as the number 1.</p>
<p>The row holds more besides: the world's name (13), its seed (7), the game versions that created it and last saved it (18, 21), and an identifier (34) that names the game's map cache (<a href="#map">4</a>).</p>
<p class="source">Sources: every world configuration in the test saves parses · <a href="../save-format/README.md#world-configuration">README §6</a></p>
</div>
</section>
</section>
<section id="playerdata">
<div class="section-content">
<h3><span class="num">3.5</span><span><code>playerdata</code></span></h3>
<p>One row per player who has joined, keyed by <code>playeruid</code>. Its message, <code>ServerWorldPlayerData</code>, holds their inventories, game mode, death count and player entity, which includes their position. Their privileges aren't in the save but in JSON files in the data folder's <code>Playerdata</code>.</p>
<p>The message isn't decoded further, but a player's position can be found in it: the only run of three little-endian 64-bit floats inside the world, stored two or three times, the entity's x, y and z in absolute block coordinates.</p>
<p>This position confirms how the game shows coordinates (<a href="#position">2.1</a>). One player stood on the ground where the game showed 409, 111, −304; that column's rain height (<a href="#mapchunk">3.2</a>) is 110, so their feet were at 111. After they flew up and moved a few blocks, the save held them at 512,409.0, 193.9, 511,699.3: x 512,409 − 512,000 = 409, and z −300.7.</p>
<p class="source">Sources: table description from the <a href="https://wiki.vintagestory.at/Modding:VCDBS_format">wiki: VCDBS format</a> · the position found in the 1.22.7 saves · <a href="../save-format/README.md#2-positions">README §2</a></p>
</div>
</section>
</section>
<section id="map">
<div class="section-content">
<h2><span class="num">4</span><span>Drawing a top-down map</span></h2>
<p>A simple map needs only the top block of each column. Scan each column down from the top until something isn't air, and colour the pixel by that height. Columns with no blocks at all stay black. Click cells in the side view to add or remove blocks.</p>
<div class="panel toy">
<div>
<p class="sub">map, one pixel per column</p>
<div class="toy-map" id="toy-map" aria-hidden="true"></div>
</div>
<div>
<p class="sub">side view</p>
<div class="toy-side" id="toy-side" role="group" aria-label="Side view. Arrow keys move, Enter or Space toggles a block."></div>
</div>
<div class="buttons" style="margin-top: 0"><button type="button" class="btn" id="toy-reset">Reset</button></div>
</div>
<p>The game's own world map works the same way, with refinements: it takes each column's height from the stored rain height (<a href="#mapchunk">3.2</a>) instead of scanning, reads liquids too (they live in field 16, not field 1), looks under snow, colours by a per-block map colour, and shades slopes by comparing each column with its neighbours. It only draws finished columns, at stage 6. Its colour-accurate mode colours each block by its texture instead, tinted by the climate (<a href="#climate">3.3.1</a>) and the season on the save's date (<a href="#date">3.4.3</a>).</p>
<p>That map isn't in the save. Each player's game keeps what it has drawn in the data folder, in <code>Maps/<id>.db</code>, where <code><id></code> is <code>gamedata</code>'s identifier (<a href="#world-config">3.4.4</a>): another SQLite database whose <code>mappiece</code> table has a row per chunk column, keyed like map chunks, holding its 32 × 32 pixels, red in the lowest byte, at index z × 32 + x. It only has what that player has seen, so a map of a whole world, or one made on a server, is drawn from the save, and the cache is a way to check it.</p>
<p class="source">Sources: 1.22.7 code, <a href="https://github.com/anegostudios/vsessentialsmod/blob/06673b67318e002332b6aa8b3d0308f11d2aba99/Systems/WorldMap/ChunkLayer/ChunkMapLayer.cs">vsessentialsmod ChunkMapLayer.cs</a> · the map cache decoded and compared with Storymap's maps of 1.22.7 worlds · <a href="../save-format/README.md#the-games-map-cache">README §7</a></p>
</div>
</section>
<section id="unknown">
<div class="section-content">
<h2><span class="num">5</span><span>Open questions</span></h2>
<ul class="list">
<li><b>The other fields.</b> Entities' data (6), field 10, the empty flag (13), decor (14) and the colour of light.</li>
<li><b>The other tables.</b> The schema names every field, but <code>playerdata</code> hasn't been decoded beyond the player's position, nor have the values of <code>mapregion</code>'s maps other than the climate's, the climate's lowest byte, or a few fields newer than the schema.</li>
<li><b>Other dimensions.</b> No test save has chunks outside dimension 0.</li>
<li><b>Mods.</b> Modded block and item codes carry their mod's domain, such as <code>primitivesurvival:</code>; which generated structures come from a mod isn't known.</li>
</ul>
<p class="source">Source: <a href="../save-format/README.md#9-open-questions">README §9</a></p>
</div>
</section>
</main>
<script>
(() => {
const $ = (sel) => document.querySelector(sel);
const el = (tag, cls, text) => {
const node = document.createElement(tag);
if (cls) node.className = cls;
if (text !== undefined) node.textContent = text;
return node;
};
const reduceMotion = matchMedia("(prefers-reduced-motion: reduce)");
const animate = (node, keyframes, options) => (reduceMotion.matches ? null : node.animate(keyframes, options));
const fmt = (n) => n.toLocaleString("en-US");
const bitsFor = (count) => {
let bits = 0;
while ((1 << bits) < count) bits++;
return bits;
};
/* contents, from the sections' headings, nested as the sections are */
const tocItems = new Map();
for (const section of document.querySelectorAll("main section[id]")) {
const heading = section.querySelector(":scope > .section-content > :is(h2, h3, h4)");
const link = el("a");
link.href = `#${section.id}`;
const title = heading.lastElementChild.cloneNode(true);
title.className = "title";
link.append(el("span", "num", heading.querySelector(".num").textContent), title);
const item = el("li");
item.append(link);
const parent = tocItems.get(section.parentElement.closest("section"));
const list = parent ? parent.querySelector(":scope > ol") ?? parent.appendChild(el("ol")) : $("#toc");
list.append(item);
tocItems.set(section, item);
}
/* position */
const MAX21 = 2097151;
const M21 = BigInt(MAX21);
const posX = $("#pos-x");
const posY = $("#pos-y");
const posZ = $("#pos-z");
const posD = $("#pos-d");
const posValue = $("#pos-value");
const posError = $("#pos-error");
const posRange = $("#pos-range");
const posGame = $("#pos-game");
const bitCells = [];
// Bit 63 reserved, then y, the dimension's high half, a guard bit, z, its low half, a guard bit, x.
const segment = (i) => i === 63 || i === 48 || i === 21 ? "seg-pad" : i >= 54 ? "seg-y" : i >= 49 ? "seg-d" : i >= 27 ? "seg-z" : i >= 22 ? "seg-d" : "seg-x";
for (let i = 63; i >= 0; i--) {
const cell = el("span", segment(i));
$("#pos-bits").append(cell);
bitCells[i] = cell;
}
const pack = (x, y, z, d) => BigInt(x) | (BigInt(d & 31) << 22n) | (BigInt(z) << 27n) | (BigInt(d >> 5) << 49n) | (BigInt(y) << 54n);
// Returns the field's integer, or an error message. Bad input never moves the display.
function readCoord(input, max, name) {
const text = input.value.trim();
if (!/^\d+$/.test(text)) return `${name} must be a whole number`;
const v = Number(text);
if (v > max) return `${name} must be 0–${fmt(max)}`;
return v;
}
function showPosition(x, y, z, d, v) {
for (let i = 0; i < 64; i++) {
const on = ((v >> BigInt(i)) & 1n) === 1n;
bitCells[i].classList.toggle("on", on);
bitCells[i].textContent = on ? "1" : "0";
}
const signed = BigInt.asIntN(64, v);
const stored = signed < 0n ? ` · stored as <b>${signed}</b>` : "";
posRange.innerHTML = `blocks <b>x ${fmt(x * 32)}–${fmt(x * 32 + 31)}</b> · <b>y ${fmt(y * 32)}–${fmt(y * 32 + 31)}</b> · <b>z ${fmt(z * 32)}–${fmt(z * 32 + 31)}</b>${d ? ` · dimension <b>${d}</b>` : ""}${stored}`;
const centre = 512000;
const shown = (n) => fmt(n).replace("-", "−");
posGame.innerHTML = `as the game shows it, in a default world: <b>x ${shown(x * 32 - centre)} to ${shown(x * 32 + 31 - centre)}</b> · <b>z ${shown(z * 32 - centre)} to ${shown(z * 32 + 31 - centre)}</b>`;
}
function setError(message, inputs) {
posError.textContent = message;
[posX, posY, posZ, posD, posValue].forEach((input) => input.setAttribute("aria-invalid", String(inputs.includes(input))));
}
function fromCoords() {
const fields = [[posX, MAX21, "x"], [posY, 511, "y"], [posZ, MAX21, "z"], [posD, 1023, "dimension"]];
const values = fields.map(([input, max, name]) => readCoord(input, max, name));
const bad = values.findIndex((v) => typeof v === "string");
if (bad >= 0) return setError(values[bad], [fields[bad][0]]);
setError("", []);
const [x, y, z, d] = values;
const v = pack(x, y, z, d);
posValue.value = BigInt.asIntN(64, v).toString();
showPosition(x, y, z, d, v);
}
function fromValue() {
const text = posValue.value.trim();
if (!/^-?\d+$/.test(text)) return setError("position must be a whole number", [posValue]);
const big = BigInt(text);
if (big < -(1n << 63n) || big >= (1n << 64n)) return setError("position must fit in 64 bits", [posValue]);
setError("", []);
const v = BigInt.asUintN(64, big);
const x = Number(v & M21);
const z = Number((v >> 27n) & M21);
const y = Number((v >> 54n) & 511n);
const d = Number(((v >> 22n) & 31n) | (((v >> 49n) & 31n) << 5n));
posX.value = x;
posY.value = y;
posZ.value = z;
posD.value = d;
showPosition(x, y, z, d, v);
}
[posX, posY, posZ, posD].forEach((input) => input.addEventListener("input", fromCoords));
posValue.addEventListener("input", fromValue);
fromCoords();
/* climate */
const climateInputs = [[$("#cl-t"), "temperature", 16], [$("#cl-r"), "rainfall", 8], [$("#cl-o"), "other", 0]];
const climateValue = $("#cl-value");
const climateError = $("#cl-error");
const climateCells = [];
const climateSegment = (i) => i >= 24 ? "seg-pad" : i >= 16 ? "seg-x" : i >= 8 ? "seg-z" : "seg-y";
for (let i = 31; i >= 0; i--) {
const cell = el("span", climateSegment(i));
$("#cl-bits").append(cell);
climateCells[i] = cell;
}
function showClimate(v) {
for (let i = 0; i < 32; i++) {
const on = ((v >>> i) & 1) === 1;
climateCells[i].classList.toggle("on", on);
climateCells[i].textContent = on ? "1" : "0";
}
}
function setClimateError(message, inputs) {
climateError.textContent = message;
[...climateInputs.map(([input]) => input), climateValue].forEach((input) => input.setAttribute("aria-invalid", String(inputs.includes(input))));
}
function climateFromParts() {
const values = climateInputs.map(([input, name]) => readCoord(input, 255, name));
const bad = values.findIndex((v) => typeof v === "string");