@divinevoxel/vlox 0.0.73 → 0.0.74

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 (217) hide show
  1. package/Contexts/Base/Remote/InitDataSync.js +4 -0
  2. package/Contexts/Base/Remote/InitWorldDataSync.js +1 -1
  3. package/Contexts/Render/DivineVoxelEngineRender.d.ts +1 -0
  4. package/Contexts/World/DivineVoxelEngineWorld.d.ts +1 -0
  5. package/Init/StartConstructor.js +2 -0
  6. package/Math/index.d.ts +5 -1
  7. package/Mesher/Functions/CompactVoxelSectionMesh.d.ts +4 -0
  8. package/Mesher/Functions/CompactVoxelSectionMesh.js +112 -0
  9. package/Mesher/Functions/MeshSection.d.ts +1 -1
  10. package/Mesher/Functions/MeshSection.js +15 -22
  11. package/Mesher/Geomtry/CompactedSectionVoxelMesh.d.ts +23 -0
  12. package/Mesher/Geomtry/CompactedSectionVoxelMesh.js +144 -0
  13. package/Mesher/Geomtry/VoxelGeometryBuilder.d.ts +1 -1
  14. package/Mesher/Geomtry/VoxelGeometryBuilder.js +118 -197
  15. package/Mesher/Geomtry/VoxelMesh.js +2 -2
  16. package/Mesher/Geomtry/VoxelMeshBVHBuilder.d.ts +8 -70
  17. package/Mesher/Geomtry/VoxelMeshBVHBuilder.js +18 -183
  18. package/Mesher/Geomtry/VoxelMeshBVHStructCursor.d.ts +22 -0
  19. package/Mesher/Geomtry/VoxelMeshBVHStructCursor.js +78 -0
  20. package/Mesher/Geomtry/VoxelMeshBuffers.js +2 -2
  21. package/Mesher/InitTask.js +5 -1
  22. package/Mesher/Models/Common/BoxGeometryNode.js +7 -7
  23. package/Mesher/Models/Common/Calc/CalcConstants.d.ts +1 -1
  24. package/Mesher/Models/Common/Calc/CalcConstants.js +1 -1
  25. package/Mesher/Models/Common/QuadGeometryNode.js +2 -2
  26. package/Mesher/Models/Nodes/Custom/Liquid/LiquidGeomtryNode.js +7 -7
  27. package/Mesher/Models/Nodes/Ruled/BoxVoxelGeometryNode.js +22 -25
  28. package/Mesher/Models/Nodes/Ruled/QuadVoxelGeometryNode.js +2 -2
  29. package/Mesher/Models/Nodes/Ruleless/RulelessBoxVoxelGeometryNode.js +2 -2
  30. package/Mesher/Models/Nodes/Ruleless/RulelessQuadVoxelGeometryNode.js +2 -2
  31. package/Mesher/Models/VoxelConstructor.d.ts +3 -3
  32. package/Mesher/Models/VoxelConstructor.js +8 -8
  33. package/Mesher/Models/VoxelGeometryBuilderCacheSpace.d.ts +2 -2
  34. package/Mesher/Models/VoxelGeometryBuilderCacheSpace.js +8 -9
  35. package/Mesher/Models/VoxelModelBuilder.js +1 -8
  36. package/Mesher/Types/Mesher.types.d.ts +1 -0
  37. package/Models/Defaults/CubeVoxelModels.js +16 -39
  38. package/Models/Defaults/LiquidVoxelModel.js +3 -3
  39. package/Models/Defaults/PanelVoxelModels.js +10 -36
  40. package/Models/Defaults/StairVoxelModel.js +6 -21
  41. package/Models/Examples.js +23 -44
  42. package/Models/Rules/Classes/VoxelRulesModel.d.ts +1 -1
  43. package/Models/Rules/Classes/VoxelRulesModel.js +3 -3
  44. package/Models/Rules/Functions/BuildFinalInputs.d.ts +1 -1
  45. package/Models/Rules/Functions/BuildFinalInputs.js +13 -13
  46. package/Models/Rules/VoxelModelRuleBuilderRegister.js +8 -8
  47. package/Models/VoxelModel.types.d.ts +3 -3
  48. package/Renderer/Classes/DVESectionMeshes.d.ts +2 -3
  49. package/Renderer/InitTasks.js +1 -9
  50. package/Renderer/MeshManager.d.ts +1 -1
  51. package/Renderer/MeshManager.js +24 -23
  52. package/Renderer/MeshRegister.d.ts +5 -5
  53. package/Renderer/MeshRegister.js +2 -2
  54. package/Settings/EngineSettings.d.ts +1 -0
  55. package/Settings/EngineSettings.js +6 -3
  56. package/Settings/EngineSettings.types.d.ts +7 -21
  57. package/Settings/EngineSettings.types.js +6 -14
  58. package/Tasks/Logic/InitTasks.d.ts +1 -0
  59. package/Tasks/Logic/InitTasks.js +10 -0
  60. package/Tasks/Logic/VoxelLogicUpdate.d.ts +3 -0
  61. package/Tasks/Logic/VoxelLogicUpdate.js +71 -0
  62. package/Tasks/Propagation/Explosion/ExplosionManager.d.ts +2 -2
  63. package/Tasks/Propagation/Explosion/ExplosionManager.js +1 -2
  64. package/Tasks/Propagation/Flow/FlowManager.d.ts +4 -4
  65. package/Tasks/Propagation/Flow/FlowRemove.d.ts +2 -2
  66. package/Tasks/Propagation/Flow/FlowUpdate.d.ts +2 -2
  67. package/Tasks/Propagation/Flow/WorldFlow.d.ts +2 -2
  68. package/Tasks/Propagation/Illumanation/RGBUpdate.d.ts +3 -3
  69. package/Tasks/Propagation/Illumanation/SunUpdate.d.ts +3 -3
  70. package/Tasks/Propagation/Illumanation/WorldRGB.d.ts +2 -2
  71. package/Tasks/Propagation/Illumanation/WorldSun.d.ts +2 -2
  72. package/Tasks/Propagation/Illumanation/WorldSun.js +8 -15
  73. package/Tasks/Propagation/InitTasks.js +4 -4
  74. package/Tasks/Propagation/Power/PowerUpdate.d.ts +3 -0
  75. package/Tasks/Propagation/Power/PowerUpdate.js +80 -0
  76. package/Tasks/Tasks.types.d.ts +2 -2
  77. package/Tasks/TasksIds.d.ts +2 -1
  78. package/Tasks/TasksIds.js +1 -0
  79. package/Tasks/Update/Common.d.ts +3 -0
  80. package/Tasks/Update/Common.js +41 -0
  81. package/Tasks/Update/EreaseUpdate.d.ts +3 -0
  82. package/Tasks/Update/EreaseUpdate.js +66 -0
  83. package/Tasks/Update/InitTasks.d.ts +2 -2
  84. package/Tasks/Update/InitTasks.js +3 -1
  85. package/Tasks/Update/PaintUpdate.d.ts +3 -0
  86. package/Tasks/Update/PaintUpdate.js +89 -0
  87. package/Tasks/Update/VoxelUpdate.d.ts +2 -5
  88. package/Tasks/Update/VoxelUpdate.js +5 -147
  89. package/Tasks/{Update/UpdateTask.d.ts → VoxelUpdateTask.d.ts} +15 -7
  90. package/Tasks/{Update/UpdateTask.js → VoxelUpdateTask.js} +20 -7
  91. package/Tasks/WorldGeneration/WorldGenBrush.d.ts +3 -3
  92. package/Tasks/WorldGeneration/WorldGenBrush.js +2 -2
  93. package/Tasks/WorldGeneration/WorldGenRegister.d.ts +1 -1
  94. package/Templates/Functions/CreateTemplate.d.ts +1 -1
  95. package/Tools/Brush/AdvancedBrushTool.js +1 -1
  96. package/Tools/Brush/Brush.d.ts +2 -2
  97. package/Tools/Brush/Brush.js +1 -1
  98. package/Tools/Tasks/TasksTool.d.ts +1 -0
  99. package/Tools/Tasks/TasksTool.js +2 -0
  100. package/Util/Binary/BinaryBuffer.d.ts +17 -11
  101. package/Util/Binary/BinaryBuffer.js +65 -59
  102. package/Util/Binary/BinaryTree.d.ts +46 -0
  103. package/Util/Binary/BinaryTree.js +104 -0
  104. package/Voxels/Cursor/VoxelCursor.interface.d.ts +7 -2
  105. package/Voxels/Cursor/VoxelCursor.interface.js +46 -2
  106. package/Voxels/Cursor/VoxelLightData.js +1 -1
  107. package/Voxels/Data/VoxelTag.types.d.ts +17 -2
  108. package/Voxels/Data/VoxelTag.types.js +6 -1
  109. package/Voxels/Data/VoxelTagsRegister.js +5 -0
  110. package/Voxels/Functions/BuildStateData.d.ts +6 -6
  111. package/Voxels/Functions/BuildStateData.js +31 -31
  112. package/Voxels/Functions/BuildTagAndPaletteData.js +5 -0
  113. package/Voxels/Indexes/VoxelIndex.d.ts +2 -2
  114. package/Voxels/Indexes/VoxelIndex.js +16 -18
  115. package/Voxels/InitVoxelData.js +12 -8
  116. package/Voxels/Logic/Classes/Default/Types/VoxelPoweredLogicType.d.ts +5 -0
  117. package/Voxels/Logic/Classes/Default/Types/VoxelPoweredLogicType.js +6 -0
  118. package/Voxels/Logic/Classes/VoxelLogic.d.ts +11 -0
  119. package/Voxels/Logic/Classes/VoxelLogic.js +49 -0
  120. package/Voxels/Logic/Classes/VoxelLogicType.d.ts +4 -0
  121. package/Voxels/Logic/Classes/VoxelLogicType.js +2 -0
  122. package/Voxels/Logic/VoxelLogic.types.d.ts +23 -0
  123. package/Voxels/Logic/VoxelLogic.types.js +1 -0
  124. package/Voxels/Logic/VoxelLogicRegister.d.ts +9 -0
  125. package/Voxels/Logic/VoxelLogicRegister.js +15 -0
  126. package/Voxels/State/SchemaRegister.js +10 -5
  127. package/Voxels/State/State.types.d.ts +1 -1
  128. package/Voxels/State/StateTreeReader.d.ts +1 -1
  129. package/Voxels/State/StateTreeReader.js +2 -3
  130. package/Voxels/Types/Voxel.types.d.ts +3 -0
  131. package/Voxels/Types/VoxelModelCompiledData.types.d.ts +6 -4
  132. package/World/Archive/Archive.types.d.ts +31 -12
  133. package/World/Archive/Classes/ArchiveClasses.d.ts +66 -0
  134. package/World/Archive/Classes/ArchiveClasses.js +78 -0
  135. package/World/Archive/Classes/ImportedSection.d.ts +40 -0
  136. package/World/Archive/Classes/ImportedSection.js +307 -0
  137. package/World/Archive/Classes/ImportedSector.d.ts +23 -0
  138. package/World/Archive/Classes/ImportedSector.js +97 -0
  139. package/World/Archive/Functions/ArchiveArea.d.ts +1 -1
  140. package/World/Archive/Functions/ArchiveArea.js +39 -36
  141. package/World/Archive/Functions/ArchiveSector.js +210 -404
  142. package/World/Archive/Functions/CreateArchivedSection.d.ts +3 -0
  143. package/World/Archive/Functions/CreateArchivedSection.js +207 -0
  144. package/World/Archive/Functions/ImportSector.d.ts +1 -3
  145. package/World/Archive/Functions/ImportSector.js +13 -244
  146. package/World/Archive/Functions/RemoveDuplicates.d.ts +3 -0
  147. package/World/Archive/Functions/RemoveDuplicates.js +92 -0
  148. package/World/Archive/Functions/Shared.d.ts +2 -2
  149. package/World/Archive/Functions/Shared.js +15 -40
  150. package/World/Archive/InitTasks.js +7 -10
  151. package/World/Cursor/SectionCursor.d.ts +1 -1
  152. package/World/Cursor/SectorCursor.d.ts +1 -1
  153. package/World/Cursor/WorldCursor.d.ts +4 -3
  154. package/World/Cursor/WorldCursor.js +16 -13
  155. package/World/Cursor/WorldVoxelCursor.d.ts +0 -4
  156. package/World/Cursor/WorldVoxelCursor.js +23 -14
  157. package/World/Dimension/Dimension.d.ts +4 -1
  158. package/World/Dimension/Dimension.js +8 -1
  159. package/World/Section/Section.d.ts +17 -4
  160. package/World/Section/Section.js +68 -6
  161. package/World/Section/SectionState.d.ts +4 -2
  162. package/World/Section/SectionState.js +4 -2
  163. package/World/Sector/Sector.d.ts +7 -1
  164. package/World/Sector/Sector.js +37 -4
  165. package/World/Sector/SectorState.d.ts +3 -2
  166. package/World/Sector/SectorState.js +3 -2
  167. package/World/Types/WorldData.types.d.ts +2 -7
  168. package/World/WorldRegister.d.ts +9 -9
  169. package/World/WorldRegister.js +9 -6
  170. package/World/WorldSpaces.js +6 -6
  171. package/{Tasks/IWG → WorldSimulation}/Internal/Classes/DimensionSegment.d.ts +2 -2
  172. package/{Tasks/IWG → WorldSimulation}/Internal/Classes/Generator.d.ts +6 -4
  173. package/{Tasks/IWG → WorldSimulation}/Internal/Classes/Generator.js +9 -5
  174. package/WorldSimulation/Internal/Classes/Queues/BuildQueue.d.ts +5 -0
  175. package/WorldSimulation/Internal/Classes/Queues/BuildQueue.js +6 -0
  176. package/WorldSimulation/Internal/Classes/Queues/LogiccQueue.d.ts +5 -0
  177. package/WorldSimulation/Internal/Classes/Queues/LogiccQueue.js +6 -0
  178. package/{Tasks/IWG → WorldSimulation}/Internal/Classes/SectorVisistedMap.js +1 -1
  179. package/WorldSimulation/Internal/Classes/TickQueue.d.ts +12 -0
  180. package/{Tasks/IWG/Internal/Classes/BuildQueue.js → WorldSimulation/Internal/Classes/TickQueue.js} +16 -7
  181. package/WorldSimulation/Internal/Classes/WorldSimulationTaskBase.d.ts +15 -0
  182. package/{Tasks/IWG/Internal/Classes/IWGTaskBase.js → WorldSimulation/Internal/Classes/WorldSimulationTaskBase.js} +6 -6
  183. package/{Tasks/IWG → WorldSimulation}/Internal/Functions/cullSectors.js +9 -9
  184. package/{Tasks/IWG → WorldSimulation}/Internal/Functions/getSectorState.d.ts +1 -1
  185. package/{Tasks/IWG → WorldSimulation}/Internal/Functions/getSectorState.js +4 -4
  186. package/WorldSimulation/Internal/Functions/runTickUpdate.d.ts +2 -0
  187. package/{Tasks/IWG/Internal/Functions/runBuildUpdate.js → WorldSimulation/Internal/Functions/runTickUpdate.js} +29 -19
  188. package/{Tasks/IWG → WorldSimulation}/Internal/Functions/runWorldUpdate.js +13 -13
  189. package/{Tasks/IWG → WorldSimulation}/Internal/TaskRegister.d.ts +2 -2
  190. package/{Tasks/IWG → WorldSimulation}/Internal/TaskRegister.js +1 -1
  191. package/WorldSimulation/Internal/WorldSimulationDimensions.d.ts +6 -0
  192. package/{Tasks/IWG/Internal/IWGDimensions.js → WorldSimulation/Internal/WorldSimulationDimensions.js} +1 -1
  193. package/WorldSimulation/Internal/WorldSimulationTasks.d.ts +30 -0
  194. package/{Tasks/IWG/Internal/IWGTasks.js → WorldSimulation/Internal/WorldSimulationTasks.js} +14 -14
  195. package/WorldSimulation/Internal/WorldSimulationTools.d.ts +8 -0
  196. package/{Tasks/IWG/Internal/IWGTools.js → WorldSimulation/Internal/WorldSimulationTools.js} +1 -1
  197. package/{Tasks/IWG → WorldSimulation}/Procedures/InitalLoad.d.ts +1 -1
  198. package/{Tasks/IWG → WorldSimulation}/Procedures/InitalLoad.js +11 -11
  199. package/{Tasks/IWG → WorldSimulation}/Procedures/SaveAllSectors.js +5 -5
  200. package/{Tasks/IWG/IWG.d.ts → WorldSimulation/WorldSimulation.d.ts} +5 -5
  201. package/{Tasks/IWG/IWG.js → WorldSimulation/WorldSimulation.js} +21 -21
  202. package/{Tasks/IWG → WorldSimulation}/index.d.ts +1 -1
  203. package/{Tasks/IWG → WorldSimulation}/index.js +1 -1
  204. package/package.json +1 -1
  205. package/Tasks/IWG/Internal/Classes/BuildQueue.d.ts +0 -11
  206. package/Tasks/IWG/Internal/Classes/IWGTaskBase.d.ts +0 -15
  207. package/Tasks/IWG/Internal/Functions/runBuildUpdate.d.ts +0 -2
  208. package/Tasks/IWG/Internal/IWGDimensions.d.ts +0 -6
  209. package/Tasks/IWG/Internal/IWGTasks.d.ts +0 -30
  210. package/Tasks/IWG/Internal/IWGTools.d.ts +0 -8
  211. /package/{Tasks/IWG → WorldSimulation}/Internal/Classes/DimensionSegment.js +0 -0
  212. /package/{Tasks/IWG → WorldSimulation}/Internal/Classes/SectorState.d.ts +0 -0
  213. /package/{Tasks/IWG → WorldSimulation}/Internal/Classes/SectorState.js +0 -0
  214. /package/{Tasks/IWG → WorldSimulation}/Internal/Classes/SectorVisistedMap.d.ts +0 -0
  215. /package/{Tasks/IWG → WorldSimulation}/Internal/Functions/cullSectors.d.ts +0 -0
  216. /package/{Tasks/IWG → WorldSimulation}/Internal/Functions/runWorldUpdate.d.ts +0 -0
  217. /package/{Tasks/IWG → WorldSimulation}/Procedures/SaveAllSectors.d.ts +0 -0
@@ -1,337 +1,25 @@
1
- import { StringPalette } from "../../../Util/StringPalette";
2
- import { NumberPalette } from "../../../Util/NumberPalette";
3
1
  import { WorldRegister } from "../../../World/WorldRegister";
4
2
  import { SchemaRegister } from "../../../Voxels/State/SchemaRegister";
5
3
  import { VoxelPalettesRegister } from "../../../Voxels/Data/VoxelPalettesRegister";
6
4
  import { VoxelTagsRegister } from "../../../Voxels/Data/VoxelTagsRegister";
7
5
  import { VoxelLightData } from "../../../Voxels/Cursor/VoxelLightData";
8
6
  import { EngineSettings } from "../../../Settings/EngineSettings";
9
- import { setNibbleArrayIndex } from "../../../Util/Binary/BinaryArrays";
10
7
  import { BinaryBuffer } from "../../../Util/Binary/BinaryBuffer";
11
- import { compareSection, lightSegments, lightSemgnetGet, uint16To4CharString, } from "./Shared";
12
- function getProcessedData(buffer) {
13
- return {
14
- buffer,
15
- allTheSame: true,
16
- isPaletted: false,
17
- remapped: false,
18
- value: 0,
19
- };
20
- }
21
- const getProcessedSection = (section) => {
22
- return {
23
- original: section,
24
- palettes: getSectionPalettes(),
25
- isBuriedAllTheSame: false,
26
- buriedValue: 0,
27
- isVoxelMapAllTheSame: false,
28
- voxelMapValue: 0,
29
- isDirtyMapAllTheSame: false,
30
- dirtyMapValue: 0,
31
- // ids
32
- ids: getProcessedData(new Uint16Array(section.ids.length)),
33
- // light
34
- light: {
35
- sun: getProcessedData(new Uint8Array(section.light.length)),
36
- red: getProcessedData(new Uint8Array(section.light.length)),
37
- green: getProcessedData(new Uint8Array(section.light.length)),
38
- blue: getProcessedData(new Uint8Array(section.light.length)),
39
- },
40
- // level
41
- level: getProcessedData(new Uint8Array(section.level.length)),
42
- // state
43
- state: getProcessedData(new Uint16Array(section.level.length)),
44
- // mod
45
- mod: getProcessedData(new Uint16Array(section.mod.length)),
46
- // secondary
47
- secondary: getProcessedData(new Uint16Array(section.mod.length)),
48
- };
49
- };
50
- function getLightPalette() {
51
- return {
52
- sun: new NumberPalette(),
53
- red: new NumberPalette(),
54
- green: new NumberPalette(),
55
- blue: new NumberPalette(),
56
- };
57
- }
58
- function getSectionPalettes() {
59
- return {
60
- ids: new NumberPalette(),
61
- level: new NumberPalette(),
62
- light: getLightPalette(),
63
- state: new NumberPalette(),
64
- mod: new NumberPalette(),
65
- secondaryId: new NumberPalette(),
66
- secondaryState: new NumberPalette(),
67
- };
68
- }
69
- function getColumnPalettes() {
70
- return {
71
- ids: new StringPalette(),
72
- level: new NumberPalette(),
73
- light: getLightPalette(),
74
- stateIdMap: [],
75
- state: new NumberPalette(),
76
- modIdMap: [],
77
- mod: new NumberPalette(),
78
- secondaryId: new StringPalette(),
79
- secondaryState: new NumberPalette(),
80
- };
81
- }
82
- function getLightBuffer(light, buffer) {
83
- const array = new Uint8Array(buffer.length / 2);
84
- for (let i = 0; i < buffer.length; i++) {
85
- let l = 0;
86
- if (light == "sun")
87
- l = lightData.getS(buffer[i]);
88
- if (light == "red")
89
- l = lightData.getR(buffer[i]);
90
- if (light == "green")
91
- l = lightData.getG(buffer[i]);
92
- if (light == "blue")
93
- l = lightData.getB(buffer[i]);
94
- setNibbleArrayIndex(array, i, l);
95
- }
96
- return array;
97
- }
98
- function GetArchivedSection(archiveSection, sectorPalettes) {
99
- const palettes = {};
100
- if (archiveSection.ids.remapped)
101
- palettes.id = Uint16Array.from(archiveSection.palettes.ids._palette);
102
- if (archiveSection.level.remapped)
103
- palettes.level = Uint8Array.from(archiveSection.palettes.level._palette);
104
- if (archiveSection.light.sun.remapped) {
105
- palettes.light ??= {};
106
- palettes.light.sun = Uint8Array.from(archiveSection.palettes.light.sun._palette);
107
- }
108
- if (archiveSection.light.red.remapped) {
109
- palettes.light ??= {};
110
- palettes.light.red = Uint8Array.from(archiveSection.palettes.light.red._palette);
111
- }
112
- if (archiveSection.light.green.remapped) {
113
- palettes.light ??= {};
114
- palettes.light.green = Uint8Array.from(archiveSection.palettes.light.green._palette);
115
- }
116
- if (archiveSection.light.blue.remapped) {
117
- palettes.light ??= {};
118
- palettes.light.blue = Uint8Array.from(archiveSection.palettes.light.blue._palette);
119
- }
120
- if (archiveSection.state.remapped)
121
- palettes.state = Uint16Array.from(archiveSection.palettes.state._palette);
122
- if (archiveSection.mod.remapped)
123
- palettes.mod = Uint16Array.from(archiveSection.palettes.mod._palette);
124
- if (archiveSection.secondary.remapped) {
125
- palettes.secondaryId = Uint16Array.from(archiveSection.palettes.secondaryId._palette);
126
- palettes.secondaryState = Uint16Array.from(archiveSection.palettes.secondaryState._palette);
127
- }
128
- const buffers = {};
129
- //id
130
- if (archiveSection.ids.allTheSame) {
131
- if (archiveSection.ids.buffer[0] !== 0) {
132
- buffers.id = archiveSection.ids.buffer[0];
133
- }
134
- }
135
- else if (archiveSection.ids.isPaletted) {
136
- const type = BinaryBuffer.DetermineSubByteArray(archiveSection.ids.remapped
137
- ? archiveSection.palettes.ids.size
138
- : sectorPalettes.ids.size);
139
- buffers.id = BinaryBuffer.Create({
140
- buffer: BinaryBuffer.Convert(archiveSection.ids.buffer, "16-bit", type),
141
- type,
142
- });
143
- }
144
- else {
145
- buffers.id = BinaryBuffer.Create({
146
- buffer: archiveSection.ids.buffer,
147
- });
148
- }
149
- //level
150
- if (archiveSection.level.allTheSame) {
151
- if (archiveSection.level.buffer[0] !== 0) {
152
- buffers.level = archiveSection.level.buffer[0];
153
- }
154
- }
155
- else if (archiveSection.level.isPaletted) {
156
- const type = BinaryBuffer.DetermineSubByteArray(archiveSection.level.remapped
157
- ? archiveSection.palettes.level.size
158
- : sectorPalettes.level.size);
159
- buffers.level = BinaryBuffer.Create({
160
- buffer: BinaryBuffer.Convert(archiveSection.level.buffer, "8-bit", type),
161
- type,
162
- });
163
- }
164
- else {
165
- buffers.level = BinaryBuffer.Create({
166
- buffer: archiveSection.original.level.slice(),
167
- });
168
- }
169
- for (const semgnet of lightSegments) {
170
- if (archiveSection.light[semgnet].allTheSame) {
171
- if (archiveSection.light[semgnet].value !== 0) {
172
- buffers.light ??= {};
173
- buffers.light[semgnet] = archiveSection.light[semgnet].value;
174
- }
175
- }
176
- else if (archiveSection.light[semgnet].isPaletted) {
177
- const type = BinaryBuffer.DetermineSubByteArray(archiveSection.light[semgnet].remapped
178
- ? archiveSection.palettes.light[semgnet].size
179
- : sectorPalettes.light[semgnet].size);
180
- buffers.light ??= {};
181
- buffers.light[semgnet] = BinaryBuffer.Create({
182
- buffer: BinaryBuffer.Convert(archiveSection.light[semgnet].buffer, "8-bit", type),
183
- type,
184
- });
185
- }
186
- else {
187
- buffers.light ??= {};
188
- buffers.light[semgnet] = BinaryBuffer.Create({
189
- buffer: getLightBuffer(semgnet, archiveSection.original.light),
190
- type: "4-bit",
191
- });
192
- }
193
- }
194
- if (archiveSection.state.allTheSame) {
195
- if (archiveSection.state.buffer[0] !== 0) {
196
- buffers.state = archiveSection.state.buffer[0];
197
- }
198
- }
199
- else if (archiveSection.state.isPaletted) {
200
- const type = BinaryBuffer.DetermineSubByteArray(archiveSection.state.remapped
201
- ? archiveSection.palettes.state.size
202
- : sectorPalettes.state.size);
203
- buffers.state = BinaryBuffer.Create({
204
- buffer: BinaryBuffer.Convert(archiveSection.state.buffer, "16-bit", type),
205
- type,
206
- });
207
- }
208
- else {
209
- buffers.state = BinaryBuffer.Create({
210
- buffer: archiveSection.state.buffer,
211
- });
212
- }
213
- if (archiveSection.mod.allTheSame) {
214
- if (archiveSection.mod.buffer[0] !== 0) {
215
- buffers.mod = archiveSection.mod.buffer[0];
216
- }
217
- }
218
- else if (archiveSection.mod.isPaletted) {
219
- const type = BinaryBuffer.DetermineSubByteArray(archiveSection.mod.remapped
220
- ? archiveSection.palettes.mod.size
221
- : sectorPalettes.mod.size);
222
- buffers.mod = BinaryBuffer.Create({
223
- buffer: BinaryBuffer.Convert(archiveSection.mod.buffer, "16-bit", type),
224
- type,
225
- });
226
- }
227
- else {
228
- buffers.mod = BinaryBuffer.Create({
229
- buffer: archiveSection.mod.buffer,
230
- });
231
- }
232
- if (archiveSection.secondary.allTheSame) {
233
- if (archiveSection.secondary.buffer[0] !== 0) {
234
- buffers.secondary = archiveSection.secondary.buffer[0];
235
- }
236
- }
237
- else if (archiveSection.secondary.isPaletted) {
238
- const type = BinaryBuffer.DetermineSubByteArray(archiveSection.secondary.remapped
239
- ? Math.max(archiveSection.palettes.secondaryState.size, archiveSection.palettes.secondaryId.size)
240
- : Math.max(sectorPalettes.secondaryState.size, sectorPalettes.secondaryId.size));
241
- buffers.secondary = BinaryBuffer.Create({
242
- buffer: BinaryBuffer.Convert(archiveSection.secondary.buffer, "16-bit", type),
243
- type,
244
- });
245
- }
246
- else {
247
- buffers.secondary = BinaryBuffer.Create({
248
- buffer: archiveSection.secondary.buffer,
249
- });
250
- }
251
- if (archiveSection.isBuriedAllTheSame) {
252
- if (archiveSection.buriedValue !== 0) {
253
- buffers.buried = archiveSection.buriedValue;
254
- }
255
- }
256
- else {
257
- buffers.buried = archiveSection.original.buried.slice();
258
- }
259
- if (archiveSection.isVoxelMapAllTheSame) {
260
- if (archiveSection.voxelMapValue !== 0) {
261
- buffers.voxelMap = archiveSection.voxelMapValue;
262
- }
263
- }
264
- else {
265
- buffers.voxelMap = archiveSection.original.voxelMap.slice();
266
- }
267
- if (archiveSection.isDirtyMapAllTheSame) {
268
- if (archiveSection.dirtyMapValue !== 0) {
269
- buffers.dirtyMap = archiveSection.dirtyMapValue;
270
- }
271
- }
272
- else {
273
- buffers.dirtyMap = archiveSection.original.dirtyMap.slice();
274
- }
275
- const flags = archiveSection.original.storeFlags();
276
- return {
277
- ...(Object.keys(flags).length ? { flags } : {}),
278
- ...(Object.keys(palettes).length ? { palettes } : {}),
279
- buffers,
280
- };
281
- }
282
- function RemoveDuplicates(data) {
283
- const duplicateSectionMap = new Map();
284
- let duplicateSections = [];
285
- for (let i = 0; i < data.sections.length; i++) {
286
- for (let j = 0; j < data.sections.length; j++) {
287
- const section1 = data.sections[i];
288
- const section2 = data.sections[j];
289
- if (i == j)
290
- continue;
291
- if (typeof section1 == "string" || typeof section2 == "string")
292
- continue;
293
- let index = -1;
294
- if (compareSection(section1, section2)) {
295
- if (duplicateSectionMap.has(section2)) {
296
- index = duplicateSectionMap.get(section2)[1];
297
- }
298
- else {
299
- let found = false;
300
- for (let k = 0; k < duplicateSections.length; k++) {
301
- if (compareSection(section1, duplicateSections[k])) {
302
- index = k;
303
- found = true;
304
- }
305
- }
306
- if (!found) {
307
- duplicateSections.push(section1);
308
- index = duplicateSections.length - 1;
309
- }
310
- }
311
- duplicateSectionMap.set(section1, [i, index]);
312
- }
313
- }
314
- }
315
- const sections = {};
316
- for (const [object, [sectionIndex, index]] of duplicateSectionMap) {
317
- const id = uint16To4CharString(index);
318
- if (!sections[id])
319
- sections[id] = object;
320
- data.sections[sectionIndex] = id;
321
- }
322
- data.duplicates = {
323
- sections,
324
- };
325
- }
8
+ import { lightSegments, lightSemgnetGet } from "./Shared";
9
+ import { ProcessedSection, SectorPalette, VoxelStateObjectMap, } from "../Classes/ArchiveClasses";
10
+ import { CreateArchivedSection } from "./CreateArchivedSection";
11
+ import { RemoveDuplicates } from "./RemoveDuplicates";
12
+ import { NumberPalette } from "../../../Util/NumberPalette";
326
13
  const lightData = new VoxelLightData();
327
14
  export default function ArchiveSector(archiveData) {
328
15
  const sector = WorldRegister.sectors.get(archiveData.location[0], archiveData.location[1], archiveData.location[2], archiveData.location[3]);
329
16
  if (!sector)
330
- throw new Error(`Column at location ${location} does not exist when trying to arhicve it.`);
331
- const sectorPalettes = getColumnPalettes();
17
+ throw new Error(`Sector at location ${location} does not exist when trying to arhicve it.`);
18
+ const sectorPalettes = new SectorPalette();
332
19
  const processedSections = [];
333
- for (const section of sector.sections) {
334
- const processedSection = getProcessedSection(section);
20
+ for (let sectionIndex = 0; sectionIndex < sector.sections.length; sectionIndex++) {
21
+ const section = sector.sections[sectionIndex];
22
+ const processedSection = new ProcessedSection(section);
335
23
  {
336
24
  let value = section.buried[0];
337
25
  processedSection.isBuriedAllTheSame = true;
@@ -392,46 +80,84 @@ export default function ArchiveSector(archiveData) {
392
80
  ? !sectorPalettes.secondaryId.isRegistered(secondaryId)
393
81
  ? sectorPalettes.secondaryId.register(secondaryId)
394
82
  : sectorPalettes.secondaryId.getNumberId(secondaryId)
395
- : !sectorPalettes.secondaryState.isRegistered(section.secondary[i])
396
- ? sectorPalettes.secondaryState.register(section.secondary[i])
397
- : sectorPalettes.secondaryState.getId(section.secondary[i]);
83
+ : !sectorPalettes.secondaryValue.isRegistered(section.secondary[i])
84
+ ? sectorPalettes.secondaryValue.register(section.secondary[i])
85
+ : sectorPalettes.secondaryValue.getId(section.secondary[i]);
398
86
  if (VoxelTagsRegister.VoxelTags[section.ids[i]]["dve_can_have_secondary"]) {
399
87
  if (!processedSection.palettes.secondaryId.isRegistered(voxelSecondary))
400
88
  processedSection.palettes.secondaryId.register(voxelSecondary);
401
89
  }
402
90
  else {
403
- if (!processedSection.palettes.secondaryState.isRegistered(voxelSecondary))
404
- processedSection.palettes.secondaryState.register(voxelSecondary);
91
+ if (!processedSection.palettes.secondaryValue.isRegistered(voxelSecondary))
92
+ processedSection.palettes.secondaryValue.register(voxelSecondary);
405
93
  }
406
94
  const voxelLevel = !sectorPalettes.level.isRegistered(section.level[i])
407
95
  ? sectorPalettes.level.register(section.level[i])
408
96
  : sectorPalettes.level.getId(section.level[i]);
409
97
  if (!processedSection.palettes.level.isRegistered(section.level[i]))
410
98
  processedSection.palettes.level.register(section.level[i]);
99
+ let stateMap;
100
+ if (secondaryId) {
101
+ if (!sectorPalettes.secondaryStateMap[voxelSecondary]) {
102
+ stateMap = new VoxelStateObjectMap();
103
+ sectorPalettes.secondaryStateMap[voxelId] = stateMap;
104
+ }
105
+ else {
106
+ stateMap = sectorPalettes.secondaryStateMap[voxelSecondary];
107
+ }
108
+ }
109
+ else {
110
+ if (!sectorPalettes.stateMap[voxelId]) {
111
+ stateMap = new VoxelStateObjectMap();
112
+ sectorPalettes.stateMap[voxelId] = stateMap;
113
+ }
114
+ else {
115
+ stateMap = sectorPalettes.stateMap[voxelId];
116
+ }
117
+ }
411
118
  let voxelState = -1;
412
- if (!sectorPalettes.state.isRegistered(section.state[i])) {
413
- voxelState = sectorPalettes.state.register(section.state[i]);
414
- sectorPalettes.stateIdMap[voxelState] = secondaryId
415
- ? section.secondary[i]
416
- : section.ids[i];
119
+ if (!stateMap.palette.isRegistered(section.state[i])) {
120
+ voxelState = stateMap.palette.register(section.state[i]);
121
+ }
122
+ else {
123
+ voxelState = stateMap.palette.getId(section.state[i]);
124
+ }
125
+ if (!processedSection.palettes.state[voxelId]) {
126
+ processedSection.palettes.state[voxelId] = new NumberPalette();
127
+ }
128
+ if (!processedSection.palettes.state[voxelId].isRegistered(voxelState))
129
+ processedSection.palettes.state[voxelId].register(voxelState);
130
+ let modMap;
131
+ if (secondaryId) {
132
+ if (!sectorPalettes.secondaryModMap[voxelSecondary]) {
133
+ modMap = new VoxelStateObjectMap();
134
+ sectorPalettes.secondaryModMap[voxelSecondary] = modMap;
135
+ }
136
+ else {
137
+ modMap = sectorPalettes.secondaryModMap[voxelSecondary];
138
+ }
417
139
  }
418
140
  else {
419
- voxelState = sectorPalettes.state.getId(section.state[i]);
141
+ if (!sectorPalettes.modMap[voxelId]) {
142
+ modMap = new VoxelStateObjectMap();
143
+ sectorPalettes.modMap[voxelSecondary] = modMap;
144
+ }
145
+ else {
146
+ modMap = sectorPalettes.modMap[voxelId];
147
+ }
420
148
  }
421
- if (!processedSection.palettes.state.isRegistered(voxelState))
422
- processedSection.palettes.state.register(voxelState);
423
149
  let voxelMod = -1;
424
- if (!sectorPalettes.mod.isRegistered(section.mod[i])) {
425
- voxelMod = sectorPalettes.mod.register(section.mod[i]);
426
- sectorPalettes.modIdMap[voxelMod] = secondaryId
427
- ? section.secondary[i]
428
- : section.ids[i];
150
+ if (!modMap.palette.isRegistered(section.mod[i])) {
151
+ voxelMod = modMap.palette.register(section.mod[i]);
429
152
  }
430
153
  else {
431
- voxelMod = sectorPalettes.mod.getId(section.mod[i]);
154
+ voxelMod = modMap.palette.getId(section.mod[i]);
155
+ }
156
+ if (!processedSection.palettes.mod[voxelId]) {
157
+ processedSection.palettes.mod[voxelId] = new NumberPalette();
432
158
  }
433
- if (!processedSection.palettes.mod.isRegistered(voxelMod))
434
- processedSection.palettes.mod.register(voxelMod);
159
+ if (!processedSection.palettes.mod[voxelId].isRegistered(voxelMod))
160
+ processedSection.palettes.mod[voxelId].register(voxelMod);
435
161
  for (let l = 0; l < lightSegments.length; l++) {
436
162
  const segment = lightSegments[l];
437
163
  const light = lightSemgnetGet[segment](section.light[i]);
@@ -461,7 +187,7 @@ export default function ArchiveSector(archiveData) {
461
187
  processedSection.mod.buffer[i] = voxelMod;
462
188
  processedSection.secondary.buffer[i] = voxelSecondary;
463
189
  }
464
- processedSections.push(processedSection);
190
+ processedSections[sectionIndex] = processedSection;
465
191
  }
466
192
  let neededPalettes = {
467
193
  level: false,
@@ -472,53 +198,78 @@ export default function ArchiveSector(archiveData) {
472
198
  blue: false,
473
199
  },
474
200
  };
201
+ for (const state of sectorPalettes.stateMap) {
202
+ if (!state)
203
+ continue;
204
+ if (state.palette.size > sectorPalettes.maxStatePaletteSize)
205
+ sectorPalettes.maxStatePaletteSize = state.palette.size;
206
+ }
207
+ for (const mod of sectorPalettes.modMap) {
208
+ if (!mod)
209
+ continue;
210
+ if (mod.palette.size > sectorPalettes.maxModPaletteSize)
211
+ sectorPalettes.maxModPaletteSize = mod.palette.size;
212
+ }
475
213
  for (const archivedSection of processedSections) {
214
+ for (const stateId in archivedSection.palettes.state) {
215
+ const state = archivedSection.palettes.state[stateId];
216
+ if (!state)
217
+ continue;
218
+ if (state.size > archivedSection.palettes.maxStatePaletteSize)
219
+ archivedSection.palettes.maxStatePaletteSize = state.size;
220
+ }
221
+ for (const modId in archivedSection.palettes.mod) {
222
+ const mod = archivedSection.palettes.state[modId];
223
+ if (!mod)
224
+ continue;
225
+ if (mod.size > archivedSection.palettes.maxModPaletteSize)
226
+ archivedSection.palettes.maxModPaletteSize = mod.size;
227
+ }
476
228
  //ids
477
229
  archivedSection.ids.isPaletted =
478
- sectorPalettes.ids.size <= BinaryBuffer.BytePaletteMax ||
479
- archivedSection.palettes.ids.size <= BinaryBuffer.BytePaletteMax;
230
+ sectorPalettes.ids.size <= BinaryBuffer.ByteArrayMax ||
231
+ archivedSection.palettes.ids.size <= BinaryBuffer.ByteArrayMax;
480
232
  archivedSection.ids.remapped =
481
- sectorPalettes.ids.size > BinaryBuffer.BytePaletteMax &&
482
- archivedSection.palettes.ids.size <= BinaryBuffer.BytePaletteMax &&
233
+ sectorPalettes.ids.size > BinaryBuffer.ByteArrayMax &&
234
+ archivedSection.palettes.ids.size <= BinaryBuffer.ByteArrayMax &&
483
235
  !archivedSection.ids.allTheSame;
484
236
  //level
485
237
  archivedSection.level.isPaletted =
486
- sectorPalettes.level.size <= BinaryBuffer.NibblePaletteMax &&
487
- archivedSection.palettes.level.size <= BinaryBuffer.NibblePaletteMax;
238
+ sectorPalettes.level.size <= BinaryBuffer.NibbleArrayMax &&
239
+ archivedSection.palettes.level.size <= BinaryBuffer.NibbleArrayMax;
488
240
  archivedSection.level.remapped =
489
- sectorPalettes.level.size > BinaryBuffer.NibblePaletteMax &&
490
- archivedSection.palettes.level.size <= BinaryBuffer.NibblePaletteMax &&
241
+ sectorPalettes.level.size > BinaryBuffer.NibbleArrayMax &&
242
+ archivedSection.palettes.level.size <= BinaryBuffer.NibbleArrayMax &&
491
243
  !archivedSection.level.allTheSame;
492
244
  if (archivedSection.level.isPaletted && !archivedSection.level.remapped) {
493
245
  neededPalettes.level = true;
494
246
  }
495
247
  //state
496
248
  archivedSection.state.isPaletted =
497
- sectorPalettes.state.size <= BinaryBuffer.BytePaletteMax ||
498
- archivedSection.palettes.state.size <= BinaryBuffer.BytePaletteMax;
249
+ sectorPalettes.maxStatePaletteSize <= BinaryBuffer.ByteArrayMax ||
250
+ archivedSection.palettes.maxStatePaletteSize <= BinaryBuffer.ByteArrayMax;
499
251
  archivedSection.state.remapped =
500
- sectorPalettes.state.size > BinaryBuffer.BytePaletteMax &&
501
- archivedSection.palettes.state.size <= BinaryBuffer.BytePaletteMax &&
252
+ sectorPalettes.maxStatePaletteSize > BinaryBuffer.ByteArrayMax &&
253
+ archivedSection.palettes.maxStatePaletteSize <=
254
+ BinaryBuffer.ByteArrayMax &&
502
255
  !archivedSection.state.allTheSame;
503
256
  //mod
504
257
  archivedSection.mod.isPaletted =
505
- sectorPalettes.mod.size <= BinaryBuffer.BytePaletteMax ||
506
- archivedSection.palettes.mod.size <= BinaryBuffer.BytePaletteMax;
258
+ sectorPalettes.maxModPaletteSize <= BinaryBuffer.ByteArrayMax ||
259
+ archivedSection.palettes.maxModPaletteSize <= BinaryBuffer.ByteArrayMax;
507
260
  archivedSection.mod.remapped =
508
- sectorPalettes.mod.size > BinaryBuffer.BytePaletteMax &&
509
- archivedSection.palettes.mod.size <= BinaryBuffer.BytePaletteMax &&
261
+ sectorPalettes.maxModPaletteSize > BinaryBuffer.ByteArrayMax &&
262
+ archivedSection.palettes.maxModPaletteSize <= BinaryBuffer.ByteArrayMax &&
510
263
  !archivedSection.mod.allTheSame;
511
264
  for (const semgnet of lightSegments) {
512
265
  archivedSection.light[semgnet].isPaletted =
513
- sectorPalettes.light[semgnet].size <=
514
- BinaryBuffer.HalfNibblePaletteMax ||
266
+ sectorPalettes.light[semgnet].size <= BinaryBuffer.HalfNibbleArrayMax ||
515
267
  archivedSection.palettes.light[semgnet].size <=
516
- BinaryBuffer.HalfNibblePaletteMax;
268
+ BinaryBuffer.HalfNibbleArrayMax;
517
269
  archivedSection.light[semgnet].remapped =
518
- sectorPalettes.light[semgnet].size >
519
- BinaryBuffer.HalfNibblePaletteMax &&
270
+ sectorPalettes.light[semgnet].size > BinaryBuffer.HalfNibbleArrayMax &&
520
271
  archivedSection.palettes.light[semgnet].size <=
521
- BinaryBuffer.HalfNibblePaletteMax &&
272
+ BinaryBuffer.HalfNibbleArrayMax &&
522
273
  !archivedSection.light[semgnet].allTheSame;
523
274
  if (archivedSection.light[semgnet].isPaletted &&
524
275
  !archivedSection.light[semgnet].remapped) {
@@ -527,15 +278,14 @@ export default function ArchiveSector(archiveData) {
527
278
  }
528
279
  //secondary
529
280
  archivedSection.secondary.isPaletted =
530
- (sectorPalettes.secondaryState.size <= BinaryBuffer.BytePaletteMax &&
531
- sectorPalettes.secondaryId.size <= BinaryBuffer.BytePaletteMax) ||
532
- (archivedSection.palettes.secondaryState.size <=
533
- BinaryBuffer.BytePaletteMax &&
534
- archivedSection.palettes.secondaryId.size <=
535
- BinaryBuffer.BytePaletteMax);
281
+ (sectorPalettes.secondaryValue.size <= BinaryBuffer.ByteArrayMax &&
282
+ sectorPalettes.secondaryId.size <= BinaryBuffer.ByteArrayMax) ||
283
+ (archivedSection.palettes.secondaryValue.size <=
284
+ BinaryBuffer.ByteArrayMax &&
285
+ archivedSection.palettes.secondaryId.size <= BinaryBuffer.ByteArrayMax);
536
286
  archivedSection.secondary.remapped =
537
- Math.max(sectorPalettes.secondaryState.size, sectorPalettes.secondaryId.size) > BinaryBuffer.BytePaletteMax &&
538
- Math.max(archivedSection.palettes.secondaryId.size, archivedSection.palettes.secondaryState.size) <= BinaryBuffer.BytePaletteMax &&
287
+ Math.max(sectorPalettes.secondaryValue.size, sectorPalettes.secondaryId.size) > BinaryBuffer.ByteArrayMax &&
288
+ Math.max(archivedSection.palettes.secondaryId.size, archivedSection.palettes.secondaryValue.size) <= BinaryBuffer.ByteArrayMax &&
539
289
  !archivedSection.secondary.allTheSame;
540
290
  if (!archivedSection.ids.remapped &&
541
291
  !archivedSection.light.sun.remapped &&
@@ -548,8 +298,21 @@ export default function ArchiveSector(archiveData) {
548
298
  continue;
549
299
  const length = archivedSection.original.ids.length;
550
300
  for (let i = 0; i < length; i++) {
301
+ let secondary = false;
302
+ if (VoxelTagsRegister.VoxelTags[archivedSection.original.ids[i]]["dve_can_have_secondary"] &&
303
+ archivedSection.original.secondary[i] !== 0) {
304
+ secondary = true;
305
+ }
306
+ let stateId = !secondary
307
+ ? archivedSection.ids.buffer[i]
308
+ : archivedSection.secondary.buffer[i];
309
+ if (archivedSection.state.remapped)
310
+ archivedSection.state.buffer[i] = archivedSection.palettes.state[stateId].getId(sectorPalettes.stateMap[stateId].palette.getId(archivedSection.state.buffer[i]));
311
+ if (archivedSection.mod.remapped)
312
+ archivedSection.mod.buffer[i] = archivedSection.palettes.mod[stateId].getId(sectorPalettes.modMap[archivedSection.ids.buffer[i]].palette.getId(stateId));
551
313
  if (archivedSection.ids.remapped)
552
- archivedSection.ids.buffer[i] = archivedSection.palettes.ids.getId(archivedSection.ids.buffer[i]);
314
+ archivedSection.ids.buffer[i] =
315
+ archivedSection.palettes.ids.getId(stateId);
553
316
  for (let l = 0; l < lightSegments.length; l++) {
554
317
  const segment = lightSegments[l];
555
318
  if (archivedSection.light[segment].remapped) {
@@ -559,48 +322,86 @@ export default function ArchiveSector(archiveData) {
559
322
  }
560
323
  if (archivedSection.level.remapped)
561
324
  archivedSection.level.buffer[i] = archivedSection.palettes.level.getId(archivedSection.original.level[i]);
562
- if (archivedSection.state.remapped)
563
- archivedSection.state.buffer[i] = archivedSection.palettes.state.getId(sectorPalettes.state.getId(archivedSection.state.buffer[i]));
564
- if (archivedSection.mod.remapped)
565
- archivedSection.mod.buffer[i] = archivedSection.palettes.mod.getId(sectorPalettes.mod.getId(archivedSection.mod.buffer[i]));
566
325
  if (archivedSection.secondary.remapped)
567
- archivedSection.secondary.buffer[i] = VoxelTagsRegister.VoxelTags[archivedSection.original.ids[i]]["dve_can_have_secondary"]
326
+ archivedSection.secondary.buffer[i] = secondary
568
327
  ? archivedSection.palettes.secondaryId.getId(archivedSection.secondary.buffer[i])
569
- : archivedSection.palettes.secondaryState.getId(archivedSection.secondary.buffer[i]);
328
+ : archivedSection.palettes.secondaryValue.getId(archivedSection.secondary.buffer[i]);
570
329
  }
571
330
  }
572
- const stateMap = {};
573
- for (let i = 0; i < sectorPalettes.state._palette.length; i++) {
574
- const state = sectorPalettes.state._palette[i];
575
- const voxelId = VoxelPalettesRegister.voxels.getStringId(sectorPalettes.stateIdMap[i]);
331
+ const palettes = {
332
+ id: sectorPalettes.ids._palette,
333
+ stateMap: [],
334
+ secondaryStateMap: [],
335
+ modMap: [],
336
+ secondaryModMap: [],
337
+ light: {},
338
+ secondaryId: sectorPalettes.secondaryId._palette,
339
+ secondaryValue: new Uint16Array(sectorPalettes.secondaryValue._palette),
340
+ };
341
+ const stateMap = palettes.stateMap;
342
+ for (let i = 0; i < sectorPalettes.stateMap.length; i++) {
343
+ const states = sectorPalettes.stateMap[i]?.palette;
344
+ if (!states)
345
+ continue;
346
+ const voxelId = sectorPalettes.ids._palette[i];
576
347
  if (!SchemaRegister.hasVoxelSchema(voxelId))
577
348
  continue;
578
349
  const schema = SchemaRegister.getVoxelSchemas(voxelId);
579
- stateMap[i] = schema.state.getStateObject(state);
350
+ const voxelStates = [];
351
+ stateMap[i] = voxelStates;
352
+ for (let k = 0; k < states._palette.length; k++) {
353
+ voxelStates[k] = schema.state.getStateObject(states._palette[k]);
354
+ }
580
355
  }
581
- const modMap = {};
582
- for (let i = 0; i < sectorPalettes.mod._palette.length; i++) {
583
- const mod = sectorPalettes.mod._palette[i];
584
- const voxelId = VoxelPalettesRegister.voxels.getStringId(sectorPalettes.modIdMap[i]);
356
+ const secondaryStateMap = palettes.secondaryStateMap;
357
+ for (let i = 0; i < sectorPalettes.secondaryStateMap.length; i++) {
358
+ const states = sectorPalettes.secondaryStateMap[i]?.palette;
359
+ if (!states)
360
+ continue;
361
+ const voxelId = sectorPalettes.secondaryId._palette[i];
585
362
  if (!SchemaRegister.hasVoxelSchema(voxelId))
586
363
  continue;
587
364
  const schema = SchemaRegister.getVoxelSchemas(voxelId);
588
- modMap[i] = schema.mod.getStateObject(mod);
365
+ const voxelStates = [];
366
+ secondaryStateMap[i] = voxelStates;
367
+ for (let k = 0; k < states._palette.length; k++) {
368
+ voxelStates[k] = schema.state.getStateObject(states._palette[k]);
369
+ }
370
+ }
371
+ const modMap = palettes.modMap;
372
+ for (let i = 0; i < sectorPalettes.modMap.length; i++) {
373
+ const mods = sectorPalettes.modMap[i]?.palette;
374
+ if (!mods)
375
+ continue;
376
+ const voxelId = sectorPalettes.ids._palette[i];
377
+ if (!SchemaRegister.hasVoxelSchema(voxelId))
378
+ continue;
379
+ const schema = SchemaRegister.getVoxelSchemas(voxelId);
380
+ const voxelMods = [];
381
+ modMap[i] = voxelMods;
382
+ for (let k = 0; k < mods._palette.length; k++) {
383
+ voxelMods[k] = schema.mod.getStateObject(mods._palette[k]);
384
+ }
385
+ }
386
+ const secondaryModMap = palettes.modMap;
387
+ for (let i = 0; i < sectorPalettes.secondaryModMap.length; i++) {
388
+ const mods = sectorPalettes.secondaryModMap[i]?.palette;
389
+ if (!mods)
390
+ continue;
391
+ const voxelId = sectorPalettes.secondaryId._palette[i];
392
+ if (!SchemaRegister.hasVoxelSchema(voxelId))
393
+ continue;
394
+ const schema = SchemaRegister.getVoxelSchemas(voxelId);
395
+ const voxelMods = [];
396
+ secondaryModMap[i] = voxelMods;
397
+ for (let k = 0; k < mods._palette.length; k++) {
398
+ voxelMods[k] = schema.mod.getStateObject(mods._palette[k]);
399
+ }
589
400
  }
590
401
  const sections = [];
591
- for (const section of processedSections) {
592
- sections.push(GetArchivedSection(section, sectorPalettes));
402
+ for (let sectionIndex = 0; sectionIndex < processedSections.length; sectionIndex++) {
403
+ sections[sectionIndex] = CreateArchivedSection(processedSections[sectionIndex], sectorPalettes);
593
404
  }
594
- const palettes = {
595
- id: sectorPalettes.ids._palette,
596
- stateMap,
597
- modMap,
598
- state: new Uint16Array(sectorPalettes.state._palette),
599
- mod: new Uint16Array(sectorPalettes.mod._palette),
600
- light: {},
601
- secondaryId: sectorPalettes.secondaryId._palette,
602
- secondaryState: new Uint16Array(sectorPalettes.secondaryState._palette),
603
- };
604
405
  if (neededPalettes.level) {
605
406
  palettes.level = new Uint8Array(sectorPalettes.level._palette);
606
407
  }
@@ -612,7 +413,12 @@ export default function ArchiveSector(archiveData) {
612
413
  const archivedSector = {
613
414
  version: "",
614
415
  vloxVersion: EngineSettings.version,
615
- location: [...archiveData.location],
416
+ dimension: WorldRegister.dimensions.get(archiveData.location[0]).id,
417
+ location: [
418
+ archiveData.location[1],
419
+ archiveData.location[2],
420
+ archiveData.location[3],
421
+ ],
616
422
  flags: sector.storeFlags(),
617
423
  timestamps: sector.storeTimestamps(),
618
424
  buffers: {},