Skip to content

Commit fec887c

Browse files
committed
deeply stringify gui items to avoid futher modifications
1 parent 369166e commit fec887c

File tree

2 files changed

+24
-15
lines changed

2 files changed

+24
-15
lines changed

pnpm-lock.yaml

Lines changed: 13 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/inventoryWindows.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,9 @@ const getImage = ({ path = undefined as string | undefined, texture = undefined
159159
if (image) {
160160
return image
161161
}
162-
if (!path && !texture) throw new Error('Either pass path or texture')
162+
if (!path && !texture) {
163+
throw new Error('Either pass path or texture')
164+
}
163165
const loadPath = (blockData ? 'blocks' : path ?? texture)!
164166
if (loadedImagesCache.has(loadPath)) {
165167
onLoad()
@@ -201,6 +203,11 @@ const itemToVisualKey = (slot: RenderItem | Item | null) => {
201203
].join('|')
202204
return keys
203205
}
206+
const validateSlot = (slot: any, index: number) => {
207+
if (!slot.texture) {
208+
throw new Error(`Slot has no texture: ${index} ${slot.name}`)
209+
}
210+
}
204211
const mapSlots = (slots: Array<RenderItem | Item | null>, isJei = false) => {
205212
const newSlots = slots.map((slot, i) => {
206213
if (!slot) return null
@@ -210,6 +217,7 @@ const mapSlots = (slots: Array<RenderItem | Item | null>, isJei = false) => {
210217
const newKey = itemToVisualKey(slot)
211218
slot['cacheKey'] = i + '|' + newKey
212219
if (oldKey && oldKey === newKey) {
220+
validateSlot(lastMappedSlots[i], i)
213221
return lastMappedSlots[i]
214222
}
215223
}
@@ -228,12 +236,13 @@ const mapSlots = (slots: Array<RenderItem | Item | null>, isJei = false) => {
228236
const { icon, ...rest } = slot
229237
return rest
230238
}
239+
validateSlot(slot, i)
231240
} catch (err) {
232241
inGameError(err)
233242
}
234243
return slot
235244
})
236-
lastMappedSlots = newSlots
245+
lastMappedSlots = JSON.parse(JSON.stringify(newSlots))
237246
return newSlots
238247
}
239248

0 commit comments

Comments
 (0)