//@ts-check import { renderToDom, ErrorBoundary } from '@zardoy/react-util' import { useSnapshot } from 'valtio' import { QRCodeSVG } from 'qrcode.react' import { createPortal } from 'react-dom' import { useEffect, useMemo, useState } from 'react' import { activeModalStack, miscUiState } from './globalState' import DeathScreenProvider from './react/DeathScreenProvider' import OptionsRenderApp from './react/OptionsRenderApp' import MainMenuRenderApp from './react/MainMenuRenderApp' import SingleplayerProvider from './react/SingleplayerProvider' import CreateWorldProvider from './react/CreateWorldProvider' import AppStatusProvider from './react/AppStatusProvider' import SelectOption from './react/SelectOption' import EnterFullscreenButton from './react/EnterFullscreenButton' import ChatProvider from './react/ChatProvider' import TitleProvider from './react/TitleProvider' import ScoreboardProvider from './react/ScoreboardProvider' import SignEditorProvider from './react/SignEditorProvider' import IndicatorEffectsProvider from './react/IndicatorEffectsProvider' import PlayerListOverlayProvider from './react/PlayerListOverlayProvider' import MinimapProvider, { DrawerAdapterImpl } from './react/MinimapProvider' import HudBarsProvider from './react/HudBarsProvider' import XPBarProvider from './react/XPBarProvider' import DebugOverlay from './react/DebugOverlay' import MobileTopButtons from './react/MobileTopButtons' import PauseScreen from './react/PauseScreen' import SoundMuffler from './react/SoundMuffler' import TouchControls from './react/TouchControls' import widgets from './react/widgets' import { useIsModalActive, useIsWidgetActive } from './react/utilsApp' import GlobalSearchInput from './react/GlobalSearchInput' import TouchAreasControlsProvider from './react/TouchAreasControlsProvider' import NotificationProvider, { showNotification } from './react/NotificationProvider' import HotbarRenderApp from './react/HotbarRenderApp' import Crosshair from './react/Crosshair' import ButtonAppProvider from './react/ButtonAppProvider' import ServersListProvider from './react/ServersListProvider' import GamepadUiCursor from './react/GamepadUiCursor' import KeybindingsScreenProvider from './react/KeybindingsScreenProvider' import HeldMapUi from './react/HeldMapUi' import BedTime from './react/BedTime' import NoModalFoundProvider from './react/NoModalFoundProvider' import SignInMessageProvider from './react/SignInMessageProvider' import BookProvider from './react/BookProvider' import { options } from './optionsStorage' import BossBarOverlayProvider from './react/BossBarOverlayProvider' import DebugEdges from './react/DebugEdges' import GameInteractionOverlay from './react/GameInteractionOverlay' import MineflayerPluginHud from './react/MineflayerPluginHud' import MineflayerPluginConsole from './react/MineflayerPluginConsole' import { UIProvider } from './react/UIProvider' import { useAppScale } from './scaleInterface' const RobustPortal = ({ children, to }) => { return createPortal({children}, to) } const DisplayQr = () => { const { currentDisplayQr } = useSnapshot(miscUiState) if (!currentDisplayQr) return null return
{ miscUiState.currentDisplayQr = null }} >
} // mounted earlier than ingame ui TODO const GameHud = ({ children }) => { const { loadedDataVersion } = useSnapshot(miscUiState) const [gameLoaded, setGameLoaded] = useState(false) useEffect(() => { customEvents.on('mineflayerBotCreated', () => { bot.once('inject_allowed', () => { setGameLoaded(true) }) }) }, []) useEffect(() => { if (!loadedDataVersion) setGameLoaded(false) }, [loadedDataVersion]) return gameLoaded ? children : null } const InGameComponent = ({ children }) => { const { gameLoaded } = useSnapshot(miscUiState) if (!gameLoaded) return null return children } // for Fullmap and Minimap in InGameUi let adapter: DrawerAdapterImpl const InGameUi = () => { const { gameLoaded, showUI: showUIRaw } = useSnapshot(miscUiState) const { disabledUiParts, displayBossBars, showMinimap } = useSnapshot(options) const modalsSnapshot = useSnapshot(activeModalStack) const hasModals = modalsSnapshot.length > 0 const showUI = showUIRaw || hasModals const displayFullmap = modalsSnapshot.some(modal => modal.reactType === 'full-map') || true // bot can't be used here if (!gameLoaded || !bot || disabledUiParts.includes('*')) return if (!adapter) adapter = new DrawerAdapterImpl(bot.entity.position) return <> {/* apply scaling */}
{!disabledUiParts.includes('death-screen') && } {!disabledUiParts.includes('debug-overlay') && } {!disabledUiParts.includes('mobile-top-buttons') && } {!disabledUiParts.includes('players-list') && } {!disabledUiParts.includes('chat') && } {showMinimap !== 'never' && } {!disabledUiParts.includes('title') && } {!disabledUiParts.includes('scoreboard') && } {!disabledUiParts.includes('effects-indicators') && } {!disabledUiParts.includes('crosshair') && } {!disabledUiParts.includes('books') && } {!disabledUiParts.includes('bossbars') && displayBossBars && }
{!disabledUiParts.includes('xp-bar') && } {!disabledUiParts.includes('hud-bars') && }
{showUI && !disabledUiParts.includes('hotbar') && }
{displayFullmap && } {/* because of z-index */} {showUI && } } const AllWidgets = () => { return widgets.map(widget => ) } const WidgetDisplay = ({ name, Component }) => { const isWidgetActive = useIsWidgetActive(name) if (!isWidgetActive) return null return } const App = () => { const scale = useAppScale() return (
) } const PerComponentErrorBoundary = ({ children }) => { return children.map((child, i) => { const componentNameClean = (child.type.name || child.type.displayName || 'Unknown').replaceAll(/__|_COMPONENT/g, '') showNotification(`UI component ${componentNameClean} crashed!`, 'Please report this. Use console for more.', true, undefined) return null }} > {child} ) } renderToDom(, { strictMode: false, selector: '#react-root', }) disableReactProfiling() function disableReactProfiling () { //@ts-expect-error window.performance.markOrig = window.performance.mark //@ts-expect-error window.performance.mark = (name, options) => { // ignore react internal marks if (!name.startsWith('⚛') && !localStorage.enableReactProfiling) { //@ts-expect-error window.performance.markOrig(name, options) } } }