Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

massive features incoming! #30

Merged
merged 39 commits into from
Oct 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
1d77887
fix(regression): display actual connection error reason
zardoy Oct 2, 2023
23ab8e5
start reworking models, bringing typesafety
zardoy Oct 2, 2023
5d11fae
fix: render block when view out of the world e.g. below bedrock level
zardoy Oct 2, 2023
6090493
fix(regression): stairs are not rendererd!
zardoy Oct 3, 2023
f6fbb96
fix: load textures earlier, speeds worlds loading. Remove initial tim…
zardoy Oct 4, 2023
a200c6d
test publishing playground to vercel
zardoy Oct 4, 2023
bff4f8d
add initial readme!
zardoy Oct 4, 2023
d30b00c
refactor: cleanup texture atlas generators: make typed to gain confid…
zardoy Oct 4, 2023
bb31aac
fix(texturepack): do not make missing textures smaller as they would …
zardoy Oct 4, 2023
a5fed75
fix(playground): correctly handle initial + metadata updates
zardoy Oct 4, 2023
4b476b3
fix(regression): sourcemap is not inlined into worker anymore, so mem…
zardoy Oct 5, 2023
30099a0
fix eslint
zardoy Oct 5, 2023
1a2a863
add plyaground
zardoy Oct 5, 2023
b5f70cb
add scene pull
zardoy Oct 6, 2023
d798605
fix worker map writing
zardoy Oct 6, 2023
3794ec3
worldView -> worldDataEmitter, remove emitter, also emit blockEntities
zardoy Oct 6, 2023
67341cb
migrate worldDataEmitter to TS!
zardoy Oct 6, 2023
589cdbc
migrate viewer to TS
zardoy Oct 6, 2023
15c820a
fix(important): Correctly load needed chunks based on render distance…
zardoy Oct 6, 2023
deb3255
should fix build
zardoy Oct 6, 2023
7ad7ef2
should fix build
zardoy Oct 6, 2023
b68ef15
display output size on build
zardoy Sep 29, 2023
6093437
feat: signs rendering support!
zardoy Oct 7, 2023
e874db0
server(dev): always use only one source of textures
zardoy Oct 7, 2023
8a3f1a5
docs(feedback): improve readme
zardoy Oct 7, 2023
ae55b89
fix(tab-complete): improve word matching!
zardoy Oct 7, 2023
31160b1
fix(ios): camera control is frozen after system gestures
zardoy Oct 7, 2023
91b73ba
fix: render world below y=0 without restrictions (fixup for 5d11fae54…
zardoy Oct 8, 2023
2c47214
version input: replace , with .
zardoy Oct 8, 2023
2e5f4a5
test deploy linking
zardoy Oct 8, 2023
6f6adaa
playground: fix initial render, add viewer.render
zardoy Oct 8, 2023
1d4e095
feat: toggle chunk section border visibility by f3+g
zardoy Oct 8, 2023
ac82a39
feat: full chests rendering support
zardoy Oct 8, 2023
6cb9d31
add chest data
zardoy Oct 8, 2023
f57e302
add experiments folder
zardoy Oct 8, 2023
999e9f3
fix: don't display survival hud in spectator (note that spectator fly…
zardoy Oct 8, 2023
df79053
another fixup for 5d11fae54c038f27b55ef86ba5cff25c367d5046, (y<0) now…
zardoy Oct 8, 2023
19ad1e5
up lockfile
zardoy Oct 8, 2023
d40f388
fix standing sign rotation step
zardoy Oct 8, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
{
"extends": "zardoy",
"ignorePatterns": [
"!*.js"
"!*.js",
"prismarine-viewer/"
],
"rules": {
"space-infix-ops": "error",
"no-multi-spaces": "error",
"space-in-parens": [
"error",
Expand Down Expand Up @@ -86,6 +88,7 @@
"unicorn/no-empty-file": "off",
"unicorn/prefer-event-target": "off",
// needs to be fixed actually
"complexity": "off",
"@typescript-eslint/no-floating-promises": "warn",
"no-async-promise-executor": "off",
"no-bitwise": "off",
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,15 @@ jobs:
run: vercel pull --yes --environment=preview --token=${{ secrets.VERCEL_TOKEN }}
- name: Build Project Artifacts
run: vercel build --token=${{ secrets.VERCEL_TOKEN }}
- name: Copy playground files
run: node prismarine-viewer/esbuild.mjs && cp prismarine-viewer/public/index.html .vercel/output/static/playground.html && cp prismarine-viewer/public/playground.js .vercel/output/static/playground.js
- name: Deploy Project Artifacts to Vercel
uses: mathiasvr/[email protected]
with:
run: vercel deploy --prebuilt --token=${{ secrets.VERCEL_TOKEN }}
id: deploy
- name: Set deployment alias
run: vercel alias set ${{ steps.deploy.outputs.stdout }} ${{ secrets.TEST_PREVIEW_DOMAIN }} --token=${{ secrets.VERCEL_TOKEN }}
- uses: mshick/add-pr-comment@v2
with:
message: |
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ jobs:
- run: vercel pull --yes --environment=production --token=${{ secrets.VERCEL_TOKEN }}
# will install + build to .vercel/output/static
- run: vercel build --token=${{ secrets.VERCEL_TOKEN }} --prod
- name: Copy playground files
run: node prismarine-viewer/esbuild.mjs && cp prismarine-viewer/public/index.html .vercel/output/static/playground.html && cp prismarine-viewer/public/playground.js .vercel/output/static/playground.js
- name: Deploy Project to Vercel
uses: mathiasvr/[email protected]
with:
Expand Down
10 changes: 5 additions & 5 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
"outFiles": [
"${workspaceFolder}/dist/**/*.js",
// "!${workspaceFolder}/dist/**/*vendors*",
"!${workspaceFolder}/dist/**/*minecraftData*",
"!${workspaceFolder}/dist/**/*mc-data*",
"!**/node_modules/**"
],
"skipFiles": [
// "<node_internals>/**/*vendors*"
"<node_internals>/**/*minecraftData*"
"<node_internals>/**/*mc-data*"
],
"port": 9222,
},
Expand All @@ -36,12 +36,12 @@
"outFiles": [
"${workspaceFolder}/dist/**/*.js",
// "!${workspaceFolder}/dist/**/*vendors*",
"!${workspaceFolder}/dist/**/*minecraftData*",
"!${workspaceFolder}/dist/**/*mc-data*",
"!**/node_modules/**"
],
"skipFiles": [
// "<node_internals>/**/*vendors*"
"<node_internals>/**/*minecraftData*"
"<node_internals>/**/*mc-data*"
],
},
{
Expand All @@ -54,7 +54,7 @@
"webRoot": "${workspaceFolder}/",
"skipFiles": [
// "<node_internals>/**/*vendors*"
"<node_internals>/**/*minecraftData*"
"<node_internals>/**/*mc-data*"
],
},
]
Expand Down
80 changes: 80 additions & 0 deletions README.MD
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# Minecraft Web Client

A true Minecraft client running in your browser! A port of the original game to the web, written in JavaScript using modern web technologies.

This project is a work in progress, but I consider it to be usable. If you encounter any bugs or usability issues, please report them!

### Big Features

- Connect to any offline server* (it's possible because of proxy servers, see below)
- Open any zip world file or even folder in read-write mode!
- Singleplayer mode with simple world generation
- Works offline
- Play with friends over global network! (P2P is powered by Peer.js servers)
- First-class touch (mobile) & controller support
- Resource pack support
- even even more!

There are a lot

### World Loading

Zip files and folders are supported. Just drag and drop them into the browser window. You can open folders in readonly and read-write mode. New chunks may be generated incorrectly for now.
In case of opening zip files they are stored in your ram entirely, so there is a ~300mb file limit on IOS.
Whatever offline mode you used (zip, folder, just single player), you can always export world with the `/export` command typed in the game chat.

### Servers

You can play almost on any server, supporting offline connections.
See the [Mineflayer](https://github.com/PrismarineJS/mineflayer) repo for the list of supported versions (should support majority of versions).
There is a builtin proxy, but you can also host a your one! Just clone the repo, run `pnpm i` (following CONTRIBUTING.MD) and run `pnpm prod-start`, then you can specify `http://localhost:8080` in the proxy field.
MS account authentication will be supported soon.

<!-- TODO proxy server communication graph -->

### Things that are not planned yet

- Mods, plugins (basically JARs) support, shaders - since they all are related to specific game pipelines

### Advanced Settings

There are many many settings, that are not exposed in the UI yet. You can find or change them by opening the browser console and typing `options`. You can also change them by typing `options.<setting_name> = <value>`.

### Console

To open the console, press `F12`, or if you are on mobile, you can type `#debug` in the URL (browser address bar), it wont't reload the page, but you will see a button to open the console. This way you can change advanced settings and see all errors or warnings. Also this way you can access global variables (described below).

### Debugging

It should be easy to build/start the project locally. See [CONTRIBUTING.MD](./CONTRIBUTING.md) for more info.

However, there are many things that can be done in online version. You can access some global variables in the console and useful examples:

- `localStorage.debug = '*'` - Enables all debug messages!

- `bot` - Mineflayer bot instance. See Mineflayer documentation for more.
- `viewer` - Three.js viewer instance, basically does all the rendering.
- `viewer.world.sectionObjects` - Object with all active chunk sections (geometries) in the world. Each chunk section is a Three.js mesh or group.
- `localServer` - Only for singleplayer mode/host. Flying Squid server instance, see it's documentation for more.
- `localServer.overworld.storageProvider.regions` - See ALL LOADED region files with all raw data.

- `nbt.simplify(someNbt)` - Simplifies nbt data, so it's easier to read.

You can also drag and drop any .dat file into the browser window to see it's contents in the console.

### F3 Keybindings

- `F3` - Toggle debug overlay
- `F3 + A` - Reload all chunks (these that are loaded from the server)
<!-- <!-- - `F3 + N` - Restart local server (basically resets the world!) -->
- `F3 + G` - Toggle chunk sections (geometries) border visibility (aka Three.js geometry helpers) - most probably need to reload chunks after toggling

### Notable Things that Power this Project

- [Mineflayer](https://github.com/PrismarineJS/mineflayer) - Handles all client-side communications with the server (including the builtin one) - forked
- [Flying Squid](https://github.com/prismarineJS/flying-squid) - The builtin server that makes single player possible! Here forked version is used.
- [Prismarine Provider Anvil](https://github.com/PrismarineJS/prismarine-provider-anvil) - Handles world loading (region format)
- [Prismarine Physics](https://github.com/PrismarineJS/prismarine-physics) - Does all the physics calculations
- [Minecraft Protocol](https://github.com/PrismarineJS/node-minecraft-protocol) - Makes connections to servers possible
- [Peer.js](https://peerjs.com/) - P2P networking (when you open to wan)
- [Three.js](https://threejs.org/) - Helping in 3D rendering
11 changes: 6 additions & 5 deletions esbuild.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import server from './server.js'
import { clients, plugins } from './scripts/esbuildPlugins.mjs'
import { generateSW } from 'workbox-build'
import { getSwAdditionalEntries } from './scripts/build.js'
import { build } from 'esbuild'

//@ts-ignore
try { await import('./localSettings.mjs') } catch { }
Expand All @@ -26,7 +27,8 @@ const banner = [

const buildingVersion = new Date().toISOString().split(':')[0]

const ctx = await esbuild.context({
/** @type {import('esbuild').BuildOptions} */
const buildOptions = {
bundle: true,
entryPoints: ['src/index.ts'],
target: ['es2020'],
Expand Down Expand Up @@ -77,9 +79,10 @@ const ctx = await esbuild.context({
write: false,
// todo would be better to enable?
// preserveSymlinks: true,
})
}

if (watch) {
const ctx = await esbuild.context(buildOptions)
await ctx.watch()
server.app.get('/esbuild', (req, res, next) => {
res.writeHead(200, {
Expand All @@ -103,7 +106,7 @@ if (watch) {
})
})
} else {
const result = await ctx.rebuild()
const result = await build(buildOptions)
// console.log(await esbuild.analyzeMetafile(result.metafile))

if (prod) {
Expand All @@ -119,6 +122,4 @@ if (watch) {
swDest: 'dist/service-worker.js',
})
}

await ctx.dispose()
}
39 changes: 39 additions & 0 deletions experiments/pointers.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div id="captured"></div>
<script>
const pointers = []
const up = () => {
captured.textContent = pointers.join(', ')
}
window.addEventListener('pointerdown', (e) => {
pointers.push(e.pointerId)
document.body.setPointerCapture(e.pointerId)
up()
e.preventDefault()
})
const remove = (id) => {
pointers.splice(pointers.indexOf(id), 1)
up()
}
window.addEventListener('pointerup', (e) => {
pointers.push('up')
remove(e.pointerId)
})
window.addEventListener('pointercancel', (e) => {
pointers.push('cancel')
remove(e.pointerId)
})
window.addEventListener('lostpointercapture', (e) => {
pointers.push('lost')
remove(e.pointerId)
})
</script>
</body>
</html>
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
"test:e2e": "start-test http-get://localhost:8080 test:cypress",
"prod-start": "node server.js",
"postinstall": "node scripts/gen-texturepack-files.mjs",
"test-mc-server": "tsx cypress/minecraft-server.mjs",
"lint": "eslint \"{src,cypress}/**/*.{ts,js,jsx,tsx}\""
},
"keywords": [
"prismarine",
"web",
"client"
],
"bin": "./server.js",
"author": "PrismarineJS",
"license": "MIT",
"dependencies": {
Expand Down Expand Up @@ -60,6 +60,7 @@
"@types/lodash-es": "^4.17.9",
"@types/stats.js": "^0.17.1",
"@types/three": "0.128.0",
"@xmcl/installer": "^5.1.0",
"assert": "^2.0.0",
"browserify-zlib": "^0.2.0",
"buffer": "^6.0.3",
Expand Down Expand Up @@ -90,6 +91,7 @@
"timers-browserify": "^2.0.12",
"typescript": "^5.2.2",
"use-typed-event-listener": "^4.0.2",
"vitest": "^0.34.6",
"yaml": "^2.3.2"
},
"pnpm": {
Expand Down
Loading
Loading