@@ -13,6 +13,7 @@ import com.noxcrew.interfaces.pane.complete
13
13
import com.noxcrew.interfaces.properties.Trigger
14
14
import com.noxcrew.interfaces.transform.AppliedTransform
15
15
import com.noxcrew.interfaces.utilities.CollapsablePaneMap
16
+ import com.noxcrew.interfaces.utilities.forEachInGrid
16
17
import com.noxcrew.interfaces.utilities.runSync
17
18
import kotlinx.coroutines.launch
18
19
import kotlinx.coroutines.sync.Semaphore
@@ -266,6 +267,12 @@ public abstract class AbstractInterfaceView<I : InterfacesInventory, P : Pane>(
266
267
}
267
268
268
269
protected open fun drawPaneToInventory (drawNormalInventory : Boolean , drawPlayerInventory : Boolean ) {
270
+ // Determine all slots we need to clear if unused
271
+ val leftovers = mutableListOf<Pair <Int , Int >>()
272
+ forEachInGrid(backing.rows, COLUMNS_IN_CHEST ) { row, column ->
273
+ leftovers + = row to column
274
+ }
275
+
269
276
var madeChanges = false
270
277
pane.forEach { row, column, element ->
271
278
// We defer drawing of any elements in the player inventory itself
@@ -278,21 +285,35 @@ public abstract class AbstractInterfaceView<I : InterfacesInventory, P : Pane>(
278
285
column,
279
286
element.itemStack.apply { this ?.let { backing.properties.itemPostProcessor?.invoke(it) } }
280
287
)
288
+ leftovers - = row to column
281
289
madeChanges = true
282
290
}
283
291
284
292
// Apply the overlay of persistent items on top
285
293
if (backing.properties.persistAddedItems) {
286
294
for ((point, item) in addedItems) {
295
+ val row = point.x
296
+ val column = point.y
297
+ val isPlayerInventory = currentInventory.isPlayerInventory(row, column)
298
+ if ((! drawNormalInventory && ! isPlayerInventory) || (! drawPlayerInventory && isPlayerInventory)) continue
299
+
287
300
currentInventory.set(
288
- point.x ,
289
- point.y ,
301
+ row ,
302
+ column ,
290
303
item
291
304
)
305
+ leftovers - = row to column
292
306
madeChanges = true
293
307
}
294
308
}
295
309
310
+ // Empty any slots that are not otherwise edited
311
+ for ((row, column) in leftovers) {
312
+ val isPlayerInventory = currentInventory.isPlayerInventory(row, column)
313
+ if ((! drawNormalInventory && ! isPlayerInventory) || (! drawPlayerInventory && isPlayerInventory)) continue
314
+ currentInventory.set(row, column, ItemStack (Material .AIR ))
315
+ }
316
+
296
317
if (madeChanges) {
297
318
Bukkit .getPluginManager().callEvent(DrawPaneEvent (player, this , drawNormalInventory, drawPlayerInventory))
298
319
}
0 commit comments