Skip to content

Commit

Permalink
massive features incoming! (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
zardoy authored Oct 8, 2023
2 parents 6f5b9db + d40f388 commit c67abaf
Show file tree
Hide file tree
Showing 63 changed files with 3,204 additions and 775 deletions.
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
2 changes: 2 additions & 0 deletions .github/workflows/preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ jobs:
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
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

0 comments on commit c67abaf

Please sign in to comment.