2021-03-13 20:20:11 -05:00
|
|
|
/* global THREE */
|
2021-03-14 15:34:35 -04:00
|
|
|
require('./lib/chat')
|
2021-12-24 07:00:07 -05:00
|
|
|
|
|
|
|
require('./lib/menus/components/button')
|
|
|
|
require('./lib/menus/components/edit_box')
|
|
|
|
require('./lib/menus/components/slider')
|
|
|
|
require('./lib/menus/components/hotbar')
|
|
|
|
require('./lib/menus/components/health_bar')
|
|
|
|
require('./lib/menus/components/food_bar')
|
|
|
|
require('./lib/menus/components/breath_bar')
|
|
|
|
require('./lib/menus/components/debug_overlay')
|
|
|
|
require('./lib/menus/components/playerlist_overlay')
|
2023-03-04 13:04:46 -05:00
|
|
|
require('./lib/menus/components/bossbars_overlay')
|
2021-12-24 07:00:07 -05:00
|
|
|
require('./lib/menus/hud')
|
|
|
|
require('./lib/menus/play_screen')
|
|
|
|
require('./lib/menus/pause_screen')
|
|
|
|
require('./lib/menus/loading_screen')
|
|
|
|
require('./lib/menus/keybinds_screen')
|
|
|
|
require('./lib/menus/options_screen')
|
|
|
|
require('./lib/menus/title_screen')
|
2021-03-13 20:20:11 -05:00
|
|
|
|
2021-03-03 19:39:21 -05:00
|
|
|
const net = require('net')
|
2021-03-23 21:23:02 -04:00
|
|
|
const Cursor = require('./lib/cursor')
|
2021-02-27 17:12:11 -05:00
|
|
|
|
|
|
|
// Workaround for process.versions.node not existing in the browser
|
|
|
|
process.versions.node = '14.0.0'
|
|
|
|
|
|
|
|
const mineflayer = require('mineflayer')
|
|
|
|
const { WorldView, Viewer } = require('prismarine-viewer/viewer')
|
2021-03-12 19:14:17 -05:00
|
|
|
const pathfinder = require('mineflayer-pathfinder')
|
2021-03-12 20:19:07 -05:00
|
|
|
const { Vec3 } = require('vec3')
|
2021-02-27 17:12:11 -05:00
|
|
|
global.THREE = require('three')
|
2021-03-21 18:13:32 -04:00
|
|
|
const { initVR } = require('./lib/vr')
|
2021-03-03 21:11:55 -05:00
|
|
|
|
2021-03-20 21:54:10 -04:00
|
|
|
if ('serviceWorker' in navigator) {
|
|
|
|
window.addEventListener('load', () => {
|
|
|
|
navigator.serviceWorker.register('/service-worker.js').then(registration => {
|
|
|
|
console.log('SW registered: ', registration)
|
|
|
|
}).catch(registrationError => {
|
|
|
|
console.log('SW registration failed: ', registrationError)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2021-02-28 14:02:22 -05:00
|
|
|
const maxPitch = 0.5 * Math.PI
|
|
|
|
const minPitch = -0.5 * Math.PI
|
|
|
|
|
2021-03-20 11:12:20 -04:00
|
|
|
// Create three.js context, add to page
|
|
|
|
const renderer = new THREE.WebGLRenderer()
|
|
|
|
renderer.setPixelRatio(window.devicePixelRatio || 1)
|
|
|
|
renderer.setSize(window.innerWidth, window.innerHeight)
|
|
|
|
document.body.appendChild(renderer.domElement)
|
|
|
|
|
|
|
|
// Create viewer
|
|
|
|
const viewer = new Viewer(renderer)
|
|
|
|
|
|
|
|
// Menu panorama background
|
2021-12-24 07:00:07 -05:00
|
|
|
function addPanoramaCubeMap () {
|
|
|
|
let time = 0
|
|
|
|
viewer.camera = new THREE.PerspectiveCamera(85, window.innerWidth / window.innerHeight, 0.05, 1000)
|
|
|
|
viewer.camera.updateProjectionMatrix()
|
|
|
|
viewer.camera.position.set(0, 0, 0)
|
|
|
|
viewer.camera.rotation.set(0, 0, 0)
|
|
|
|
const panorGeo = new THREE.BoxGeometry(1000, 1000, 1000)
|
|
|
|
|
|
|
|
const loader = new THREE.TextureLoader()
|
|
|
|
const panorMaterials = [
|
|
|
|
new THREE.MeshBasicMaterial({ map: loader.load('extra-textures/background/panorama_1.png'), transparent: true, side: THREE.DoubleSide }), // WS
|
|
|
|
new THREE.MeshBasicMaterial({ map: loader.load('extra-textures/background/panorama_3.png'), transparent: true, side: THREE.DoubleSide }), // ES
|
|
|
|
new THREE.MeshBasicMaterial({ map: loader.load('extra-textures/background/panorama_4.png'), transparent: true, side: THREE.DoubleSide }), // Up
|
|
|
|
new THREE.MeshBasicMaterial({ map: loader.load('extra-textures/background/panorama_5.png'), transparent: true, side: THREE.DoubleSide }), // Down
|
|
|
|
new THREE.MeshBasicMaterial({ map: loader.load('extra-textures/background/panorama_0.png'), transparent: true, side: THREE.DoubleSide }), // NS
|
|
|
|
new THREE.MeshBasicMaterial({ map: loader.load('extra-textures/background/panorama_2.png'), transparent: true, side: THREE.DoubleSide }) // SS
|
|
|
|
]
|
|
|
|
|
|
|
|
const panoramaBox = new THREE.Mesh(panorGeo, panorMaterials)
|
|
|
|
|
|
|
|
panoramaBox.onBeforeRender = () => {
|
|
|
|
time += 0.01
|
|
|
|
panoramaBox.rotation.y = Math.PI + time * 0.01
|
|
|
|
panoramaBox.rotation.z = Math.sin(-time * 0.001) * 0.001
|
2021-03-20 11:12:20 -04:00
|
|
|
}
|
2021-12-24 07:00:07 -05:00
|
|
|
|
2021-04-01 06:24:26 -04:00
|
|
|
const group = new THREE.Object3D()
|
2021-12-24 07:00:07 -05:00
|
|
|
group.add(panoramaBox)
|
|
|
|
|
2021-04-01 06:24:26 -04:00
|
|
|
const Entity = require('prismarine-viewer/viewer/lib/entity/Entity')
|
|
|
|
for (let i = 0; i < 42; i++) {
|
|
|
|
const m = new Entity('1.16.4', 'squid').mesh
|
2021-12-24 07:00:07 -05:00
|
|
|
m.position.set(Math.random() * 30 - 15, Math.random() * 20 - 10, Math.random() * 10 - 17)
|
2021-04-01 06:24:26 -04:00
|
|
|
m.rotation.set(0, Math.PI + Math.random(), -Math.PI / 4, 'ZYX')
|
|
|
|
const v = Math.random() * 0.01
|
|
|
|
m.children[0].onBeforeRender = () => {
|
|
|
|
m.rotation.y += v
|
2021-12-24 07:00:07 -05:00
|
|
|
m.rotation.z = Math.cos(panoramaBox.rotation.y * 3) * Math.PI / 4 - Math.PI / 2
|
2021-04-01 06:24:26 -04:00
|
|
|
}
|
|
|
|
group.add(m)
|
|
|
|
}
|
2021-12-24 07:00:07 -05:00
|
|
|
|
|
|
|
viewer.scene.add(group)
|
2021-04-01 06:24:26 -04:00
|
|
|
return group
|
2021-03-20 11:12:20 -04:00
|
|
|
}
|
|
|
|
|
2021-12-24 07:00:07 -05:00
|
|
|
const panoramaCubeMap = addPanoramaCubeMap()
|
|
|
|
|
2021-03-20 11:12:20 -04:00
|
|
|
function removePanorama () {
|
2021-12-24 07:00:07 -05:00
|
|
|
viewer.camera = new THREE.PerspectiveCamera(document.getElementById('options-screen').fov, window.innerWidth / window.innerHeight, 0.1, 1000)
|
|
|
|
viewer.camera.updateProjectionMatrix()
|
|
|
|
viewer.scene.remove(panoramaCubeMap)
|
2021-03-20 11:12:20 -04:00
|
|
|
}
|
|
|
|
|
2021-03-23 21:23:02 -04:00
|
|
|
let animate = () => {
|
2021-03-20 11:12:20 -04:00
|
|
|
window.requestAnimationFrame(animate)
|
|
|
|
viewer.update()
|
|
|
|
renderer.render(viewer.scene, viewer.camera)
|
|
|
|
}
|
|
|
|
animate()
|
|
|
|
|
|
|
|
window.addEventListener('resize', () => {
|
|
|
|
viewer.camera.aspect = window.innerWidth / window.innerHeight
|
|
|
|
viewer.camera.updateProjectionMatrix()
|
|
|
|
renderer.setSize(window.innerWidth, window.innerHeight)
|
|
|
|
})
|
|
|
|
|
2021-12-24 07:00:07 -05:00
|
|
|
const showEl = (str) => { document.getElementById(str).style = 'display:block' }
|
2021-02-27 17:12:11 -05:00
|
|
|
async function main () {
|
2021-12-24 07:00:07 -05:00
|
|
|
const menu = document.getElementById('play-screen')
|
|
|
|
|
2021-03-13 20:20:11 -05:00
|
|
|
menu.addEventListener('connect', e => {
|
|
|
|
const options = e.detail
|
|
|
|
menu.style = 'display: none;'
|
2021-12-24 07:00:07 -05:00
|
|
|
showEl('loading-screen')
|
2021-03-20 11:12:20 -04:00
|
|
|
removePanorama()
|
2021-03-13 20:20:11 -05:00
|
|
|
connect(options)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
async function connect (options) {
|
2021-12-24 07:00:07 -05:00
|
|
|
const loadingScreen = document.getElementById('loading-screen')
|
|
|
|
|
|
|
|
const hud = document.getElementById('hud')
|
|
|
|
const chat = hud.shadowRoot.querySelector('#chat')
|
|
|
|
const debugMenu = hud.shadowRoot.querySelector('#debug-overlay')
|
|
|
|
const optionsScrn = document.getElementById('options-screen')
|
|
|
|
const keyBindScrn = document.getElementById('keybinds-screen')
|
|
|
|
const gameMenu = document.getElementById('pause-screen')
|
|
|
|
|
|
|
|
const viewDistance = optionsScrn.renderDistance
|
2021-03-13 20:20:11 -05:00
|
|
|
const hostprompt = options.server
|
|
|
|
const proxyprompt = options.proxy
|
|
|
|
const username = options.username
|
|
|
|
const password = options.password
|
2021-03-03 19:39:21 -05:00
|
|
|
|
|
|
|
let host, port, proxy, proxyport
|
|
|
|
if (!hostprompt.includes(':')) {
|
|
|
|
host = hostprompt
|
|
|
|
port = 25565
|
|
|
|
} else {
|
|
|
|
[host, port] = hostprompt.split(':')
|
|
|
|
port = parseInt(port, 10)
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!proxyprompt.includes(':')) {
|
|
|
|
proxy = proxyprompt
|
|
|
|
proxyport = undefined
|
|
|
|
} else {
|
|
|
|
[proxy, proxyport] = proxyprompt.split(':')
|
|
|
|
proxyport = parseInt(proxyport, 10)
|
|
|
|
}
|
2021-02-27 17:12:11 -05:00
|
|
|
console.log(`connecting to ${host} ${port} with ${username}`)
|
|
|
|
|
2021-03-03 19:39:21 -05:00
|
|
|
if (proxy) {
|
|
|
|
console.log(`using proxy ${proxy} ${proxyport}`)
|
|
|
|
net.setProxy({ hostname: proxy, port: proxyport })
|
|
|
|
}
|
|
|
|
|
2021-03-14 13:24:09 -04:00
|
|
|
loadingScreen.status = 'Logging in'
|
2021-03-02 15:44:42 -05:00
|
|
|
|
2021-02-27 17:12:11 -05:00
|
|
|
const bot = mineflayer.createBot({
|
|
|
|
host,
|
|
|
|
port,
|
2021-12-24 15:02:11 -05:00
|
|
|
version: options.botVersion === '' ? false : options.botVersion,
|
2021-02-27 17:12:11 -05:00
|
|
|
username,
|
2021-03-12 20:35:07 -05:00
|
|
|
password,
|
2021-03-13 07:51:13 -05:00
|
|
|
viewDistance: 'tiny',
|
2021-03-12 20:51:45 -05:00
|
|
|
checkTimeoutInterval: 240 * 1000,
|
|
|
|
noPongTimeout: 240 * 1000,
|
|
|
|
closeTimeout: 240 * 1000
|
2021-02-27 17:12:11 -05:00
|
|
|
})
|
2023-03-04 13:04:46 -05:00
|
|
|
hud.preload(bot)
|
2021-02-27 17:12:11 -05:00
|
|
|
|
2021-03-07 13:32:41 -05:00
|
|
|
bot.on('error', (err) => {
|
|
|
|
console.log('Encountered error!', err)
|
2021-03-28 16:34:58 -04:00
|
|
|
loadingScreen.status = `Error encountered. Error message: ${err}. Please reload the page`
|
|
|
|
loadingScreen.style = 'display: block;'
|
2021-12-24 07:00:07 -05:00
|
|
|
loadingScreen.hasError = true
|
2021-03-02 15:44:42 -05:00
|
|
|
})
|
|
|
|
|
2021-03-12 20:27:03 -05:00
|
|
|
bot.on('kicked', (kickReason) => {
|
|
|
|
console.log('User was kicked!', kickReason)
|
2021-03-28 16:34:58 -04:00
|
|
|
loadingScreen.status = `The Minecraft server kicked you. Kick reason: ${kickReason}. Please reload the page to rejoin`
|
|
|
|
loadingScreen.style = 'display: block;'
|
2021-12-24 07:00:07 -05:00
|
|
|
loadingScreen.hasError = true
|
2021-03-02 15:44:42 -05:00
|
|
|
})
|
|
|
|
|
2021-03-12 20:27:03 -05:00
|
|
|
bot.on('end', (endReason) => {
|
|
|
|
console.log('disconnected for', endReason)
|
2021-03-28 16:34:58 -04:00
|
|
|
loadingScreen.status = `You have been disconnected from the server. End reason: ${endReason}. Please reload the page to rejoin`
|
|
|
|
loadingScreen.style = 'display: block;'
|
2021-12-24 07:00:07 -05:00
|
|
|
loadingScreen.hasError = true
|
2021-03-02 15:44:42 -05:00
|
|
|
})
|
2021-03-07 16:49:49 -05:00
|
|
|
|
2021-03-02 15:44:42 -05:00
|
|
|
bot.once('login', () => {
|
2021-04-04 10:43:43 -04:00
|
|
|
loadingScreen.status = 'Loading world'
|
2021-02-27 17:12:11 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
bot.once('spawn', () => {
|
2021-03-12 19:14:17 -05:00
|
|
|
const mcData = require('minecraft-data')(bot.version)
|
|
|
|
|
2021-12-24 07:00:07 -05:00
|
|
|
loadingScreen.status = 'Placing blocks (starting viewer)'
|
2021-03-02 15:44:42 -05:00
|
|
|
|
2021-02-27 17:12:11 -05:00
|
|
|
console.log('bot spawned - starting viewer')
|
|
|
|
|
|
|
|
const version = bot.version
|
|
|
|
|
|
|
|
const center = bot.entity.position
|
|
|
|
|
2021-12-24 07:00:07 -05:00
|
|
|
console.log(viewDistance)
|
2021-02-27 17:12:11 -05:00
|
|
|
const worldView = new WorldView(bot.world, viewDistance, center)
|
|
|
|
|
2021-04-06 07:31:02 -04:00
|
|
|
gameMenu.init(renderer)
|
2021-12-24 07:00:07 -05:00
|
|
|
optionsScrn.isInsideWorld = true
|
|
|
|
optionsScrn.addEventListener('fov_changed', (e) => {
|
|
|
|
viewer.camera.fov = e.detail.fov
|
|
|
|
viewer.camera.updateProjectionMatrix()
|
|
|
|
})
|
2021-02-27 18:18:58 -05:00
|
|
|
|
2021-02-27 17:12:11 -05:00
|
|
|
viewer.setVersion(version)
|
|
|
|
|
2021-03-12 19:14:17 -05:00
|
|
|
window.worldView = worldView
|
|
|
|
window.bot = bot
|
|
|
|
window.mcData = mcData
|
|
|
|
window.viewer = viewer
|
|
|
|
window.Vec3 = Vec3
|
|
|
|
window.pathfinder = pathfinder
|
2021-03-16 19:00:26 -04:00
|
|
|
window.debugMenu = debugMenu
|
2021-12-24 07:00:07 -05:00
|
|
|
window.settings = optionsScrn
|
2021-03-18 03:28:47 -04:00
|
|
|
window.renderer = renderer
|
2021-03-12 19:14:17 -05:00
|
|
|
|
2021-03-21 18:13:32 -04:00
|
|
|
initVR(bot, renderer, viewer)
|
|
|
|
|
2021-04-12 16:25:41 -04:00
|
|
|
const cursor = new Cursor(viewer, renderer, bot)
|
2021-03-23 21:23:02 -04:00
|
|
|
animate = () => {
|
|
|
|
window.requestAnimationFrame(animate)
|
|
|
|
viewer.update()
|
|
|
|
cursor.update(bot)
|
|
|
|
debugMenu.cursorBlock = cursor.cursorBlock
|
|
|
|
renderer.render(viewer.scene, viewer.camera)
|
|
|
|
}
|
|
|
|
|
2021-03-12 22:35:11 -05:00
|
|
|
// Link WorldView and Viewer
|
|
|
|
viewer.listen(worldView)
|
2021-02-27 17:12:11 -05:00
|
|
|
worldView.listenToBot(bot)
|
|
|
|
worldView.init(bot.entity.position)
|
|
|
|
|
2021-03-21 11:04:22 -04:00
|
|
|
// Bot position callback
|
2021-02-27 17:12:11 -05:00
|
|
|
function botPosition () {
|
|
|
|
viewer.setFirstPersonCamera(bot.entity.position, bot.entity.yaw, bot.entity.pitch)
|
|
|
|
worldView.updatePosition(bot.entity.position)
|
|
|
|
}
|
|
|
|
bot.on('move', botPosition)
|
2021-03-21 18:13:32 -04:00
|
|
|
botPosition()
|
2021-02-27 17:12:11 -05:00
|
|
|
|
2021-12-24 07:00:07 -05:00
|
|
|
loadingScreen.status = 'Setting callbacks'
|
2021-03-02 15:44:42 -05:00
|
|
|
|
2021-02-27 17:12:11 -05:00
|
|
|
function moveCallback (e) {
|
2021-12-24 07:00:07 -05:00
|
|
|
bot.entity.pitch -= e.movementY * optionsScrn.mouseSensitivityY * 0.0001
|
2021-02-28 14:02:22 -05:00
|
|
|
bot.entity.pitch = Math.max(minPitch, Math.min(maxPitch, bot.entity.pitch))
|
2021-12-24 07:00:07 -05:00
|
|
|
bot.entity.yaw -= e.movementX * optionsScrn.mouseSensitivityX * 0.0001
|
2021-02-28 14:02:22 -05:00
|
|
|
|
2021-03-01 18:44:41 -05:00
|
|
|
viewer.setFirstPersonCamera(null, bot.entity.yaw, bot.entity.pitch)
|
2021-02-27 17:12:11 -05:00
|
|
|
}
|
2021-03-01 19:00:57 -05:00
|
|
|
|
2021-02-27 17:12:11 -05:00
|
|
|
function changeCallback () {
|
|
|
|
if (document.pointerLockElement === renderer.domElement ||
|
|
|
|
document.mozPointerLockElement === renderer.domElement ||
|
|
|
|
document.webkitPointerLockElement === renderer.domElement) {
|
|
|
|
document.addEventListener('mousemove', moveCallback, false)
|
|
|
|
} else {
|
|
|
|
document.removeEventListener('mousemove', moveCallback, false)
|
|
|
|
}
|
|
|
|
}
|
2021-03-01 18:44:41 -05:00
|
|
|
|
2021-02-27 17:12:11 -05:00
|
|
|
document.addEventListener('pointerlockchange', changeCallback, false)
|
|
|
|
document.addEventListener('mozpointerlockchange', changeCallback, false)
|
|
|
|
document.addEventListener('webkitpointerlockchange', changeCallback, false)
|
2021-03-01 18:44:41 -05:00
|
|
|
|
2021-03-20 20:32:46 -04:00
|
|
|
let lastTouch
|
|
|
|
document.addEventListener('touchmove', (e) => {
|
2021-03-20 20:57:54 -04:00
|
|
|
window.scrollTo(0, 0)
|
2021-03-20 20:38:10 -04:00
|
|
|
e.preventDefault()
|
2021-03-20 20:57:54 -04:00
|
|
|
e.stopPropagation()
|
2021-03-20 20:32:46 -04:00
|
|
|
if (lastTouch !== undefined) {
|
|
|
|
moveCallback({ movementX: e.touches[0].pageX - lastTouch.pageX, movementY: e.touches[0].pageY - lastTouch.pageY })
|
|
|
|
}
|
|
|
|
lastTouch = e.touches[0]
|
2021-03-20 20:57:54 -04:00
|
|
|
}, { passive: false })
|
2021-03-20 20:32:46 -04:00
|
|
|
|
2021-03-21 20:28:26 -04:00
|
|
|
document.addEventListener('touchend', (e) => {
|
|
|
|
lastTouch = undefined
|
|
|
|
}, { passive: false })
|
|
|
|
|
2021-02-27 17:12:11 -05:00
|
|
|
renderer.domElement.requestPointerLock = renderer.domElement.requestPointerLock ||
|
|
|
|
renderer.domElement.mozRequestPointerLock ||
|
|
|
|
renderer.domElement.webkitRequestPointerLock
|
|
|
|
document.addEventListener('mousedown', (e) => {
|
2021-04-06 07:31:02 -04:00
|
|
|
if (!chat.inChat && !gameMenu.inMenu) {
|
|
|
|
renderer.domElement.requestPointerLock()
|
|
|
|
}
|
2021-02-27 17:12:11 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
document.addEventListener('contextmenu', (e) => e.preventDefault(), false)
|
2021-03-01 03:41:12 -05:00
|
|
|
|
2021-04-03 15:03:02 -04:00
|
|
|
window.addEventListener('blur', (e) => {
|
|
|
|
bot.clearControlStates()
|
|
|
|
}, false)
|
|
|
|
|
2021-02-27 17:12:11 -05:00
|
|
|
document.addEventListener('keydown', (e) => {
|
2021-03-01 23:06:51 -05:00
|
|
|
if (chat.inChat) return
|
2021-04-06 07:31:02 -04:00
|
|
|
if (gameMenu.inMenu) return
|
2021-12-24 07:00:07 -05:00
|
|
|
|
|
|
|
keyBindScrn.keymaps.forEach(km => {
|
|
|
|
if (e.code === km.key) {
|
|
|
|
switch (km.defaultKey) {
|
|
|
|
case 'KeyQ':
|
|
|
|
if (bot.heldItem) bot.tossStack(bot.heldItem)
|
|
|
|
break
|
|
|
|
case 'ControlLeft':
|
|
|
|
bot.setControlState('sprint', true)
|
|
|
|
break
|
|
|
|
case 'ShiftLeft':
|
|
|
|
bot.setControlState('sneak', true)
|
|
|
|
break
|
|
|
|
case 'Space':
|
|
|
|
bot.setControlState('jump', true)
|
|
|
|
break
|
|
|
|
case 'KeyD':
|
|
|
|
bot.setControlState('left', true)
|
|
|
|
break
|
|
|
|
case 'KeyA':
|
|
|
|
bot.setControlState('right', true)
|
|
|
|
break
|
|
|
|
case 'KeyS':
|
|
|
|
bot.setControlState('back', true)
|
|
|
|
break
|
|
|
|
case 'KeyW':
|
|
|
|
bot.setControlState('forward', true)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
2021-02-27 17:12:11 -05:00
|
|
|
}, false)
|
2021-03-01 03:41:12 -05:00
|
|
|
|
2021-02-27 17:12:11 -05:00
|
|
|
document.addEventListener('keyup', (e) => {
|
2021-12-24 07:00:07 -05:00
|
|
|
keyBindScrn.keymaps.forEach(km => {
|
|
|
|
if (e.code === km.key) {
|
|
|
|
switch (km.defaultKey) {
|
|
|
|
case 'ControlLeft':
|
|
|
|
bot.setControlState('sprint', false)
|
|
|
|
break
|
|
|
|
case 'ShiftLeft':
|
|
|
|
bot.setControlState('sneak', false)
|
|
|
|
break
|
|
|
|
case 'Space':
|
|
|
|
bot.setControlState('jump', false)
|
|
|
|
break
|
|
|
|
case 'KeyD':
|
|
|
|
bot.setControlState('left', false)
|
|
|
|
break
|
|
|
|
case 'KeyA':
|
|
|
|
bot.setControlState('right', false)
|
|
|
|
break
|
|
|
|
case 'KeyS':
|
|
|
|
bot.setControlState('back', false)
|
|
|
|
break
|
|
|
|
case 'KeyW':
|
|
|
|
bot.setControlState('forward', false)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
2021-02-27 17:12:11 -05:00
|
|
|
}, false)
|
2021-03-01 18:44:41 -05:00
|
|
|
|
2021-03-14 13:24:09 -04:00
|
|
|
loadingScreen.status = 'Done!'
|
|
|
|
console.log(loadingScreen.status) // only do that because it's read in index.html and npm run fix complains.
|
2021-03-02 15:44:42 -05:00
|
|
|
|
2021-12-24 07:00:07 -05:00
|
|
|
hud.init(renderer, bot, host)
|
|
|
|
hud.style.display = 'block'
|
|
|
|
|
2021-03-02 15:44:42 -05:00
|
|
|
setTimeout(function () {
|
|
|
|
// remove loading screen, wait a second to make sure a frame has properly rendered
|
2021-03-14 13:24:09 -04:00
|
|
|
loadingScreen.style = 'display: none;'
|
2021-03-02 15:44:42 -05:00
|
|
|
}, 2500)
|
2021-02-27 17:12:11 -05:00
|
|
|
})
|
2021-02-27 16:27:59 -05:00
|
|
|
}
|
2022-03-08 09:46:50 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param {URLSearchParams} params
|
|
|
|
*/
|
|
|
|
async function fromTheOutside (params, addr) {
|
|
|
|
const opts = {}
|
|
|
|
const dfltConfig = await (await window.fetch('config.json')).json()
|
|
|
|
|
|
|
|
let server, port, proxy, proxyPort
|
|
|
|
|
|
|
|
if (address.includes(':')) {
|
|
|
|
const s = address.split(':')
|
|
|
|
server = s[0]
|
|
|
|
port = Number(s[1]) || 25565
|
|
|
|
} else {
|
|
|
|
server = address
|
|
|
|
port = Number(params.get('port')) || 25565
|
|
|
|
}
|
|
|
|
|
|
|
|
const proxyAddr = params.get('proxy')
|
|
|
|
if (proxyAddr) {
|
|
|
|
const s = proxyAddr.split(':')
|
|
|
|
proxy = s[0]
|
|
|
|
proxyPort = Number(s[1] ?? 'NaN') || 22
|
|
|
|
} else {
|
|
|
|
proxy = dfltConfig.defaultProxy
|
|
|
|
proxyPort = !dfltConfig.defaultProxy && !dfltConfig.defaultProxyPort ? '' : dfltConfig.defaultProxyPort ?? 443
|
|
|
|
}
|
|
|
|
|
|
|
|
opts.server = `${server}:${port}`
|
|
|
|
opts.proxy = `${proxy}:${proxyPort}`
|
|
|
|
opts.username = params.get('username') ?? `pviewer${Math.floor(Math.random() * 1000)}`
|
|
|
|
opts.password = params.get('password') ?? ''
|
|
|
|
opts.botVersion = params.get('version') ?? false
|
|
|
|
|
|
|
|
console.log(opts)
|
|
|
|
|
|
|
|
showEl('loading-screen')
|
|
|
|
removePanorama()
|
|
|
|
connect(opts)
|
|
|
|
}
|
|
|
|
|
|
|
|
const params = new URLSearchParams(window.location.search)
|
|
|
|
let address
|
|
|
|
if ((address = params.get('address'))) {
|
|
|
|
fromTheOutside(params, address)
|
|
|
|
} else {
|
|
|
|
showEl('title-screen')
|
|
|
|
main()
|
|
|
|
}
|