Skip to content

Commit 4c55f59

Browse files
committed
Properly clear out slots
1 parent 95452a5 commit 4c55f59

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

interfaces/src/main/kotlin/com/noxcrew/interfaces/view/AbstractInterfaceView.kt

+23-2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import com.noxcrew.interfaces.pane.complete
1313
import com.noxcrew.interfaces.properties.Trigger
1414
import com.noxcrew.interfaces.transform.AppliedTransform
1515
import com.noxcrew.interfaces.utilities.CollapsablePaneMap
16+
import com.noxcrew.interfaces.utilities.forEachInGrid
1617
import com.noxcrew.interfaces.utilities.runSync
1718
import kotlinx.coroutines.launch
1819
import kotlinx.coroutines.sync.Semaphore
@@ -266,6 +267,12 @@ public abstract class AbstractInterfaceView<I : InterfacesInventory, P : Pane>(
266267
}
267268

268269
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+
269276
var madeChanges = false
270277
pane.forEach { row, column, element ->
271278
// We defer drawing of any elements in the player inventory itself
@@ -278,21 +285,35 @@ public abstract class AbstractInterfaceView<I : InterfacesInventory, P : Pane>(
278285
column,
279286
element.itemStack.apply { this?.let { backing.properties.itemPostProcessor?.invoke(it) } }
280287
)
288+
leftovers -= row to column
281289
madeChanges = true
282290
}
283291

284292
// Apply the overlay of persistent items on top
285293
if (backing.properties.persistAddedItems) {
286294
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+
287300
currentInventory.set(
288-
point.x,
289-
point.y,
301+
row,
302+
column,
290303
item
291304
)
305+
leftovers -= row to column
292306
madeChanges = true
293307
}
294308
}
295309

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+
296317
if (madeChanges) {
297318
Bukkit.getPluginManager().callEvent(DrawPaneEvent(player, this, drawNormalInventory, drawPlayerInventory))
298319
}

0 commit comments

Comments
 (0)