Skip to content

Commit afffdce

Browse files
committed
Merge pull request #32 from Avanatiker/28-120x-121x-forge-neoforge-cannot-use-locked-vanilla-registries-urgent
[1.20.x, 1.21.x] [Forge, NeoForge] Cannot use locked vanilla registries
1 parent 8cf14fb commit afffdce

File tree

14 files changed

+130
-16
lines changed

14 files changed

+130
-16
lines changed
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package com.lambda.core
22

3+
/**
4+
* Represents a loadable object.
5+
*/
36
interface Loadable {
47
fun load() = this::class.simpleName?.let { "Loaded $it" } ?: "Loaded"
5-
}
8+
}

common/src/main/kotlin/com/lambda/core/PingManager.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,4 @@ object PingManager : Loadable {
2626
pings.add(Util.getMeasuringTimeMs() - event.packet.startTime)
2727
}
2828
}
29-
}
29+
}

common/src/main/kotlin/com/lambda/core/TimerManager.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ object TimerManager : Loadable {
1616
}
1717
}
1818
}
19-
}
19+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.lambda.core.registry
2+
3+
import net.minecraft.registry.Registry
4+
import net.minecraft.registry.RegistryKey
5+
import net.minecraft.util.Identifier
6+
7+
8+
object RegistryController {
9+
private val REGISTRIES = HashMap<RegistryKey<out Registry<*>?>, MutableList<RegistryHolder<*>>>()
10+
11+
fun <T> register(registry: Registry<T>, id: Identifier, value: T): RegistryHolder<T> {
12+
val holder = RegistryHolder(id, value)
13+
14+
REGISTRIES.computeIfAbsent(registry.key) { mutableListOf(holder) }
15+
return holder
16+
}
17+
18+
/**
19+
* Loads the temporary registry holders into the actual registry.
20+
* This should be called after all registry holders have been created.
21+
*/
22+
fun register(resourceKey: RegistryKey<out Registry<*>?>, registry: RegistryWrapper<*>) {
23+
REGISTRIES[resourceKey]?.forEach { it.handleRegister(registry) }
24+
REGISTRIES.remove(resourceKey)
25+
}
26+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.lambda.core.registry
2+
3+
import net.minecraft.registry.entry.RegistryEntry
4+
import net.minecraft.util.Identifier
5+
import java.util.function.Supplier
6+
7+
8+
class RegistryHolder<T> internal constructor(
9+
val id: Identifier,
10+
var value: T,
11+
) : Supplier<T> {
12+
private var holder: RegistryEntry<T>? = null
13+
14+
override fun get(): T {
15+
with(holder) {
16+
checkNotNull(this) { "RegistryHolder not populated" }
17+
18+
return this.value()
19+
}
20+
}
21+
22+
fun handleRegister(registry: RegistryWrapper<*>) {
23+
this.holder = registry.registerForHolder(id, value)
24+
}
25+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.lambda.core.registry
2+
3+
import net.minecraft.registry.entry.RegistryEntry
4+
import net.minecraft.util.Identifier
5+
6+
interface RegistryWrapper<T> {
7+
fun <T> registerForHolder(id: Identifier?, value: T): RegistryEntry<T>
8+
}

common/src/main/kotlin/com/lambda/graphics/renderer/gui/font/LambdaFont.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,4 @@ enum class LambdaFont(private val fontName: String) {
2626
return "Loaded ${entries.size} fonts"
2727
}
2828
}
29-
}
29+
}

common/src/main/kotlin/com/lambda/gui/AbstractGuiConfigurable.kt

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@ abstract class AbstractGuiConfigurable(
1717
var mainWindows by setting("windows", defaultWindows)
1818
open var customWindows = mutableListOf<CustomModuleWindow>()
1919

20-
private val defaultWindows get() =
21-
tags.mapIndexed { index, tag ->
22-
TagWindow(tag, ownerGui).apply {
23-
val step = 5.0
24-
position = Vec2d((width + step) * index, 0.0) + step
20+
private val defaultWindows
21+
get() =
22+
tags.mapIndexed { index, tag ->
23+
TagWindow(tag, ownerGui).apply {
24+
val step = 5.0
25+
position = Vec2d((width + step) * index, 0.0) + step
26+
}
2527
}
26-
}
27-
}
28+
}

common/src/main/kotlin/com/lambda/interaction/RotationManager.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
package com.lambda.interaction
22

33
import com.lambda.Lambda.mc
4-
import com.lambda.config.groups.IRotationConfig
54
import com.lambda.config.groups.RotationSettings
6-
import com.lambda.core.Loadable
75
import com.lambda.context.SafeContext
6+
import com.lambda.core.Loadable
87
import com.lambda.event.EventFlow.post
98
import com.lambda.event.events.*
109
import com.lambda.event.listener.SafeListener.Companion.listener

common/src/main/kotlin/com/lambda/sound/SoundRegistry.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
package com.lambda.sound
22

33
import com.lambda.core.Loadable
4+
import com.lambda.core.registry.RegistryController
45
import net.minecraft.registry.Registries
5-
import net.minecraft.registry.Registry
66

77
object SoundRegistry : Loadable {
88
override fun load(): String {
99
LambdaSound.entries.forEach {
10-
Registry.register(Registries.SOUND_EVENT, it.id, it.event)
10+
RegistryController.register(Registries.SOUND_EVENT, it.id, it.event)
1111
}
1212

1313
return "Loaded ${LambdaSound.entries.size} sounds"

0 commit comments

Comments
 (0)