Skip to content

Commit

Permalink
next release (#145)
Browse files Browse the repository at this point in the history
  • Loading branch information
zardoy authored Jun 15, 2024
2 parents 7efd187 + 5409f6f commit 7220e39
Show file tree
Hide file tree
Showing 135 changed files with 3,487 additions and 356 deletions.
17 changes: 17 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,5 +96,22 @@
"unicorn/filename-case": "off",
"max-depth": "off"
},
"overrides": [
{
"files": [
"*.js"
],
"rules": {
"space-before-function-paren": [
"error",
{
"anonymous": "always",
"named": "never",
"asyncArrow": "always"
}
]
}
}
],
"root": true
}
5 changes: 5 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ jobs:
steps:
- name: Checkout repository
uses: actions/checkout@master
- name: Setup Java JDK
uses: actions/[email protected]
with:
java-version: 17
java-package: jre
- name: Install pnpm
run: npm i -g [email protected]
- uses: actions/setup-node@v4
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ out
.vercel
generated
storybook-static
server-jar

src/react/npmReactComponents.ts
2 changes: 1 addition & 1 deletion README.NPM.MD
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const App = () => {
}
```

See [Storybook](https://mcraft.fun/storybook/) or [Storybook (Mirror link)](https://mcon.vercel.app/storybook/) for more examples and full components list. Also take a look at the full [standalone example](https://github.com/zardoy/prismarine-web-client/tree/experiments/UiStandaloneExample.tsx).
See [Storybook](https://mcraft.fun/storybook/) or [Storybook (Mirror link)](https://mcon.vercel.app/storybook/) for more examples and full components list. Also take a look at the full [standalone example](https://github.com/zardoy/minecraft-web-client/tree/experiments/UiStandaloneExample.tsx).

There are two types of components:

Expand Down
4 changes: 2 additions & 2 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
"description": "One of the best servers here. Join now!"
},
{
"ip": "play.minemalia.com",
"ip": "sus.shhnowisnottheti.me",
"version": "1.18.2",
"description": "Only login with existing accounts."
"description": "Creative, your own 'boxes' (islands)"
}
]
}
57 changes: 55 additions & 2 deletions cypress/e2e/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
/* eslint-disable max-nested-callbacks */
/// <reference types="cypress" />
import supportedVersions from '../../src/supportedVersions.mjs'
import { setOptions, cleanVisit, visit } from './shared'

// todo use ssl
Expand All @@ -12,7 +14,7 @@ const compareRenderedFlatWorld = () => {
}

const testWorldLoad = () => {
cy.document().then({ timeout: 20_000 }, doc => {
return cy.document().then({ timeout: 20_000 }, doc => {
return new Cypress.Promise(resolve => {
doc.addEventListener('cypress-world-ready', resolve)
})
Expand All @@ -36,7 +38,7 @@ it('Loads & renders singleplayer', () => {
testWorldLoad()
})

it('Joins to server', () => {
it('Joins to local flying-squid server', () => {
visit('/?ip=localhost&version=1.16.1')
window.localStorage.version = ''
// todo replace with data-test
Expand All @@ -47,9 +49,60 @@ it('Joins to server', () => {
testWorldLoad()
})

it('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')
cy.get('[data-test-id="connect-qs"]').click()
testWorldLoad().then(() => {
let x = 0
let z = 0
cy.window().then((win) => {
x = win.bot.entity.position.x
z = win.bot.entity.position.z
})
cy.document().trigger('keydown', { code: 'KeyW' })
cy.wait(1500).then(() => {
cy.document().trigger('keyup', { code: 'KeyW' })
cy.window().then(async (win) => {
// eslint-disable-next-line prefer-destructuring
const bot: typeof __type_bot = win.bot
// todo use f3 stats instead
if (bot.entity.position.x === x && bot.entity.position.z === z) {
throw new Error('Player not moved')
}

bot.chat('Hello') // todo assert
bot.chat('/gamemode creative')
// bot.on('message', () => {
void bot.creative.setInventorySlot(bot.inventory.hotbarStart, new win.PrismarineItem(1, 1, 0))
// })
await bot.lookAt(bot.entity.position.offset(1, 0, 1))
}).then(() => {
cy.document().trigger('mousedown', { button: 2, isTrusted: true, force: true }) // right click
cy.document().trigger('mouseup', { button: 2, isTrusted: true, force: true })
cy.wait(1000)
})
})
})
})
})

it('Loads & renders zip world', () => {
cleanVisit()
cy.get('[data-test-id="select-file-folder"]').click({ shiftKey: true })
cy.get('input[type="file"]').selectFile('cypress/superflat.zip', { force: true })
testWorldLoad()
})


it.skip('Loads & renders world from folder', () => {
cleanVisit()
// dragndrop folder
cy.get('[data-test-id="select-file-folder"]').click()
cy.get('input[type="file"]').selectFile('server-jar/world', {
force: true,
// action: 'drag-drop',
})
testWorldLoad()
})
3 changes: 3 additions & 0 deletions cypress/e2e/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import { AppOptions } from '../../src/optionsStorage'
export const cleanVisit = (url?) => {
cy.clearLocalStorage()
visit(url)
window.localStorage.options = {
chatOpacity: 0
}
}
export const visit = (url = '/') => {
window.localStorage.cypress = 'true'
Expand Down
9 changes: 8 additions & 1 deletion cypress/plugins/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
const { cypressEsbuildPreprocessor } = require('cypress-esbuild-preprocessor')
const { initPlugin } = require('cypress-plugin-snapshots/plugin')
const polyfill = require('esbuild-plugin-polyfill-node')
const { startMinecraftServer } = require('./startServer')

module.exports = (on, config) => {
initPlugin(on, config)
on('file:preprocessor', cypressEsbuildPreprocessor({
esbuildOptions: {
sourcemap: true,
plugins: [
polyfill.polyfillNode({
polyfills: {
Expand All @@ -17,10 +19,15 @@ module.exports = (on, config) => {
},
}))
on('task', {
log (message) {
log(message) {
console.log(message)
return null
},
})
on('task', {
async startServer([version, port]) {
return startMinecraftServer(version, port)
}
})
return config
}
8 changes: 8 additions & 0 deletions cypress/plugins/ops.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[
{
"uuid": "67128b5b-2e6b-3ad1-baa0-1b937b03e5c5",
"name": "bot",
"level": 4,
"bypassesPlayerLimit": false
}
]
61 changes: 61 additions & 0 deletions cypress/plugins/server.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
#Minecraft server properties
allow-flight=false
allow-nether=true
broadcast-console-to-ops=true
broadcast-rcon-to-ops=true
difficulty=peaceful
enable-command-block=false
enable-jmx-monitoring=false
enable-query=false
enable-rcon=false
enable-status=true
enforce-secure-profile=true
enforce-whitelist=false
entity-broadcast-range-percentage=100
force-gamemode=false
function-permission-level=2
gamemode=survival
generate-structures=true
generator-settings={}
hardcore=false
hide-online-players=false
initial-disabled-packs=
initial-enabled-packs=vanilla
level-name=world
level-seed=
level-type=flat
log-ips=true
max-build-height=256
max-chained-neighbor-updates=1000000
max-players=20
max-tick-time=60000
max-world-size=29999984
motd=A Minecraft Server
network-compression-threshold=256
online-mode=false
op-permission-level=4
player-idle-timeout=0
prevent-proxy-connections=false
pvp=true
query.port=25565
rate-limit=0
rcon.password=
rcon.port=25575
require-resource-pack=false
resource-pack=
resource-pack-id=
resource-pack-prompt=
resource-pack-sha1=
server-ip=
server-port=25565
simulation-distance=10
snooper-enabled=true
spawn-animals=true
spawn-monsters=true
spawn-npcs=true
spawn-protection=16
sync-chunk-writes=true
text-filtering-config=
use-native-transport=true
view-distance=10
white-list=false
45 changes: 45 additions & 0 deletions cypress/plugins/startServer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { ChildProcess, spawn } from 'child_process'
import * as fs from 'fs'
import * as path from 'path'
import { promisify } from 'util'
import { downloadServer } from 'minecraft-wrap'
import * as waitOn from 'wait-on'

let prevProcess: ChildProcess | null = null
export const startMinecraftServer = async (version: string, port: number) => {
if (prevProcess) return null
const jar = `./server-jar/${version}.jar`

const start = () => {
// if (prevProcess) {
// prevProcess.kill()
// }

prevProcess = spawn('java', ['-jar', path.basename(jar), 'nogui', '--port', `${port}`], {
stdio: 'inherit',
cwd: path.dirname(jar),
})
}

let coldStart = false
if (fs.existsSync(jar)) {
start()
} else {
coldStart = true
promisify(downloadServer)(version, jar).then(() => {
// add eula.txt
fs.writeFileSync(path.join(path.dirname(jar), 'eula.txt'), 'eula=true')
// copy cypress/plugins/server.properties
fs.copyFileSync(path.join(__dirname, 'server.properties'), path.join(path.dirname(jar), 'server.properties'))
// copy ops.json
fs.copyFileSync(path.join(__dirname, 'ops.json'), path.join(path.dirname(jar), 'ops.json'))
start()
})
}

return new Promise<null>((res) => {
waitOn({ resources: [`tcp:localhost:${port}`] }, () => {
setTimeout(() => res(null), coldStart ? 6500 : 2000) // todo retry instead of timeout
})
})
}
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
</div>
<div>
<div style="font-size: calc(var(--font-size) * 1.8);color: lightgray;" class="title">Loading...</div>
<div style="font-size: var(--font-size);color: rgb(176, 176, 176);" class="subtitle">A true Minecraft client in your browser!</div>
<div style="font-size: var(--font-size);color: rgb(176, 176, 176);margin-top: 3px;text-align: center" class="subtitle">A true Minecraft client in your browser!</div>
</div>
</div>
`
Expand Down
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "prismarine-web-client",
"name": "minecraft-web-client",
"version": "0.0.0-dev",
"description": "A minecraft client running in a browser",
"scripts": {
Expand Down Expand Up @@ -63,7 +63,7 @@
"esbuild-plugin-polyfill-node": "^0.3.0",
"express": "^4.18.2",
"filesize": "^10.0.12",
"flying-squid": "npm:@zardoy/flying-squid@^0.0.24",
"flying-squid": "npm:@zardoy/flying-squid@^0.0.29",
"fs-extra": "^11.1.1",
"google-drive-browserfs": "github:zardoy/browserfs#google-drive",
"iconify-icon": "^1.0.8",
Expand Down Expand Up @@ -100,6 +100,7 @@
"use-typed-event-listener": "^4.0.2",
"valtio": "^1.11.1",
"vec3": "^0.1.7",
"wait-on": "^7.2.0",
"workbox-build": "^7.0.0"
},
"devDependencies": {
Expand All @@ -113,6 +114,7 @@
"@types/stats.js": "^0.17.1",
"@types/three": "0.154.0",
"@types/ua-parser-js": "^0.7.39",
"@types/wait-on": "^5.3.4",
"@xmcl/installer": "^5.1.0",
"assert": "^2.0.0",
"browserify-zlib": "^0.2.0",
Expand Down
2 changes: 1 addition & 1 deletion package.npm.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
},
"module": "./dist/react/npmReactComponents.js",
"types": "./dist/react/npmReactComponents.d.ts",
"repository": "zardoy/prismarine-web-client",
"repository": "zardoy/minecraft-web-client",
"version": "0.0.0-dev",
"dependencies": {},
"peerDependencies": {
Expand Down
Loading

0 comments on commit 7220e39

Please sign in to comment.