fix: Fix crash in getItemUv function. now dropped items are always displayed
This commit is contained in:
parent
c1d7d7c33f
commit
1de6ae8f2c
2 changed files with 26 additions and 15 deletions
39
src/index.ts
39
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 = {
|
||||
|
|
|
|||
|
|
@ -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}`)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue