diff --git a/src/main/kotlin/ru/dbotthepony/kstarbound/collect/IdMap.kt b/src/main/kotlin/ru/dbotthepony/kstarbound/collect/IdMap.kt index 820cc0d8..a77f9472 100644 --- a/src/main/kotlin/ru/dbotthepony/kstarbound/collect/IdMap.kt +++ b/src/main/kotlin/ru/dbotthepony/kstarbound/collect/IdMap.kt @@ -19,7 +19,7 @@ class IdMap(val min: Int = 0, val max: Int = Int.MAX_VALUE, private val return nextIndex } - fun add(value: T): Int { + fun nextFreeIndex(): Int { var i = 0 var index = next() @@ -41,6 +41,11 @@ class IdMap(val min: Int = 0, val max: Int = Int.MAX_VALUE, private val } } + return index + } + + fun add(value: T): Int { + val index = nextFreeIndex() map[index] = value return index }