Skip to content

Commit

Permalink
Merge branch 'master' into feature/timecycle-lighting
Browse files Browse the repository at this point in the history
  • Loading branch information
rom1504 authored Dec 17, 2023
2 parents e83ce65 + 216fbb9 commit c6b0647
Show file tree
Hide file tree
Showing 25 changed files with 116 additions and 77 deletions.
31 changes: 16 additions & 15 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,39 +6,40 @@ on:
pull_request:

jobs:
Lint:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Use Node.js 18.x
uses: actions/[email protected]
with:
node-version: 18.x
- run: npm i && npm run lint
build:

runs-on: ubuntu-latest

strategy:
matrix:
node-version: [16.x]
javaVersion: [1.8]
mcVersionIndex: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
include:
- javaVersion: 16
mcVersionIndex: 10
- javaVersion: 17
mcVersionIndex: 11
mcVersion: ['1.8.8', '1.9.4', '1.10.2', '1.11.2', '1.12.2', '1.13.2', '1.14.4', '1.15.2', '1.16.1', '1.16.4', '1.17.1', '1.18.1', '1.19.1', '1.20.1']
fail-fast: false

steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
- name: Use Node.js 18.x
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
node-version: 18.x
- name: Setup Java JDK
uses: actions/setup-java@v1
with:
java-version: ${{ matrix.javaVersion }}
java-version: 17
java-package: jre
- name: Install xi
run: sudo apt-get install -y libxi-dev libglu1-mesa-dev
- run: npm install
- env:
CIRCLE_NODE_INDEX: ${{ matrix.mcVersionIndex }}
CIRCLE_NODE_TOTAL: 12
run: npm test
- run: npm run jestTest -- -t ${{ matrix.mcVersion }}
- uses: actions/upload-artifact@v2
with:
name: test_picture
Expand Down
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@ package-lock.json
versions/
public/index.js*
public/worker.js*
public/supportedVersions.json
public/textures/
public/blocksStates/
examples/standalone/public/index.js
examples/standalone/public/worker.js
examples/standalone/public/supportedVersions.json
examples/standalone/public/textures/
examples/standalone/public/blocksStates/
*.DS_Store
1 change: 0 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@ package-lock.json
versions/
examples/standalone/public/index.js
examples/standalone/public/worker.js
examples/standalone/public/supportedVersions.json
examples/standalone/public/textures/
examples/standalone/public/blocksStates/
8 changes: 5 additions & 3 deletions readme.md → README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@
Web based viewer for servers and bots

[![NPM version](https://img.shields.io/npm/v/prismarine-viewer.svg)](http://npmjs.com/package/prismarine-viewer)
[![Build Status](https://github.com/PrismarineJS/prismarine-viewer/workflows/CI/badge.svg)](https://github.com/PrismarineJS/prismarine-viewer/actions?query=workflow%3A%22CI%22)
[![Build Status](https://img.shields.io/github/actions/workflow/status/PrismarineJS/prismarine-viewer/ci.yml.svg?label=CI&logo=github&logoColor=lightgrey)](https://github.com/PrismarineJS/prismarine-viewer/actions?query=workflow%3A%22CI%22)
[![Discord](https://img.shields.io/badge/chat-on%20discord-brightgreen.svg)](https://discord.gg/GsEFRM8)
[![Gitter](https://img.shields.io/badge/chat-on%20gitter-brightgreen.svg)](https://gitter.im/PrismarineJS/general)
[![Irc](https://img.shields.io/badge/chat-on%20irc-brightgreen.svg)](https://irc.gitter.im/)
[![Issue Hunt](https://github.com/BoostIO/issuehunt-materials/blob/master/v1/issuehunt-shield-v1.svg)](https://issuehunt.io/r/PrismarineJS/prismarine-viewer)

[![Try it on gitpod](https://img.shields.io/badge/try-on%20gitpod-brightgreen.svg)](https://gitpod.io/#https://github.com/PrismarineJS/prismarine-viewer)

[<img src="https://prismarine.js.org/prismarine-viewer/test_1.18.1.png" alt="viewer" width="300">](https://prismarine.js.org/prismarine-viewer/)
[<img src="https://prismarinejs.github.io/prismarine-viewer/test_1.18.1.png" alt="viewer" width="300">](https://prismarinejs.github.io/prismarine-viewer/)

Supports versions 1.8.8, 1.9.4, 1.10.2, 1.11.2, 1.12.2, 1.13.2, 1.14.4, 1.15.2, 1.16.1, 1.16.4, 1.17.1, 1.18.1, 1.19.1, 1.20.1.

## Install

Expand Down Expand Up @@ -138,4 +140,4 @@ Stop the server and disconnect users.

## Tests

`node_modules/.bin/jest --verbose --runInBand --forceExit -t "1.16.4"`
`npm run jestTest -- -t "1.9.4"`
4 changes: 3 additions & 1 deletion examples/core/headless.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ const start = (bot, { viewDistance = 6, output = 'output.mp4', frames = 200, wid
const renderer = new THREE.WebGLRenderer({ canvas })
const viewer = new Viewer(renderer)

viewer.setVersion(bot.version)
if (!viewer.setVersion(bot.version)) {
return false
}
viewer.setFirstPersonCamera(bot.entity.position, bot.entity.yaw, bot.entity.pitch)

// Load world
Expand Down
4 changes: 3 additions & 1 deletion examples/electron/client/localViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ class LocalViewer {

// Create viewer
this.viewer = new Viewer(this.renderer)
this.viewer.setVersion(this.version)
if (!this.viewer.setVersion(this.version)) {
return false
}
// Attach controls to viewer
this.controls = new MapControls(this.viewer.camera, this.renderer.domElement)
// Enable damping (inertia) on movement
Expand Down
4 changes: 3 additions & 1 deletion examples/exporter/3dmodel.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ const main = async () => {

await schem.paste(world, new Vec3(0, 60, 0))

viewer.setVersion(version)
if (viewer.setVersion(version)) {
return false
}

// Load world
const worldView = new WorldView(world, viewDistance, center)
Expand Down
4 changes: 3 additions & 1 deletion examples/exporter/screenshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ const main = async () => {

await schem.paste(world, new Vec3(0, 60, 0))

viewer.setVersion(version)
if (viewer.setVersion(version)) {
return false
}

// Load world
const worldView = new WorldView(world, viewDistance, center)
Expand Down
8 changes: 4 additions & 4 deletions examples/proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const srv = mc.createServer({
'online-mode': false,
port: 25566,
keepAlive: false,
version: version
version
})

srv.on('login', function (client) {
Expand All @@ -47,11 +47,11 @@ srv.on('login', function (client) {
if (!endedTargetClient) { targetClient.end('Error') }
})
const targetClient = mc.createClient({
host: host,
port: port,
host,
port,
username: client.username,
keepAlive: false,
version: version
version
})
client.on('packet', function (data, meta) {
if (targetClient.state === states.PLAY && meta.state === states.PLAY) {
Expand Down
4 changes: 3 additions & 1 deletion examples/standalone/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ async function main () {

// Create viewer
const viewer = new Viewer(renderer)
viewer.setVersion(version)
if (viewer.setVersion(version)) {
return false
}
// Attach controls to viewer
const controls = new MapControls(viewer.camera, renderer.domElement)

Expand Down
1 change: 0 additions & 1 deletion examples/standalone/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ const config = {
{ from: '../../public/blocksStates/', to: './blocksStates/' },
{ from: '../../public/textures/*.png', to: './textures/' },
{ from: '../../public/worker.js', to: './' },
{ from: '../../public/supportedVersions.json', to: './' }
]
})
],
Expand Down
4 changes: 3 additions & 1 deletion examples/web_client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ async function main () {

// Create viewer
const viewer = new Viewer(renderer)
viewer.setVersion(version)
if (viewer.setVersion(version)) {
return false
}

worldView.listenToBot(bot)
worldView.init(bot.entity.position)
Expand Down
1 change: 0 additions & 1 deletion examples/web_client/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ const config = {
{ from: '../../public/blocksStates/', to: './blocksStates/' },
{ from: '../../public/textures/', to: './textures/' },
{ from: '../../public/worker.js', to: './' },
{ from: '../../public/supportedVersions.json', to: './' }
]
}),
new webpack.optimize.ModuleConcatenationPlugin(),
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ module.exports = {
standalone: require('./lib/standalone'),
headless: require('./lib/headless'),
viewer: require('./viewer'),
supportedVersions: ['1.8.8', '1.9.4', '1.10.2', '1.11.2', '1.12.2', '1.13.2', '1.14.4', '1.15.2', '1.16.1', '1.16.4', '1.17.1', '1.18.1']
supportedVersions: require('./viewer').supportedVersions
}
4 changes: 3 additions & 1 deletion lib/headless.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ module.exports = (bot, { viewDistance = 6, output = 'output.mp4', frames = -1, w
const renderer = new THREE.WebGLRenderer({ canvas })
const viewer = new Viewer(renderer)

viewer.setVersion(bot.version)
if (viewer.setVersion(bot.version)) {
return false
}
viewer.setFirstPersonCamera(bot.entity.position, bot.entity.yaw, bot.entity.pitch)

// Load world
Expand Down
4 changes: 3 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ window.addEventListener('resize', () => {
})

socket.on('version', (version) => {
viewer.setVersion(version)
if (viewer.setVersion(version)) {
return false
}

firstPositionUpdate = true
viewer.listen(socket)
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"description": "Web based viewer",
"main": "index.js",
"scripts": {
"test": "jest --verbose --runInBand --forceExit",
"jestTest": "jest --verbose --runInBand --forceExit",
"test": "npm run test",
"pretest": "npm run lint",
"lint": "standard",
"prepare": "node viewer/prerender.js && webpack",
Expand Down Expand Up @@ -51,7 +52,7 @@
"prismarine-viewer": "file:./",
"process": "^0.11.10",
"puppeteer": "^16.0.0",
"standard": "^17.0.0",
"standard": "^17.1.0",
"webpack": "^5.10.2",
"webpack-cli": "^5.1.1"
}
Expand Down
12 changes: 12 additions & 0 deletions test/common/util.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const net = require('net')

const getPort = () => new Promise(resolve => {
const server = net.createServer()
server.listen(0, '127.0.0.1')
server.on('listening', () => {
const { port } = server.address()
server.close(() => resolve(port))
})
})

module.exports = { getPort }
20 changes: 0 additions & 20 deletions test/parallel.js

This file was deleted.

44 changes: 31 additions & 13 deletions test/viewer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ const os = require('os')

const Wrap = require('minecraft-wrap').Wrap

const { firstVersion, lastVersion } = require('./parallel')
const { getPort } = require('./common/util')

const download = require('minecraft-wrap').download
const TIMEOUT = 5 * 60 * 1000
const TIMEOUT_SCREENSHOT = 2 * 60 * 1000

supportedVersions.forEach(function (supportedVersion, i) {
if (!(i >= firstVersion && i <= lastVersion)) { return }

const PORT = Math.round(30000 + Math.random() * 20000)
supportedVersions.forEach(function (supportedVersion) {
let PORT = null
const mcData = require('minecraft-data')(supportedVersion)
const version = mcData.version
const MC_SERVER_JAR_DIR = process.env.MC_SERVER_JAR_DIR || os.tmpdir()
Expand All @@ -30,14 +30,17 @@ supportedVersions.forEach(function (supportedVersion, i) {
})

describe('client ' + version.minecraftVersion, function () {
beforeAll(download.bind(null, version.minecraftVersion, MC_SERVER_JAR), 3 * 60 * 1000)
beforeAll(async () => {
await new Promise(resolve => download(version.minecraftVersion, MC_SERVER_JAR, resolve))
PORT = await getPort()
}, TIMEOUT)

afterAll(function (done) {
wrap.deleteServerData(function (err) {
if (err) { console.log(err) }
done(err)
})
}, 3 * 60 * 1000)
}, TIMEOUT)

describe('offline', function () {
beforeAll(function (done) {
Expand All @@ -52,7 +55,7 @@ supportedVersions.forEach(function (supportedVersion, i) {
console.log(new Date() + 'started server ' + version.minecraftVersion)
done(err)
})
}, 3 * 60 * 1000)
}, TIMEOUT)

afterAll(function (done) {
console.log(new Date() + 'stopping server' + version.minecraftVersion)
Expand All @@ -61,7 +64,7 @@ supportedVersions.forEach(function (supportedVersion, i) {
console.log(new Date() + 'stopped server ' + version.minecraftVersion)
done(err)
})
}, 3 * 60 * 1000)
}, TIMEOUT)

it('doesn\'t crash', function (done) {
console.log('test')
Expand All @@ -71,7 +74,7 @@ supportedVersions.forEach(function (supportedVersion, i) {
it('starts the viewer', function (done) {
const mineflayer = require('mineflayer')
const mineflayerViewer = require('../').mineflayer
setTimeout(() => done(new Error('too slow !!!')), 180000)
setTimeout(() => done(new Error('too slow !!!')), TIMEOUT)

const bot = mineflayer.createBot({
username: 'Bot',
Expand All @@ -89,7 +92,22 @@ supportedVersions.forEach(function (supportedVersion, i) {
}

page.goto('http://localhost:3000').then(() => {
page.on('console', msg => console.log('PAGE LOG:', msg.text()))
// https://github.com/puppeteer/puppeteer/issues/3397
page.on('console', async (message) => {
let toPrint = ''
if (message.text() !== 'JSHandle@error') {
toPrint = `${message.type().substring(0, 3).toUpperCase()} ${message.text()}`
} else {
const messages = await Promise.all(message.args().map((arg) => {
return arg.getProperty('message')
}))

toPrint = `${message.type().substring(0, 3).toUpperCase()} ${messages.filter(Boolean)}`
}
if (!toPrint.includes('Unknown entity')) {
console.log(toPrint)
}
})

page.on('error', err => {
exit(err)
Expand All @@ -100,10 +118,10 @@ supportedVersions.forEach(function (supportedVersion, i) {
})
setTimeout(() => {
page.screenshot({ path: path.join(__dirname, `test_${supportedVersion}.png`) }).then(() => exit()).catch(err => exit(err))
}, 120000)
}, TIMEOUT_SCREENSHOT)
}).catch(err => exit(err))
})
}, 180000)
}, TIMEOUT)
})
})
})
Loading

0 comments on commit c6b0647

Please sign in to comment.