minecraft-renderer 0.1.0

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 (187) hide show
  1. package/README.md +297 -0
  2. package/dist/index.html +83 -0
  3. package/dist/static/image/arrow.6f27b59f.png +0 -0
  4. package/dist/static/image/blocksAtlasLatest.7850afa3.png +0 -0
  5. package/dist/static/image/blocksAtlasLegacy.5c76823d.png +0 -0
  6. package/dist/static/image/itemsAtlasLatest.36036f95.png +0 -0
  7. package/dist/static/image/itemsAtlasLegacy.dcb1b58d.png +0 -0
  8. package/dist/static/image/tipped_arrow.6f27b59f.png +0 -0
  9. package/dist/static/js/365.f05233ab.js +8462 -0
  10. package/dist/static/js/365.f05233ab.js.LICENSE.txt +52 -0
  11. package/dist/static/js/async/738.efa27644.js +1 -0
  12. package/dist/static/js/index.092ec5be.js +56 -0
  13. package/dist/static/js/lib-polyfill.98986ac5.js +1 -0
  14. package/dist/static/js/lib-react.5c9129e0.js +2 -0
  15. package/dist/static/js/lib-react.5c9129e0.js.LICENSE.txt +39 -0
  16. package/package.json +104 -0
  17. package/src/assets/destroy_stage_0.png +0 -0
  18. package/src/assets/destroy_stage_1.png +0 -0
  19. package/src/assets/destroy_stage_2.png +0 -0
  20. package/src/assets/destroy_stage_3.png +0 -0
  21. package/src/assets/destroy_stage_4.png +0 -0
  22. package/src/assets/destroy_stage_5.png +0 -0
  23. package/src/assets/destroy_stage_6.png +0 -0
  24. package/src/assets/destroy_stage_7.png +0 -0
  25. package/src/assets/destroy_stage_8.png +0 -0
  26. package/src/assets/destroy_stage_9.png +0 -0
  27. package/src/examples/README.md +146 -0
  28. package/src/examples/appViewerExample.ts +205 -0
  29. package/src/examples/initialMenuStart.ts +161 -0
  30. package/src/graphicsBackend/appViewer.ts +297 -0
  31. package/src/graphicsBackend/config.ts +119 -0
  32. package/src/graphicsBackend/index.ts +10 -0
  33. package/src/graphicsBackend/playerState.ts +61 -0
  34. package/src/graphicsBackend/types.ts +143 -0
  35. package/src/index.ts +97 -0
  36. package/src/lib/DebugGui.ts +190 -0
  37. package/src/lib/animationController.ts +85 -0
  38. package/src/lib/buildSharedConfig.mjs +1 -0
  39. package/src/lib/cameraBobbing.ts +94 -0
  40. package/src/lib/canvas2DOverlay.example.ts +361 -0
  41. package/src/lib/canvas2DOverlay.quickstart.ts +242 -0
  42. package/src/lib/canvas2DOverlay.ts +381 -0
  43. package/src/lib/cleanupDecorator.ts +29 -0
  44. package/src/lib/createPlayerObject.ts +55 -0
  45. package/src/lib/frameTimingCollector.ts +164 -0
  46. package/src/lib/guiRenderer.ts +283 -0
  47. package/src/lib/items.ts +140 -0
  48. package/src/lib/mesherlogReader.ts +131 -0
  49. package/src/lib/moreBlockDataGenerated.json +714 -0
  50. package/src/lib/preflatMap.json +1741 -0
  51. package/src/lib/simpleUtils.ts +40 -0
  52. package/src/lib/smoothSwitcher.ts +168 -0
  53. package/src/lib/spiral.ts +29 -0
  54. package/src/lib/ui/newStats.ts +120 -0
  55. package/src/lib/utils/proxy.ts +23 -0
  56. package/src/lib/utils/skins.ts +63 -0
  57. package/src/lib/utils.ts +76 -0
  58. package/src/lib/workerProxy.ts +342 -0
  59. package/src/lib/worldrendererCommon.ts +1088 -0
  60. package/src/mesher/mesher.ts +253 -0
  61. package/src/mesher/models.ts +769 -0
  62. package/src/mesher/modelsGeometryCommon.ts +142 -0
  63. package/src/mesher/shared.ts +80 -0
  64. package/src/mesher/standaloneRenderer.ts +270 -0
  65. package/src/mesher/test/a.ts +3 -0
  66. package/src/mesher/test/mesherTester.ts +76 -0
  67. package/src/mesher/test/playground.ts +19 -0
  68. package/src/mesher/test/test-perf.ts +74 -0
  69. package/src/mesher/test/tests.test.ts +56 -0
  70. package/src/mesher/world.ts +294 -0
  71. package/src/mesher/worldConstants.ts +1 -0
  72. package/src/modules/index.ts +11 -0
  73. package/src/modules/starfield.ts +313 -0
  74. package/src/modules/types.ts +110 -0
  75. package/src/playerState/playerState.ts +78 -0
  76. package/src/playerState/types.ts +36 -0
  77. package/src/playground/allEntitiesDebug.ts +170 -0
  78. package/src/playground/baseScene.ts +587 -0
  79. package/src/playground/mobileControls.tsx +268 -0
  80. package/src/playground/playground.html +83 -0
  81. package/src/playground/playground.ts +11 -0
  82. package/src/playground/playgroundUi.tsx +140 -0
  83. package/src/playground/reactUtils.ts +71 -0
  84. package/src/playground/scenes/allEntities.ts +13 -0
  85. package/src/playground/scenes/entities.ts +37 -0
  86. package/src/playground/scenes/floorRandom.ts +33 -0
  87. package/src/playground/scenes/frequentUpdates.ts +148 -0
  88. package/src/playground/scenes/geometryExport.ts +142 -0
  89. package/src/playground/scenes/index.ts +12 -0
  90. package/src/playground/scenes/lightingStarfield.ts +40 -0
  91. package/src/playground/scenes/main.ts +313 -0
  92. package/src/playground/scenes/railsCobweb.ts +14 -0
  93. package/src/playground/scenes/rotationIssue.ts +7 -0
  94. package/src/playground/scenes/slabsOptimization.ts +16 -0
  95. package/src/playground/scenes/transparencyIssue.ts +11 -0
  96. package/src/playground/shared.ts +79 -0
  97. package/src/resourcesManager/index.ts +5 -0
  98. package/src/resourcesManager/resourcesManager.ts +314 -0
  99. package/src/shims/minecraftData.ts +41 -0
  100. package/src/sign-renderer/index.html +21 -0
  101. package/src/sign-renderer/index.ts +216 -0
  102. package/src/sign-renderer/noop.js +1 -0
  103. package/src/sign-renderer/playground.ts +38 -0
  104. package/src/sign-renderer/tests.test.ts +69 -0
  105. package/src/sign-renderer/vite.config.ts +10 -0
  106. package/src/three/appShared.ts +75 -0
  107. package/src/three/bannerRenderer.ts +275 -0
  108. package/src/three/cameraShake.ts +120 -0
  109. package/src/three/cinimaticScript.ts +350 -0
  110. package/src/three/documentRenderer.ts +491 -0
  111. package/src/three/entities.ts +1580 -0
  112. package/src/three/entity/EntityMesh.ts +707 -0
  113. package/src/three/entity/animations.js +171 -0
  114. package/src/three/entity/armorModels.json +204 -0
  115. package/src/three/entity/armorModels.ts +36 -0
  116. package/src/three/entity/entities.json +6230 -0
  117. package/src/three/entity/exportedModels.js +38 -0
  118. package/src/three/entity/externalTextures.json +1 -0
  119. package/src/three/entity/models/allay.obj +325 -0
  120. package/src/three/entity/models/arrow.obj +60 -0
  121. package/src/three/entity/models/axolotl.obj +509 -0
  122. package/src/three/entity/models/blaze.obj +601 -0
  123. package/src/three/entity/models/boat.obj +417 -0
  124. package/src/three/entity/models/camel.obj +1061 -0
  125. package/src/three/entity/models/cat.obj +509 -0
  126. package/src/three/entity/models/chicken.obj +371 -0
  127. package/src/three/entity/models/cod.obj +371 -0
  128. package/src/three/entity/models/creeper.obj +279 -0
  129. package/src/three/entity/models/dolphin.obj +371 -0
  130. package/src/three/entity/models/ender_dragon.obj +2993 -0
  131. package/src/three/entity/models/enderman.obj +325 -0
  132. package/src/three/entity/models/endermite.obj +187 -0
  133. package/src/three/entity/models/fox.obj +463 -0
  134. package/src/three/entity/models/frog.obj +739 -0
  135. package/src/three/entity/models/ghast.obj +463 -0
  136. package/src/three/entity/models/goat.obj +601 -0
  137. package/src/three/entity/models/guardian.obj +1015 -0
  138. package/src/three/entity/models/horse.obj +1061 -0
  139. package/src/three/entity/models/llama.obj +509 -0
  140. package/src/three/entity/models/minecart.obj +233 -0
  141. package/src/three/entity/models/parrot.obj +509 -0
  142. package/src/three/entity/models/piglin.obj +739 -0
  143. package/src/three/entity/models/pillager.obj +371 -0
  144. package/src/three/entity/models/rabbit.obj +555 -0
  145. package/src/three/entity/models/sheep.obj +555 -0
  146. package/src/three/entity/models/shulker.obj +141 -0
  147. package/src/three/entity/models/sniffer.obj +693 -0
  148. package/src/three/entity/models/spider.obj +509 -0
  149. package/src/three/entity/models/tadpole.obj +95 -0
  150. package/src/three/entity/models/turtle.obj +371 -0
  151. package/src/three/entity/models/vex.obj +325 -0
  152. package/src/three/entity/models/villager.obj +509 -0
  153. package/src/three/entity/models/warden.obj +463 -0
  154. package/src/three/entity/models/witch.obj +647 -0
  155. package/src/three/entity/models/wolf.obj +509 -0
  156. package/src/three/entity/models/zombie_villager.obj +463 -0
  157. package/src/three/entity/objModels.js +1 -0
  158. package/src/three/fireworks.ts +661 -0
  159. package/src/three/fireworksRenderer.ts +434 -0
  160. package/src/three/globals.d.ts +7 -0
  161. package/src/three/graphicsBackend.ts +274 -0
  162. package/src/three/graphicsBackendOffThread.ts +107 -0
  163. package/src/three/hand.ts +89 -0
  164. package/src/three/holdingBlock.ts +926 -0
  165. package/src/three/index.ts +20 -0
  166. package/src/three/itemMesh.ts +427 -0
  167. package/src/three/modules.d.ts +14 -0
  168. package/src/three/panorama.ts +308 -0
  169. package/src/three/panoramaShared.ts +1 -0
  170. package/src/three/renderSlot.ts +82 -0
  171. package/src/three/skyboxRenderer.ts +406 -0
  172. package/src/three/starField.ts +13 -0
  173. package/src/three/threeJsMedia.ts +731 -0
  174. package/src/three/threeJsMethods.ts +15 -0
  175. package/src/three/threeJsParticles.ts +160 -0
  176. package/src/three/threeJsSound.ts +95 -0
  177. package/src/three/threeJsUtils.ts +90 -0
  178. package/src/three/waypointSprite.ts +435 -0
  179. package/src/three/waypoints.ts +163 -0
  180. package/src/three/world/cursorBlock.ts +172 -0
  181. package/src/three/world/vr.ts +257 -0
  182. package/src/three/worldGeometryExport.ts +259 -0
  183. package/src/three/worldGeometryHandler.ts +279 -0
  184. package/src/three/worldRendererThree.ts +1381 -0
  185. package/src/worldView/index.ts +6 -0
  186. package/src/worldView/types.ts +66 -0
  187. package/src/worldView/worldView.ts +424 -0
@@ -0,0 +1,39 @@
1
+ /**
2
+ * @license React
3
+ * react-dom.production.min.js
4
+ *
5
+ * Copyright (c) Facebook, Inc. and its affiliates.
6
+ *
7
+ * This source code is licensed under the MIT license found in the
8
+ * LICENSE file in the root directory of this source tree.
9
+ */
10
+
11
+ /**
12
+ * @license React
13
+ * react-jsx-runtime.production.min.js
14
+ *
15
+ * Copyright (c) Facebook, Inc. and its affiliates.
16
+ *
17
+ * This source code is licensed under the MIT license found in the
18
+ * LICENSE file in the root directory of this source tree.
19
+ */
20
+
21
+ /**
22
+ * @license React
23
+ * react.production.min.js
24
+ *
25
+ * Copyright (c) Facebook, Inc. and its affiliates.
26
+ *
27
+ * This source code is licensed under the MIT license found in the
28
+ * LICENSE file in the root directory of this source tree.
29
+ */
30
+
31
+ /**
32
+ * @license React
33
+ * scheduler.production.min.js
34
+ *
35
+ * Copyright (c) Facebook, Inc. and its affiliates.
36
+ *
37
+ * This source code is licensed under the MIT license found in the
38
+ * LICENSE file in the root directory of this source tree.
39
+ */
package/package.json ADDED
@@ -0,0 +1,104 @@
1
+ {
2
+ "name": "minecraft-renderer",
3
+ "version": "0.1.0",
4
+ "description": "The most Modular Minecraft world renderer with Three.js WebGL backend",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "module": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "files": [
10
+ "dist",
11
+ "src"
12
+ ],
13
+ "keywords": [
14
+ "minecraft",
15
+ "renderer",
16
+ "threejs",
17
+ "webgl",
18
+ "prismarine"
19
+ ],
20
+ "release": {
21
+ "initialVersion": {
22
+ "version": "0.1.0"
23
+ }
24
+ },
25
+ "license": "MIT",
26
+ "dependencies": {
27
+ "@tweenjs/tween.js": "^20.0.3",
28
+ "@types/events": "^3.0.3",
29
+ "@xmcl/text-component": "^2.1.3",
30
+ "deepslate": "^0.24.0",
31
+ "events": "^3.3.0",
32
+ "mc-bridge": "^0.1.3",
33
+ "mineflayer-mouse": "^0.1.24",
34
+ "prismarine-chat": "^1.10.0",
35
+ "prismarine-nbt": "^2.5.0",
36
+ "skinview-utils": "^0.7.1",
37
+ "skinview3d": "^3.4.1",
38
+ "stats-gl": "^1.0.5",
39
+ "stats.js": "^0.17.0",
40
+ "three": "0.154.0",
41
+ "three-stdlib": "^2.36.1",
42
+ "type-fest": "^5.3.0",
43
+ "typed-emitter": "^2.1.0",
44
+ "valtio": "^1.11.1",
45
+ "vec3": "^0.1.10"
46
+ },
47
+ "devDependencies": {
48
+ "@emotion/css": "^11.13.5",
49
+ "@rsbuild/core": "1.3.5",
50
+ "@rsbuild/plugin-node-polyfill": "1.3.0",
51
+ "@rsbuild/plugin-react": "1.2.0",
52
+ "@types/react": "^19.2.7",
53
+ "@types/stats.js": "^0.17.1",
54
+ "@types/three": "0.154.0",
55
+ "@zardoy/react-util": "^0.2.7",
56
+ "@zardoy/tsconfig": "^1.5.1",
57
+ "esbuild": "^0.19.3",
58
+ "esbuild-plugin-polyfill-node": "^0.3.0",
59
+ "fs-extra": "^11.0.0",
60
+ "lil-gui": "^0.18.2",
61
+ "lodash": "^4.17.21",
62
+ "mc-assets": "^0.2.72",
63
+ "minecraft-data": "3.98.0",
64
+ "mineflayer": "^4.33.0",
65
+ "npm-run-all": "^4.1.5",
66
+ "prismarine-block": "github:zardoy/prismarine-block#next-era",
67
+ "prismarine-chunk": "github:zardoy/prismarine-chunk#master",
68
+ "prismarine-world": "github:zardoy/prismarine-world#next-era",
69
+ "react": "^18.2.0",
70
+ "react-dom": "^18.2.0",
71
+ "typescript": "^5.9.3",
72
+ "vitest": "^4.0.14"
73
+ },
74
+ "peerDependencies": {
75
+ "mc-assets": ">=0.2.0",
76
+ "minecraft-data": ">=3.0.0",
77
+ "three": ">=0.150.0"
78
+ },
79
+ "peerDependenciesMeta": {
80
+ "mc-assets": {
81
+ "optional": true
82
+ },
83
+ "minecraft-data": {
84
+ "optional": true
85
+ }
86
+ },
87
+ "repository": "https://github.com/zardoy/minecraft-renderer",
88
+ "engines": {
89
+ "node": "^12.20.0 || ^14.13.1 || >=16.0.0"
90
+ },
91
+ "scripts": {
92
+ "build": "pnpm build:all",
93
+ "build:all": "run-s build:lib build-mesher build:playground",
94
+ "build:lib": "node scripts/buildLib.mjs",
95
+ "build:lib:minify": "node scripts/buildLib.mjs --minify",
96
+ "watch:lib": "node scripts/buildLib.mjs -w",
97
+ "build-mesher": "node scripts/buildMesherWorker.mjs",
98
+ "watch-mesher": "pnpm build-mesher -w",
99
+ "build:playground": "rsbuild build --config rsbuild.config.ts",
100
+ "dev": "run-p watch-mesher dev:playground",
101
+ "dev:playground": "rsbuild dev --config rsbuild.config.ts",
102
+ "typecheck": "tsc --noEmit"
103
+ }
104
+ }
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -0,0 +1,146 @@
1
+ # Examples
2
+
3
+ This directory contains examples showing how to use the `@minecraft-renderer` library.
4
+
5
+ ## AppViewerExample
6
+
7
+ **File**: `appViewerExample.ts`
8
+
9
+ A comprehensive example showing how to:
10
+ - Initialize the AppViewer
11
+ - Load a graphics backend
12
+ - Set up a world with blocks
13
+ - Handle player state
14
+ - Switch between panorama and world modes
15
+
16
+ ### Usage
17
+
18
+ ```typescript
19
+ import { AppViewerExample, runExample } from 'minecraft-renderer'
20
+
21
+ // Run the complete example
22
+ await runExample()
23
+
24
+ // Or use the class directly
25
+ const example = new AppViewerExample()
26
+ await example.init()
27
+ await example.startWorld()
28
+ ```
29
+
30
+ ## Initial Menu Start
31
+
32
+ **File**: `initialMenuStart.ts`
33
+
34
+ A recreation of the original app viewer functionality, showing how to:
35
+ - Create a global app viewer instance
36
+ - Handle demo mode vs panorama mode
37
+ - Load Minecraft data
38
+ - Set up a simple world with water blocks
39
+ - Position the camera
40
+
41
+ This example closely mirrors your original implementation and can be used as a reference for migrating existing code.
42
+
43
+ ### Usage
44
+
45
+ ```typescript
46
+ import { appViewer, initialize, initialMenuStart } from 'minecraft-renderer'
47
+
48
+ // Initialize everything
49
+ await initialize()
50
+
51
+ // Or just start the menu
52
+ await initialMenuStart()
53
+
54
+ // Access the global app viewer
55
+ appViewer.startPanorama()
56
+ ```
57
+
58
+ ## Building the Library
59
+
60
+ To build the library for distribution:
61
+
62
+ ```bash
63
+ # Build TypeScript declarations
64
+ npm run build
65
+
66
+ # Build the bundled library
67
+ npm run build:lib
68
+
69
+ # Build minified version
70
+ npm run build:lib:minify
71
+
72
+ # Watch mode for development
73
+ npm run watch:lib
74
+
75
+ # Build everything
76
+ npm run build:all
77
+ ```
78
+
79
+ ## Integration Guide
80
+
81
+ ### 1. Basic Setup
82
+
83
+ ```typescript
84
+ import { AppViewer, createGraphicsBackend } from 'minecraft-renderer'
85
+
86
+ const viewer = new AppViewer({
87
+ config: {
88
+ fpsLimit: 60,
89
+ powerPreference: 'high-performance'
90
+ }
91
+ })
92
+
93
+ // Set up resource manager
94
+ viewer.resourcesManager = new ResourcesManager()
95
+
96
+ // Load backend
97
+ await viewer.loadBackend(createGraphicsBackend)
98
+ ```
99
+
100
+ ### 2. Starting a World
101
+
102
+ ```typescript
103
+ // Create your world provider
104
+ const world = {
105
+ getColumnAt: (pos) => ({ /* chunk data */ }),
106
+ setBlockStateId: (pos, stateId) => { /* set block */ }
107
+ }
108
+
109
+ // Start the world
110
+ await viewer.startWorld(world, renderDistance)
111
+
112
+ // Initialize world view
113
+ await viewer.worldView?.init(startPosition)
114
+ ```
115
+
116
+ ### 3. Camera Control
117
+
118
+ ```typescript
119
+ viewer.updateCamera(
120
+ new Vec3(x, y, z), // position
121
+ yaw, // rotation Y
122
+ pitch // rotation X
123
+ )
124
+ ```
125
+
126
+ ### 4. Player State
127
+
128
+ ```typescript
129
+ // Update player state
130
+ Object.assign(viewer.playerState.reactive, {
131
+ username: 'Player',
132
+ gameMode: 'creative'
133
+ })
134
+ ```
135
+
136
+ ## Migration from Original Code
137
+
138
+ If you're migrating from the original implementation:
139
+
140
+ 1. **Replace imports**: Update import paths to use the new module structure
141
+ 2. **Use AppViewer**: Replace direct backend usage with AppViewer
142
+ 3. **Update WorldView**: Use the new WorldView class instead of WorldDataEmitter
143
+ 4. **Resource Manager**: Set up ResourcesManager on the AppViewer instance
144
+ 5. **Player State**: Use the new player state structure
145
+
146
+ See `initialMenuStart.ts` for a direct migration example.
@@ -0,0 +1,205 @@
1
+ /**
2
+ * AppViewer Example - Shows how to use the AppViewer class
3
+ *
4
+ * This example demonstrates:
5
+ * - Loading a graphics backend
6
+ * - Setting up a world
7
+ * - Managing player state
8
+ * - Handling panorama mode
9
+ */
10
+
11
+ import { Vec3 } from 'vec3'
12
+ import { AppViewer } from '../graphicsBackend/appViewer'
13
+ import { ResourcesManager } from '../resourcesManager/resourcesManager'
14
+ import { WorldView } from '../worldView'
15
+ import { getInitialPlayerState } from '../graphicsBackend/playerState'
16
+
17
+ // Example world provider implementation
18
+ class ExampleWorldProvider {
19
+ private blocks = new Map<string, number>()
20
+
21
+ getColumnAt(pos: Vec3) {
22
+ // Return a simple column with some blocks
23
+ return {
24
+ toJson: () => new Uint8Array([1, 2, 3]), // Simple chunk data
25
+ minY: 0,
26
+ worldHeight: 256,
27
+ blockEntities: {}
28
+ }
29
+ }
30
+
31
+ setBlockStateId(pos: Vec3, stateId: number) {
32
+ this.blocks.set(`${pos.x},${pos.y},${pos.z}`, stateId)
33
+ }
34
+
35
+ getBiome(pos: Vec3) {
36
+ return 1 // Plains biome
37
+ }
38
+ }
39
+
40
+ // Example usage class
41
+ export class AppViewerExample {
42
+ private appViewer: AppViewer
43
+ private resourcesManager: ResourcesManager
44
+
45
+ constructor() {
46
+ // Create resource manager
47
+ this.resourcesManager = new ResourcesManager()
48
+
49
+ // Create app viewer with custom config
50
+ this.appViewer = new AppViewer({
51
+ config: {
52
+ fpsLimit: 60,
53
+ powerPreference: 'high-performance',
54
+ sceneBackground: '#87CEEB', // Sky blue
55
+ statsVisible: 1
56
+ },
57
+ rendererConfig: {
58
+ renderEntities: true,
59
+ smoothLighting: true,
60
+ fov: 75,
61
+ renderDistance: 10
62
+ }
63
+ })
64
+
65
+ // Set the resource manager
66
+ this.appViewer.resourcesManager = this.resourcesManager
67
+ }
68
+
69
+ /**
70
+ * Initialize and load the graphics backend
71
+ */
72
+ async init() {
73
+ try {
74
+ // Load minecraft data for version 1.16.4
75
+ const version = '1.16.4'
76
+ await this.resourcesManager.loadSourceData(version)
77
+ this.resourcesManager.currentConfig = { version }
78
+
79
+ // Load graphics backend (Three.js)
80
+ const { createGraphicsBackend } = await import('../three/graphicsBackend')
81
+ await this.appViewer.loadBackend(createGraphicsBackend)
82
+
83
+ console.log('AppViewer initialized successfully')
84
+ } catch (error) {
85
+ console.error('Failed to initialize AppViewer:', error)
86
+ throw error
87
+ }
88
+ }
89
+
90
+ /**
91
+ * Start panorama mode (menu background)
92
+ */
93
+ startPanorama() {
94
+ this.appViewer.startPanorama()
95
+ console.log('Panorama started')
96
+ }
97
+
98
+ /**
99
+ * Start world rendering
100
+ */
101
+ async startWorld() {
102
+ try {
103
+ // Create a simple world
104
+ const world = new ExampleWorldProvider()
105
+
106
+ // Set some blocks
107
+ world.setBlockStateId(new Vec3(0, 64, 0), 1) // Stone
108
+ world.setBlockStateId(new Vec3(1, 64, 0), 2) // Grass
109
+ world.setBlockStateId(new Vec3(0, 64, 1), 3) // Dirt
110
+
111
+ // Start the world with render distance 5
112
+ const renderDistance = 5
113
+ const startPosition = new Vec3(0, 65, 0)
114
+
115
+ await this.appViewer.startWorld(world, renderDistance, undefined, startPosition)
116
+
117
+ // Initialize world view
118
+ if (this.appViewer.worldView) {
119
+ await this.appViewer.worldView.init(startPosition)
120
+ }
121
+
122
+ // Set camera position
123
+ this.appViewer.updateCamera(
124
+ new Vec3(0, 66, 5), // Position
125
+ 0, // Yaw
126
+ -Math.PI / 6 // Pitch (looking down slightly)
127
+ )
128
+
129
+ console.log('World started successfully')
130
+ } catch (error) {
131
+ console.error('Failed to start world:', error)
132
+ throw error
133
+ }
134
+ }
135
+
136
+ /**
137
+ * Update player state
138
+ */
139
+ updatePlayerState(updates: Partial<any>) {
140
+ Object.assign(this.appViewer.playerState.reactive, updates)
141
+ }
142
+
143
+ /**
144
+ * Get current renderer state
145
+ */
146
+ getRendererState() {
147
+ return {
148
+ reactive: this.appViewer.rendererState,
149
+ nonReactive: this.appViewer.nonReactiveState
150
+ }
151
+ }
152
+
153
+ /**
154
+ * Wait for world to be ready
155
+ */
156
+ async waitForWorldReady() {
157
+ await this.appViewer.worldReady
158
+ console.log('World is ready')
159
+ }
160
+
161
+ /**
162
+ * Cleanup resources
163
+ */
164
+ destroy() {
165
+ this.appViewer.destroyAll()
166
+ console.log('AppViewer destroyed')
167
+ }
168
+ }
169
+
170
+ // Usage example
171
+ export async function runExample() {
172
+ const example = new AppViewerExample()
173
+
174
+ try {
175
+ // Initialize
176
+ await example.init()
177
+
178
+ // Start with panorama
179
+ example.startPanorama()
180
+
181
+ // Wait a bit, then switch to world
182
+ setTimeout(async () => {
183
+ await example.startWorld()
184
+ await example.waitForWorldReady()
185
+
186
+ // Update player state
187
+ example.updatePlayerState({
188
+ username: 'ExamplePlayer',
189
+ gameMode: 'creative'
190
+ })
191
+
192
+ console.log('Example completed successfully')
193
+ }, 2000)
194
+
195
+ } catch (error) {
196
+ console.error('Example failed:', error)
197
+ example.destroy()
198
+ }
199
+ }
200
+
201
+ // For browser usage
202
+ if (typeof window !== 'undefined') {
203
+ (window as any).AppViewerExample = AppViewerExample
204
+ ; (window as any).runAppViewerExample = runExample
205
+ }
@@ -0,0 +1,161 @@
1
+ /**
2
+ * Initial Menu Start Example - Similar to your original implementation
3
+ *
4
+ * This demonstrates how to recreate the functionality from your original appViewer code.
5
+ */
6
+
7
+ import { Vec3 } from 'vec3'
8
+ import { AppViewer } from '../graphicsBackend/appViewer'
9
+ import { ResourcesManager } from '../resourcesManager/resourcesManager'
10
+ import { WorldView } from '../worldView'
11
+ import { getInitialPlayerState } from '../graphicsBackend/playerState'
12
+
13
+ // Global app viewer instance (similar to your original)
14
+ export const appViewer = new AppViewer({
15
+ config: {
16
+ fpsLimit: undefined,
17
+ powerPreference: 'high-performance', // You can change this based on options
18
+ sceneBackground: 'lightblue',
19
+ timeoutRendering: false
20
+ }
21
+ })
22
+
23
+ // Set up resource manager
24
+ appViewer.resourcesManager = new ResourcesManager()
25
+
26
+ // Make it globally available (similar to your original)
27
+ if (typeof window !== 'undefined') {
28
+ ; (window as any).appViewer = appViewer
29
+ }
30
+
31
+ /**
32
+ * Load Minecraft data for a specific version
33
+ */
34
+ async function loadMinecraftData(version: string) {
35
+ if (!appViewer.resourcesManager) {
36
+ throw new Error('Resource manager not initialized')
37
+ }
38
+
39
+ await appViewer.resourcesManager.loadSourceData(version)
40
+ appViewer.resourcesManager.currentConfig = { version }
41
+ await appViewer.resourcesManager.updateAssetsData?.({})
42
+ }
43
+
44
+ /**
45
+ * Get sync world (placeholder - you'll need to implement this based on your needs)
46
+ */
47
+ function getSyncWorld(version: string) {
48
+ // This is a placeholder - you'll need to implement this based on your world provider
49
+ return {
50
+ setBlockStateId: (pos: Vec3, stateId: number) => {
51
+ console.log(`Setting block at ${pos.x},${pos.y},${pos.z} to state ${stateId}`)
52
+ },
53
+ getColumnAt: (pos: Vec3) => ({
54
+ toJson: () => new Uint8Array([1, 2, 3]),
55
+ minY: 0,
56
+ worldHeight: 256,
57
+ blockEntities: {}
58
+ })
59
+ }
60
+ }
61
+
62
+ /**
63
+ * Initial menu start function - similar to your original
64
+ */
65
+ export const initialMenuStart = async () => {
66
+ try {
67
+ if (appViewer.currentDisplay === 'world') {
68
+ appViewer.resetBackend(true)
69
+ }
70
+
71
+ // Check for demo mode
72
+ const demo = new URLSearchParams(window.location.search).get('demo')
73
+ if (!demo) {
74
+ appViewer.startPanorama()
75
+ return
76
+ }
77
+
78
+ // Demo mode - create a simple world
79
+ const version = '1.16.4' // You can change this
80
+
81
+ // Load minecraft data
82
+ await loadMinecraftData(version)
83
+
84
+ // Get world
85
+ const world = getSyncWorld(version)
86
+
87
+ // Set some example blocks (you'll need to get proper state IDs)
88
+ const waterStateId = 1 // Placeholder - get from mcData.blocksByName.water.defaultState
89
+ world.setBlockStateId(new Vec3(0, 64, 0), waterStateId)
90
+ world.setBlockStateId(new Vec3(1, 64, 0), waterStateId)
91
+ world.setBlockStateId(new Vec3(1, 64, 1), waterStateId)
92
+ world.setBlockStateId(new Vec3(0, 64, 1), waterStateId)
93
+ world.setBlockStateId(new Vec3(-1, 64, -1), waterStateId)
94
+ world.setBlockStateId(new Vec3(-1, 64, 0), waterStateId)
95
+ world.setBlockStateId(new Vec3(0, 64, -1), waterStateId)
96
+
97
+ // Set initial player state
98
+ appViewer.playerState.reactive = getInitialPlayerState()
99
+
100
+ // Start world
101
+ await appViewer.startWorld(world, 3)
102
+
103
+ // Update camera to look down at the water
104
+ appViewer.backend?.updateCamera(
105
+ new Vec3(0, 65.7, 0), // Position
106
+ 0, // Yaw
107
+ -Math.PI / 2 // Pitch (looking down)
108
+ )
109
+
110
+ // Initialize world view
111
+ if (appViewer.worldView) {
112
+ await appViewer.worldView.init(new Vec3(0, 64, 0))
113
+ }
114
+
115
+ console.log('Demo world started successfully')
116
+ } catch (error) {
117
+ console.error('Failed to start demo:', error)
118
+ }
119
+ }
120
+
121
+ /**
122
+ * Initialize the graphics backend
123
+ */
124
+ export async function initializeGraphicsBackend() {
125
+ try {
126
+ // Load the Three.js backend
127
+ const { createGraphicsBackend } = await import('../three/graphicsBackend')
128
+ await appViewer.loadBackend(createGraphicsBackend)
129
+ console.log('Graphics backend loaded successfully')
130
+ } catch (error) {
131
+ console.error('Failed to load graphics backend:', error)
132
+ throw error
133
+ }
134
+ }
135
+
136
+ /**
137
+ * Complete initialization function
138
+ */
139
+ export async function initialize() {
140
+ await initializeGraphicsBackend()
141
+ await initialMenuStart()
142
+ }
143
+
144
+ // Make functions globally available for browser usage
145
+ if (typeof window !== 'undefined') {
146
+ ; (window as any).initialMenuStart = initialMenuStart
147
+ ; (window as any).initializeGraphicsBackend = initializeGraphicsBackend
148
+ ; (window as any).initialize = initialize
149
+ }
150
+
151
+ // Auto-initialize if in browser and not in a module context
152
+ if (typeof window !== 'undefined' && !window.location.search.includes('manual')) {
153
+ // Auto-initialize after DOM is ready
154
+ if (document.readyState === 'loading') {
155
+ document.addEventListener('DOMContentLoaded', () => {
156
+ void initialize()
157
+ })
158
+ } else {
159
+ void initialize()
160
+ }
161
+ }