Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release #312

Merged
merged 14 commits into from
Mar 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
"mojangson": "^2.0.4",
"net-browserify": "github:zardoy/prismarinejs-net-browserify",
"node-gzip": "^1.1.2",
"mcraft-fun-mineflayer": "^0.1.12",
"mcraft-fun-mineflayer": "^0.1.14",
"peerjs": "^1.5.0",
"pixelarticons": "^1.8.1",
"pretty-bytes": "^6.1.1",
Expand Down Expand Up @@ -151,7 +151,7 @@
"http-server": "^14.1.1",
"https-browserify": "^1.0.0",
"mc-assets": "^0.2.42",
"mineflayer-mouse": "^0.1.1",
"mineflayer-mouse": "^0.1.2",
"minecraft-inventory-gui": "github:zardoy/minecraft-inventory-gui#next",
"mineflayer": "github:zardoy/mineflayer",
"mineflayer-pathfinder": "^2.4.4",
Expand Down
57 changes: 44 additions & 13 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/api/mcStatusApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const isServerValid = (ip: string) => {
return !isInLocalNetwork && VALID_IP_OR_DOMAIN
}

export async function fetchServerStatus (ip: string, signal?: AbortSignal) {
export async function fetchServerStatus (ip: string, signal?: AbortSignal, versionOverride?: string) {
if (!isServerValid(ip)) return

const response = await fetch(`https://api.mcstatus.io/v2/status/java/${ip}`, { signal })
Expand All @@ -25,7 +25,7 @@ export async function fetchServerStatus (ip: string, signal?: AbortSignal) {
return {
formattedText: data.motd?.raw ?? '',
textNameRight: data.online ?
`${versionClean} ${data.players?.online ?? '??'}/${data.players?.max ?? '??'}` :
`${versionOverride ?? versionClean} ${data.players?.online ?? '??'}/${data.players?.max ?? '??'}` :
'',
icon: data.icon,
offline: !data.online,
Expand Down
3 changes: 3 additions & 0 deletions src/appConfig.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { disabledSettings, options, qsOptions } from './optionsStorage'
import { miscUiState } from './globalState'
import { setLoadingScreenStatus } from './appStatus'
import { setStorageDataOnAppConfigLoad } from './react/appStorageProvider'

export type AppConfig = {
// defaultHost?: string
Expand Down Expand Up @@ -42,6 +43,8 @@ export const loadAppConfig = (appConfig: AppConfig) => {
}
}
}

setStorageDataOnAppConfigLoad()
}

export const isBundledConfigUsed = !!process.env.INLINED_APP_CONFIG
Expand Down
5 changes: 3 additions & 2 deletions src/appParams.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { AppConfig } from './appConfig'
import { miscUiState } from './globalState'

const qsParams = new URLSearchParams(window.location?.search ?? '')

Expand Down Expand Up @@ -73,7 +74,7 @@ export const appQueryParams = new Proxy<AppQsParams>({} as AppQsParams, {
}
const qsParam = qsParams.get(property)
if (qsParam) return qsParam
return initialAppConfig.appParams?.[property]
return miscUiState.appConfig?.appParams?.[property]
},
})

Expand All @@ -84,7 +85,7 @@ export const appQueryParamsArray = new Proxy({} as AppQsParamsArrayTransformed,
}
const qsParam = qsParams.getAll(property)
if (qsParam.length) return qsParam
return initialAppConfig.appParams?.[property] ?? []
return miscUiState.appConfig?.appParams?.[property] ?? []
},
})

Expand Down
20 changes: 5 additions & 15 deletions src/browserfs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { getFixedFilesize } from './downloadAndOpenFile'
import { packetsReplayState } from './react/state/packetsReplayState'
import { createFullScreenProgressReporter } from './core/progressReporter'
import { showNotification } from './react/NotificationProvider'
import { resetAppStorage } from './react/appStorageProvider'
const { GoogleDriveFileSystem } = require('google-drive-browserfs/src/backends/GoogleDrive')

browserfs.install(window)
Expand Down Expand Up @@ -620,24 +621,13 @@ export const openWorldZip = async (...args: Parameters<typeof openWorldZipInner>
}
}

export const resetLocalStorageWorld = () => {
for (const key of Object.keys(localStorage)) {
if (/^[\da-fA-F]{8}(?:\b-[\da-fA-F]{4}){3}\b-[\da-fA-F]{12}$/g.test(key) || key === '/') {
localStorage.removeItem(key)
}
}
}

export const resetLocalStorageWithoutWorld = () => {
for (const key of Object.keys(localStorage)) {
if (!/^[\da-fA-F]{8}(?:\b-[\da-fA-F]{4}){3}\b-[\da-fA-F]{12}$/g.test(key) && key !== '/') {
localStorage.removeItem(key)
}
}
export const resetLocalStorage = () => {
resetOptions()
resetAppStorage()
}

window.resetLocalStorageWorld = resetLocalStorageWorld
window.resetLocalStorage = resetLocalStorage

export const openFilePicker = (specificCase?: 'resourcepack') => {
// create and show input picker
let picker: HTMLInputElement = document.body.querySelector('input#file-zip-picker')!
Expand Down
24 changes: 17 additions & 7 deletions src/controls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { ControMax } from 'contro-max/build/controMax'
import { CommandEventArgument, SchemaCommandInput } from 'contro-max/build/types'
import { stringStartsWith } from 'contro-max/build/stringUtils'
import { UserOverrideCommand, UserOverridesConfig } from 'contro-max/build/types/store'
import { GameMode } from 'mineflayer'
import { isGameActive, showModal, gameAdditionalState, activeModalStack, hideCurrentModal, miscUiState, hideModal, hideAllModals } from './globalState'
import { goFullscreen, isInRealGameSession, pointerLock, reloadChunks } from './utils'
import { options } from './optionsStorage'
Expand All @@ -25,11 +26,13 @@ import { showNotification } from './react/NotificationProvider'
import { lastConnectOptions } from './react/AppStatusProvider'
import { onCameraMove, onControInit } from './cameraRotationControls'
import { createNotificationProgressReporter } from './core/progressReporter'
import { appStorage } from './react/appStorageProvider'
import { switchGameMode } from './packetsReplay/replayPackets'


export const customKeymaps = proxy(JSON.parse(localStorage.keymap || '{}')) as UserOverridesConfig
export const customKeymaps = proxy(appStorage.keybindings)
subscribe(customKeymaps, () => {
localStorage.keymap = JSON.stringify(customKeymaps)
appStorage.keybindings = customKeymaps
})

const controlOptions = {
Expand Down Expand Up @@ -636,29 +639,35 @@ export const f3Keybinds: Array<{
{
key: 'F4',
async action () {
let nextGameMode: GameMode
switch (bot.game.gameMode) {
case 'creative': {
bot.chat('/gamemode survival')
nextGameMode = 'survival'

break
}
case 'survival': {
bot.chat('/gamemode adventure')
nextGameMode = 'adventure'

break
}
case 'adventure': {
bot.chat('/gamemode spectator')
nextGameMode = 'spectator'

break
}
case 'spectator': {
bot.chat('/gamemode creative')
nextGameMode = 'creative'

break
}
// No default
}
if (lastConnectOptions.value?.worldStateFileContents) {
switchGameMode(nextGameMode)
} else {
bot.chat(`/gamemode ${nextGameMode}`)
}
},
mobileTitle: 'Cycle Game Mode'
},
Expand Down Expand Up @@ -809,15 +818,16 @@ let allowFlying = false
export const onBotCreate = () => {
let wasSpectatorFlying = false
bot._client.on('abilities', ({ flags }) => {
allowFlying = !!(flags & 4)
if (flags & 2) { // flying
toggleFly(true, false)
} else {
toggleFly(false, false)
}
allowFlying = !!(flags & 4)
})
const gamemodeCheck = () => {
if (bot.game.gameMode === 'spectator') {
allowFlying = true
toggleFly(true, false)
wasSpectatorFlying = true
} else if (wasSpectatorFlying) {
Expand Down
34 changes: 32 additions & 2 deletions src/downloadAndOpenFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,43 @@ export const getFixedFilesize = (bytes: number) => {
const inner = async () => {
const { replayFileUrl } = appQueryParams
if (replayFileUrl) {
setLoadingScreenStatus('Downloading replay file...')
setLoadingScreenStatus('Downloading replay file')
const response = await fetch(replayFileUrl)
const contentLength = response.headers?.get('Content-Length')
const size = contentLength ? +contentLength : undefined
const filename = replayFileUrl.split('/').pop()

const contents = await response.text()
let downloadedBytes = 0
const buffer = await new Response(new ReadableStream({
async start (controller) {
if (!response.body) throw new Error('Server returned no response!')
const reader = response.body.getReader()

// eslint-disable-next-line no-constant-condition
while (true) {
const { done, value } = await reader.read()

if (done) {
controller.close()
break
}

downloadedBytes += value.byteLength

// Calculate download progress as a percentage
const progress = size ? (downloadedBytes / size) * 100 : undefined
setLoadingScreenStatus(`Download replay file progress: ${progress === undefined ? '?' : Math.floor(progress)}% (${getFixedFilesize(downloadedBytes)} / ${size && getFixedFilesize(size)})`, false, true)

// Pass the received data to the controller
controller.enqueue(value)
}
},
})).arrayBuffer()

// Convert buffer to text, handling any compression automatically
const decoder = new TextDecoder()
const contents = decoder.decode(buffer)

openFile({
contents,
filename,
Expand Down
7 changes: 1 addition & 6 deletions src/globalState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,12 @@
import { proxy, ref, subscribe } from 'valtio'
import type { WorldWarp } from 'flying-squid/dist/lib/modules/warps'
import type { OptionsGroupType } from './optionsGuiScheme'
import { appQueryParams } from './appParams'
import { options, disabledSettings } from './optionsStorage'
import { AppConfig } from './appConfig'

// todo: refactor structure with support of hideNext=false

const notHideableModalsWithoutForce = new Set(['app-status'])

if (appQueryParams.lockConnect) {
notHideableModalsWithoutForce.add('editServer')
}
export const notHideableModalsWithoutForce = new Set(['app-status'])

type Modal = ({ elem?: HTMLElement & Record<string, any> } & { reactType: string })

Expand Down
2 changes: 1 addition & 1 deletion src/globals.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ declare const customEvents: import('typed-emitter').default<{
mineflayerBotCreated (): void
search (q: string): void
activateItem (item: Item, slot: number, offhand: boolean): void
hurtAnimation (): void
hurtAnimation (yaw?: number): void
}>
declare const beforeRenderFrame: Array<() => void>

Expand Down
Loading
Loading