diff --git a/.eslintignore b/.eslintignore index ce8d8d374..4c431739f 100644 --- a/.eslintignore +++ b/.eslintignore @@ -3,4 +3,6 @@ rsbuild.config.ts *.module.css.d.ts *.generated.ts generated +dist public +**/*/rsbuildSharedConfig.ts diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 29b2f2d55..2208e460c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -35,10 +35,8 @@ jobs: if: failure() with: name: cypress-images - path: cypress/integration/__image_snapshots__/ - - name: print current ref - run: echo ${{ github.event.pull_request.base.ref }} - - run: node scripts/outdatedGitPackages.mjs - if: ${{ github.event.pull_request.base.ref == 'next' }} - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + path: cypress/screenshots/ + # - run: node scripts/outdatedGitPackages.mjs + # if: ${{ github.event.pull_request.base.ref == 'release' }} + # env: + # GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/merge-next.yml b/.github/workflows/merge-next.yml index 9bed1b3d7..ee02789ba 100644 --- a/.github/workflows/merge-next.yml +++ b/.github/workflows/merge-next.yml @@ -17,10 +17,11 @@ jobs: - uses: actions/checkout@v2 with: fetch-depth: 0 # Fetch all history so we can merge branches + ref: refs/pull/${{ github.event.issue.number }}/head - name: Fetch All Branches run: git fetch --all - - name: Checkout PR - run: git checkout ${{ github.event.issue.pull_request.head.ref }} + # - name: Checkout PR + # run: git checkout ${{ github.event.issue.pull_request.head.ref }} - name: Merge From Next run: git merge origin/next --strategy-option=theirs - name: Push Changes diff --git a/.github/workflows/next-deploy.yml b/.github/workflows/next-deploy.yml index f6915839b..a01e0bb8e 100644 --- a/.github/workflows/next-deploy.yml +++ b/.github/workflows/next-deploy.yml @@ -24,7 +24,10 @@ jobs: run: vercel build --token=${{ secrets.VERCEL_TOKEN }} - run: pnpm build-storybook - name: Copy playground files - run: pnpm build-playground && cp prismarine-viewer/public/index.html .vercel/output/static/playground.html && cp prismarine-viewer/public/playground.js .vercel/output/static/playground.js + run: | + mkdir -p .vercel/output/static/playground + pnpm build-playground + cp -r prismarine-viewer/dist/* .vercel/output/static/playground/ - name: Download Generated Sounds map run: node scripts/downloadSoundsMap.mjs - name: Deploy Project Artifacts to Vercel diff --git a/.github/workflows/preview.yml b/.github/workflows/preview.yml index e0f9736a0..526705e9d 100644 --- a/.github/workflows/preview.yml +++ b/.github/workflows/preview.yml @@ -35,7 +35,10 @@ jobs: run: vercel build --token=${{ secrets.VERCEL_TOKEN }} - run: pnpm build-storybook - name: Copy playground files - run: pnpm build-playground && cp prismarine-viewer/public/index.html .vercel/output/static/playground.html && cp prismarine-viewer/public/playground.js .vercel/output/static/playground.js + run: | + mkdir -p .vercel/output/static/playground + pnpm build-playground + cp -r prismarine-viewer/dist/* .vercel/output/static/playground/ - name: Download Generated Sounds map run: node scripts/downloadSoundsMap.mjs - name: Deploy Project Artifacts to Vercel @@ -48,7 +51,7 @@ jobs: allow-repeats: true message: | Deployed to Vercel Preview: ${{ steps.deploy.outputs.stdout }} - [Playground](${{ steps.deploy.outputs.stdout }}/playground.html) + [Playground](${{ steps.deploy.outputs.stdout }}/playground/) [Storybook](${{ steps.deploy.outputs.stdout }}/storybook/) # - run: git checkout next scripts/githubActions.mjs - name: Get deployment alias diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 9472118bc..fa1f02810 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -23,7 +23,10 @@ jobs: - run: vercel build --token=${{ secrets.VERCEL_TOKEN }} --prod - run: pnpm build-storybook - name: Copy playground files - run: pnpm build-playground && cp prismarine-viewer/public/index.html .vercel/output/static/playground.html && cp prismarine-viewer/public/playground.js .vercel/output/static/playground.js + run: | + mkdir -p .vercel/output/static/playground + pnpm build-playground + cp -r prismarine-viewer/dist/* .vercel/output/static/playground/ - name: Download Generated Sounds map run: node scripts/downloadSoundsMap.mjs - name: Deploy Project to Vercel diff --git a/README.MD b/README.MD index ae23b60b0..9b07bdb56 100644 --- a/README.MD +++ b/README.MD @@ -87,7 +87,7 @@ To open the console, press `F12`, or if you are on mobile, you can type `#dev` i It should be easy to build/start the project locally. See [CONTRIBUTING.MD](./CONTRIBUTING.md) for more info. Also you can look at Dockerfile for reference. -There is world renderer playground ([link](https://mcon.vercel.app/playground.html)). +There is world renderer playground ([link](https://mcon.vercel.app/playground/)). However, there are many things that can be done in online production version (like debugging actual source code). Also you can access some global variables in the console and there are a few useful examples: diff --git a/assets/playground.html b/assets/playground.html new file mode 100644 index 000000000..8c394f91e --- /dev/null +++ b/assets/playground.html @@ -0,0 +1,4 @@ + + diff --git a/cypress.config.ts b/cypress.config.ts index f9bd94783..861931e39 100644 --- a/cypress.config.ts +++ b/cypress.config.ts @@ -3,6 +3,7 @@ import { defineConfig } from 'cypress' export default defineConfig({ video: false, chromeWebSecurity: false, + screenshotOnRunFailure: true, // Enable screenshots on test failures e2e: { // We've imported your old cypress plugins here. // You may want to clean this up later by importing these. diff --git a/cypress/e2e/index.spec.ts b/cypress/e2e/index.spec.ts index cb1b68807..fc67ad218 100644 --- a/cypress/e2e/index.spec.ts +++ b/cypress/e2e/index.spec.ts @@ -49,7 +49,7 @@ it('Joins to local flying-squid server', () => { testWorldLoad() }) -it('Joins to local latest Java vanilla server', () => { +it.skip('Joins to local latest Java vanilla server', () => { const version = supportedVersions.at(-1)! cy.task('startServer', [version, 25_590]).then(() => { visit('/?ip=localhost:25590&username=bot') diff --git a/package.json b/package.json index c0ac0cc1a..4b41660a6 100644 --- a/package.json +++ b/package.json @@ -6,9 +6,8 @@ "dev-rsbuild": "rsbuild dev", "dev-proxy": "node server.js", "start": "run-p dev-rsbuild dev-proxy watch-mesher", - "start-watch-script": "nodemon -w rsbuild.config.ts --watch", - "build": "rsbuild build", - "build-analyze": "BUNDLE_ANALYZE=true rsbuild build", + "build": "pnpm build-other-workers && rsbuild build", + "build-analyze": "BUNDLE_ANALYZE=true rsbuild build && pnpm build-other-workers", "check-build": "tsx scripts/genShims.ts && tsc && pnpm build", "test:cypress": "cypress run", "test-unit": "vitest", @@ -20,13 +19,13 @@ "build-storybook": "storybook build && node scripts/build.js moveStorybookFiles", "start-experiments": "vite --config experiments/vite.config.ts --host", "watch-other-workers": "echo NOT IMPLEMENTED", + "build-other-workers": "echo NOT IMPLEMENTED", "build-mesher": "node prismarine-viewer/buildMesherWorker.mjs", "watch-mesher": "pnpm build-mesher -w", - "run-playground": "run-p watch-mesher watch-other-workers playground-server watch-playground", + "run-playground": "run-p watch-mesher watch-other-workers watch-playground", "run-all": "run-p start run-playground", - "playground-server": "live-server --port=9090 prismarine-viewer/public", - "build-playground": "node prismarine-viewer/esbuild.mjs", - "watch-playground": "node prismarine-viewer/esbuild.mjs -w" + "build-playground": "rsbuild build --config prismarine-viewer/rsbuild.config.ts", + "watch-playground": "rsbuild dev --config prismarine-viewer/rsbuild.config.ts" }, "keywords": [ "prismarine", diff --git a/prismarine-viewer/buildMesherWorker.mjs b/prismarine-viewer/buildMesherWorker.mjs index f70b81288..03b952b4f 100644 --- a/prismarine-viewer/buildMesherWorker.mjs +++ b/prismarine-viewer/buildMesherWorker.mjs @@ -30,7 +30,7 @@ const buildOptions = { sourcemap: 'linked', write: false, metafile: true, - outdir: path.join(__dirname, './public'), + outdir: path.join(__dirname, './dist'), define: { 'process.env.BROWSER': '"true"', }, @@ -108,9 +108,9 @@ const buildOptions = { }) build.onEnd(({ metafile, outputFiles }) => { if (!metafile) return - fs.mkdirSync(path.join(__dirname, './public'), { recursive: true }) - fs.writeFileSync(path.join(__dirname, './public/metafile.json'), JSON.stringify(metafile)) - for (const outDir of ['../dist/', './public/']) { + fs.mkdirSync(path.join(__dirname, './dist'), { recursive: true }) + fs.writeFileSync(path.join(__dirname, './dist/metafile.json'), JSON.stringify(metafile)) + for (const outDir of ['../dist/', './dist/']) { for (const outputFile of outputFiles) { if (outDir === '../dist/' && outputFile.path.endsWith('.map')) { // skip writing & browser loading sourcemap there, worker debugging should be done in playground diff --git a/prismarine-viewer/esbuild.mjs b/prismarine-viewer/esbuild.mjs deleted file mode 100644 index e410c8b61..000000000 --- a/prismarine-viewer/esbuild.mjs +++ /dev/null @@ -1,96 +0,0 @@ -//@ts-check -import * as fs from 'fs' -import fsExtra from 'fs-extra' - -import * as esbuild from 'esbuild' -import { polyfillNode } from 'esbuild-plugin-polyfill-node' -import path, { dirname, join } from 'path' -import { fileURLToPath } from 'url' -import childProcess from 'child_process' -import supportedVersions from '../src/supportedVersions.mjs' - -const dev = process.argv.includes('-w') - -const __dirname = path.dirname(fileURLToPath(new URL(import.meta.url))) - -const mcDataPath = join(__dirname, '../generated/minecraft-data-optimized.json') -if (!fs.existsSync(mcDataPath)) { - childProcess.execSync('tsx ../scripts/makeOptimizedMcData.mjs', { stdio: 'inherit', cwd: __dirname }) -} - -fs.copyFileSync(join(__dirname, 'playground.html'), join(__dirname, 'public/index.html')) - -/** @type {import('esbuild').BuildOptions} */ -const buildOptions = { - bundle: true, - entryPoints: [join(__dirname, './examples/playground.ts')], - // target: ['es2020'], - // logLevel: 'debug', - logLevel: 'info', - platform: 'browser', - sourcemap: dev ? 'inline' : false, - minify: !dev, - outfile: join(__dirname, 'public/playground.js'), - mainFields: [ - 'browser', 'module', 'main' - ], - keepNames: true, - banner: { - js: `globalThis.global = globalThis;globalThis.includedVersions = ${JSON.stringify(supportedVersions)};`, - }, - alias: { - events: 'events', - buffer: 'buffer', - 'fs': 'browserfs/dist/shims/fs.js', - http: 'http-browserify', - stream: 'stream-browserify', - net: 'net-browserify', - // 'mc-assets': '/Users/vitaly/Documents/mc-assets', - }, - inject: [], - metafile: true, - loader: { - '.png': 'dataurl', - '.obj': 'text', - }, - plugins: [ - { - name: 'minecraft-data', - setup(build) { - build.onLoad({ - filter: /minecraft-data[\/\\]data.js$/, - }, () => { - const defaultVersionsObj = {} - return { - contents: fs.readFileSync(join(__dirname, '../src/shims/minecraftData.ts'), 'utf8'), - loader: 'ts', - resolveDir: join(__dirname, '../src/shims'), - } - }) - build.onEnd((e) => { - if (e.errors.length) return - fs.writeFileSync(join(__dirname, './public/metafile.json'), JSON.stringify(e.metafile), 'utf8') - }) - } - }, - polyfillNode({ - polyfills: { - fs: false, - crypto: false, - events: false, - http: false, - stream: false, - buffer: false, - perf_hooks: false, - net: false, - }, - }) - ], -} -if (dev) { - (await esbuild.context(buildOptions)).watch() -} else { - await esbuild.build(buildOptions) -} - -// await ctx.rebuild() diff --git a/prismarine-viewer/playground.html b/prismarine-viewer/playground.html index f1b360157..c8ea00d2f 100644 --- a/prismarine-viewer/playground.html +++ b/prismarine-viewer/playground.html @@ -29,8 +29,14 @@ src: url(../../../assets/mojangles.ttf); } + - +
diff --git a/prismarine-viewer/rsbuild.config.ts b/prismarine-viewer/rsbuild.config.ts new file mode 100644 index 000000000..cea001db6 --- /dev/null +++ b/prismarine-viewer/rsbuild.config.ts @@ -0,0 +1,40 @@ +import { defineConfig, mergeRsbuildConfig } from '@rsbuild/core'; +import supportedVersions from '../src/supportedVersions.mjs' +import childProcess from 'child_process' +import path, { dirname, join } from 'path' +import { pluginReact } from '@rsbuild/plugin-react'; +import { pluginNodePolyfill } from '@rsbuild/plugin-node-polyfill'; +import fs from 'fs' +import { appAndRendererSharedConfig, rspackViewerConfig } from './rsbuildSharedConfig'; + +const mcDataPath = join(__dirname, '../generated/minecraft-data-optimized.json') + +if (!fs.existsSync(mcDataPath)) { + childProcess.execSync('tsx ./scripts/makeOptimizedMcData.mjs', { stdio: 'inherit', cwd: path.join(__dirname, '..') }) +} + +export default mergeRsbuildConfig( + appAndRendererSharedConfig(), + defineConfig({ + html: { + template: join(__dirname, './playground.html'), + }, + output: { + cleanDistPath: false, + distPath: { + root: join(__dirname, './dist'), + }, + }, + server: { + port: 9090, + }, + source: { + entry: { + index: join(__dirname, './examples/playground.ts') + }, + define: { + 'globalThis.includedVersions': JSON.stringify(supportedVersions), + }, + }, + }) +) diff --git a/prismarine-viewer/rsbuildSharedConfig.ts b/prismarine-viewer/rsbuildSharedConfig.ts new file mode 100644 index 000000000..0c248f6c5 --- /dev/null +++ b/prismarine-viewer/rsbuildSharedConfig.ts @@ -0,0 +1,101 @@ +import { defineConfig, ModifyRspackConfigUtils } from '@rsbuild/core'; +import { pluginNodePolyfill } from '@rsbuild/plugin-node-polyfill'; +import { pluginReact } from '@rsbuild/plugin-react'; +import path from 'path' + +export const appAndRendererSharedConfig = () => defineConfig({ + dev: { + progressBar: true, + writeToDisk: true, + watchFiles: { + paths: [ + path.join(__dirname, './dist/webgpuRendererWorker.js'), + path.join(__dirname, './dist/mesher.js'), + ] + }, + }, + output: { + polyfill: 'usage', + // 50kb limit for data uri + dataUriLimit: 50 * 1024, + assetPrefix: './', + }, + source: { + alias: { + fs: path.join(__dirname, `../src/shims/fs.js`), + http: 'http-browserify', + stream: 'stream-browserify', + net: 'net-browserify', + 'minecraft-protocol$': 'minecraft-protocol/src/index.js', + 'buffer$': 'buffer', + // avoid bundling, not used on client side + 'prismarine-auth': path.join(__dirname, `../src/shims/prismarineAuthReplacement.ts`), + perf_hooks: path.join(__dirname, `../src/shims/perf_hooks_replacement.js`), + crypto: path.join(__dirname, `../src/shims/crypto.js`), + dns: path.join(__dirname, `../src/shims/dns.js`), + yggdrasil: path.join(__dirname, `../src/shims/yggdrasilReplacement.ts`), + 'three$': 'three/src/Three.js', + 'stats.js$': 'stats.js/src/Stats.js', + }, + define: { + 'process.platform': '"browser"', + }, + decorators: { + version: 'legacy', // default is a lie + }, + }, + server: { + htmlFallback: false, + publicDir: false, + headers: { + // enable shared array buffer + 'Cross-Origin-Opener-Policy': 'same-origin', + 'Cross-Origin-Embedder-Policy': 'require-corp', + }, + open: process.env.OPEN_BROWSER === 'true', + }, + plugins: [ + pluginReact(), + pluginNodePolyfill() + ], + tools: { + rspack (config, helpers) { + rspackViewerConfig(config, helpers) + } + }, +}) + +export const rspackViewerConfig = (config, { appendPlugins, addRules, rspack }: ModifyRspackConfigUtils) => { + appendPlugins(new rspack.NormalModuleReplacementPlugin(/data/, (resource) => { + let absolute: string + const request = resource.request.replaceAll('\\', '/') + absolute = path.join(resource.context, request).replaceAll('\\', '/') + if (request.includes('minecraft-data/data/pc/1.')) { + console.log('Error: incompatible resource', request, resource.contextInfo.issuer) + process.exit(1) + // throw new Error(`${resource.request} was requested by ${resource.contextInfo.issuer}`) + } + if (absolute.endsWith('/minecraft-data/data.js')) { + resource.request = path.join(__dirname, `../src/shims/minecraftData.ts`) + } + })) + addRules([ + { + test: /\.obj$/, + type: 'asset/source', + }, + { + test: /\.wgsl$/, + type: 'asset/source', + }, + { + test: /\.mp3$/, + type: 'asset/source', + } + ]) + config.ignoreWarnings = [ + /the request of a dependency is an expression/, + /Unsupported pseudo class or element: xr-overlay/ + ] + +} diff --git a/prismarine-viewer/viewer/lib/entities.ts b/prismarine-viewer/viewer/lib/entities.ts index 281a442e5..ee659263a 100644 --- a/prismarine-viewer/viewer/lib/entities.ts +++ b/prismarine-viewer/viewer/lib/entities.ts @@ -340,9 +340,8 @@ export class Entities extends EventEmitter { } update (entity: import('prismarine-entity').Entity & { delete?; pos }, overrides) { - let isPlayerModel = entity.name === 'player' + const isPlayerModel = entity.name === 'player' if (entity.name === 'zombie' || entity.name === 'zombie_villager' || entity.name === 'husk') { - isPlayerModel = true overrides.texture = `textures/1.16.4/entity/${entity.name === 'zombie_villager' ? 'zombie_villager/zombie_villager.png' : `zombie/${entity.name}.png`}` } if (!this.entities[entity.id] && !entity.delete) { diff --git a/prismarine-viewer/viewer/lib/entity/EntityMesh.js b/prismarine-viewer/viewer/lib/entity/EntityMesh.js index 39b2d62de..a518171ff 100644 --- a/prismarine-viewer/viewer/lib/entity/EntityMesh.js +++ b/prismarine-viewer/viewer/lib/entity/EntityMesh.js @@ -1,6 +1,8 @@ //@ts-check import * as THREE from 'three' import { OBJLoader } from 'three-stdlib' +import huskPng from 'mc-assets/dist/other-textures/latest/entity/zombie/husk.png' +import { Vec3 } from 'vec3' import entities from './entities.json' import { externalModels } from './objModels' import externalTexturesJson from './externalTextures.json' @@ -290,6 +292,16 @@ const getEntity = (name) => { // zombie_villager: 'zombie_villager/zombie_villager' // } +const scaleEntity = { + zombie: 1.85, + husk: 1.85 +} +const offsetEntity = { + zombie: new Vec3(0, 1, 0), + husk: new Vec3(0, 1, 0), + boat: new Vec3(0, -1, 0), +} + // eslint-disable-next-line @typescript-eslint/no-extraneous-class export class EntityMesh { constructor(version, type, scene, /** @type {{textures?, rotation?: Record}} */overrides = {}) { @@ -303,6 +315,9 @@ export class EntityMesh { if (originalType === 'zombie_horse') { texturePath = `textures/${version}/entity/horse/horse_zombie.png` } + if (originalType === 'husk') { + texturePath = huskPng + } if (originalType === 'skeleton_horse') { texturePath = `textures/${version}/entity/horse/horse_skeleton.png` } @@ -325,7 +340,10 @@ export class EntityMesh { alphaTest: 0.1 }) const obj = objLoader.parse(externalModels[type]) - if (type === 'boat') obj.position.y = -1 // todo, should not be hardcoded + const scale = scaleEntity[originalType] + if (scale) obj.scale.set(scale, scale, scale) + const offset = offsetEntity[originalType] + if (offset) obj.position.set(offset.x, offset.y, offset.z) obj.traverse((child) => { if (child instanceof THREE.Mesh) { child.material = material diff --git a/prismarine-viewer/viewer/lib/entity/exportedModels.js b/prismarine-viewer/viewer/lib/entity/exportedModels.js index b43658ec2..53d55d5eb 100644 --- a/prismarine-viewer/viewer/lib/entity/exportedModels.js +++ b/prismarine-viewer/viewer/lib/entity/exportedModels.js @@ -35,4 +35,5 @@ export { default as witch } from './models/witch.obj' export { default as wolf } from './models/wolf.obj' export { default as zombie_villager } from './models/zombie_villager.obj' export { default as zombie } from './models/zombie.obj' +export { default as husk } from './models/zombie.obj' export { default as boat } from './models/boat.obj' diff --git a/prismarine-viewer/viewer/lib/entity/models/zombie.obj b/prismarine-viewer/viewer/lib/entity/models/zombie.obj index bcd7444c9..fa5d8f4d5 100644 --- a/prismarine-viewer/viewer/lib/entity/models/zombie.obj +++ b/prismarine-viewer/viewer/lib/entity/models/zombie.obj @@ -1,325 +1,325 @@ -# Made in Blockbench 4.9.4 +# Made in Blockbench 4.10.4 mtllib materials.mtl -o Body -v 0.25 1.5 0.125 -v 0.25 1.5 -0.125 -v 0.25 0.75 0.125 -v 0.25 0.75 -0.125 -v -0.25 1.5 -0.125 -v -0.25 1.5 0.125 -v -0.25 0.75 -0.125 -v -0.25 0.75 0.125 -vt 0.3125 0.375 -vt 0.4375 0.375 -vt 0.4375 0 -vt 0.3125 0 -vt 0.25 0.375 -vt 0.3125 0.375 -vt 0.3125 0 -vt 0.25 0 -vt 0.5 0.375 -vt 0.625 0.375 -vt 0.625 0 -vt 0.5 0 -vt 0.4375 0.375 -vt 0.5 0.375 -vt 0.5 0 -vt 0.4375 0 -vt 0.4375 0.375 -vt 0.3125 0.375 -vt 0.3125 0.5 -vt 0.4375 0.5 -vt 0.5625 0.5 -vt 0.4375 0.5 -vt 0.4375 0.375 -vt 0.5625 0.375 +o /head +v 0.125 0.5 0.125 +v 0.125 0.5 -0.125 +v 0.125 0.25 0.125 +v 0.125 0.25 -0.125 +v -0.125 0.5 -0.125 +v -0.125 0.5 0.125 +v -0.125 0.25 -0.125 +v -0.125 0.25 0.125 +vt 0.125 0.875 +vt 0.25 0.875 +vt 0.25 0.75 +vt 0.125 0.75 +vt 0 0.875 +vt 0.125 0.875 +vt 0.125 0.75 +vt 0 0.75 +vt 0.375 0.875 +vt 0.5 0.875 +vt 0.5 0.75 +vt 0.375 0.75 +vt 0.25 0.875 +vt 0.375 0.875 +vt 0.375 0.75 +vt 0.25 0.75 +vt 0.25 0.875 +vt 0.125 0.875 +vt 0.125 1 +vt 0.25 1 +vt 0.25 1 +vt 0.375 1 +vt 0.375 0.875 +vt 0.25 0.875 vn 0 0 -1 vn 1 0 0 vn 0 0 1 vn -1 0 0 vn 0 1 0 vn 0 -1 0 -usemtl m_9eb5cf2e-0212-52a4-6070-8cb3b67f2e24 +usemtl none f 4/4/1 7/3/1 5/2/1 2/1/1 f 3/8/2 4/7/2 2/6/2 1/5/2 f 8/12/3 3/11/3 1/10/3 6/9/3 f 7/16/4 8/15/4 6/14/4 5/13/4 f 6/20/5 1/19/5 2/18/5 5/17/5 f 7/24/6 4/23/6 3/22/6 8/21/6 -o Head -v 0.25 2 0.25 -v 0.25 2 -0.25 -v 0.25 1.5 0.25 -v 0.25 1.5 -0.25 -v -0.25 2 -0.25 -v -0.25 2 0.25 -v -0.25 1.5 -0.25 -v -0.25 1.5 0.25 -vt 0.125 0.75 -vt 0.25 0.75 -vt 0.25 0.5 -vt 0.125 0.5 -vt 0 0.75 -vt 0.125 0.75 -vt 0.125 0.5 -vt 0 0.5 -vt 0.375 0.75 -vt 0.5 0.75 -vt 0.5 0.5 -vt 0.375 0.5 -vt 0.25 0.75 -vt 0.375 0.75 -vt 0.375 0.5 -vt 0.25 0.5 -vt 0.25 0.75 -vt 0.125 0.75 -vt 0.125 1 -vt 0.25 1 -vt 0.375 1 -vt 0.25 1 -vt 0.25 0.75 -vt 0.375 0.75 +o /right_arm +v -0.125 0.25 0.0625 +v -0.125 0.25 -0.3125 +v -0.125 0.125 0.0625 +v -0.125 0.125 -0.3125 +v -0.25 0.25 -0.3125 +v -0.25 0.25 0.0625 +v -0.25 0.125 -0.3125 +v -0.25 0.125 0.0625 +vt 0.8125 0.6875 +vt 0.75 0.6875 +vt 0.75 0.75 +vt 0.8125 0.75 +vt 0.6875 0.6875 +vt 0.6875 0.5 +vt 0.625 0.5 +vt 0.625 0.6875 +vt 0.75 0.6875 +vt 0.6875 0.6875 +vt 0.6875 0.75 +vt 0.75 0.75 +vt 0.75 0.5 +vt 0.75 0.6875 +vt 0.8125 0.6875 +vt 0.8125 0.5 +vt 0.75 0.5 +vt 0.6875 0.5 +vt 0.6875 0.6875 +vt 0.75 0.6875 +vt 0.8125 0.6875 +vt 0.875 0.6875 +vt 0.875 0.5 +vt 0.8125 0.5 vn 0 0 -1 vn 1 0 0 vn 0 0 1 vn -1 0 0 vn 0 1 0 vn 0 -1 0 -usemtl m_9eb5cf2e-0212-52a4-6070-8cb3b67f2e24 +usemtl none f 12/28/7 15/27/7 13/26/7 10/25/7 f 11/32/8 12/31/8 10/30/8 9/29/8 f 16/36/9 11/35/9 9/34/9 14/33/9 f 15/40/10 16/39/10 14/38/10 13/37/10 f 14/44/11 9/43/11 10/42/11 13/41/11 f 15/48/12 12/47/12 11/46/12 16/45/12 -o Hat Layer -v 0.28125 2.03125 0.28125 -v 0.28125 2.03125 -0.28125 -v 0.28125 1.46875 0.28125 -v 0.28125 1.46875 -0.28125 -v -0.28125 2.03125 -0.28125 -v -0.28125 2.03125 0.28125 -v -0.28125 1.46875 -0.28125 -v -0.28125 1.46875 0.28125 -vt 0.625 0.75 -vt 0.75 0.75 -vt 0.75 0.5 -vt 0.625 0.5 -vt 0.5 0.75 -vt 0.625 0.75 -vt 0.625 0.5 -vt 0.5 0.5 -vt 0.875 0.75 -vt 1 0.75 -vt 1 0.5 -vt 0.875 0.5 -vt 0.75 0.75 -vt 0.875 0.75 -vt 0.875 0.5 -vt 0.75 0.5 -vt 0.75 0.75 -vt 0.625 0.75 -vt 0.625 1 -vt 0.75 1 -vt 0.875 1 -vt 0.75 1 -vt 0.75 0.75 -vt 0.875 0.75 +o /left_leg +v 0.12187499999999996 -0.125 0.0625 +v 0.12187499999999996 -0.125 -0.0625 +v 0.12187499999999996 -0.5 0.0625 +v 0.12187499999999996 -0.5 -0.0625 +v -0.0031250000000000444 -0.125 -0.0625 +v -0.0031250000000000444 -0.125 0.0625 +v -0.0031250000000000444 -0.5 -0.0625 +v -0.0031250000000000444 -0.5 0.0625 +vt 0.0625 0.6875 +vt 0.125 0.6875 +vt 0.125 0.5 +vt 0.0625 0.5 +vt 0 0.6875 +vt 0.0625 0.6875 +vt 0.0625 0.5 +vt 0 0.5 +vt 0.1875 0.6875 +vt 0.25 0.6875 +vt 0.25 0.5 +vt 0.1875 0.5 +vt 0.125 0.6875 +vt 0.1875 0.6875 +vt 0.1875 0.5 +vt 0.125 0.5 +vt 0.125 0.6875 +vt 0.0625 0.6875 +vt 0.0625 0.75 +vt 0.125 0.75 +vt 0.125 0.75 +vt 0.1875 0.75 +vt 0.1875 0.6875 +vt 0.125 0.6875 vn 0 0 -1 vn 1 0 0 vn 0 0 1 vn -1 0 0 vn 0 1 0 vn 0 -1 0 -usemtl m_9eb5cf2e-0212-52a4-6070-8cb3b67f2e24 +usemtl none f 20/52/13 23/51/13 21/50/13 18/49/13 f 19/56/14 20/55/14 18/54/14 17/53/14 f 24/60/15 19/59/15 17/58/15 22/57/15 f 23/64/16 24/63/16 22/62/16 21/61/16 f 22/68/17 17/67/17 18/66/17 21/65/17 f 23/72/18 20/71/18 19/70/18 24/69/18 -o RightArm -v 0.5 1.5 0.125 -v 0.5 1.5 -0.125 -v 0.5 0.75 0.125 -v 0.5 0.75 -0.125 -v 0.25 1.5 -0.125 -v 0.25 1.5 0.125 -v 0.25 0.75 -0.125 -v 0.25 0.75 0.125 -vt 0.6875 0.375 -vt 0.75 0.375 -vt 0.75 0 -vt 0.6875 0 -vt 0.625 0.375 -vt 0.6875 0.375 -vt 0.6875 0 -vt 0.625 0 -vt 0.8125 0.375 -vt 0.875 0.375 -vt 0.875 0 -vt 0.8125 0 -vt 0.75 0.375 -vt 0.8125 0.375 -vt 0.8125 0 -vt 0.75 0 -vt 0.75 0.375 -vt 0.6875 0.375 +o /left_arm +v 0.25 0.25 0.0625 +v 0.25 0.25 -0.3125 +v 0.25 0.125 0.0625 +v 0.25 0.125 -0.3125 +v 0.125 0.25 -0.3125 +v 0.125 0.25 0.0625 +v 0.125 0.125 -0.3125 +v 0.125 0.125 0.0625 +vt 0.8125 0.6875 +vt 0.75 0.6875 +vt 0.75 0.75 +vt 0.8125 0.75 +vt 0.6875 0.6875 vt 0.6875 0.5 +vt 0.625 0.5 +vt 0.625 0.6875 +vt 0.75 0.6875 +vt 0.6875 0.6875 +vt 0.6875 0.75 +vt 0.75 0.75 vt 0.75 0.5 +vt 0.75 0.6875 +vt 0.8125 0.6875 vt 0.8125 0.5 vt 0.75 0.5 -vt 0.75 0.375 -vt 0.8125 0.375 +vt 0.6875 0.5 +vt 0.6875 0.6875 +vt 0.75 0.6875 +vt 0.8125 0.6875 +vt 0.875 0.6875 +vt 0.875 0.5 +vt 0.8125 0.5 vn 0 0 -1 vn 1 0 0 vn 0 0 1 vn -1 0 0 vn 0 1 0 vn 0 -1 0 -usemtl m_9eb5cf2e-0212-52a4-6070-8cb3b67f2e24 +usemtl none f 28/76/19 31/75/19 29/74/19 26/73/19 f 27/80/20 28/79/20 26/78/20 25/77/20 f 32/84/21 27/83/21 25/82/21 30/81/21 f 31/88/22 32/87/22 30/86/22 29/85/22 f 30/92/23 25/91/23 26/90/23 29/89/23 f 31/96/24 28/95/24 27/94/24 32/93/24 -o LeftArm -v -0.25 1.5 0.125 -v -0.25 1.5 -0.125 -v -0.25 0.75 0.125 -v -0.25 0.75 -0.125 -v -0.5 1.5 -0.125 -v -0.5 1.5 0.125 -v -0.5 0.75 -0.125 -v -0.5 0.75 0.125 -vt 0.75 0.375 -vt 0.6875 0.375 -vt 0.6875 0 -vt 0.75 0 -vt 0.8125 0.375 -vt 0.75 0.375 -vt 0.75 0 -vt 0.8125 0 -vt 0.875 0.375 -vt 0.8125 0.375 -vt 0.8125 0 -vt 0.875 0 -vt 0.6875 0.375 -vt 0.625 0.375 -vt 0.625 0 -vt 0.6875 0 -vt 0.6875 0.375 -vt 0.75 0.375 -vt 0.75 0.5 -vt 0.6875 0.5 -vt 0.75 0.5 -vt 0.8125 0.5 -vt 0.8125 0.375 -vt 0.75 0.375 +o /right_leg +v 0.0031250000000000444 -0.125 0.0625 +v 0.0031250000000000444 -0.125 -0.0625 +v 0.0031250000000000444 -0.5 0.0625 +v 0.0031250000000000444 -0.5 -0.0625 +v -0.12187499999999996 -0.125 -0.0625 +v -0.12187499999999996 -0.125 0.0625 +v -0.12187499999999996 -0.5 -0.0625 +v -0.12187499999999996 -0.5 0.0625 +vt 0.0625 0.6875 +vt 0.125 0.6875 +vt 0.125 0.5 +vt 0.0625 0.5 +vt 0 0.6875 +vt 0.0625 0.6875 +vt 0.0625 0.5 +vt 0 0.5 +vt 0.1875 0.6875 +vt 0.25 0.6875 +vt 0.25 0.5 +vt 0.1875 0.5 +vt 0.125 0.6875 +vt 0.1875 0.6875 +vt 0.1875 0.5 +vt 0.125 0.5 +vt 0.125 0.6875 +vt 0.0625 0.6875 +vt 0.0625 0.75 +vt 0.125 0.75 +vt 0.125 0.75 +vt 0.1875 0.75 +vt 0.1875 0.6875 +vt 0.125 0.6875 vn 0 0 -1 vn 1 0 0 vn 0 0 1 vn -1 0 0 vn 0 1 0 vn 0 -1 0 -usemtl m_9eb5cf2e-0212-52a4-6070-8cb3b67f2e24 +usemtl none f 36/100/25 39/99/25 37/98/25 34/97/25 f 35/104/26 36/103/26 34/102/26 33/101/26 f 40/108/27 35/107/27 33/106/27 38/105/27 f 39/112/28 40/111/28 38/110/28 37/109/28 f 38/116/29 33/115/29 34/114/29 37/113/29 f 39/120/30 36/119/30 35/118/30 40/117/30 -o RightLeg -v 0.24375000000000002 0.75 0.125 -v 0.24375000000000002 0.75 -0.125 -v 0.24375000000000002 0 0.125 -v 0.24375000000000002 0 -0.125 -v -0.006249999999999978 0.75 -0.125 -v -0.006249999999999978 0.75 0.125 -v -0.006249999999999978 0 -0.125 -v -0.006249999999999978 0 0.125 -vt 0.0625 0.375 -vt 0.125 0.375 -vt 0.125 0 -vt 0.0625 0 -vt 0 0.375 -vt 0.0625 0.375 -vt 0.0625 0 -vt 0 0 -vt 0.1875 0.375 -vt 0.25 0.375 -vt 0.25 0 -vt 0.1875 0 -vt 0.125 0.375 -vt 0.1875 0.375 -vt 0.1875 0 -vt 0.125 0 -vt 0.125 0.375 -vt 0.0625 0.375 -vt 0.0625 0.5 -vt 0.125 0.5 -vt 0.1875 0.5 -vt 0.125 0.5 -vt 0.125 0.375 -vt 0.1875 0.375 +o /hat +v 0.140625 0.515625 0.140625 +v 0.140625 0.515625 -0.140625 +v 0.140625 0.234375 0.140625 +v 0.140625 0.234375 -0.140625 +v -0.140625 0.515625 -0.140625 +v -0.140625 0.515625 0.140625 +v -0.140625 0.234375 -0.140625 +v -0.140625 0.234375 0.140625 +vt 0.625 0.875 +vt 0.75 0.875 +vt 0.75 0.75 +vt 0.625 0.75 +vt 0.5 0.875 +vt 0.625 0.875 +vt 0.625 0.75 +vt 0.5 0.75 +vt 0.875 0.875 +vt 1 0.875 +vt 1 0.75 +vt 0.875 0.75 +vt 0.75 0.875 +vt 0.875 0.875 +vt 0.875 0.75 +vt 0.75 0.75 +vt 0.75 0.875 +vt 0.625 0.875 +vt 0.625 1 +vt 0.75 1 +vt 0.75 1 +vt 0.875 1 +vt 0.875 0.875 +vt 0.75 0.875 vn 0 0 -1 vn 1 0 0 vn 0 0 1 vn -1 0 0 vn 0 1 0 vn 0 -1 0 -usemtl m_9eb5cf2e-0212-52a4-6070-8cb3b67f2e24 +usemtl none f 44/124/31 47/123/31 45/122/31 42/121/31 f 43/128/32 44/127/32 42/126/32 41/125/32 f 48/132/33 43/131/33 41/130/33 46/129/33 f 47/136/34 48/135/34 46/134/34 45/133/34 f 46/140/35 41/139/35 42/138/35 45/137/35 f 47/144/36 44/143/36 43/142/36 48/141/36 -o LeftLeg -v 0.006249999999999978 0.75 0.125 -v 0.006249999999999978 0.75 -0.125 -v 0.006249999999999978 0 0.125 -v 0.006249999999999978 0 -0.125 -v -0.24375000000000002 0.75 -0.125 -v -0.24375000000000002 0.75 0.125 -v -0.24375000000000002 0 -0.125 -v -0.24375000000000002 0 0.125 -vt 0.125 0.375 -vt 0.0625 0.375 -vt 0.0625 0 -vt 0.125 0 -vt 0.1875 0.375 -vt 0.125 0.375 -vt 0.125 0 -vt 0.1875 0 -vt 0.25 0.375 -vt 0.1875 0.375 -vt 0.1875 0 -vt 0.25 0 -vt 0.0625 0.375 -vt 0 0.375 -vt 0 0 -vt 0.0625 0 -vt 0.0625 0.375 -vt 0.125 0.375 -vt 0.125 0.5 -vt 0.0625 0.5 -vt 0.125 0.5 -vt 0.1875 0.5 -vt 0.1875 0.375 -vt 0.125 0.375 +o /body +v 0.125 0.25 0.0625 +v 0.125 0.25 -0.0625 +v 0.125 -0.125 0.0625 +v 0.125 -0.125 -0.0625 +v -0.125 0.25 -0.0625 +v -0.125 0.25 0.0625 +v -0.125 -0.125 -0.0625 +v -0.125 -0.125 0.0625 +vt 0.3125 0.6875 +vt 0.4375 0.6875 +vt 0.4375 0.5 +vt 0.3125 0.5 +vt 0.25 0.6875 +vt 0.3125 0.6875 +vt 0.3125 0.5 +vt 0.25 0.5 +vt 0.5 0.6875 +vt 0.625 0.6875 +vt 0.625 0.5 +vt 0.5 0.5 +vt 0.4375 0.6875 +vt 0.5 0.6875 +vt 0.5 0.5 +vt 0.4375 0.5 +vt 0.4375 0.6875 +vt 0.3125 0.6875 +vt 0.3125 0.75 +vt 0.4375 0.75 +vt 0.4375 0.75 +vt 0.5625 0.75 +vt 0.5625 0.6875 +vt 0.4375 0.6875 vn 0 0 -1 vn 1 0 0 vn 0 0 1 vn -1 0 0 vn 0 1 0 vn 0 -1 0 -usemtl m_9eb5cf2e-0212-52a4-6070-8cb3b67f2e24 +usemtl none f 52/148/37 55/147/37 53/146/37 50/145/37 f 51/152/38 52/151/38 50/150/38 49/149/38 f 56/156/39 51/155/39 49/154/39 54/153/39 f 55/160/40 56/159/40 54/158/40 53/157/40 f 54/164/41 49/163/41 50/162/41 53/161/41 -f 55/168/42 52/167/42 51/166/42 56/165/42 \ No newline at end of file +f 55/168/42 52/167/42 51/166/42 56/165/42 diff --git a/rsbuild.config.ts b/rsbuild.config.ts index 588cc35d0..88280acfa 100644 --- a/rsbuild.config.ts +++ b/rsbuild.config.ts @@ -1,4 +1,4 @@ -import { defineConfig, RsbuildPluginAPI } from '@rsbuild/core' +import { defineConfig, mergeRsbuildConfig, RsbuildPluginAPI } from '@rsbuild/core' import { pluginReact } from '@rsbuild/plugin-react' import { pluginTypedCSSModules } from '@rsbuild/plugin-typed-css-modules' import { pluginNodePolyfill } from '@rsbuild/plugin-node-polyfill' @@ -10,6 +10,7 @@ import fsExtra from 'fs-extra' import { promisify } from 'util' import { generateSW } from 'workbox-build' import { getSwAdditionalEntries } from './scripts/build' +import { appAndRendererSharedConfig } from './prismarine-viewer/rsbuildSharedConfig' //@ts-ignore try { require('./localSettings.js') } catch { } @@ -20,16 +21,12 @@ const buildingVersion = new Date().toISOString().split(':')[0] const dev = process.env.NODE_ENV === 'development' -export default defineConfig({ - dev: { - progressBar: true, - writeToDisk: true - }, +// base options are in ./prismarine-viewer/rsbuildSharedConfig.ts +const appConfig = defineConfig({ html: { template: './index.html', }, output: { - polyfill: 'usage', externals: [ 'sharp' ], @@ -37,25 +34,8 @@ export default defineConfig({ js: 'source-map', css: true, }, - // 50kb limit for data uri - dataUriLimit: 50 * 1024 }, source: { - alias: { - fs: './src/shims/fs.js', - http: 'http-browserify', - stream: 'stream-browserify', - net: 'net-browserify', - 'minecraft-protocol$': 'minecraft-protocol/src/index.js', - 'buffer$': 'buffer', - // avoid bundling, not used on client side - 'prismarine-auth': './src/shims/prismarineAuthReplacement.ts', - perf_hooks: './src/shims/perf_hooks_replacement.js', - crypto: './src/shims/crypto.js', - dns: './src/shims/dns.js', - yggdrasil: './src/shims/yggdrasilReplacement.ts', - 'three$': 'three/src/Three.js' - }, entry: { index: './src/index.ts', }, @@ -65,36 +45,22 @@ export default defineConfig({ define: { 'process.env.BUILD_VERSION': JSON.stringify(!dev ? buildingVersion : 'undefined'), 'process.env.MAIN_MENU_LINKS': JSON.stringify(process.env.MAIN_MENU_LINKS), - 'process.platform': '"browser"', 'process.env.GITHUB_URL': JSON.stringify(`https://github.com/${process.env.GITHUB_REPOSITORY || `${process.env.VERCEL_GIT_REPO_OWNER}/${process.env.VERCEL_GIT_REPO_SLUG}`}`), 'process.env.DEPS_VERSIONS': JSON.stringify({}) }, - decorators: { - version: 'legacy', // default is a lie - }, }, server: { // strictPort: true, - htmlFallback: false, - publicDir: false, // publicDir: { // name: 'assets', // }, - headers: { - // enable shared array buffer - 'Cross-Origin-Opener-Policy': 'same-origin', - 'Cross-Origin-Embedder-Policy': 'require-corp', - }, - open: process.env.OPEN_BROWSER === 'true', proxy: { '/api': 'http://localhost:8080', }, }, plugins: [ - pluginReact(), pluginTypedCSSModules(), - pluginNodePolyfill(), { name: 'test', setup (build: RsbuildPluginAPI) { @@ -111,6 +77,7 @@ export default defineConfig({ fsExtra.copySync('./node_modules/mc-assets/dist/other-textures/latest/entity', './dist/textures/entity') fsExtra.copySync('./assets/background', './dist/background') fs.copyFileSync('./assets/favicon.png', './dist/favicon.png') + fs.copyFileSync('./assets/playground.html', './dist/playground.html') fs.copyFileSync('./assets/manifest.json', './dist/manifest.json') fs.copyFileSync('./assets/loading-bg.jpg', './dist/loading-bg.jpg') const configJson = JSON.parse(fs.readFileSync('./config.json', 'utf8')) @@ -121,9 +88,9 @@ export default defineConfig({ // childProcess.execSync('./scripts/prepareSounds.mjs', { stdio: 'inherit' }) // childProcess.execSync('tsx ./scripts/genMcDataTypes.ts', { stdio: 'inherit' }) // childProcess.execSync('tsx ./scripts/genPixelartTypes.ts', { stdio: 'inherit' }) - if (fs.existsSync('./prismarine-viewer/public/mesher.js') && dev) { + if (fs.existsSync('./prismarine-viewer/dist/mesher.js') && dev) { // copy mesher - fs.copyFileSync('./prismarine-viewer/public/mesher.js', './dist/mesher.js') + fs.copyFileSync('./prismarine-viewer/dist/mesher.js', './dist/mesher.js') } else if (!dev) { await execAsync('pnpm run build-mesher') } @@ -150,39 +117,6 @@ export default defineConfig({ }, }, ], - tools: { - bundlerChain (chain, { CHAIN_ID }) { - }, - rspack (config, { addRules, appendPlugins, rspack }) { - appendPlugins(new rspack.NormalModuleReplacementPlugin(/data/, (resource) => { - let absolute: string - const request = resource.request.replaceAll('\\', '/') - absolute = path.join(resource.context, request).replaceAll('\\', '/') - if (request.includes('minecraft-data/data/pc/1.')) { - console.log('Error: incompatible resource', request, resource.contextInfo.issuer) - process.exit(1) - // throw new Error(`${resource.request} was requested by ${resource.contextInfo.issuer}`) - } - if (absolute.endsWith('/minecraft-data/data.js')) { - resource.request = path.join(__dirname, './src/shims/minecraftData.ts') - } - })) - addRules([ - { - test: /\.obj$/, - type: 'asset/source', - }, - { - test: /\.mp3$/, - type: 'asset/source', - } - ]) - config.ignoreWarnings = [ - /the request of a dependency is an expression/, - /Unsupported pseudo class or element: xr-overlay/ - ] - } - }, // performance: { // bundleAnalyze: { // analyzerMode: 'json', @@ -190,3 +124,8 @@ export default defineConfig({ // }, // }, }) + +export default mergeRsbuildConfig( + appAndRendererSharedConfig(), + appConfig +) diff --git a/src/controls.ts b/src/controls.ts index 39e4c8c74..d882e9673 100644 --- a/src/controls.ts +++ b/src/controls.ts @@ -291,6 +291,27 @@ const alwaysPressedHandledCommand = (command: Command) => { hideCurrentModal() } } + if (command === 'advanced.lockUrl') { + lockUrl() + } +} + +function lockUrl () { + let newQs = '' + if (fsState.saveLoaded) { + const save = localServer!.options.worldFolder.split('/').at(-1) + newQs = `loadSave=${save}` + } else if (process.env.NODE_ENV === 'development') { + newQs = `reconnect=1` + } else { + const qs = new URLSearchParams() + const { server, version } = localStorage + qs.set('server', server) + if (version) qs.set('version', version) + newQs = String(qs.toString()) + } + + window.history.replaceState({}, '', `${window.location.pathname}?${newQs}`) } function cycleHotbarSlot (dir: 1 | -1) { @@ -390,24 +411,6 @@ contro.on('trigger', ({ command }) => { break } } - if (command === 'advanced.lockUrl') { - let newQs = '' - if (fsState.saveLoaded) { - const save = localServer!.options.worldFolder.split('/').at(-1) - newQs = `loadSave=${save}` - } else if (process.env.NODE_ENV === 'development') { - newQs = `reconnect=1` - } else { - const qs = new URLSearchParams() - const { server, version } = localStorage - qs.set('server', server) - if (version) qs.set('version', version) - newQs = String(qs.toString()) - } - - window.history.replaceState({}, '', `${window.location.pathname}?${newQs}`) - // return - } if (command === 'ui.pauseMenu') { showModal({ reactType: 'pause-screen' }) @@ -472,7 +475,36 @@ export const f3Keybinds = [ await completeTexturePackInstall('default', 'default') } }, - mobileTitle: 'Open Widget' + mobileTitle: 'Reload Textures' + }, + { + key: 'F4', + async action () { + switch (bot.game.gameMode) { + case 'creative': { + bot.chat('/gamemode survival') + + break + } + case 'survival': { + bot.chat('/gamemode adventure') + + break + } + case 'adventure': { + bot.chat('/gamemode spectator') + + break + } + case 'spectator': { + bot.chat('/gamemode creative') + + break + } + // No default + } + }, + mobileTitle: 'Cycle Game Mode' } ] diff --git a/src/worldInteractions.ts b/src/worldInteractions.ts index cef65b96a..dd5f0aec4 100644 --- a/src/worldInteractions.ts +++ b/src/worldInteractions.ts @@ -48,7 +48,7 @@ class WorldInteraction { breakTextures: THREE.Texture[] lastDigged: number lineMaterial: LineMaterial - debugStatus: string + debugDigStatus: string oneTimeInit () { const loader = new THREE.TextureLoader() @@ -129,11 +129,11 @@ class WorldInteraction { // TODO: If the tool and enchantments immediately exceed the hardness times 30, the block breaks with no delay; SO WE NEED TO CHECK THAT // TODO: Any blocks with a breaking time of 0.05 this.lastDigged = Date.now() - this.debugStatus = 'done' + this.debugDigStatus = 'done' }) bot.on('diggingAborted', (block) => { if (!this.cursorBlock?.position.equals(block.position)) return - this.debugStatus = 'aborted' + this.debugDigStatus = 'aborted' // if (this.lastDugBlock) this.breakStartTime = undefined if (this.buttons[0]) { @@ -326,7 +326,8 @@ class WorldInteraction { // We stopped breaking if ((!this.buttons[0] && this.lastButtons[0])) { this.lastDugBlock = null - this.debugStatus = 'cancelled' + this.breakStartTime = undefined + this.debugDigStatus = 'cancelled' } const onGround = bot.entity.onGround || bot.game.gameMode === 'creative' @@ -340,7 +341,7 @@ class WorldInteraction { && (!this.lastButtons[0] || ((cursorChanged || (this.lastDugBlock && !this.lastDugBlock.equals(cursorBlock!.position))) && Date.now() - (this.lastDigged ?? 0) > 300) || onGround !== this.prevOnGround) && onGround) { this.lastDugBlock = null - this.debugStatus = 'breaking' + this.debugDigStatus = 'breaking' this.currentDigTime = bot.digTime(cursorBlockDiggable) this.breakStartTime = performance.now() const vecArray = [new Vec3(0, -1, 0), new Vec3(0, 1, 0), new Vec3(0, 0, -1), new Vec3(0, 0, 1), new Vec3(-1, 0, 0), new Vec3(1, 0, 0)]