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

View File

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