diff --git a/src/index.ts b/src/index.ts index 1797c894..89baaa10 100644 --- a/src/index.ts +++ b/src/index.ts @@ -142,24 +142,35 @@ new THREE.TextureLoader().load(itemsPng, (texture) => { viewer.entities.itemsTexture = texture // todo unify viewer.entities.getItemUv = (id) => { - const name = loadedData.items[id]?.name - const uv = itemsAtlases.latest.textures[name] - if (!uv) { - const variant = viewer.world.downloadedBlockStatesData[name]?.variants?.[''] - if (!variant) return - const uvBlock = (Array.isArray(variant) ? variant[0] : variant).model?.elements?.[0]?.faces?.north.texture - if (!uvBlock) return + try { + const name = loadedData.items[id]?.name + const uv = itemsAtlases.latest.textures[name] + if (!uv) { + const variant = viewer.world.downloadedBlockStatesData[name]?.variants?.[''] + if (!variant) return + const faces = (Array.isArray(variant) ? variant[0] : variant).model?.elements?.[0]?.faces + const uvBlock = faces?.north?.texture ?? faces?.up?.texture ?? faces?.down?.texture ?? faces?.west?.texture ?? faces?.east?.texture ?? faces?.south?.texture + if (!uvBlock) return + return { + ...uvBlock, + size: Math.abs(uvBlock.su), + texture: viewer.world.material.map + } + } return { - ...uvBlock, - size: Math.abs(uvBlock.su), + ...uv, + size: itemsAtlases.latest.size, + texture: viewer.entities.itemsTexture + } + } catch (err) { + reportError?.(err) + return { + u: 0, + v: 0, + size: 16 / viewer.world.material.map!.image.width, texture: viewer.world.material.map } } - return { - ...uv, - size: itemsAtlases.latest.size, - texture: viewer.entities.itemsTexture - } } }) viewer.entities.entitiesOptions = { diff --git a/src/react/ChatProvider.tsx b/src/react/ChatProvider.tsx index 0322c60f..ad4a705d 100644 --- a/src/react/ChatProvider.tsx +++ b/src/react/ChatProvider.tsx @@ -74,7 +74,7 @@ export default () => { if (items[0].match) items = items.map(i => i.match) } if (completeValue === '/') { - if (!items[0].startsWith('/')) { + if (!items[0]?.startsWith('/')) { // normalize items = items.map(item => `/${item}`) }