minecraft-renderer 0.1.79 → 0.1.80
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.
- package/README.md +29 -25
- package/dist/mesher.js +36 -36
- package/dist/mesher.js.map +4 -4
- package/dist/mesherWasm.js +217 -217
- package/dist/minecraft-renderer.js +27 -27
- package/dist/minecraft-renderer.js.meta.json +1 -1
- package/dist/threeWorker.js +133 -133
- package/package.json +5 -2
- package/src/bundler/bundlePrepare.ts +3 -8
- package/src/graphicsBackend/appViewer.ts +10 -7
- package/src/graphicsBackend/config.ts +1 -5
- package/src/graphicsBackend/playerState.ts +35 -34
- package/src/graphicsBackend/preloadWorkers.ts +43 -41
- package/src/graphicsBackend/rendererDefaultOptions.ts +68 -70
- package/src/graphicsBackend/rendererOptionsSync.ts +24 -50
- package/src/graphicsBackend/types.ts +2 -2
- package/src/index.ts +6 -27
- package/src/lib/DebugGui.ts +34 -31
- package/src/lib/animationController.ts +9 -9
- package/src/lib/bakeLegacyLight.ts +1 -6
- package/src/lib/bindAbortableListener.test.ts +32 -12
- package/src/lib/bindAbortableListener.ts +14 -6
- package/src/lib/blockEntityLightRegistry.ts +11 -20
- package/src/lib/blockEntityLighting.test.ts +1 -6
- package/src/lib/blockEntityLighting.ts +5 -5
- package/src/lib/buildSharedConfig.mjs +4 -4
- package/src/lib/buildWorkerMcDataIndexes.test.ts +4 -4
- package/src/lib/buildWorkerMcDataIndexes.ts +11 -19
- package/src/lib/cameraBobbing.ts +1 -1
- package/src/lib/canvas2DOverlay.example.ts +13 -33
- package/src/lib/canvas2DOverlay.quickstart.ts +24 -54
- package/src/lib/canvas2DOverlay.ts +28 -47
- package/src/lib/cleanupDecorator.ts +2 -2
- package/src/lib/createPlayerObject.test.ts +2 -7
- package/src/lib/createPlayerObject.ts +18 -25
- package/src/lib/frameTimingCollector.ts +2 -5
- package/src/lib/guiRenderer.ts +57 -42
- package/src/lib/items.ts +15 -9
- package/src/lib/mesherlogReader.ts +5 -6
- package/src/lib/simpleUtils.ts +5 -5
- package/src/lib/skyLight.ts +3 -3
- package/src/lib/smoothSwitcher.ts +11 -18
- package/src/lib/ui/newStats.ts +10 -12
- package/src/lib/utils/proxy.ts +7 -1
- package/src/lib/utils/skins.ts +4 -4
- package/src/lib/utils.ts +1 -1
- package/src/lib/workerMessageSanitize.ts +5 -12
- package/src/lib/workerProxy.ts +52 -42
- package/src/lib/workerSyncOps.test.ts +58 -41
- package/src/lib/worldrendererCommon.reconfigure.test.ts +24 -21
- package/src/lib/worldrendererCommon.removeColumn.test.ts +11 -13
- package/src/lib/worldrendererCommon.ts +338 -211
- package/src/mesher-legacy/mesher.ts +9 -4
- package/src/mesher-legacy/test/a.ts +1 -1
- package/src/mesher-legacy/test/mesherTester.ts +2 -2
- package/src/mesher-legacy/test/playground.ts +1 -1
- package/src/mesher-legacy/test/run/test-js.ts +1 -1
- package/src/mesher-legacy/test/snapshotUtils.ts +3 -8
- package/src/mesher-legacy/test/test-perf.ts +1 -1
- package/src/mesher-legacy/test/tests.test.ts +2 -2
- package/src/mesher-shared/blockEntityMetadata.test.ts +7 -5
- package/src/mesher-shared/blockEntityMetadata.ts +28 -19
- package/src/mesher-shared/blockPropertiesForMeshing.ts +2 -2
- package/src/mesher-shared/computeHeightmap.ts +2 -4
- package/src/mesher-shared/exportedGeometryTypes.ts +3 -3
- package/src/mesher-shared/faceOcclusion.ts +324 -0
- package/src/mesher-shared/models.ts +80 -131
- package/src/mesher-shared/modelsGeometryCommon.ts +30 -15
- package/src/mesher-shared/shared.ts +46 -46
- package/src/mesher-shared/standaloneRenderer.ts +40 -44
- package/src/mesher-shared/tests/faceOcclusion.test.ts +179 -0
- package/src/mesher-shared/tests/liquidQuadInvariant.test.ts +12 -8
- package/src/mesher-shared/vertexShading.ts +2 -11
- package/src/mesher-shared/world.ts +19 -19
- package/src/mesher-shared/worldLighting.test.ts +2 -2
- package/src/performanceMonitor/PerformanceMonitor.ts +4 -13
- package/src/performanceMonitor/formatPerformanceFactorsDebug.ts +2 -2
- package/src/performanceMonitor/index.ts +1 -5
- package/src/performanceMonitor/types.ts +1 -1
- package/src/playerState/playerState.ts +55 -50
- package/src/playerState/types.ts +2 -8
- package/src/playground/allEntitiesDebug.ts +19 -16
- package/src/playground/baseScene.ts +29 -32
- package/src/playground/mobileControls.tsx +133 -129
- package/src/playground/playground.html +76 -73
- package/src/playground/playground.ts +14 -1
- package/src/playground/playgroundUi.tsx +100 -74
- package/src/playground/reactUtils.ts +3 -7
- package/src/playground/scenes/entities.ts +10 -7
- package/src/playground/scenes/frequentUpdates.ts +5 -5
- package/src/playground/scenes/geometryExport.ts +6 -20
- package/src/playground/scenes/highPosEntityUpdates.ts +2 -10
- package/src/playground/scenes/index.ts +1 -1
- package/src/playground/scenes/lightingStarfield.ts +18 -12
- package/src/playground/scenes/main.ts +15 -11
- package/src/playground/scenes/partialBlockCulling.ts +31 -0
- package/src/playground/scenes/railsCobweb.ts +1 -1
- package/src/playground/scenes/rotationIssue.ts +1 -1
- package/src/playground/scenes/slabsOptimization.ts +1 -2
- package/src/playground/scenes/transparencyIssue.ts +1 -1
- package/src/playground/shared.ts +2 -2
- package/src/resourcesManager/resourcesManager.ts +29 -54
- package/src/resourcesManager/resourcesManager.worker.test.ts +6 -10
- package/src/shims/minecraftData.ts +70 -24
- package/src/sign-renderer/index.html +10 -12
- package/src/sign-renderer/index.ts +29 -29
- package/src/sign-renderer/playground.ts +22 -15
- package/src/sign-renderer/tests.test.ts +16 -13
- package/src/sign-renderer/vite.config.ts +2 -2
- package/src/three/appShared.ts +46 -25
- package/src/three/bannerRenderer.ts +33 -61
- package/src/three/cameraShake.ts +15 -6
- package/src/three/chunkMeshManager.ts +239 -282
- package/src/three/cinimaticScript.ts +26 -15
- package/src/three/cubeDrawSpans.ts +27 -37
- package/src/three/cubeMultiDraw.ts +9 -22
- package/src/three/documentRenderer.ts +15 -18
- package/src/three/entities.ts +175 -150
- package/src/three/entity/EntityMesh.ts +114 -108
- package/src/three/entity/animations.js +3 -3
- package/src/three/entity/armorModels.ts +15 -15
- package/src/three/entity/gltfAnimationUtils.ts +2 -5
- package/src/three/fireworks.ts +34 -32
- package/src/three/fireworksRenderer.ts +32 -29
- package/src/three/globalBlockBuffer.ts +167 -100
- package/src/three/globalLegacyBuffer.ts +257 -166
- package/src/three/graphicsBackendBase.ts +19 -25
- package/src/three/graphicsBackendOffThread.ts +12 -15
- package/src/three/hand.ts +21 -21
- package/src/three/handLegacy.ts +3 -13
- package/src/three/holdingBlock.ts +116 -79
- package/src/three/holdingBlockFactory.ts +1 -4
- package/src/three/holdingBlockItemIdentity.test.ts +25 -17
- package/src/three/holdingBlockItemIdentity.ts +9 -6
- package/src/three/holdingBlockLegacy.ts +113 -132
- package/src/three/itemMesh.ts +20 -29
- package/src/three/legacyMultiDraw.ts +10 -16
- package/src/three/legacySectionCull.ts +8 -14
- package/src/three/menuBackground/activeView.ts +1 -4
- package/src/three/menuBackground/assetUrl.ts +1 -1
- package/src/three/menuBackground/classic.ts +4 -12
- package/src/three/menuBackground/gpuPreference.ts +1 -3
- package/src/three/menuBackground/index.ts +2 -11
- package/src/three/menuBackground/renderer.ts +1 -5
- package/src/three/menuBackground/types.ts +1 -4
- package/src/three/menuBackground/v2.ts +196 -96
- package/src/three/menuBackground/v2Meta.ts +3 -3
- package/src/three/menuBackground/worldBlocks.ts +37 -35
- package/src/three/modules/blockBreakParticles.ts +59 -28
- package/src/three/modules/cameraBobbing.ts +3 -6
- package/src/three/modules/index.ts +1 -1
- package/src/three/modules/rain.ts +10 -23
- package/src/three/modules/sciFiWorldReveal.ts +11 -25
- package/src/three/modules/starfield.ts +7 -13
- package/src/three/renderSlot.ts +28 -16
- package/src/three/rendererModuleSystem.ts +1 -3
- package/src/three/sceneOrigin.ts +96 -33
- package/src/three/sectionRaycastAabb.ts +30 -18
- package/src/three/shaderCubeMesh.ts +6 -17
- package/src/three/shaders/cubeBlockShader.ts +85 -96
- package/src/three/shaders/legacyBlockShader.ts +21 -43
- package/src/three/shaders/textureIndexMapping.ts +89 -95
- package/src/three/shaders/tintPalette.ts +156 -170
- package/src/three/signTextureCache.ts +9 -12
- package/src/three/skyboxRenderer.ts +62 -70
- package/src/three/tests/chunkMeshManagerLegacy.test.ts +34 -34
- package/src/three/tests/cubeDrawSpans.test.ts +55 -25
- package/src/three/tests/globalBlockBuffer.test.ts +217 -0
- package/src/three/tests/globalLegacyBuffer.test.ts +300 -41
- package/src/three/tests/legacyMultiDraw.test.ts +8 -29
- package/src/three/tests/pr3PerFrameCpuCuts.test.ts +106 -29
- package/src/three/tests/signTextureCache.test.ts +4 -4
- package/src/three/threeJsMedia.ts +55 -72
- package/src/three/threeJsParticles.ts +32 -41
- package/src/three/threeJsSound.ts +3 -3
- package/src/three/threeJsUtils.ts +3 -3
- package/src/three/threeWorker.ts +2 -2
- package/src/three/waypointSprite.ts +55 -82
- package/src/three/waypoints.ts +20 -23
- package/src/three/world/cursorBlock.ts +25 -12
- package/src/three/world/vr.ts +11 -17
- package/src/three/worldGeometryExport.ts +15 -34
- package/src/three/worldRendererThree.ts +117 -129
- package/src/wasm-mesher/bridge/convertChunk.ts +3 -9
- package/src/wasm-mesher/bridge/render-from-wasm.ts +204 -229
- package/src/wasm-mesher/bridge/shaderCubeBridge.ts +26 -67
- package/src/wasm-mesher/tests/cullingRegression.test.ts +307 -0
- package/src/wasm-mesher/tests/heightmapParity.test.ts +8 -18
- package/src/wasm-mesher/tests/mesherWasmConversionCache.test.ts +2 -2
- package/src/wasm-mesher/tests/sectionRaycastAabb.test.ts +17 -4
- package/src/wasm-mesher/tests/shaderCubeInstances.test.ts +103 -141
- package/src/wasm-mesher/tests/splitColumnWasmOutput.test.ts +14 -22
- package/src/wasm-mesher/worker/mesherWasm.ts +150 -141
- package/src/wasm-mesher/worker/mesherWasmConversionCache.ts +2 -8
- package/src/wasm-mesher/worker/mesherWasmLightDirty.test.ts +1 -3
- package/src/wasm-mesher/worker/mesherWasmLightDirty.ts +1 -5
- package/src/wasm-mesher/worker/mesherWasmRequestTracker.ts +42 -42
- package/src/worldView/worldView.spiral.test.ts +1 -1
- package/src/worldView/worldView.ts +34 -39
- package/src/worldView/worldViewWorkerBridge.test.ts +4 -4
|
@@ -8,7 +8,6 @@
|
|
|
8
8
|
|
|
9
9
|
import { NonReactiveState } from '../graphicsBackend'
|
|
10
10
|
|
|
11
|
-
|
|
12
11
|
export interface FrameTimingEvent {
|
|
13
12
|
type: 'frameStart' | 'frameEnd' | 'cameraUpdate' | 'frameDisplay'
|
|
14
13
|
timestamp: number
|
|
@@ -29,12 +28,10 @@ export class FrameTimingCollector {
|
|
|
29
28
|
private readonly maxEvents = 500 // Limit events to prevent memory issues
|
|
30
29
|
private readonly lastSecondUpdateInterval = 1000 // Update once per second
|
|
31
30
|
|
|
32
|
-
constructor(
|
|
33
|
-
private nonReactiveState: NonReactiveState
|
|
34
|
-
) {
|
|
31
|
+
constructor(private nonReactiveState: NonReactiveState) {
|
|
35
32
|
// Initialize timeline if not exists
|
|
36
33
|
if (!this.nonReactiveState.renderer) {
|
|
37
|
-
(this.nonReactiveState as any).renderer = { timeline: { live: [], frozen: [], lastSecond: [] } }
|
|
34
|
+
;(this.nonReactiveState as any).renderer = { timeline: { live: [], frozen: [], lastSecond: [] } }
|
|
38
35
|
}
|
|
39
36
|
if (!this.nonReactiveState.renderer.timeline) {
|
|
40
37
|
this.nonReactiveState.renderer.timeline = { live: [], frozen: [], lastSecond: [] }
|
package/src/lib/guiRenderer.ts
CHANGED
|
@@ -1,6 +1,19 @@
|
|
|
1
1
|
//@ts-nocheck
|
|
2
2
|
// Import placeholders - replace with actual imports for your environment
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
ItemRenderer,
|
|
5
|
+
Identifier,
|
|
6
|
+
ItemStack,
|
|
7
|
+
NbtString,
|
|
8
|
+
Structure,
|
|
9
|
+
StructureRenderer,
|
|
10
|
+
ItemRendererResources,
|
|
11
|
+
BlockDefinition,
|
|
12
|
+
BlockModel,
|
|
13
|
+
TextureAtlas,
|
|
14
|
+
Resources,
|
|
15
|
+
ItemModel
|
|
16
|
+
} from 'deepslate'
|
|
4
17
|
import { AssetsParser } from 'mc-assets/dist/assetsParser'
|
|
5
18
|
import { getLoadedImage, versionToNumber } from 'mc-assets/dist/utils'
|
|
6
19
|
import { BlockModel as BlockModelMcAssets, AtlasParser } from 'mc-assets'
|
|
@@ -18,24 +31,16 @@ export const getNonFullBlocksModels = (appViewer: AppViewer) => {
|
|
|
18
31
|
const itemsModelsResolved = {} as Record<string, any>
|
|
19
32
|
const fullBlocksWithNonStandardDisplay = [] as string[]
|
|
20
33
|
const handledItemsWithDefinitions = new Set()
|
|
21
|
-
const assetsParser = new AssetsParser(
|
|
34
|
+
const assetsParser = new AssetsParser(
|
|
35
|
+
version,
|
|
36
|
+
getLoadedBlockstatesStore(appViewer.resourcesManager.currentResources!.blockstatesModels),
|
|
37
|
+
getLoadedModelsStore(appViewer.resourcesManager.currentResources!.blockstatesModels)
|
|
38
|
+
)
|
|
22
39
|
|
|
23
40
|
const standardGuiDisplay = {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
0
|
|
28
|
-
],
|
|
29
|
-
'translation': [
|
|
30
|
-
0,
|
|
31
|
-
0,
|
|
32
|
-
0
|
|
33
|
-
],
|
|
34
|
-
'scale': [
|
|
35
|
-
0.625,
|
|
36
|
-
0.625,
|
|
37
|
-
0.625
|
|
38
|
-
]
|
|
41
|
+
rotation: [30, 225, 0],
|
|
42
|
+
translation: [0, 0, 0],
|
|
43
|
+
scale: [0.625, 0.625, 0.625]
|
|
39
44
|
}
|
|
40
45
|
|
|
41
46
|
const arrEqual = (a: number[], b: number[]) => a.length === b.length && a.every((x, i) => x === b[i])
|
|
@@ -56,8 +61,8 @@ export const getNonFullBlocksModels = (appViewer: AppViewer) => {
|
|
|
56
61
|
version,
|
|
57
62
|
name,
|
|
58
63
|
properties: {
|
|
59
|
-
'minecraft:display_context': 'gui'
|
|
60
|
-
}
|
|
64
|
+
'minecraft:display_context': 'gui'
|
|
65
|
+
}
|
|
61
66
|
})
|
|
62
67
|
if (item) {
|
|
63
68
|
const { resolvedModel } = assetsParser.getResolvedModelsByModel((item.special ? name : item.model).replace('minecraft:', '')) ?? {}
|
|
@@ -68,9 +73,9 @@ export const getNonFullBlocksModels = (appViewer: AppViewer) => {
|
|
|
68
73
|
let hasStandardDisplay = true
|
|
69
74
|
if (resolvedModel['display']?.gui) {
|
|
70
75
|
hasStandardDisplay =
|
|
71
|
-
arrEqual(resolvedModel['display'].gui.rotation, standardGuiDisplay.rotation)
|
|
72
|
-
|
|
73
|
-
|
|
76
|
+
arrEqual(resolvedModel['display'].gui.rotation, standardGuiDisplay.rotation) &&
|
|
77
|
+
arrEqual(resolvedModel['display'].gui.translation, standardGuiDisplay.translation) &&
|
|
78
|
+
arrEqual(resolvedModel['display'].gui.scale, standardGuiDisplay.scale)
|
|
74
79
|
}
|
|
75
80
|
|
|
76
81
|
addModelIfNotFullblock(name, resolvedModel)
|
|
@@ -130,14 +135,14 @@ const generateItemsGui = async (appViewer: AppViewer, models: Record<string, Blo
|
|
|
130
135
|
const atlasParser = isItems ? appViewer.resourcesManager.itemsAtlasParser : appViewer.resourcesManager.blocksAtlasParser
|
|
131
136
|
const textureAtlas = new TextureAtlas(
|
|
132
137
|
ctx.getImageData(0, 0, imgBitmap.width, imgBitmap.height),
|
|
133
|
-
Object.fromEntries(
|
|
134
|
-
|
|
135
|
-
value.u,
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
138
|
+
Object.fromEntries(
|
|
139
|
+
Object.entries(atlasParser.atlas.latest.textures).map(([key, value]) => {
|
|
140
|
+
return [key, [value.u, value.v, value.u + (value.su ?? atlasParser.atlas.latest.suSv), value.v + (value.sv ?? atlasParser.atlas.latest.suSv)]] as [
|
|
141
|
+
string,
|
|
142
|
+
[number, number, number, number]
|
|
143
|
+
]
|
|
144
|
+
})
|
|
145
|
+
)
|
|
141
146
|
)
|
|
142
147
|
|
|
143
148
|
const PREVIEW_ID = Identifier.parse('preview:preview')
|
|
@@ -155,7 +160,9 @@ const generateItemsGui = async (appViewer: AppViewer, models: Record<string, Blo
|
|
|
155
160
|
},
|
|
156
161
|
getTextureUV(texture) {
|
|
157
162
|
textureWasRequested = true
|
|
158
|
-
return textureAtlas.getTextureUV(
|
|
163
|
+
return textureAtlas.getTextureUV(
|
|
164
|
+
texture.toString().replace('minecraft:', '').replace('block/', '').replace('item/', '').replace('blocks/', '').replace('items/', '') as any
|
|
165
|
+
)
|
|
159
166
|
},
|
|
160
167
|
getTextureAtlas() {
|
|
161
168
|
return textureAtlas.getTextureAtlas()
|
|
@@ -169,15 +176,17 @@ const generateItemsGui = async (appViewer: AppViewer, models: Record<string, Blo
|
|
|
169
176
|
if (id.equals(PREVIEW_ID)) {
|
|
170
177
|
return ItemModel.fromJson({
|
|
171
178
|
type: isSpecial ? 'minecraft:special' : 'minecraft:model',
|
|
172
|
-
model: isSpecial
|
|
173
|
-
|
|
174
|
-
|
|
179
|
+
model: isSpecial
|
|
180
|
+
? {
|
|
181
|
+
type: currentModelName
|
|
182
|
+
}
|
|
183
|
+
: PREVIEW_ID.toString(),
|
|
175
184
|
base: PREVIEW_ID.toString(),
|
|
176
|
-
tints: modelData?.tints
|
|
185
|
+
tints: modelData?.tints
|
|
177
186
|
})
|
|
178
187
|
}
|
|
179
188
|
return null
|
|
180
|
-
}
|
|
189
|
+
}
|
|
181
190
|
}
|
|
182
191
|
|
|
183
192
|
const canvas = document.createElement('canvas')
|
|
@@ -197,9 +206,15 @@ const generateItemsGui = async (appViewer: AppViewer, models: Record<string, Blo
|
|
|
197
206
|
const includeOnly = [] as string[]
|
|
198
207
|
|
|
199
208
|
const images: Record<string, HTMLImageElement> = {}
|
|
200
|
-
const item = new ItemStack(
|
|
201
|
-
|
|
202
|
-
|
|
209
|
+
const item = new ItemStack(
|
|
210
|
+
PREVIEW_ID,
|
|
211
|
+
1,
|
|
212
|
+
new Map(
|
|
213
|
+
Object.entries({
|
|
214
|
+
'minecraft:item_model': new NbtString(PREVIEW_ID.toString())
|
|
215
|
+
})
|
|
216
|
+
)
|
|
217
|
+
)
|
|
203
218
|
const renderer = new ItemRenderer(gl, item, resources, { display_context: 'gui' })
|
|
204
219
|
const missingTextures = new Set()
|
|
205
220
|
for (const [modelName, model] of Object.entries(models)) {
|
|
@@ -248,9 +263,9 @@ const generateAtlas = async (appViewer: AppViewer, images: Record<string, HTMLIm
|
|
|
248
263
|
tileSize: RENDER_SIZE,
|
|
249
264
|
getLoadedImage(name) {
|
|
250
265
|
return {
|
|
251
|
-
image: images[name]
|
|
266
|
+
image: images[name]
|
|
252
267
|
}
|
|
253
|
-
}
|
|
268
|
+
}
|
|
254
269
|
})
|
|
255
270
|
|
|
256
271
|
// const atlasParser = new AtlasParser({ latest: atlas.json }, atlas.canvas.toDataURL())
|
|
@@ -261,7 +276,7 @@ const generateAtlas = async (appViewer: AppViewer, images: Record<string, HTMLIm
|
|
|
261
276
|
|
|
262
277
|
appViewer.resourcesManager.currentResources!.guiAtlas = {
|
|
263
278
|
json: atlas.json,
|
|
264
|
-
image: await createImageBitmap(atlas.canvas)
|
|
279
|
+
image: await createImageBitmap(atlas.canvas)
|
|
265
280
|
}
|
|
266
281
|
|
|
267
282
|
return atlas
|
package/src/lib/items.ts
CHANGED
|
@@ -9,7 +9,7 @@ import { ItemSpecificContextProperties } from '../playerState/types'
|
|
|
9
9
|
import { PlayerStateRenderer } from '../playerState/playerState'
|
|
10
10
|
|
|
11
11
|
type RenderSlotComponent = {
|
|
12
|
-
type: string
|
|
12
|
+
type: string
|
|
13
13
|
data: any
|
|
14
14
|
// example
|
|
15
15
|
// {
|
|
@@ -18,11 +18,11 @@ type RenderSlotComponent = {
|
|
|
18
18
|
// }
|
|
19
19
|
}
|
|
20
20
|
export type RenderItem = Pick<import('prismarine-item').Item, 'name' | 'displayName' | 'durabilityUsed' | 'maxDurability' | 'enchants' | 'nbt'> & {
|
|
21
|
-
components?: RenderSlotComponent[]
|
|
21
|
+
components?: RenderSlotComponent[]
|
|
22
22
|
// componentMap?: Map<string, RenderSlotComponent>
|
|
23
23
|
}
|
|
24
24
|
export type GeneralInputItem = Pick<import('prismarine-item').Item, 'name' | 'nbt'> & {
|
|
25
|
-
components?: RenderSlotComponent[]
|
|
25
|
+
components?: RenderSlotComponent[]
|
|
26
26
|
displayName?: string
|
|
27
27
|
modelResolved?: boolean
|
|
28
28
|
}
|
|
@@ -64,10 +64,12 @@ export const getItemMetadata = (item: GeneralInputItem, resourcesManager: Resour
|
|
|
64
64
|
let customModelData: number | undefined
|
|
65
65
|
if (typeof customModelDataComponent.data === 'number') {
|
|
66
66
|
customModelData = customModelDataComponent.data
|
|
67
|
-
} else if (
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
67
|
+
} else if (
|
|
68
|
+
typeof customModelDataComponent.data === 'object' &&
|
|
69
|
+
'floats' in customModelDataComponent.data &&
|
|
70
|
+
Array.isArray(customModelDataComponent.data.floats) &&
|
|
71
|
+
customModelDataComponent.data.floats.length > 0
|
|
72
|
+
) {
|
|
71
73
|
customModelData = customModelDataComponent.data.floats[0]
|
|
72
74
|
}
|
|
73
75
|
if (customModelData && customModelDataDefinitions[customModelData]) {
|
|
@@ -99,7 +101,6 @@ export const getItemMetadata = (item: GeneralInputItem, resourcesManager: Resour
|
|
|
99
101
|
}
|
|
100
102
|
}
|
|
101
103
|
|
|
102
|
-
|
|
103
104
|
export const getItemNameRaw = (item: Pick<import('prismarine-item').Item, 'nbt'> | null, resourcesManager: ResourcesManagerCommon) => {
|
|
104
105
|
if (!item) return ''
|
|
105
106
|
const { customText } = getItemMetadata(item as GeneralInputItem, resourcesManager)
|
|
@@ -121,7 +122,12 @@ export const getItemNameRaw = (item: Pick<import('prismarine-item').Item, 'nbt'>
|
|
|
121
122
|
}
|
|
122
123
|
}
|
|
123
124
|
|
|
124
|
-
export const getItemModelName = (
|
|
125
|
+
export const getItemModelName = (
|
|
126
|
+
item: GeneralInputItem,
|
|
127
|
+
specificProps: ItemSpecificContextProperties,
|
|
128
|
+
resourcesManager: ResourcesManagerCommon,
|
|
129
|
+
playerState: PlayerStateRenderer
|
|
130
|
+
) => {
|
|
125
131
|
let itemModelName = item.name
|
|
126
132
|
const { customModel } = getItemMetadata(item, resourcesManager)
|
|
127
133
|
if (customModel) {
|
|
@@ -6,7 +6,6 @@ import { Vec3 } from 'vec3'
|
|
|
6
6
|
import { WorldRendererCommon } from './worldrendererCommon'
|
|
7
7
|
const log = ''
|
|
8
8
|
|
|
9
|
-
|
|
10
9
|
export class MesherLogReader {
|
|
11
10
|
chunksToReceive: Array<{
|
|
12
11
|
x: number
|
|
@@ -25,11 +24,11 @@ export class MesherLogReader {
|
|
|
25
24
|
} | null
|
|
26
25
|
replayStarted = false
|
|
27
26
|
|
|
28
|
-
constructor
|
|
27
|
+
constructor(private readonly worldRenderer: WorldRendererCommon) {
|
|
29
28
|
this.parseMesherLog()
|
|
30
29
|
}
|
|
31
30
|
|
|
32
|
-
chunkReceived
|
|
31
|
+
chunkReceived(x: number, z: number, chunkLength: number) {
|
|
33
32
|
// remove existing chunks with same x and z
|
|
34
33
|
const existingChunkIndex = this.chunksToReceive.findIndex(chunk => chunk.x === x && chunk.z === z)
|
|
35
34
|
if (existingChunkIndex === -1) {
|
|
@@ -45,7 +44,7 @@ export class MesherLogReader {
|
|
|
45
44
|
this.maybeStartReplay()
|
|
46
45
|
}
|
|
47
46
|
|
|
48
|
-
async maybeStartReplay
|
|
47
|
+
async maybeStartReplay() {
|
|
49
48
|
if (this.chunksToReceive.length !== 0 || this.replayStarted) return
|
|
50
49
|
const lines = log.split('\n')
|
|
51
50
|
console.log('starting replay')
|
|
@@ -99,7 +98,7 @@ export class MesherLogReader {
|
|
|
99
98
|
}
|
|
100
99
|
}
|
|
101
100
|
|
|
102
|
-
workerMessageReceived
|
|
101
|
+
workerMessageReceived(type: string, message: any) {
|
|
103
102
|
if (type === 'sectionFinished') {
|
|
104
103
|
const { key } = message
|
|
105
104
|
if (!this.sectionFinishedToReceive) {
|
|
@@ -119,7 +118,7 @@ export class MesherLogReader {
|
|
|
119
118
|
}
|
|
120
119
|
}
|
|
121
120
|
|
|
122
|
-
parseMesherLog
|
|
121
|
+
parseMesherLog() {
|
|
123
122
|
const lines = log.split('\n')
|
|
124
123
|
for (const line of lines) {
|
|
125
124
|
if (line.startsWith('-> chunk')) {
|
package/src/lib/simpleUtils.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
//@ts-nocheck
|
|
2
|
-
export async function getBufferFromStream
|
|
2
|
+
export async function getBufferFromStream(stream) {
|
|
3
3
|
return new Promise((resolve, reject) => {
|
|
4
4
|
let buffer = Buffer.from([])
|
|
5
5
|
stream.on('data', buf => {
|
|
@@ -11,11 +11,11 @@ export async function getBufferFromStream (stream) {
|
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
// used for custom blocks
|
|
14
|
-
export function getBlockPosKey
|
|
14
|
+
export function getBlockPosKey(pos: { x: number; y: number; z: number }) {
|
|
15
15
|
return `${pos.x},${pos.y},${pos.z}`
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
export function openURL
|
|
18
|
+
export function openURL(url, newTab = true) {
|
|
19
19
|
if (newTab) {
|
|
20
20
|
window.open(url, '_blank', 'noopener,noreferrer')
|
|
21
21
|
} else {
|
|
@@ -27,13 +27,13 @@ export const isMobile = () => {
|
|
|
27
27
|
return window.matchMedia('(pointer: coarse)').matches || navigator.userAgent.includes('Mobile')
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
export function chunkPos
|
|
30
|
+
export function chunkPos(pos: { x: number; z: number }) {
|
|
31
31
|
const x = Math.floor(pos.x / 16)
|
|
32
32
|
const z = Math.floor(pos.z / 16)
|
|
33
33
|
return [x, z]
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
export function sectionPos
|
|
36
|
+
export function sectionPos(pos: { x: number; y: number; z: number }) {
|
|
37
37
|
const x = Math.floor(pos.x / 16)
|
|
38
38
|
const y = Math.floor(pos.y / 16)
|
|
39
39
|
const z = Math.floor(pos.z / 16)
|
package/src/lib/skyLight.ts
CHANGED
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
*/
|
|
20
20
|
export const getCelestialAngle = (timeOfDay: number): number => {
|
|
21
21
|
// Normalize time to 0-1 range
|
|
22
|
-
let angle = (
|
|
22
|
+
let angle = (timeOfDay % 24_000) / 24_000 - 0.25
|
|
23
23
|
|
|
24
24
|
if (angle < 0) angle += 1
|
|
25
25
|
if (angle > 1) angle -= 1
|
|
@@ -107,7 +107,7 @@ export const debugSkyLight = () => {
|
|
|
107
107
|
{ ticks: 18_000, label: '12:00 AM (midnight)' },
|
|
108
108
|
{ ticks: 19_000, label: '1:00 AM' },
|
|
109
109
|
{ ticks: 23_000, label: '5:00 AM (dawn begins)' },
|
|
110
|
-
{ ticks: 23_500, label: '5:30 AM (dawn mid)' }
|
|
110
|
+
{ ticks: 23_500, label: '5:30 AM (dawn mid)' }
|
|
111
111
|
]
|
|
112
112
|
|
|
113
113
|
console.log('Sky Light Debug:')
|
|
@@ -121,5 +121,5 @@ export const debugSkyLight = () => {
|
|
|
121
121
|
|
|
122
122
|
// Export for global access in console
|
|
123
123
|
if (typeof window !== 'undefined') {
|
|
124
|
-
(window as any).debugSkyLight = debugSkyLight
|
|
124
|
+
;(window as any).debugSkyLight = debugSkyLight
|
|
125
125
|
}
|
|
@@ -24,12 +24,11 @@ export class SmoothSwitcher {
|
|
|
24
24
|
public currentStateName = ''
|
|
25
25
|
public transitioningToStateName = ''
|
|
26
26
|
|
|
27
|
-
constructor
|
|
27
|
+
constructor(
|
|
28
28
|
public getState: StateGetterFn,
|
|
29
29
|
public setState: StateSetterFn,
|
|
30
30
|
speeds?: Partial<Record<string, number>>
|
|
31
31
|
) {
|
|
32
|
-
|
|
33
32
|
// Initialize speeds with defaults and overrides
|
|
34
33
|
this.speeds = { ...DEFAULT_SPEEDS }
|
|
35
34
|
if (speeds) {
|
|
@@ -43,7 +42,7 @@ export class SmoothSwitcher {
|
|
|
43
42
|
/**
|
|
44
43
|
* Calculate transition duration based on the largest property change
|
|
45
44
|
*/
|
|
46
|
-
private calculateDuration
|
|
45
|
+
private calculateDuration(newState: Partial<StateProperties>): number {
|
|
47
46
|
let maxDuration = 0
|
|
48
47
|
const currentState = this.getState()
|
|
49
48
|
|
|
@@ -60,7 +59,7 @@ export class SmoothSwitcher {
|
|
|
60
59
|
return Math.min(Math.max(maxDuration, 200), 2000)
|
|
61
60
|
}
|
|
62
61
|
|
|
63
|
-
private getPropertySpeed
|
|
62
|
+
private getPropertySpeed(property: string): number {
|
|
64
63
|
// Check for specific property speed
|
|
65
64
|
if (property in this.speeds) {
|
|
66
65
|
return this.speeds[property]
|
|
@@ -81,7 +80,7 @@ export class SmoothSwitcher {
|
|
|
81
80
|
* @param newState Partial state - only need to specify properties that change
|
|
82
81
|
* @param easing Easing function to use
|
|
83
82
|
*/
|
|
84
|
-
startTransition
|
|
83
|
+
startTransition(
|
|
85
84
|
newState: Partial<StateProperties>,
|
|
86
85
|
stateName?: string,
|
|
87
86
|
onEnd?: () => void,
|
|
@@ -103,7 +102,7 @@ export class SmoothSwitcher {
|
|
|
103
102
|
new tweenJs.Tween(state, group)
|
|
104
103
|
.to(newState, duration)
|
|
105
104
|
.easing(easing)
|
|
106
|
-
.onUpdate(
|
|
105
|
+
.onUpdate(obj => {
|
|
107
106
|
for (const key of Object.keys(obj)) {
|
|
108
107
|
this.setState(key, obj[key])
|
|
109
108
|
}
|
|
@@ -122,48 +121,42 @@ export class SmoothSwitcher {
|
|
|
122
121
|
/**
|
|
123
122
|
* Reset to default state
|
|
124
123
|
*/
|
|
125
|
-
reset
|
|
124
|
+
reset(): void {
|
|
126
125
|
this.startTransition(this.defaultState)
|
|
127
126
|
}
|
|
128
127
|
|
|
129
|
-
|
|
130
128
|
/**
|
|
131
129
|
* Update the animation (should be called in your render/update loop)
|
|
132
130
|
*/
|
|
133
|
-
update
|
|
131
|
+
update(): void {
|
|
134
132
|
this.animationController.update()
|
|
135
133
|
}
|
|
136
134
|
|
|
137
135
|
/**
|
|
138
136
|
* Force finish the current transition
|
|
139
137
|
*/
|
|
140
|
-
forceFinish
|
|
138
|
+
forceFinish(): void {
|
|
141
139
|
this.animationController.forceFinish()
|
|
142
140
|
}
|
|
143
141
|
|
|
144
142
|
/**
|
|
145
143
|
* Start a new transition to the specified state
|
|
146
144
|
*/
|
|
147
|
-
transitionTo (
|
|
148
|
-
newState: Partial<StateProperties>,
|
|
149
|
-
stateName?: string,
|
|
150
|
-
onEnd?: () => void,
|
|
151
|
-
onCancelled?: () => void
|
|
152
|
-
): void {
|
|
145
|
+
transitionTo(newState: Partial<StateProperties>, stateName?: string, onEnd?: () => void, onCancelled?: () => void): void {
|
|
153
146
|
this.startTransition(newState, stateName, onEnd, tweenJs.Easing.Linear.None, onCancelled)
|
|
154
147
|
}
|
|
155
148
|
|
|
156
149
|
/**
|
|
157
150
|
* Get the current value of a property
|
|
158
151
|
*/
|
|
159
|
-
getCurrentValue
|
|
152
|
+
getCurrentValue(property: string): number {
|
|
160
153
|
return this.getState()[property]
|
|
161
154
|
}
|
|
162
155
|
|
|
163
156
|
/**
|
|
164
157
|
* Check if currently transitioning
|
|
165
158
|
*/
|
|
166
|
-
get isTransitioning
|
|
159
|
+
get isTransitioning(): boolean {
|
|
167
160
|
return this.animationController.isActive
|
|
168
161
|
}
|
|
169
162
|
}
|
package/src/lib/ui/newStats.ts
CHANGED
|
@@ -11,14 +11,8 @@ let lastY = 40
|
|
|
11
11
|
/** Class for advanced stats pane; host app should set z-index (see integrating app global CSS). */
|
|
12
12
|
export const MC_RENDERER_DEBUG_OVERLAY_CLASS = 'mc-renderer-debug-overlay'
|
|
13
13
|
|
|
14
|
-
export const addNewStat = (
|
|
15
|
-
|
|
16
|
-
width = 80,
|
|
17
|
-
x = rightOffset,
|
|
18
|
-
y = lastY,
|
|
19
|
-
opts?: { className?: string },
|
|
20
|
-
) => {
|
|
21
|
-
if (isWebWorker) return { updateText() { }, setVisibility() { } }
|
|
14
|
+
export const addNewStat = (id: string, width = 80, x = rightOffset, y = lastY, opts?: { className?: string }) => {
|
|
15
|
+
if (isWebWorker) return { updateText() {}, setVisibility() {} }
|
|
22
16
|
|
|
23
17
|
const pane = document.createElement('div')
|
|
24
18
|
pane.style.position = 'fixed'
|
|
@@ -38,7 +32,8 @@ export const addNewStat = (
|
|
|
38
32
|
pane.style.pointerEvents = 'none'
|
|
39
33
|
document.body.appendChild(pane)
|
|
40
34
|
stats[id] = pane
|
|
41
|
-
if (y === undefined && x === rightOffset) {
|
|
35
|
+
if (y === undefined && x === rightOffset) {
|
|
36
|
+
// otherwise it's a custom position
|
|
42
37
|
// rightOffset += width
|
|
43
38
|
lastY += 20
|
|
44
39
|
}
|
|
@@ -54,8 +49,11 @@ export const addNewStat = (
|
|
|
54
49
|
}
|
|
55
50
|
}
|
|
56
51
|
|
|
57
|
-
export const addNewStat2 = (
|
|
58
|
-
|
|
52
|
+
export const addNewStat2 = (
|
|
53
|
+
id: string,
|
|
54
|
+
{ top, bottom, right, left, displayOnlyWhenWider }: { top?: number; bottom?: number; right?: number; left?: number; displayOnlyWhenWider?: number }
|
|
55
|
+
) => {
|
|
56
|
+
if (isWebWorker) return { updateText() {}, setVisibility() {} }
|
|
59
57
|
|
|
60
58
|
if (top === undefined && bottom === undefined) top = 0
|
|
61
59
|
const pane = document.createElement('div')
|
|
@@ -121,7 +119,7 @@ export const removeAllStats = () => {
|
|
|
121
119
|
}
|
|
122
120
|
}
|
|
123
121
|
|
|
124
|
-
export const removeStat =
|
|
122
|
+
export const removeStat = id => {
|
|
125
123
|
if (isWebWorker || !stats[id]) return
|
|
126
124
|
stats[id].remove()
|
|
127
125
|
delete stats[id]
|
package/src/lib/utils/proxy.ts
CHANGED
|
@@ -2,7 +2,13 @@
|
|
|
2
2
|
import { subscribeKey } from 'valtio/utils'
|
|
3
3
|
|
|
4
4
|
// eslint-disable-next-line max-params
|
|
5
|
-
export function watchProperty<T extends Record<string, any>, K>
|
|
5
|
+
export function watchProperty<T extends Record<string, any>, K>(
|
|
6
|
+
asyncGetter: (value: T[keyof T]) => Promise<K>,
|
|
7
|
+
valtioProxy: T,
|
|
8
|
+
key: keyof T,
|
|
9
|
+
readySetter: (res: K) => void,
|
|
10
|
+
cleanup?: (res: K) => void
|
|
11
|
+
) {
|
|
6
12
|
let i = 0
|
|
7
13
|
let lastRes: K | undefined
|
|
8
14
|
const request = async () => {
|
package/src/lib/utils/skins.ts
CHANGED
|
@@ -18,14 +18,14 @@ export const isLikelySkinImageSize = (width: number, height: number) => {
|
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
const config = {
|
|
21
|
-
apiEnabled: true
|
|
21
|
+
apiEnabled: true
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
export const setSkinsConfig = (newConfig: Partial<typeof config>) => {
|
|
25
25
|
Object.assign(config, newConfig)
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
export async function loadSkinFromUsername
|
|
28
|
+
export async function loadSkinFromUsername(username: string, type: 'skin' | 'cape'): Promise<string | undefined> {
|
|
29
29
|
if (!config.apiEnabled) return
|
|
30
30
|
|
|
31
31
|
if (type === 'cape') return
|
|
@@ -54,7 +54,7 @@ export const parseSkinTexturesValue = (value: string) => {
|
|
|
54
54
|
return decodedData.textures?.SKIN?.url
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
-
export async function loadSkinImage
|
|
57
|
+
export async function loadSkinImage(skinUrl: string): Promise<{ canvas: OffscreenCanvas; image: ImageBitmap }> {
|
|
58
58
|
if (!skinUrl.startsWith('data:')) {
|
|
59
59
|
skinUrl = await fetchAndConvertBase64Skin(skinUrl.replace('http://', 'https://'))
|
|
60
60
|
}
|
|
@@ -66,7 +66,7 @@ export async function loadSkinImage (skinUrl: string): Promise<{ canvas: Offscre
|
|
|
66
66
|
}
|
|
67
67
|
|
|
68
68
|
const fetchAndConvertBase64Skin = async (skinUrl: string) => {
|
|
69
|
-
const response = await fetch(skinUrl, {
|
|
69
|
+
const response = await fetch(skinUrl, {})
|
|
70
70
|
const arrayBuffer = await response.arrayBuffer()
|
|
71
71
|
const base64 = Buffer.from(arrayBuffer).toString('base64')
|
|
72
72
|
return `data:image/png;base64,${base64}`
|
package/src/lib/utils.ts
CHANGED
|
@@ -18,7 +18,7 @@ export const loadScript = async function (scriptSrc: string, highPriority = true
|
|
|
18
18
|
resolve(scriptElement)
|
|
19
19
|
})
|
|
20
20
|
|
|
21
|
-
scriptElement.onerror =
|
|
21
|
+
scriptElement.onerror = error => {
|
|
22
22
|
reject(new Error(typeof error === 'string' ? error : (error as any).message))
|
|
23
23
|
scriptElement.remove()
|
|
24
24
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/**
|
|
3
3
|
* Strip non–structured-clone values before Worker.postMessage (e.g. mineflayer `debug` on entities).
|
|
4
4
|
*/
|
|
5
|
-
export function sanitizeForWorkerPostMessage
|
|
5
|
+
export function sanitizeForWorkerPostMessage(value: unknown, depth = 0): unknown {
|
|
6
6
|
if (depth > 16) return undefined
|
|
7
7
|
if (value === null || value === undefined) return value
|
|
8
8
|
|
|
@@ -19,18 +19,11 @@ export function sanitizeForWorkerPostMessage (value: unknown, depth = 0): unknow
|
|
|
19
19
|
if (value instanceof Date) return value.toISOString()
|
|
20
20
|
|
|
21
21
|
if (Array.isArray(value)) {
|
|
22
|
-
return value
|
|
23
|
-
.map((entry) => sanitizeForWorkerPostMessage(entry, depth + 1))
|
|
24
|
-
.filter((entry) => entry !== undefined)
|
|
22
|
+
return value.map(entry => sanitizeForWorkerPostMessage(entry, depth + 1)).filter(entry => entry !== undefined)
|
|
25
23
|
}
|
|
26
24
|
|
|
27
25
|
const record = value as Record<string, unknown>
|
|
28
|
-
if (
|
|
29
|
-
typeof record.x === 'number'
|
|
30
|
-
&& typeof record.y === 'number'
|
|
31
|
-
&& typeof record.z === 'number'
|
|
32
|
-
&& !('w' in record)
|
|
33
|
-
) {
|
|
26
|
+
if (typeof record.x === 'number' && typeof record.y === 'number' && typeof record.z === 'number' && !('w' in record)) {
|
|
34
27
|
return { x: record.x, y: record.y, z: record.z }
|
|
35
28
|
}
|
|
36
29
|
|
|
@@ -43,6 +36,6 @@ export function sanitizeForWorkerPostMessage (value: unknown, depth = 0): unknow
|
|
|
43
36
|
return out
|
|
44
37
|
}
|
|
45
38
|
|
|
46
|
-
export function sanitizeWorkerEventArgs
|
|
47
|
-
return args.map(
|
|
39
|
+
export function sanitizeWorkerEventArgs(args: unknown[]): unknown[] {
|
|
40
|
+
return args.map(arg => sanitizeForWorkerPostMessage(arg))
|
|
48
41
|
}
|