This commit is contained in:
DBotThePony 2024-01-05 22:59:33 +07:00
commit e51ba7015a
Signed by: DBot
GPG Key ID: DCC23B5715498507

View File

@ -22,8 +22,8 @@ import kotlin.reflect.KProperty
/**
* DeferredRegister which allows parallel initialization
*/
class MDeferredRegister<R : Any>(val registry: ResourceKey<out Registry<R>>, val modId: String = OverdriveThatMatters.MOD_ID) {
constructor(registry: IForgeRegistry<R>, modId: String = OverdriveThatMatters.MOD_ID) : this(registry.registryKey, modId)
class MDeferredRegister<R : Any>(val registry: ResourceKey<out Registry<R>>, val modId: String = OverdriveThatMatters.MOD_ID, val allowParallel: Boolean = false) {
constructor(registry: IForgeRegistry<R>, modId: String = OverdriveThatMatters.MOD_ID, allowParallel: Boolean = false) : this(registry.registryKey, modId, allowParallel)
private val entries = Object2ObjectLinkedOpenHashMap<String, Entry<R>>()
private var allowRegistration = true
@ -74,8 +74,10 @@ class MDeferredRegister<R : Any>(val registry: ResourceKey<out Registry<R>>, val
check(allowRegistration) { "Unable to register new entries after RegisterEvent has been fired" }
require(entries.put(name, this) == null) { "Duplicate entry $name for registry $registry" }
if (stages.isEmpty() || stages.last().serial != serial) {
val stage = RegistrationStage(serial)
val actualSerial = if (allowParallel) serial else true
if (stages.isEmpty() || stages.last().serial != actualSerial) {
val stage = RegistrationStage(actualSerial)
stage.add(this)
stages.add(stage)
} else {