diff --git a/index.html b/index.html index c599e9a..6cdd82d 100644 --- a/index.html +++ b/index.html @@ -51,10 +51,10 @@ .chat { overflow: hidden; color: white; - font-size: 32px; + font-size: 16px; margin: 0px; line-height: 100%; - text-shadow: 4px 4px 0px #3f3f3f; + text-shadow: 2px 2px 0px #3f3f3f; font-family: mojangles, minecraft, monospace; width: 100%; max-height: calc(90px * 8) @@ -83,7 +83,7 @@ } - +
diff --git a/index.js b/index.js index 0815772..de4547e 100644 --- a/index.js +++ b/index.js @@ -7,7 +7,7 @@ const mineflayer = require('mineflayer') const { WorldView, Viewer } = require('prismarine-viewer/viewer') const Vec3 = require('vec3').Vec3 global.THREE = require('three') -const chat = require('./lib/chat') +const Chat = require('./lib/chat') const maxPitch = 0.5 * Math.PI const minPitch = -0.5 * Math.PI @@ -47,7 +47,7 @@ async function main () { renderer.setSize(window.innerWidth, window.innerHeight) document.body.appendChild(renderer.domElement) - chat.init(undefined, bot._client, renderer) + const chat = Chat.init(bot._client, renderer) // Create viewer const viewer = new Viewer(renderer) @@ -109,8 +109,8 @@ async function main () { } document.addEventListener('keydown', (e) => { + if (chat.inChat) return console.log(e.code) - if (e.code in codes) { bot.setControlState(codes[e.code], true) } @@ -127,7 +127,7 @@ async function main () { if (!ButtonBlock) return if (e.button === 0) { if (bot.canDigBlock(ButtonBlock)) { - bot.dig(ButtonBlock) + bot.dig(ButtonBlock, 'ignore') } } else if (e.button === 2) { const vecArray = [new Vec3(0, -1, 0), new Vec3(0, 1, 0), new Vec3(0, 0, -1), new Vec3(0, 0, 1), new Vec3(-1, 0, 0), new Vec3(1, 0, 0)] diff --git a/lib/chat.js b/lib/chat.js index 4dbf54c..6cb196b 100644 --- a/lib/chat.js +++ b/lib/chat.js @@ -33,7 +33,7 @@ const dictionary = { 'chat.type.text': '<%s> %s' } -export function init (mineweb, client, renderer) { +export function init (client, renderer) { const chat = document.querySelector('#chat') const chatInput = document.querySelector('#chatinput') @@ -47,10 +47,13 @@ export function init (mineweb, client, renderer) { // Show chat chat.style.display = 'block' - let inChat = false + const chatState = { + inChat: false + } + // Esc event - Doesnt work with onkeypress?! document.onkeydown = function (e) { - if (!inChat) return + if (!chatState.inChat) return e = e || window.event if (e.keyCode === 27 || e.key === 'Escape' || e.key === 'Esc') { disableChat() @@ -66,7 +69,7 @@ export function init (mineweb, client, renderer) { // Chat events document.onkeypress = function (e) { e = e || window.event - if (inChat === false) { + if (chatState.inChat === false) { if (e.code === 'KeyT') { enableChat(false) } @@ -77,13 +80,11 @@ export function init (mineweb, client, renderer) { return false } - if (!inChat) return + if (!chatState.inChat) return e.stopPropagation() if (e.code === 'Enter') { chatHistory.push(chatInput.value) - /* TODO: mineweb._client */ client.write('chat', { - message: chatInput.value - }) + client.write('chat', { message: chatInput.value }) disableChat() } } @@ -95,13 +96,13 @@ export function init (mineweb, client, renderer) { document.mozPointerLockElement === canvas ) { // Someone focused the game back so we hide chat. - inChat = false; + chatState.inChat = false; hideChat(); } }); */ function enableChat (isCommand) { // Set inChat value - inChat = true + chatState.inChat = true // Exit the pointer lock document.exitPointerLock() // Show chat input @@ -114,25 +115,19 @@ export function init (mineweb, client, renderer) { } // Focus element chatInput.focus() - // Disable controls - // mineweb._noa.inputs.disabled = true; chatHistoryPos = chatHistory.length } + function disableChat () { // Set inChat value - inChat = false + chatState.inChat = false + // Hide chat hideChat() renderer.domElement.requestPointerLock() - // Enable controls - // mineweb._noa.inputs.disabled = false; - // Focus noa again - /* const canvas = document.getElementById("noa-canvas"); - canvas.requestPointerLock = - canvas.requestPointerLock || canvas.mozRequestPointerLock; - canvas.requestPointerLock(); */ } + function hideChat () { // Clear chat input chatInput.value = '' @@ -166,8 +161,8 @@ export function init (mineweb, client, renderer) { } return shouldReturn } - // Client part - /* TODO: mineweb._client */ client.on('chat', function (packet) { + + client.on('chat', (packet) => { // Reading of chat message const fullmessage = JSON.parse(packet.message.toString()) let msglist = [] @@ -223,4 +218,8 @@ export function init (mineweb, client, renderer) { chat.appendChild(li) chat.scrollTop = chat.scrollHeight // Stay bottom of the list }) + + hideChat() + + return chatState }