Skip to content

Commit a7519e8

Browse files
authored
Support for rendering schematics (#57)
* Start adding support to render schematics * Fix bit size error with litematica and improve errors * Add supprt for world edit schematics * Parse block entity NBT from schematics * Fix XZ order of schem files * Update deepslate, skip invisible blocks on large structures * Disable invisible blocks toggle for large structures * Make schematics fully readonly * Schem order is YZX * Support schem files with a pallet larger than 127
1 parent 389fc8a commit a7519e8

10 files changed

+2022
-33
lines changed

package-lock.json

+7-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
"lint": "eslint . --ext .ts"
6767
},
6868
"dependencies": {
69-
"deepslate": "^0.18.1",
69+
"deepslate": "^0.18.2",
7070
"env-paths": "^2.2.1",
7171
"follow-redirects": "^1.14.8",
7272
"gl-matrix": "^3.4.3",

res/editor.css

+5
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,11 @@ span.nbt-value {
368368
display: none;
369369
}
370370

371+
.btn.unavailable {
372+
cursor: unset;
373+
background-color: var(--vscode-button-secondaryBackground);
374+
}
375+
371376
.btn:not(:last-child) {
372377
margin-right: 5px;
373378
}

src/NbtDocument.ts

+15-3
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@ export class NbtDocument extends Disposable implements vscode.CustomDocument {
9393
if (file instanceof NbtRegion) {
9494
const firstChunk = file.getFirstChunk()
9595
return firstChunk?.getRoot().getNumber('DataVersion') ?? 0
96+
} else if (file.root.has('Blocks') && file.root.has('Data')) {
97+
// schematic files don't have DataVersion
98+
// should be 1.12 but mcmeta doesn't have that, so using 1.14
99+
// TODO: handle {Materials:"Pocket"} differently
100+
return 1952
96101
} else {
97102
return file.root.getNumber('DataVersion') ?? 0
98103
}
@@ -143,10 +148,17 @@ export class NbtDocument extends Disposable implements vscode.CustomDocument {
143148
}
144149

145150
private isStructureData() {
146-
if (this._documentData instanceof NbtRegion) return false
151+
if (this._documentData instanceof NbtRegion) {
152+
return false // region file
153+
}
154+
if (this.uri.fsPath.endsWith('.schem') || this.uri.fsPath.endsWith('.schematic') || this.uri.fsPath.endsWith('.litematic')) {
155+
return true // schematic
156+
}
147157
const root = this._documentData.root
148-
return root.hasList('size', NbtType.Int, 3)
149-
&& root.hasList('blocks') && root.hasList('palette')
158+
if (root.hasList('size', NbtType.Int, 3) && root.hasList('blocks') && root.hasList('palette')) {
159+
return true // vanilla structure
160+
}
161+
return false // anything else
150162
}
151163

152164
private isMapData() {

0 commit comments

Comments
 (0)