Skip to content

Commit

Permalink
Merge branch 'next' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
zardoy committed Jun 30, 2024
2 parents 0d20c70 + 74c5518 commit 6a21596
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
12 changes: 10 additions & 2 deletions src/inventoryWindows.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { subscribe } from 'valtio'
import { proxy, subscribe } from 'valtio'
import { showInventory } from 'minecraft-inventory-gui/web/ext.mjs'
import InventoryGui from 'minecraft-assets/minecraft-assets/data/1.17.1/gui/container/inventory.png'
import ChestLikeGui from 'minecraft-assets/minecraft-assets/data/1.17.1/gui/container/shulker_box.png'
Expand Down Expand Up @@ -66,11 +66,19 @@ let version: string
let PrismarineBlock: typeof PrismarineBlockLoader.Block
let PrismarineItem: typeof Item

export const allImagesLoadedState = proxy({
value: false
})

export const onGameLoad = (onLoad) => {
allImagesLoadedState.value = false
let loaded = 0
const onImageLoaded = () => {
loaded++
if (loaded === 3) onLoad?.()
if (loaded === 3) {
onLoad?.()
allImagesLoadedState.value = true
}
}
version = bot.version
getImage({ path: 'invsprite' }, onImageLoaded)
Expand Down
4 changes: 2 additions & 2 deletions src/localServerMultiplayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ export const connectToPeer = async (peerId: string) => {
}))

const clientDuplex = new CustomDuplex({}, (data) => {
// todo rm debug
console.debug('sending', data.toString())
// todo debug until play state
// console.debug('sending', data.toString())
connection.send(data)
})
connection.on('data', (data: any) => {
Expand Down
10 changes: 7 additions & 3 deletions src/react/HotbarRenderApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { useEffect, useRef, useState } from 'react'
import { Transition } from 'react-transition-group'
import { createPortal } from 'react-dom'
import { subscribe, useSnapshot } from 'valtio'
import { getItemNameRaw, openItemsCanvas, openPlayerInventory, upInventoryItems } from '../inventoryWindows'
import { allImagesLoadedState, getItemNameRaw, openItemsCanvas, openPlayerInventory, upInventoryItems } from '../inventoryWindows'
import { activeModalStack, isGameActive, miscUiState } from '../globalState'
import { currentScaling } from '../scaleInterface'
import { watchUnloadForCleanup } from '../gameUnload'
Expand All @@ -19,7 +19,7 @@ const ItemName = ({ itemKey }: { itemKey: string }) => {

const defaultStyle: React.CSSProperties = {
position: 'fixed',
bottom: `calc(env(safe-area-inset-bottom) + ${bot ? bot.game.gameMode === 'creative' ? '35px' : '50px' : '50px'})`,
bottom: `calc(env(safe-area-inset-bottom) + ${bot ? bot.game.gameMode === 'creative' ? '40px' : '50px' : '50px'})`,
left: 0,
right: 0,
fontSize: 10,
Expand Down Expand Up @@ -111,7 +111,7 @@ export default () => {
inv.canvas.style.pointerEvents = 'auto'
container.current.appendChild(inv.canvas)
const upHotbarItems = () => {
if (!viewer.world.downloadedTextureImage || !viewer.world.customTexturesDataUrl) return
if (!viewer.world.downloadedTextureImage || !viewer.world.downloadedBlockStatesData || !allImagesLoadedState.value) return
upInventoryItems(true, inv)
}

Expand All @@ -127,6 +127,9 @@ export default () => {
bot.inventory.on('updateSlot', upHotbarItems)
viewer.world.renderUpdateEmitter.on('textureDownloaded', upHotbarItems)
viewer.world.renderUpdateEmitter.on('blockStatesDownloaded', upHotbarItems)
const unsub2 = subscribe(allImagesLoadedState, () => {
upHotbarItems()
})

const setSelectedSlot = (index: number) => {
if (index === bot.quickBarSlot) return
Expand Down Expand Up @@ -195,6 +198,7 @@ export default () => {
return () => {
inv.destroy()
controller.abort()
unsub2()
viewer.world.renderUpdateEmitter.off('textureDownloaded', upHotbarItems)
viewer.world.renderUpdateEmitter.off('blockStatesDownloaded', upHotbarItems)
}
Expand Down

0 comments on commit 6a21596

Please sign in to comment.