fix: Fix crash in getItemUv function. now dropped items are always displayed

This commit is contained in:
Vitaly Turovsky 2024-05-24 04:19:33 +03:00
commit 1de6ae8f2c
2 changed files with 26 additions and 15 deletions

View file

@ -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 = {

View file

@ -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}`)
}