const { LitElement, html, css } = require('lit-element') class DebugMenu extends LitElement { constructor () { super() this.isOpen = false this.customEntries = {} } firstUpdated () { document.addEventListener('keydown', e => { e ??= window.event if (e.key === 'F3') { this.isOpen = !this.isOpen e.preventDefault() } }) } static get styles () { return css` .debugmenu-wrapper { position: fixed; z-index:25; } .debugmenu { overflow: hidden; color: white; font-size: 16px; margin: 0px; line-height: 100%; text-shadow: 2px 2px 0px #3f3f3f; font-family: mojangles, minecraft, monospace; width: calc(320px * 4); max-height: calc(90px * 8); top: calc(8px * 16); padding: 4px; } .debugmenu p { margin: 0px; padding: 1px; width: fit-content; background-color: rgba(0, 0, 0, 0.5); } ` } static get properties () { return { isOpen: { type: Boolean }, cursorBlock: { type: Object }, bot: { type: Object }, customEntries: { type: Object } } } updated (changedProperties) { if (changedProperties.has('bot')) { this.bot.on('move', () => { this.requestUpdate() }) } } render () { if (!this.isOpen) { return html`` } const target = this.cursorBlock const targetDiggable = (target && this.bot.canDigBlock(target)) const pos = this.bot.entity.position const rot = [this.bot.entity.yaw, this.bot.entity.pitch] const viewDegToMinecraft = (yaw) => { return yaw % 360 - 180 * (yaw < 0 ? -1 : 1) } const quadsDescription = [ 'north (towards negative Z)', 'east (towards positive X)', 'south (towards positive Z)', 'west (towards negative X)' ] const minecraftYaw = viewDegToMinecraft(rot[0] * -180 / Math.PI) const minecraftQuad = Math.floor(((minecraftYaw + 180) / 90 + 0.5) % 4) const renderProp = (name, value, nextItem) => { return html`${name}: ${typeof value === 'boolean' ? html`${value}` : value}${nextItem ? ' / ' : ''}` } return html`
` } } window.customElements.define('debug-menu', DebugMenu)