diff --git a/package.json b/package.json index dc1b4775..a1425c29 100644 --- a/package.json +++ b/package.json @@ -119,11 +119,11 @@ "workbox-build": "^7.0.0" }, "devDependencies": { - "@rsbuild/core": "^1.0.1-beta.9", - "@rsbuild/plugin-node-polyfill": "^1.0.3", - "@rsbuild/plugin-react": "^1.0.1-beta.9", - "@rsbuild/plugin-type-check": "^1.0.1-beta.9", - "@rsbuild/plugin-typed-css-modules": "^1.0.1", + "@rsbuild/core": "1.0.1-beta.9", + "@rsbuild/plugin-node-polyfill": "1.0.3", + "@rsbuild/plugin-react": "1.0.1-beta.9", + "@rsbuild/plugin-type-check": "1.0.1-beta.9", + "@rsbuild/plugin-typed-css-modules": "1.0.1", "@storybook/addon-essentials": "^7.4.6", "@storybook/addon-links": "^7.4.6", "@storybook/blocks": "^7.4.6", @@ -154,7 +154,7 @@ "mc-assets": "^0.2.52", "mineflayer-mouse": "^0.1.7", "minecraft-inventory-gui": "github:zardoy/minecraft-inventory-gui#next", - "mineflayer": "github:zardoy/mineflayer", + "mineflayer": "github:GenerelSchwerz/mineflayer", "mineflayer-pathfinder": "^2.4.4", "npm-run-all": "^4.1.5", "os-browserify": "^0.3.0", @@ -196,9 +196,9 @@ }, "pnpm": { "overrides": { + "@nxg-org/mineflayer-physics-util": "1.8.6", "buffer": "^6.0.3", "vec3": "0.1.10", - "@nxg-org/mineflayer-physics-util": "1.5.8", "three": "0.154.0", "diamond-square": "github:zardoy/diamond-square", "prismarine-block": "github:zardoy/prismarine-block#next-era", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index e36135e2..9d2cad2a 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -5,9 +5,9 @@ settings: excludeLinksFromLockfile: false overrides: + '@nxg-org/mineflayer-physics-util': 1.8.6 buffer: ^6.0.3 vec3: 0.1.10 - '@nxg-org/mineflayer-physics-util': 1.5.8 three: 0.154.0 diamond-square: github:zardoy/diamond-square prismarine-block: github:zardoy/prismarine-block#next-era @@ -136,7 +136,7 @@ importers: version: 4.17.21 mcraft-fun-mineflayer: specifier: ^0.1.14 - version: 0.1.14(encoding@0.1.13)(mineflayer@https://codeload.github.com/zardoy/mineflayer/tar.gz/06e3050ddf4d9aa655fea6e2bed182937a81705d(encoding@0.1.13)) + version: 0.1.14(encoding@0.1.13)(mineflayer@https://codeload.github.com/GenerelSchwerz/mineflayer/tar.gz/d459d2ed76a997af1a7c94718ed7d5dee4478b8a(encoding@0.1.13)) minecraft-data: specifier: 3.83.1 version: 3.83.1 @@ -257,19 +257,19 @@ importers: version: 5.22.7 devDependencies: '@rsbuild/core': - specifier: ^1.0.1-beta.9 + specifier: 1.0.1-beta.9 version: 1.0.1-beta.9 '@rsbuild/plugin-node-polyfill': - specifier: ^1.0.3 + specifier: 1.0.3 version: 1.0.3(@rsbuild/core@1.0.1-beta.9) '@rsbuild/plugin-react': - specifier: ^1.0.1-beta.9 + specifier: 1.0.1-beta.9 version: 1.0.1-beta.9(@rsbuild/core@1.0.1-beta.9) '@rsbuild/plugin-type-check': - specifier: ^1.0.1-beta.9 + specifier: 1.0.1-beta.9 version: 1.0.1-beta.9(@rsbuild/core@1.0.1-beta.9)(esbuild@0.19.11)(typescript@5.5.4) '@rsbuild/plugin-typed-css-modules': - specifier: ^1.0.1 + specifier: 1.0.1 version: 1.0.1(@rsbuild/core@1.0.1-beta.9) '@storybook/addon-essentials': specifier: ^7.4.6 @@ -362,8 +362,8 @@ importers: specifier: file:../minecraft-lighting version: file:../minecraft-lighting mineflayer: - specifier: github:zardoy/mineflayer - version: https://codeload.github.com/zardoy/mineflayer/tar.gz/06e3050ddf4d9aa655fea6e2bed182937a81705d(encoding@0.1.13) + specifier: github:GenerelSchwerz/mineflayer + version: https://codeload.github.com/GenerelSchwerz/mineflayer/tar.gz/d459d2ed76a997af1a7c94718ed7d5dee4478b8a(encoding@0.1.13) mineflayer-mouse: specifier: ^0.1.7 version: 0.1.7(@types/debug@4.1.12)(@types/node@22.8.1)(terser@5.31.3)(tsx@4.7.0)(yaml@2.4.1) @@ -441,7 +441,7 @@ importers: version: 1.3.6 prismarine-block: specifier: github:zardoy/prismarine-block#next-era - version: https://codeload.github.com/zardoy/prismarine-block/tar.gz/853c559bff2b402863ee9a75b125a3ca320838f9(prismarine-registry@1.11.0) + version: https://codeload.github.com/zardoy/prismarine-block/tar.gz/853c559bff2b402863ee9a75b125a3ca320838f9 prismarine-chunk: specifier: github:zardoy/prismarine-chunk#master version: https://codeload.github.com/zardoy/prismarine-chunk/tar.gz/e68e9a423b5b1907535878fb636f12c28a1a9374(minecraft-data@3.83.1) @@ -2144,8 +2144,8 @@ packages: '@nxg-org/mineflayer-auto-jump@0.7.12': resolution: {integrity: sha512-F5vX/lerlWx/5HVlkDNbvrtQ19PL6iG8i4ItPTIRtjGiFzusDefP7DI226zSFR8Wlaw45qHv0jn814p/4/qVdQ==} - '@nxg-org/mineflayer-physics-util@1.5.8': - resolution: {integrity: sha512-KmCkAqpUo8BbuRdIBs6+V2hWHehz++PRz3lRwIsb47CuG0u4sgLYh37RY3ifAznC6uWvmPK+q3B4ZXwJzPy1MQ==} + '@nxg-org/mineflayer-physics-util@1.8.6': + resolution: {integrity: sha512-eRn9e9OMvl1+kEfwPPshAl1A5MX0eDWaI7WVRf7ht9qo9N3fKiw+mM/AGPuhVjEr16zUls77P6Sn9cVZJuUdlw==} '@nxg-org/mineflayer-tracker@1.2.1': resolution: {integrity: sha512-SI1ffF8zvg3/ZNE021Ja2W0FZPN+WbQDZf8yFqOcXtPRXAtM9W6HvoACdzXep8BZid7WYgYLIgjKpB+9RqvCNQ==} @@ -4962,9 +4962,6 @@ packages: es-module-lexer@0.9.3: resolution: {integrity: sha512-1HQ2M2sPtxwnvOvT1ZClHyQDiggdNjURWpY2we6aMKCQiUVxTmVs2UYPLIrD84sS+kMdUwfBSylbJPwNnBrnHQ==} - es-module-lexer@1.5.4: - resolution: {integrity: sha512-MVNK56NiMrOwitFB7cqDwq0CQutbw+0BvLshJSse0MUNU+y1FC3bUS/AQg7oUng+/wKrrki7JfmwtVHkVfPLlw==} - es-module-lexer@1.6.0: resolution: {integrity: sha512-qqnD1yMU6tk/jnaMosogGySTZP8YtUgAffA9nMN+E/rjxcfRQ6IEk7IiozUjgxKoFHBGjTLnrHB/YC45r/59EQ==} @@ -6955,14 +6952,14 @@ packages: mineflayer-pathfinder@2.4.4: resolution: {integrity: sha512-HAXakZrJRb1UC+5dv8EaDrqjW3ZnBnBk3nkb6x/YWyhHCUKn/E7VU0FO+UN9whuqPlkSaVumEdXJdydE6lSYxQ==} - mineflayer@4.25.0: - resolution: {integrity: sha512-q7cmpZFaSI6sodcMJxc2GkV8IO84HbsUP+xNipGKfGg+FMISKabzdJ838Axb60qRtZrp6ny7LluQE7lesHvvxQ==} - engines: {node: '>=18'} + mineflayer@4.27.0: + resolution: {integrity: sha512-3bxph4jfbkBh5HpeouorxzrfSLNV+i+1gugNJ2jf52HW+rt+tW7eiiFPxrJEsOVkPT/3O/dEIW7j93LRlojMkQ==} + engines: {node: '>=22'} - mineflayer@https://codeload.github.com/zardoy/mineflayer/tar.gz/06e3050ddf4d9aa655fea6e2bed182937a81705d: - resolution: {tarball: https://codeload.github.com/zardoy/mineflayer/tar.gz/06e3050ddf4d9aa655fea6e2bed182937a81705d} - version: 4.25.0 - engines: {node: '>=18'} + mineflayer@https://codeload.github.com/GenerelSchwerz/mineflayer/tar.gz/d459d2ed76a997af1a7c94718ed7d5dee4478b8a: + resolution: {tarball: https://codeload.github.com/GenerelSchwerz/mineflayer/tar.gz/d459d2ed76a997af1a7c94718ed7d5dee4478b8a} + version: 4.27.0 + engines: {node: '>=22'} minimalistic-assert@1.0.1: resolution: {integrity: sha512-UtJcAD4yEaGtjPezWuO9wC4nwUnVH/8/Im3yEHQP4b67cXlD/Qr9hdITCU1xDbSEXg2XKNaP8jsReV7vQd00/A==} @@ -7674,6 +7671,9 @@ packages: prismarine-entity@2.3.1: resolution: {integrity: sha512-HOv8l7IetHNf4hwZ7V/W4vM3GNl+e6VCtKDkH9h02TRq7jWngsggKtJV+VanCce/sNwtJUhJDjORGs728ep4MA==} + prismarine-entity@2.5.0: + resolution: {integrity: sha512-nRPCawUwf9r3iKqi4I7mZRlir1Ix+DffWYdWq6p/KNnmiXve+xHE5zv8XCdhZlUmOshugHv5ONl9o6ORAkCNIA==} + prismarine-item@1.16.0: resolution: {integrity: sha512-88Tz+/6HquYIsDuseae5G3IbqLeMews2L+ba2gX+p6K6soU9nuFhCfbwN56QuB7d/jZFcWrCYAPE5+UhwWh67w==} @@ -11685,10 +11685,10 @@ snapshots: '@nxg-org/mineflayer-auto-jump@0.7.12': dependencies: - '@nxg-org/mineflayer-physics-util': 1.5.8 + '@nxg-org/mineflayer-physics-util': 1.8.6 strict-event-emitter-types: 2.0.0 - '@nxg-org/mineflayer-physics-util@1.5.8': + '@nxg-org/mineflayer-physics-util@1.8.6': dependencies: '@nxg-org/mineflayer-util-plugin': 1.8.3 @@ -13044,7 +13044,7 @@ snapshots: '@types/eslint-scope@3.7.7': dependencies: '@types/eslint': 9.6.0 - '@types/estree': 1.0.5 + '@types/estree': 1.0.6 '@types/eslint@9.6.0': dependencies: @@ -15484,8 +15484,6 @@ snapshots: es-module-lexer@0.9.3: {} - es-module-lexer@1.5.4: {} - es-module-lexer@1.6.0: {} es-object-atoms@1.1.1: @@ -16236,7 +16234,7 @@ snapshots: minimatch: 3.1.2 node-abort-controller: 3.1.1 schema-utils: 3.3.0 - semver: 7.6.0 + semver: 7.7.1 tapable: 2.2.1 typescript: 5.5.4 webpack: 5.93.0(esbuild@0.19.11) @@ -17621,12 +17619,12 @@ snapshots: maxrects-packer: '@zardoy/maxrects-packer@2.7.4' zod: 3.24.1 - mcraft-fun-mineflayer@0.1.14(encoding@0.1.13)(mineflayer@https://codeload.github.com/zardoy/mineflayer/tar.gz/06e3050ddf4d9aa655fea6e2bed182937a81705d(encoding@0.1.13)): + mcraft-fun-mineflayer@0.1.14(encoding@0.1.13)(mineflayer@https://codeload.github.com/GenerelSchwerz/mineflayer/tar.gz/d459d2ed76a997af1a7c94718ed7d5dee4478b8a(encoding@0.1.13)): dependencies: '@zardoy/flying-squid': 0.0.49(encoding@0.1.13) exit-hook: 2.2.1 minecraft-protocol: https://codeload.github.com/PrismarineJS/node-minecraft-protocol/tar.gz/3bd4dc1b2002cd7badfa5b9cf8dda35cd6cc9ac1(patch_hash=dkeyukcqlupmk563gwxsmjr3yu)(encoding@0.1.13) - mineflayer: https://codeload.github.com/zardoy/mineflayer/tar.gz/06e3050ddf4d9aa655fea6e2bed182937a81705d(encoding@0.1.13) + mineflayer: https://codeload.github.com/GenerelSchwerz/mineflayer/tar.gz/d459d2ed76a997af1a7c94718ed7d5dee4478b8a(encoding@0.1.13) prismarine-item: 1.16.0 ws: 8.18.0 transitivePeerDependencies: @@ -18046,7 +18044,7 @@ snapshots: mineflayer-item-map-downloader@https://codeload.github.com/zardoy/mineflayer-item-map-downloader/tar.gz/a8d210ecdcf78dd082fa149a96e1612cc9747824(patch_hash=bck55yjvd4wrgz46x7o4vfur5q)(encoding@0.1.13): dependencies: - mineflayer: 4.25.0(encoding@0.1.13) + mineflayer: 4.27.0(encoding@0.1.13) sharp: 0.30.7 transitivePeerDependencies: - encoding @@ -18083,22 +18081,22 @@ snapshots: mineflayer-pathfinder@2.4.4: dependencies: minecraft-data: 3.83.1 - prismarine-block: https://codeload.github.com/zardoy/prismarine-block/tar.gz/853c559bff2b402863ee9a75b125a3ca320838f9(prismarine-registry@1.11.0) + prismarine-block: https://codeload.github.com/zardoy/prismarine-block/tar.gz/853c559bff2b402863ee9a75b125a3ca320838f9 prismarine-entity: 2.3.1 prismarine-item: 1.16.0 prismarine-nbt: 2.5.0 prismarine-physics: https://codeload.github.com/zardoy/prismarine-physics/tar.gz/353e25b800149393f40539ec381218be44cbb03b vec3: 0.1.10 - mineflayer@4.25.0(encoding@0.1.13): + mineflayer@4.27.0(encoding@0.1.13): dependencies: minecraft-data: 3.83.1 - minecraft-protocol: https://codeload.github.com/PrismarineJS/node-minecraft-protocol/tar.gz/5ec3dd4b367fcc039fbcb3edd214fe3cf8178a6d(patch_hash=dkeyukcqlupmk563gwxsmjr3yu)(encoding@0.1.13) + minecraft-protocol: https://codeload.github.com/PrismarineJS/node-minecraft-protocol/tar.gz/9e116c3dd4682b17c4e2c80249a2447a093d9284(encoding@0.1.13) prismarine-biome: 1.3.0(minecraft-data@3.83.1)(prismarine-registry@1.11.0) - prismarine-block: https://codeload.github.com/zardoy/prismarine-block/tar.gz/853c559bff2b402863ee9a75b125a3ca320838f9(prismarine-registry@1.11.0) + prismarine-block: https://codeload.github.com/zardoy/prismarine-block/tar.gz/853c559bff2b402863ee9a75b125a3ca320838f9 prismarine-chat: 1.10.1 prismarine-chunk: https://codeload.github.com/zardoy/prismarine-chunk/tar.gz/e68e9a423b5b1907535878fb636f12c28a1a9374(minecraft-data@3.83.1) - prismarine-entity: 2.3.1 + prismarine-entity: 2.5.0 prismarine-item: 1.16.0 prismarine-nbt: 2.5.0 prismarine-physics: https://codeload.github.com/zardoy/prismarine-physics/tar.gz/353e25b800149393f40539ec381218be44cbb03b @@ -18113,17 +18111,18 @@ snapshots: - encoding - supports-color - mineflayer@https://codeload.github.com/zardoy/mineflayer/tar.gz/06e3050ddf4d9aa655fea6e2bed182937a81705d(encoding@0.1.13): + mineflayer@https://codeload.github.com/GenerelSchwerz/mineflayer/tar.gz/d459d2ed76a997af1a7c94718ed7d5dee4478b8a(encoding@0.1.13): dependencies: + '@nxg-org/mineflayer-physics-util': 1.8.6 minecraft-data: 3.83.1 - minecraft-protocol: https://codeload.github.com/PrismarineJS/node-minecraft-protocol/tar.gz/5ec3dd4b367fcc039fbcb3edd214fe3cf8178a6d(patch_hash=dkeyukcqlupmk563gwxsmjr3yu)(encoding@0.1.13) + minecraft-protocol: https://codeload.github.com/PrismarineJS/node-minecraft-protocol/tar.gz/9e116c3dd4682b17c4e2c80249a2447a093d9284(encoding@0.1.13) prismarine-biome: 1.3.0(minecraft-data@3.83.1)(prismarine-registry@1.11.0) - prismarine-block: https://codeload.github.com/zardoy/prismarine-block/tar.gz/853c559bff2b402863ee9a75b125a3ca320838f9(prismarine-registry@1.11.0) + prismarine-block: https://codeload.github.com/zardoy/prismarine-block/tar.gz/853c559bff2b402863ee9a75b125a3ca320838f9 prismarine-chat: 1.10.1 prismarine-chunk: https://codeload.github.com/zardoy/prismarine-chunk/tar.gz/e68e9a423b5b1907535878fb636f12c28a1a9374(minecraft-data@3.83.1) - prismarine-entity: 2.3.1 + prismarine-entity: 2.5.0 prismarine-item: 1.16.0 - prismarine-nbt: 2.5.0 + prismarine-nbt: 2.7.0 prismarine-physics: https://codeload.github.com/zardoy/prismarine-physics/tar.gz/353e25b800149393f40539ec381218be44cbb03b prismarine-recipe: 1.3.1(prismarine-registry@1.11.0) prismarine-registry: 1.11.0 @@ -18907,7 +18906,7 @@ snapshots: minecraft-data: 3.83.1 prismarine-registry: 1.11.0 - prismarine-block@https://codeload.github.com/zardoy/prismarine-block/tar.gz/853c559bff2b402863ee9a75b125a3ca320838f9(prismarine-registry@1.11.0): + prismarine-block@https://codeload.github.com/zardoy/prismarine-block/tar.gz/853c559bff2b402863ee9a75b125a3ca320838f9: dependencies: minecraft-data: 3.83.1 prismarine-biome: 1.3.0(minecraft-data@3.83.1)(prismarine-registry@1.11.0) @@ -18915,8 +18914,6 @@ snapshots: prismarine-item: 1.16.0 prismarine-nbt: 2.5.0 prismarine-registry: 1.11.0 - transitivePeerDependencies: - - prismarine-registry prismarine-chat@1.10.1: dependencies: @@ -18927,7 +18924,7 @@ snapshots: prismarine-chunk@https://codeload.github.com/zardoy/prismarine-chunk/tar.gz/e68e9a423b5b1907535878fb636f12c28a1a9374(minecraft-data@3.83.1): dependencies: prismarine-biome: 1.3.0(minecraft-data@3.83.1)(prismarine-registry@1.11.0) - prismarine-block: https://codeload.github.com/zardoy/prismarine-block/tar.gz/853c559bff2b402863ee9a75b125a3ca320838f9(prismarine-registry@1.11.0) + prismarine-block: https://codeload.github.com/zardoy/prismarine-block/tar.gz/853c559bff2b402863ee9a75b125a3ca320838f9 prismarine-nbt: 2.5.0 prismarine-registry: 1.11.0 smart-buffer: 4.2.0 @@ -18944,6 +18941,13 @@ snapshots: prismarine-registry: 1.11.0 vec3: 0.1.10 + prismarine-entity@2.5.0: + dependencies: + prismarine-chat: 1.10.1 + prismarine-item: 1.16.0 + prismarine-registry: 1.11.0 + vec3: 0.1.10 + prismarine-item@1.16.0: dependencies: prismarine-nbt: 2.7.0 @@ -18965,7 +18969,7 @@ snapshots: prismarine-provider-anvil@https://codeload.github.com/zardoy/prismarine-provider-anvil/tar.gz/1d548fac63fe977c8281f0a9a522b37e4d92d0b7(minecraft-data@3.83.1): dependencies: - prismarine-block: https://codeload.github.com/zardoy/prismarine-block/tar.gz/853c559bff2b402863ee9a75b125a3ca320838f9(prismarine-registry@1.11.0) + prismarine-block: https://codeload.github.com/zardoy/prismarine-block/tar.gz/853c559bff2b402863ee9a75b125a3ca320838f9 prismarine-chunk: https://codeload.github.com/zardoy/prismarine-chunk/tar.gz/e68e9a423b5b1907535878fb636f12c28a1a9374(minecraft-data@3.83.1) prismarine-nbt: 2.5.0 prismarine-world: https://codeload.github.com/zardoy/prismarine-world/tar.gz/ab2146c9933eef3247c3f64446de4ccc2c484c7c @@ -18989,13 +18993,13 @@ snapshots: prismarine-registry@1.11.0: dependencies: minecraft-data: 3.83.1 - prismarine-block: https://codeload.github.com/zardoy/prismarine-block/tar.gz/853c559bff2b402863ee9a75b125a3ca320838f9(prismarine-registry@1.11.0) + prismarine-block: https://codeload.github.com/zardoy/prismarine-block/tar.gz/853c559bff2b402863ee9a75b125a3ca320838f9 prismarine-nbt: 2.7.0 prismarine-schematic@1.2.3: dependencies: minecraft-data: 3.83.1 - prismarine-block: https://codeload.github.com/zardoy/prismarine-block/tar.gz/853c559bff2b402863ee9a75b125a3ca320838f9(prismarine-registry@1.11.0) + prismarine-block: https://codeload.github.com/zardoy/prismarine-block/tar.gz/853c559bff2b402863ee9a75b125a3ca320838f9 prismarine-nbt: 2.5.0 prismarine-world: https://codeload.github.com/zardoy/prismarine-world/tar.gz/ab2146c9933eef3247c3f64446de4ccc2c484c7c vec3: 0.1.10 @@ -19840,8 +19844,7 @@ snapshots: dependencies: lru-cache: 6.0.0 - semver@7.7.1: - optional: true + semver@7.7.1: {} send@0.18.0: dependencies: @@ -21275,7 +21278,7 @@ snapshots: webpack@5.93.0(esbuild@0.19.11): dependencies: '@types/eslint-scope': 3.7.7 - '@types/estree': 1.0.5 + '@types/estree': 1.0.6 '@webassemblyjs/ast': 1.12.1 '@webassemblyjs/wasm-edit': 1.12.1 '@webassemblyjs/wasm-parser': 1.12.1 @@ -21284,7 +21287,7 @@ snapshots: browserslist: 4.23.2 chrome-trace-event: 1.0.4 enhanced-resolve: 5.17.1 - es-module-lexer: 1.5.4 + es-module-lexer: 1.6.0 eslint-scope: 5.1.1 events: 3.3.0 glob-to-regexp: 0.4.1 diff --git a/renderer/buildMesherWorker.mjs b/renderer/buildMesherWorker.mjs index 2f9a4a02..47ea5771 100644 --- a/renderer/buildMesherWorker.mjs +++ b/renderer/buildMesherWorker.mjs @@ -22,7 +22,7 @@ const buildOptions = { }, platform: 'browser', entryPoints: [path.join(__dirname, './viewer/lib/mesher/mesher.ts')], - minify: true, + minify: !watch, logLevel: 'info', drop: !watch ? [ 'debugger' @@ -39,7 +39,7 @@ const buildOptions = { ...mesherSharedPlugins, { name: 'external-json', - setup (build) { + setup(build) { build.onResolve({ filter: /\.json$/ }, args => { const fileName = args.path.split('/').pop().replace('.json', '') if (args.resolveDir.includes('minecraft-data')) { diff --git a/renderer/playground.html b/renderer/playground.html index ec4c0f33..258426fe 100644 --- a/renderer/playground.html +++ b/renderer/playground.html @@ -11,11 +11,17 @@ html, body { height: 100%; + touch-action: none; margin: 0; padding: 0; } + * { + user-select: none; + -webkit-user-select: none; + } + canvas { height: 100%; width: 100%; diff --git a/renderer/viewer/lib/basePlayerState.ts b/renderer/viewer/lib/basePlayerState.ts index 93f4f6ce..df8cbc61 100644 --- a/renderer/viewer/lib/basePlayerState.ts +++ b/renderer/viewer/lib/basePlayerState.ts @@ -14,6 +14,9 @@ export type PlayerStateEvents = { heldItemChanged: (item: HandItemBlock | undefined, isLeftHand: boolean) => void } +export type BlockShape = { position: any; width: any; height: any; depth: any; } +export type BlocksShapes = BlockShape[] + export interface IPlayerState { getEyeHeight(): number getMovementState(): MovementState @@ -39,6 +42,21 @@ export interface IPlayerState { ambientLight: number directionalLight: number gameMode?: GameMode + lookingAtBlock?: { + x: number + y: number + z: number + face?: number + shapes: BlocksShapes + } + diggingBlock?: { + x: number + y: number + z: number + stage: number + face?: number + mergedShape?: BlockShape + } } } diff --git a/renderer/viewer/lib/mesher/models.ts b/renderer/viewer/lib/mesher/models.ts index 677886f9..66b1fe58 100644 --- a/renderer/viewer/lib/mesher/models.ts +++ b/renderer/viewer/lib/mesher/models.ts @@ -2,7 +2,7 @@ import { Vec3 } from 'vec3' import worldBlockProvider, { WorldBlockProvider } from 'mc-assets/dist/worldBlockProvider' import legacyJson from '../../../../src/preflatMap.json' import { BlockType } from '../../../playground/shared' -import { World, BlockModelPartsResolved, WorldBlock as Block } from './world' +import { World, BlockModelPartsResolved, WorldBlock as Block, WorldBlock } from './world' import { BlockElement, buildRotationMatrix, elemFaces, matmul3, matmulmat3, vecadd3, vecsub3 } from './modelsGeometryCommon' import { INVISIBLE_BLOCKS } from './worldConstants' import { MesherGeometryOutput, HighestBlockInfo } from './shared' @@ -103,7 +103,8 @@ function tintToGl (tint) { return [r / 255, g / 255, b / 255] } -function getLiquidRenderHeight (world, block, type, pos) { +function getLiquidRenderHeight (world: World, block: WorldBlock | null, type: number, pos: Vec3, isRealWater: boolean) { + if (!isRealWater || (block && isBlockWaterlogged(block))) return 8 / 9 if (!block || block.type !== type) return 1 / 9 if (block.metadata === 0) { // source block const blockAbove = world.getBlock(pos.offset(0, 1, 0)) @@ -124,12 +125,12 @@ const isCube = (block: Block) => { })) } -function renderLiquid (world: World, cursor: Vec3, texture: any | undefined, type: number, biome: string, water: boolean, attr: Record) { +function renderLiquid (world: World, cursor: Vec3, texture: any | undefined, type: number, biome: string, water: boolean, attr: Record, isRealWater: boolean) { const heights: number[] = [] for (let z = -1; z <= 1; z++) { for (let x = -1; x <= 1; x++) { const pos = cursor.offset(x, 0, z) - heights.push(getLiquidRenderHeight(world, world.getBlock(pos), type, pos)) + heights.push(getLiquidRenderHeight(world, world.getBlock(pos), type, pos, isRealWater)) } } const cornerHeights = [ @@ -147,9 +148,8 @@ function renderLiquid (world: World, cursor: Vec3, texture: any | undefined, typ const neighborPos = cursor.offset(...dir as [number, number, number]) const neighbor = world.getBlock(neighborPos) if (!neighbor) continue - if (neighbor.type === type) continue - const isGlass = neighbor.name.includes('glass') - if ((isCube(neighbor) && !isUp) || neighbor.material === 'plant' || neighbor.getProperties().waterlogged) continue + if (neighbor.type === type || (water && (neighbor.name === 'water' || isBlockWaterlogged(neighbor)))) continue + if (isCube(neighbor) && !isUp) continue let tint = [1, 1, 1] if (water) { @@ -253,7 +253,7 @@ function renderElement (world: World, cursor: Vec3, element: BlockElement, doAO: if (!neighbor.transparent && (isCube(neighbor) || identicalCull(element, neighbor, new Vec3(...dir)))) continue } else { needSectionRecomputeOnChange = true - continue + // continue } } @@ -539,11 +539,11 @@ export function getSectionGeometry (sx, sy, sz, world: World) { const pos = cursor.clone() // eslint-disable-next-line @typescript-eslint/no-loop-func delayedRender.push(() => { - renderLiquid(world, pos, blockProvider.getTextureInfo('water_still'), block.type, biome, true, attr) + renderLiquid(world, pos, blockProvider.getTextureInfo('water_still'), block.type, biome, true, attr, !isWaterlogged) }) attr.blocksCount++ } else if (block.name === 'lava') { - renderLiquid(world, cursor, blockProvider.getTextureInfo('lava_still'), block.type, biome, false, attr) + renderLiquid(world, cursor, blockProvider.getTextureInfo('lava_still'), block.type, biome, false, attr, false) attr.blocksCount++ } if (block.name !== 'water' && block.name !== 'lava' && !INVISIBLE_BLOCKS.has(block.name)) { diff --git a/renderer/viewer/lib/ui/newStats.ts b/renderer/viewer/lib/ui/newStats.ts index 8ccd4e57..4a1b0a0f 100644 --- a/renderer/viewer/lib/ui/newStats.ts +++ b/renderer/viewer/lib/ui/newStats.ts @@ -7,7 +7,7 @@ let lastY = 40 export const addNewStat = (id: string, width = 80, x = rightOffset, y = lastY) => { const pane = document.createElement('div') pane.style.position = 'fixed' - pane.style.top = `${y}px` + pane.style.top = `${y ?? lastY}px` pane.style.right = `${x}px` // gray bg pane.style.backgroundColor = 'rgba(0, 0, 0, 0.7)' @@ -19,7 +19,7 @@ export const addNewStat = (id: string, width = 80, x = rightOffset, y = lastY) = pane.style.pointerEvents = 'none' document.body.appendChild(pane) stats[id] = pane - if (y === 0) { // otherwise it's a custom position + if (y === undefined && x === rightOffset) { // otherwise it's a custom position // rightOffset += width lastY += 20 } @@ -35,6 +35,50 @@ export const addNewStat = (id: string, width = 80, x = rightOffset, y = lastY) = } } +export const addNewStat2 = (id: string, { top, bottom, right, left, displayOnlyWhenWider }: { top?: number, bottom?: number, right?: number, left?: number, displayOnlyWhenWider?: number }) => { + if (top === undefined && bottom === undefined) top = 0 + const pane = document.createElement('div') + pane.style.position = 'fixed' + if (top !== undefined) { + pane.style.top = `${top}px` + } + if (bottom !== undefined) { + pane.style.bottom = `${bottom}px` + } + if (left !== undefined) { + pane.style.left = `${left}px` + } + if (right !== undefined) { + pane.style.right = `${right}px` + } + // gray bg + pane.style.backgroundColor = 'rgba(0, 0, 0, 0.7)' + pane.style.color = 'white' + pane.style.padding = '2px' + pane.style.fontFamily = 'monospace' + pane.style.fontSize = '12px' + pane.style.zIndex = '10000' + pane.style.pointerEvents = 'none' + document.body.appendChild(pane) + stats[id] = pane + + const resizeCheck = () => { + if (!displayOnlyWhenWider) return + pane.style.display = window.innerWidth > displayOnlyWhenWider ? 'block' : 'none' + } + window.addEventListener('resize', resizeCheck) + resizeCheck() + + return { + updateText (text: string) { + pane.innerText = text + }, + setVisibility (visible: boolean) { + pane.style.display = visible ? 'block' : 'none' + } + } +} + export const updateStatText = (id, text) => { if (!stats[id]) return stats[id].innerText = text diff --git a/renderer/viewer/lib/workerProxy.ts b/renderer/viewer/lib/workerProxy.ts index a27c817d..9d8e7fcc 100644 --- a/renderer/viewer/lib/workerProxy.ts +++ b/renderer/viewer/lib/workerProxy.ts @@ -1,5 +1,6 @@ -export function createWorkerProxy void>> (handlers: T): { __workerProxy: T } { - addEventListener('message', (event) => { +export function createWorkerProxy void>> (handlers: T, channel?: MessagePort): { __workerProxy: T } { + const target = channel ?? globalThis + target.addEventListener('message', (event: any) => { const { type, args } = event.data if (handlers[type]) { handlers[type](...args) @@ -19,7 +20,7 @@ export function createWorkerProxy v * const workerChannel = useWorkerProxy(worker) * ``` */ -export const useWorkerProxy = void> }> (worker: Worker, autoTransfer = true): T['__workerProxy'] & { +export const useWorkerProxy = void> }> (worker: Worker | MessagePort, autoTransfer = true): T['__workerProxy'] & { transfer: (...args: Transferable[]) => T['__workerProxy'] } => { // in main thread @@ -40,11 +41,11 @@ export const useWorkerProxy = { - const transfer = autoTransfer ? args.filter(arg => arg instanceof ArrayBuffer || arg instanceof MessagePort || arg instanceof ImageBitmap || arg instanceof OffscreenCanvas) : [] + const transfer = autoTransfer ? args.filter(arg => arg instanceof ArrayBuffer || arg instanceof MessagePort || arg instanceof ImageBitmap || arg instanceof OffscreenCanvas || arg instanceof ImageData) : [] worker.postMessage({ type: prop, args, - }, transfer) + }, transfer as any[]) } } }) diff --git a/renderer/viewer/lib/worldrendererCommon.ts b/renderer/viewer/lib/worldrendererCommon.ts index 49983f7c..d8ece1ac 100644 --- a/renderer/viewer/lib/worldrendererCommon.ts +++ b/renderer/viewer/lib/worldrendererCommon.ts @@ -54,6 +54,7 @@ export const defaultWorldRendererConfig = { export type WorldRendererConfig = typeof defaultWorldRendererConfig export abstract class WorldRendererCommon { + timeOfTheDay = 0 worldSizeParams = { minY: 0, worldHeight: 256 } active = false @@ -187,7 +188,7 @@ export abstract class WorldRendererCommon if (this.mainThreadRendering) { this.fpsUpdate() } - }, 1000) + }, 500) } fpsUpdate () { @@ -498,10 +499,23 @@ export abstract class WorldRendererCommon } getMesherConfig (): MesherConfig { + let skyLight = 15 + const timeOfDay = this.timeOfTheDay + if (timeOfDay < 0 || timeOfDay > 24_000) { + // + } else if (timeOfDay <= 6000 || timeOfDay >= 18_000) { + skyLight = 15 + } else if (timeOfDay > 6000 && timeOfDay < 12_000) { + skyLight = 15 - ((timeOfDay - 6000) / 6000) * 15 + } else if (timeOfDay >= 12_000 && timeOfDay < 18_000) { + skyLight = ((timeOfDay - 12_000) / 6000) * 15 + } + + skyLight = Math.floor(skyLight) return { version: this.version, enableLighting: this.worldRendererConfig.enableLighting, - skyLight: 15, + skyLight, smoothLighting: this.worldRendererConfig.smoothLighting, outputFormat: this.outputFormat, textureSize: this.resourcesManager.currentResources!.blocksAtlasParser.atlas.latest.width, @@ -612,7 +626,7 @@ export abstract class WorldRendererCommon this.logWorkerWork(`-> unloadChunk ${JSON.stringify({ x, z })}`) delete this.finishedChunks[`${x},${z}`] this.allChunksFinished = Object.keys(this.finishedChunks).length === this.chunksLength - if (!this.allChunksFinished) { + if (Object.keys(this.finishedChunks).length === 0) { this.allLoadedIn = undefined this.initialChunkLoadWasStartedIn = undefined } @@ -739,18 +753,11 @@ export abstract class WorldRendererCommon worldEmitter.on('time', (timeOfDay) => { this.timeUpdated?.(timeOfDay) - let skyLight = 15 if (timeOfDay < 0 || timeOfDay > 24_000) { throw new Error('Invalid time of day. It should be between 0 and 24000.') - } else if (timeOfDay <= 6000 || timeOfDay >= 18_000) { - skyLight = 15 - } else if (timeOfDay > 6000 && timeOfDay < 12_000) { - skyLight = 15 - ((timeOfDay - 6000) / 6000) * 15 - } else if (timeOfDay >= 12_000 && timeOfDay < 18_000) { - skyLight = ((timeOfDay - 12_000) / 6000) * 15 } - skyLight = Math.floor(skyLight) // todo: remove this after optimization + this.timeOfTheDay = timeOfDay // if (this.worldRendererConfig.skyLight === skyLight) return // this.worldRendererConfig.skyLight = skyLight diff --git a/renderer/viewer/three/graphicsBackend.ts b/renderer/viewer/three/graphicsBackend.ts index c6d23a2e..f8cf14a4 100644 --- a/renderer/viewer/three/graphicsBackend.ts +++ b/renderer/viewer/three/graphicsBackend.ts @@ -19,8 +19,6 @@ const getBackendMethods = (worldRenderer: WorldRendererThree) => { playEntityAnimation: worldRenderer.entities.playAnimation.bind(worldRenderer.entities), damageEntity: worldRenderer.entities.handleDamageEvent.bind(worldRenderer.entities), updatePlayerSkin: worldRenderer.entities.updatePlayerSkin.bind(worldRenderer.entities), - setHighlightCursorBlock: worldRenderer.cursorBlock.setHighlightCursorBlock.bind(worldRenderer.cursorBlock), - updateBreakAnimation: worldRenderer.cursorBlock.updateBreakAnimation.bind(worldRenderer.cursorBlock), changeHandSwingingState: worldRenderer.changeHandSwingingState.bind(worldRenderer), getHighestBlocks: worldRenderer.getHighestBlocks.bind(worldRenderer), rerenderAllChunks: worldRenderer.rerenderAllChunks.bind(worldRenderer), diff --git a/renderer/viewer/three/threeJsMedia.ts b/renderer/viewer/three/threeJsMedia.ts index a8855f7c..af95f416 100644 --- a/renderer/viewer/three/threeJsMedia.ts +++ b/renderer/viewer/three/threeJsMedia.ts @@ -529,6 +529,9 @@ export class ThreeJsMedia { } tryIntersectMedia () { + // hack: need to optimize this by pulling only in distance of interaction instead (or throttle)! + if (this.customMedia.size === 0) return + const { camera, scene } = this.worldRenderer const raycaster = new THREE.Raycaster() diff --git a/renderer/viewer/three/world/cursorBlock.ts b/renderer/viewer/three/world/cursorBlock.ts index ab0c4854..fe95c2c9 100644 --- a/renderer/viewer/three/world/cursorBlock.ts +++ b/renderer/viewer/three/world/cursorBlock.ts @@ -3,6 +3,7 @@ import { LineMaterial, LineSegmentsGeometry, Wireframe } from 'three-stdlib' import { Vec3 } from 'vec3' import { subscribeKey } from 'valtio/utils' import { Block } from 'prismarine-block' +import { BlockShape, BlocksShapes } from 'renderer/viewer/lib/basePlayerState' import { WorldRendererThree } from '../worldrendererThree' import destroyStage0 from '../../../../assets/destroy_stage_0.png' import destroyStage1 from '../../../../assets/destroy_stage_1.png' @@ -89,15 +90,13 @@ export class CursorBlock { this.prevColor = this.worldRenderer.worldRendererConfig.highlightBlockColor } - updateBreakAnimation (block: Block | undefined, stage: number | null) { + updateBreakAnimation (blockPosition: { x: number, y: number, z: number } | undefined, stage: number | null, mergedShape?: BlockShape) { this.hideBreakAnimation() - if (stage === null || !block) return + if (stage === null || !blockPosition || !mergedShape) return - const mergedShape = bot.mouse.getMergedCursorShape(block) - if (!mergedShape) return - const { position, width, height, depth } = bot.mouse.getDataFromShape(mergedShape) + const { position, width, height, depth } = mergedShape this.blockBreakMesh.scale.set(width * 1.001, height * 1.001, depth * 1.001) - position.add(block.position) + position.add(blockPosition) this.blockBreakMesh.position.set(position.x, position.y, position.z) this.blockBreakMesh.visible = true; @@ -119,7 +118,7 @@ export class CursorBlock { } } - setHighlightCursorBlock (blockPos: Vec3 | null, shapePositions?: Array<{ position: any; width: any; height: any; depth: any; }>): void { + setHighlightCursorBlock (blockPos: Vec3 | null, shapePositions?: BlocksShapes): void { if (blockPos && this.interactionLines && blockPos.equals(this.interactionLines.blockPos)) { return } @@ -143,7 +142,7 @@ export class CursorBlock { group.add(wireframe) } this.worldRenderer.scene.add(group) - group.visible = this.cursorLinesHidden + group.visible = !this.cursorLinesHidden this.interactionLines = { blockPos, mesh: group } } diff --git a/renderer/viewer/three/worldrendererThree.ts b/renderer/viewer/three/worldrendererThree.ts index e901905e..482b0255 100644 --- a/renderer/viewer/three/worldrendererThree.ts +++ b/renderer/viewer/three/worldrendererThree.ts @@ -140,6 +140,7 @@ export class WorldRendererThree extends WorldRendererCommon { } override watchReactivePlayerState () { + super.watchReactivePlayerState() this.onReactiveValueUpdated('inWater', (value) => { this.scene.fog = value ? new THREE.Fog(0x00_00_ff, 0.1, this.displayOptions.playerState.reactive.waterBreathing ? 100 : 20) : null }) @@ -151,6 +152,12 @@ export class WorldRendererThree extends WorldRendererCommon { if (!value) return this.directionalLight.intensity = value }) + this.onReactiveValueUpdated('lookingAtBlock', (value) => { + this.cursorBlock.setHighlightCursorBlock(value ? new Vec3(value.x, value.y, value.z) : null, value?.shapes) + }) + this.onReactiveValueUpdated('diggingBlock', (value) => { + this.cursorBlock.updateBreakAnimation(value ? { x: value.x, y: value.y, z: value.z } : undefined, value?.stage ?? null, value?.mergedShape) + }) } changeHandSwingingState (isAnimationPlaying: boolean, isLeft = false) { diff --git a/src/appViewer.ts b/src/appViewer.ts index 1b973ad2..0f29b9a6 100644 --- a/src/appViewer.ts +++ b/src/appViewer.ts @@ -155,6 +155,12 @@ export class AppViewer { } } + async startWithBot () { + const renderDistance = miscUiState.singleplayer ? options.renderDistance : options.multiplayerRenderDistance + await this.startWorld(bot.world, renderDistance) + this.worldView!.listenToBot(bot) + } + async startWorld (world, renderDistance: number, playerStateSend: IPlayerState = this.playerState) { if (this.currentDisplay === 'world') throw new Error('World already started') this.currentDisplay = 'world' @@ -185,11 +191,7 @@ export class AppViewer { } resetBackend (cleanState = false) { - if (cleanState) { - this.currentState = undefined - this.currentDisplay = null - this.worldView = undefined - } + this.disconnectBackend(cleanState) if (this.backendLoader) { this.loadBackend(this.backendLoader) } @@ -216,7 +218,12 @@ export class AppViewer { this.resourcesManager.destroy() } - disconnectBackend () { + disconnectBackend (cleanState = false) { + if (cleanState) { + this.currentState = undefined + this.currentDisplay = null + this.worldView = undefined + } if (this.backend) { this.backend.disconnect() this.backend = undefined @@ -225,7 +232,7 @@ export class AppViewer { const { promise, resolve } = Promise.withResolvers() this.worldReady = promise this.resolveWorldReady = resolve - Object.assign(this.rendererState, getDefaultRendererState()) + this.rendererState = proxy(getDefaultRendererState()) // this.queuedDisplay = undefined } diff --git a/src/appViewerLoad.ts b/src/appViewerLoad.ts index 8110ac89..96e3bf03 100644 --- a/src/appViewerLoad.ts +++ b/src/appViewerLoad.ts @@ -37,3 +37,13 @@ const animLoop = () => { requestAnimationFrame(animLoop) watchOptionsAfterViewerInit() + +// reset backend when renderer changes + +subscribeKey(options, 'activeRenderer', () => { + if (appViewer.currentDisplay === 'world' && bot) { + appViewer.resetBackend(true) + loadBackend() + void appViewer.startWithBot() + } +}) diff --git a/src/controls.ts b/src/controls.ts index d4522eae..0633ea8e 100644 --- a/src/controls.ts +++ b/src/controls.ts @@ -714,142 +714,32 @@ document.addEventListener('visibilitychange', (e) => { } }) -// #region creative fly -// these controls are more like for gamemode 3 - -const makeInterval = (fn, interval) => { - const intervalId = setInterval(fn, interval) - - const cleanup = () => { - clearInterval(intervalId) - cleanup.active = false - } - cleanup.active = true - return cleanup -} - -const isFlying = () => bot.physics.gravity === 0 -let endFlyLoop: ReturnType | undefined - -const currentFlyVector = new Vec3(0, 0, 0) -window.currentFlyVector = currentFlyVector - -// todo cleanup -const flyingPressedKeys = { - down: false, - up: false -} - -const startFlyLoop = () => { - if (!isFlying()) return - endFlyLoop?.() - - endFlyLoop = makeInterval(() => { - if (!bot) { - endFlyLoop?.() - return - } - - bot.entity.position.add(currentFlyVector.clone().multiply(new Vec3(0, 0.5, 0))) - }, 50) -} - -// todo we will get rid of patching it when refactor controls -let originalSetControlState -const patchedSetControlState = (action, state) => { - if (!isFlying()) { - return originalSetControlState(action, state) - } - - const actionPerFlyVector = { - jump: new Vec3(0, 1, 0), - sneak: new Vec3(0, -1, 0), - } - - const changeVec = actionPerFlyVector[action] - if (!changeVec) { - return originalSetControlState(action, state) - } - if (flyingPressedKeys[state === 'jump' ? 'up' : 'down'] === state) return - const toAddVec = changeVec.scaled(state ? 1 : -1) - for (const coord of ['x', 'y', 'z']) { - if (toAddVec[coord] === 0) continue - if (currentFlyVector[coord] === toAddVec[coord]) return - } - currentFlyVector.add(toAddVec) - flyingPressedKeys[state === 'jump' ? 'up' : 'down'] = state -} +const isFlying = () => (bot.entity as any).flying const startFlying = (sendAbilities = true) => { - bot.entity['creativeFly'] = true if (sendAbilities) { bot._client.write('abilities', { flags: 2, }) } - // window.flyingSpeed will be removed - bot.physics['airborneAcceleration'] = window.flyingSpeed ?? 0.1 // todo use abilities - bot.entity.velocity = new Vec3(0, 0, 0) - bot.creative.startFlying() - startFlyLoop() + (bot.entity as any).flying = true } const endFlying = (sendAbilities = true) => { - bot.entity['creativeFly'] = false - if (bot.physics.gravity !== 0) return + if (!isFlying()) return if (sendAbilities) { bot._client.write('abilities', { flags: 0, }) } - Object.assign(flyingPressedKeys, { - up: false, - down: false - }) - currentFlyVector.set(0, 0, 0) - bot.physics['airborneAcceleration'] = standardAirborneAcceleration - bot.creative.stopFlying() - endFlyLoop?.() + (bot.entity as any).flying = false } -let allowFlying = false - export const onBotCreate = () => { - let wasSpectatorFlying = false - bot._client.on('abilities', ({ flags }) => { - allowFlying = !!(flags & 4) - if (flags & 2) { // flying - toggleFly(true, false) - } else { - toggleFly(false, false) - } - }) - const gamemodeCheck = () => { - if (bot.game.gameMode === 'spectator') { - allowFlying = true - toggleFly(true, false) - wasSpectatorFlying = true - } else if (wasSpectatorFlying) { - toggleFly(false, false) - wasSpectatorFlying = false - } - } - bot.on('game', () => { - gamemodeCheck() - }) - bot.on('login', () => { - gamemodeCheck() - }) } -const standardAirborneAcceleration = 0.02 const toggleFly = (newState = !isFlying(), sendAbilities?: boolean) => { - // if (bot.game.gameMode !== 'creative' && bot.game.gameMode !== 'spectator') return - if (!allowFlying) return - if (bot.setControlState !== patchedSetControlState) { - originalSetControlState = bot.setControlState - bot.setControlState = patchedSetControlState - } + if (!bot.entity.canFly) return if (newState) { startFlying(sendAbilities) @@ -858,7 +748,6 @@ const toggleFly = (newState = !isFlying(), sendAbilities?: boolean) => { } gameAdditionalState.isFlying = isFlying() } -// #endregion const selectItem = async () => { const block = bot.blockAtCursor(5) diff --git a/src/localServerMultiplayer.ts b/src/localServerMultiplayer.ts index de49ffd6..bbbf0db6 100644 --- a/src/localServerMultiplayer.ts +++ b/src/localServerMultiplayer.ts @@ -1,5 +1,5 @@ import { Duplex } from 'stream' -import Peer, { DataConnection } from 'peerjs' +import { Peer, DataConnection } from 'peerjs' import Client from 'minecraft-protocol/src/client' import { resolveTimeout } from './utils' import { setLoadingScreenStatus } from './appStatus' diff --git a/src/mineflayer/playerState.ts b/src/mineflayer/playerState.ts index 964e3d1b..e88933b9 100644 --- a/src/mineflayer/playerState.ts +++ b/src/mineflayer/playerState.ts @@ -77,9 +77,9 @@ export class PlayerStateManager implements IPlayerState { // #region Movement and Physics State private updateState () { - if (!bot.player?.entity || this.disableStateUpdates) return + if (!bot?.entity || this.disableStateUpdates) return - const { velocity } = bot.player.entity + const { velocity } = bot.entity const isOnGround = bot.entity.onGround const VELOCITY_THRESHOLD = 0.01 const SPRINTING_VELOCITY = 0.15 @@ -138,7 +138,7 @@ export class PlayerStateManager implements IPlayerState { } getPosition (): Vec3 { - return bot.player?.entity.position ?? new Vec3(0, 0, 0) + return bot.entity?.position ?? new Vec3(0, 0, 0) } // #endregion diff --git a/src/mineflayer/plugins/mouse.ts b/src/mineflayer/plugins/mouse.ts index 219a8be8..4e82b770 100644 --- a/src/mineflayer/plugins/mouse.ts +++ b/src/mineflayer/plugins/mouse.ts @@ -11,20 +11,32 @@ import { sendVideoInteraction, videoCursorInteraction } from '../../customChanne function cursorBlockDisplay (bot: Bot) { const updateCursorBlock = (data?: { block: Block }) => { if (!data?.block) { - getThreeJsRendererMethods()?.setHighlightCursorBlock(null) + playerState.reactive.lookingAtBlock = undefined return } const { block } = data - getThreeJsRendererMethods()?.setHighlightCursorBlock(block.position, bot.mouse.getBlockCursorShapes(block).map(shape => { - return bot.mouse.getDataFromShape(shape) - })) + playerState.reactive.lookingAtBlock = { + x: block.position.x, + y: block.position.y, + z: block.position.z, + shapes: bot.mouse.getBlockCursorShapes(block).map(shape => { + return bot.mouse.getDataFromShape(shape) + }) + } } bot.on('highlightCursorBlock', updateCursorBlock) bot.on('blockBreakProgressStage', (block, stage) => { - getThreeJsRendererMethods()?.updateBreakAnimation(block, stage) + const mergedShape = bot.mouse.getMergedCursorShape(block) + playerState.reactive.diggingBlock = stage === null ? undefined : { + x: block.position.x, + y: block.position.y, + z: block.position.z, + stage, + mergedShape: mergedShape ? bot.mouse.getDataFromShape(mergedShape) : undefined + } }) } diff --git a/src/react/DebugOverlay.tsx b/src/react/DebugOverlay.tsx index 1aff4a0e..af0d6675 100644 --- a/src/react/DebugOverlay.tsx +++ b/src/react/DebugOverlay.tsx @@ -34,6 +34,7 @@ export default () => { const [blockL, setBlockL] = useState(0) const [biomeId, setBiomeId] = useState(0) const [day, setDay] = useState(0) + const [timeOfDay, setTimeOfDay] = useState(0) const [dimension, setDimension] = useState('') const [cursorBlock, setCursorBlock] = useState(null) const [blockInfo, setBlockInfo] = useState<{ customBlockName?: string, modelInfo?: BlockStateModelInfo } | null>(null) @@ -132,6 +133,7 @@ export default () => { setBiomeId(bot.world.getBiome(bot.entity.position)) setDimension(bot.game.dimension) setDay(bot.time.day) + setTimeOfDay(bot.time.timeOfDay) setCursorBlock(bot.mouse.getCursorState().cursorBlock) }, 100) @@ -185,7 +187,7 @@ export default () => {

Light: {blockL} ({skyL} sky)

Biome: minecraft:{loadedData.biomesArray[biomeId]?.name ?? 'unknown biome'}

-

Day: {day}

+

Day: {day} Time: {timeOfDay}

{Object.entries(appViewer.backend?.getDebugOverlay?.().left ?? {}).map(([name, value]) =>

{name}: {value}

)}
diff --git a/src/react/KeybindingsScreen.tsx b/src/react/KeybindingsScreen.tsx index 79d9e186..e56b0189 100644 --- a/src/react/KeybindingsScreen.tsx +++ b/src/react/KeybindingsScreen.tsx @@ -303,10 +303,10 @@ export const ButtonWithMatchesAlert = ({ {userConfig?.[group]?.[action]?.[inputType === 'keyboard' ? 'keys' : 'gamepad']?.some(key => Object.keys(bindsMap[inputType]).includes(key) - && bindsMap[inputType][key].length > 1 - && bindsMap[inputType][key].some(prop => prop.index === index - && prop.group === group - && prop.action === action)) ? ( + && bindsMap[inputType][key].length > 1 + && bindsMap[inputType][key].some(prop => prop.index === index + && prop.group === group + && prop.action === action)) ? ( //@ts-format-ignore-region
implements let color: string if (this.isOldVersion) { color = BlockData.colors[preflatMap.blocks[`${block.type}:${block.metadata}`]?.replaceAll(/\[.*?]/g, '')] - ?? 'rgb(0, 0, 255)' + ?? 'rgb(0, 0, 255)' } else { color = this.blockData.get(block.name) ?? 'rgb(0, 255, 0)' } diff --git a/src/sounds/botSoundSystem.ts b/src/sounds/botSoundSystem.ts index 2f872015..882fd2b7 100644 --- a/src/sounds/botSoundSystem.ts +++ b/src/sounds/botSoundSystem.ts @@ -132,9 +132,9 @@ subscribeKey(miscUiState, 'gameLoaded', async () => { let lastStepSound = 0 const movementHappening = async () => { - if (!bot.player || !soundMap) return // no info yet + if (!bot.entity || !soundMap) return // no info yet const VELOCITY_THRESHOLD = 0.1 - const { x, z, y } = bot.player.entity.velocity + const { x, z, y } = bot.entity.velocity if (bot.entity.onGround && Math.abs(x) < VELOCITY_THRESHOLD && (Math.abs(z) > VELOCITY_THRESHOLD || Math.abs(y) > VELOCITY_THRESHOLD)) { // movement happening if (Date.now() - lastStepSound > 300) { diff --git a/src/watchOptions.ts b/src/watchOptions.ts index 41f78d07..9fe55289 100644 --- a/src/watchOptions.ts +++ b/src/watchOptions.ts @@ -8,8 +8,6 @@ import { reloadChunks } from './utils' import { miscUiState } from './globalState' import { isCypress } from './standaloneUtils' -globalThis.viewer ??= { world: {} } - subscribeKey(options, 'renderDistance', reloadChunks) subscribeKey(options, 'multiplayerRenderDistance', reloadChunks)