Add IEnhancedContainer specific optimization

This commit is contained in:
DBotThePony 2025-03-23 01:28:06 +07:00
parent 65bbc56014
commit 9f8e7693a8
Signed by: DBot
GPG Key ID: DCC23B5715498507

View File

@ -9,6 +9,7 @@ import net.minecraft.world.item.ItemStack
import net.minecraft.world.level.storage.loot.LootParams
import net.minecraft.world.level.storage.loot.LootTable
import org.apache.logging.log4j.LogManager
import ru.dbotthepony.mc.otm.container.IEnhancedContainer
import ru.dbotthepony.mc.otm.container.get
import ru.dbotthepony.mc.otm.container.set
import ru.dbotthepony.mc.otm.core.isNotEmpty
@ -105,9 +106,14 @@ private fun shuffle(items: MutableList<ItemStack>, emptySlotCount: Int, random:
fun LootTable.fill(params: LootParams, random: RandomSource, container: Container, rounds: Int = 1) {
val emptySlots = IntArrayList()
for (i in 0 until container.containerSize)
if (container[i].isEmpty)
if (container is IEnhancedContainer<*>) {
for (i in container.emptySlotIndexIterator())
emptySlots.add(i)
} else {
for (i in 0 until container.containerSize)
if (container[i].isEmpty)
emptySlots.add(i)
}
emptySlots.shuffle(random)