@xiaozhu2007/koishi-plugin-litematic-renderer 0.5.2 → 0.5.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (18) hide show
  1. package/README.md +1 -0
  2. package/assets/threeviews/assets/block-assets.js +3 -0
  3. package/assets/threeviews/assets/block-flags.js +413 -0
  4. package/assets/threeviews/{/346/210/221/347/232/204/344/270/226/347/225/214-Litematic/346/212/225/345/275/261/344/270/211/350/247/206/345/233/276/351/242/204/350/247/210_files/deepslate-helpers.js./344/270/213/350/275/275 → assets/deepslate-resources.js} +67 -35
  5. package/assets/threeviews/assets/deepslate.min.js +7558 -0
  6. package/assets/threeviews/assets/gl-matrix.min.js +4195 -0
  7. package/assets/threeviews/{/346/210/221/347/232/204/344/270/226/347/225/214-Litematic/346/212/225/345/275/261/344/270/211/350/247/206/345/233/276/351/242/204/350/247/210_files/litematic-utils.js./344/270/213/350/275/275 → assets/litematic.js} +63 -64
  8. package/assets/threeviews/assets/renderer-api.js +936 -0
  9. package/assets/threeviews/index.html +1205 -1212
  10. package/lib/index.d.ts +11 -10
  11. package/lib/index.js +1 -1
  12. package/package.json +31 -27
  13. package/assets/threeviews//346/210/221/347/232/204/344/270/226/347/225/214-Litematic/346/212/225/345/275/261/344/270/211/350/247/206/345/233/276/351/242/204/350/247/210_files/api.js./344/270/213/350/275/275 +0 -917
  14. package/assets/threeviews//346/210/221/347/232/204/344/270/226/347/225/214-Litematic/346/212/225/345/275/261/344/270/211/350/247/206/345/233/276/351/242/204/350/247/210_files/assets.js./344/270/213/350/275/275 +0 -1
  15. package/assets/threeviews//346/210/221/347/232/204/344/270/226/347/225/214-Litematic/346/212/225/345/275/261/344/270/211/350/247/206/345/233/276/351/242/204/350/247/210_files/deepslate.js./344/270/213/350/275/275 +0 -2
  16. package/assets/threeviews//346/210/221/347/232/204/344/270/226/347/225/214-Litematic/346/212/225/345/275/261/344/270/211/350/247/206/345/233/276/351/242/204/350/247/210_files/gl-matrix-min.js./344/270/213/350/275/275 +0 -28
  17. package/assets/threeviews//346/210/221/347/232/204/344/270/226/347/225/214-Litematic/346/212/225/345/275/261/344/270/211/350/247/206/345/233/276/351/242/204/350/247/210_files/opaque.js./344/270/213/350/275/275 +0 -413
  18. /package/assets/threeviews/{/346/210/221/347/232/204/344/270/226/347/225/214-Litematic/346/212/225/345/275/261/344/270/211/350/247/206/345/233/276/351/242/204/350/247/210_files/atlas.png" → assets/atlas.png} +0 -0
@@ -1,4 +1,4 @@
1
- class Litematic { }
1
+ class Litematic {}
2
2
 
3
3
  class LitematicRegion {
4
4
  constructor(width, height, depth) {
@@ -8,31 +8,30 @@ class LitematicRegion {
8
8
  }
9
9
  }
10
10
 
11
- function readLitematicFromNBTData(nbtdata) {
11
+ function readLitematicFromNBTData(nbtData) {
12
12
  // Get rid of all the annoying stuff basically
13
13
 
14
- var litematic = new Litematic();
14
+ const litematic = new Litematic();
15
15
  litematic.regions = new Array();
16
16
 
17
- var regions = nbtdata.value.Regions.value;
18
- for (let regionName in regions) {
19
-
20
- var region = regions[regionName].value;
21
-
22
- var blockPalette = __stripNBTTyping(region.BlockStatePalette);
23
-
17
+ const regions = nbtData.value.Regions.value;
18
+ for (const regionName in regions) {
19
+ const region = regions[regionName].value;
20
+
21
+ const blockPalette = __stripNBTTyping(region.BlockStatePalette);
22
+
24
23
  // Find the minimum number of bits needed to express all blocks
25
- nbits = Math.max(2, Math.ceil(Math.log2(blockPalette.length)));
24
+ const nbits = Math.max(2, Math.ceil(Math.log2(blockPalette.length)));
26
25
 
27
- width = region.Size.value.x.value;
28
- height = region.Size.value.y.value;
29
- depth = region.Size.value.z.value;
26
+ const width = region.Size.value.x.value;
27
+ const height = region.Size.value.y.value;
28
+ const depth = region.Size.value.z.value;
30
29
 
31
- var blockData = region.BlockStates.value;
30
+ const blockData = region.BlockStates.value;
32
31
 
33
- var blocks = processNBTRegionData(blockData, nbits, width, height, depth);
32
+ const blocks = processNBTRegionData(blockData, nbits, width, height, depth);
34
33
 
35
- var litematicRegion = new LitematicRegion(width, height, depth);
34
+ const litematicRegion = new LitematicRegion(width, height, depth);
36
35
  litematicRegion.blocks = blocks;
37
36
  litematicRegion.blockPalette = blockPalette;
38
37
  litematicRegion.position = {
@@ -52,50 +51,51 @@ function processNBTRegionData(regionData, nbits, width, height, depth) {
52
51
  // The raw data is a list of nbits-wide numbers all packed together into a single array of 64-bit* ints
53
52
  // I ripped off some python code for this, can't remember where from.
54
53
  // (* of course this is javascript so each int is split into an array fo 2 32-bit ints)
55
-
56
- mask = (1 << nbits) - 1;
57
-
58
- y_shift = Math.abs(width * depth);
59
- z_shift = Math.abs(width);
60
- var blocks = new Array();
61
- for (let x=0; x < Math.abs(width); x++) {
54
+
55
+ const mask = (1 << nbits) - 1;
56
+
57
+ const y_shift = Math.abs(width * depth);
58
+ const z_shift = Math.abs(width);
59
+ const blocks = new Array();
60
+ for (let x = 0; x < Math.abs(width); x++) {
62
61
  blocks[x] = new Array();
63
- for (let y=0; y < Math.abs(height); y++) {
62
+ for (let y = 0; y < Math.abs(height); y++) {
64
63
  blocks[x][y] = new Array();
65
- for (let z=0; z < Math.abs(depth); z++) {
66
-
67
- index = y * y_shift + z * z_shift + x;
68
-
69
- start_offset = index * nbits;
70
-
71
- start_arr_index = start_offset >>> 5; /// divide by 32
72
- end_arr_index = ((index + 1) * nbits - 1) >>> 5;
73
- start_bit_offset = start_offset & 0x1F; // % 32
74
-
64
+ for (let z = 0; z < Math.abs(depth); z++) {
65
+ const index = y * y_shift + z * z_shift + x;
66
+
67
+ const start_offset = index * nbits;
68
+
69
+ const start_arr_index = start_offset >>> 5; /// divide by 32
70
+ const end_arr_index = ((index + 1) * nbits - 1) >>> 5;
71
+ const start_bit_offset = start_offset & 0x1f; // % 32
72
+
75
73
  // This bit here is to handle the fact that the 64 bit numbers have to be broken down to
76
74
  // 32bit numbers in javascript.
77
- half_ind = start_arr_index >>> 1;
75
+ const half_ind = start_arr_index >>> 1;
76
+ let blockStart;
77
+ let blockEnd;
78
78
  if ((start_arr_index & 0x1) == 0) {
79
79
  blockStart = regionData[half_ind][1];
80
80
  blockEnd = regionData[half_ind][0];
81
81
  } else {
82
82
  blockStart = regionData[half_ind][0];
83
- if (half_ind+1 < regionData.length) {
84
- blockEnd = regionData[half_ind+1][1];
83
+ if (half_ind + 1 < regionData.length) {
84
+ blockEnd = regionData[half_ind + 1][1];
85
85
  } else {
86
86
  // It seems that sometimes the index can extend past the end of the array, but this fix works (for now)
87
87
  blockEnd = 0x0;
88
88
  }
89
89
  }
90
-
90
+
91
91
  if (start_arr_index == end_arr_index) {
92
- blocks[x][y][z] = (blockStart >>> start_bit_offset) & mask;
92
+ blocks[x][y][z] = (blockStart >>> start_bit_offset) & mask;
93
93
  } else {
94
- end_offset = 32 - start_bit_offset; // num curtailed bits
95
- val = ((blockStart >>> start_bit_offset) & mask) | ((blockEnd << end_offset) & mask);
96
- blocks[x][y][z] = val;// & mask;
94
+ const end_offset = 32 - start_bit_offset; // num curtailed bits
95
+ const val =
96
+ ((blockStart >>> start_bit_offset) & mask) | ((blockEnd << end_offset) & mask);
97
+ blocks[x][y][z] = val; // & mask;
97
98
  }
98
-
99
99
  }
100
100
  }
101
101
  }
@@ -106,9 +106,9 @@ function processNBTRegionData(regionData, nbits, width, height, depth) {
106
106
  // use at your own risk
107
107
  function __stripNBTTyping(nbtData) {
108
108
  if (nbtData.hasOwnProperty("type")) {
109
- switch(nbtData.type) {
109
+ switch (nbtData.type) {
110
110
  case "compound":
111
- var newDict = {}
111
+ var newDict = {};
112
112
  for (const [k, v] of Object.entries(nbtData.value)) {
113
113
  newDict[k] = __stripNBTTyping(v);
114
114
  }
@@ -123,11 +123,11 @@ function __stripNBTTyping(nbtData) {
123
123
  break;
124
124
  default:
125
125
  return nbtData.value;
126
- }
126
+ }
127
127
  } else {
128
- switch(nbtData.constructor) {
128
+ switch (nbtData.constructor) {
129
129
  case Object:
130
- var newDict = {}
130
+ var newDict = {};
131
131
  for (const [k, v] of Object.entries(nbtData)) {
132
132
  newDict[k] = __stripNBTTyping(v);
133
133
  }
@@ -139,25 +139,24 @@ function __stripNBTTyping(nbtData) {
139
139
  }
140
140
  }
141
141
 
142
-
143
142
  function getMaterialList(litematic) {
144
- var blockCounts = {};
143
+ const blockCounts = {};
145
144
 
146
145
  for (const region of litematic.regions) {
147
- var blocks = region.blocks;
148
- var blockPalette = region.blockPalette;
149
-
150
- width = blocks.length;
151
- height = blocks[0].length;
152
- depth = blocks[0][0].length;
153
- for (let x=0; x < width; x++) {
154
- for (let y=0; y < height; y++) {
155
- for (let z=0; z < depth; z++) {
156
- blockID = blocks[x][y][z];
146
+ const blocks = region.blocks;
147
+ const blockPalette = region.blockPalette;
148
+
149
+ const width = blocks.length;
150
+ const height = blocks[0].length;
151
+ const depth = blocks[0][0].length;
152
+ for (let x = 0; x < width; x++) {
153
+ for (let y = 0; y < height; y++) {
154
+ for (let z = 0; z < depth; z++) {
155
+ const blockID = blocks[x][y][z];
157
156
  if (blockID > 0) {
158
- if(blockID < blockPalette.length) {
159
- blockInfo = blockPalette[blockID];
160
- blockName = blockInfo.Name;
157
+ if (blockID < blockPalette.length) {
158
+ const blockInfo = blockPalette[blockID];
159
+ const blockName = blockInfo.Name;
161
160
  blockCounts[blockName] = (blockCounts[blockName] || 0) + 1;
162
161
  } else {
163
162
  // Something obvious so we know when things go wrong