diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/OverdriveThatMatters.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/OverdriveThatMatters.kt index caddadd36..58603f67f 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/OverdriveThatMatters.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/OverdriveThatMatters.kt @@ -103,6 +103,8 @@ object OverdriveThatMatters { fun loc(path: String): ResourceLocation = ResourceLocation.fromNamespaceAndPath(MOD_ID, path) init { + MBuiltInRegistries.register(MOD_BUS) + MBlocks.register(MOD_BUS) MFluids.register(MOD_BUS) MBlockEntities.register(MOD_BUS) @@ -133,9 +135,7 @@ object OverdriveThatMatters { MOD_BUS.addListener(::registerNetworkPackets) DecimalProvider.register(MOD_BUS) - AndroidResearchDescription.register(MOD_BUS) AndroidResearchDescriptions.register(MOD_BUS) - AndroidResearchResult.register(MOD_BUS) AndroidResearchResults.register(MOD_BUS) AbstractRegistryAction.register(MOD_BUS) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/data/world/DecimalProvider.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/data/world/DecimalProvider.kt index bdda35e24..67a993e4e 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/data/world/DecimalProvider.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/data/world/DecimalProvider.kt @@ -7,12 +7,12 @@ import com.mojang.serialization.codecs.RecordCodecBuilder import net.minecraft.util.RandomSource import net.neoforged.bus.api.IEventBus import ru.dbotthepony.mc.otm.OverdriveThatMatters -import ru.dbotthepony.mc.otm.core.ResourceLocation import ru.dbotthepony.mc.otm.core.math.Decimal import ru.dbotthepony.mc.otm.core.math.nextDecimal import ru.dbotthepony.mc.otm.data.codec.DecimalCodec +import ru.dbotthepony.mc.otm.registry.MBuiltInRegistries import ru.dbotthepony.mc.otm.registry.MDeferredRegister -import ru.dbotthepony.mc.otm.registry.RegistryDelegate +import ru.dbotthepony.mc.otm.registry.MRegistries fun interface SampledDecimal { fun sample(source: RandomSource): Decimal @@ -28,33 +28,25 @@ abstract class DecimalProvider : SampledDecimal { abstract val type: Type<*> companion object { - private val registryHolder = RegistryDelegate>("decimal_provider_type") { - defaultKey(ResourceLocation(OverdriveThatMatters.MOD_ID, "zero")) - } - val CODEC: Codec by lazy { Codec - .either(DecimalCodec, registry.byNameCodec().dispatch({ it.type }, { it.codec })) + .either(DecimalCodec, MBuiltInRegistries.DECIMAL_PROVIDER_TYPE.byNameCodec().dispatch({ it.type }, { it.codec })) .xmap( { c -> c.map(::ConstantDecimal, { it }) }, { if (it.type === ConstantDecimal) Either.left(it.minValue) else Either.right(it) } ) } - val registry by registryHolder - val registryKey get() = registryHolder.key - - private val registror = MDeferredRegister(registryKey, OverdriveThatMatters.MOD_ID) + private val registrar = MDeferredRegister(MRegistries.DECIMAL_PROVIDER_TYPE, OverdriveThatMatters.MOD_ID) init { - registror.register("zero") { ConstantDecimal.Zero } - registror.register("constant") { ConstantDecimal } - registror.register("uniform") { UniformDecimal } + registrar.register("zero") { ConstantDecimal.Zero } + registrar.register("constant") { ConstantDecimal } + registrar.register("uniform") { UniformDecimal } } internal fun register(bus: IEventBus) { - bus.addListener(registryHolder::build) - registror.register(bus) + registrar.register(bus) } } } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/matter/AbstractRegistryAction.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/matter/AbstractRegistryAction.kt index a72d7c944..227dd5ab6 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/matter/AbstractRegistryAction.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/matter/AbstractRegistryAction.kt @@ -13,8 +13,9 @@ import net.minecraft.tags.TagKey import net.minecraft.world.item.Item import net.neoforged.bus.api.IEventBus import ru.dbotthepony.mc.otm.OverdriveThatMatters +import ru.dbotthepony.mc.otm.registry.MBuiltInRegistries import ru.dbotthepony.mc.otm.registry.MDeferredRegister -import ru.dbotthepony.mc.otm.registry.RegistryDelegate +import ru.dbotthepony.mc.otm.registry.MRegistries import java.util.* abstract class AbstractRegistryAction( @@ -99,12 +100,7 @@ abstract class AbstractRegistryAction( } companion object { - private val registryDelegate = RegistryDelegate>("matter_registry_action") { sync(false) } - - val registryKey get() = registryDelegate.key - val registry by registryDelegate - - private val registrar = MDeferredRegister(registryKey, OverdriveThatMatters.MOD_ID) + private val registrar = MDeferredRegister(MRegistries.MATTER_REGISTRY_ACTION, OverdriveThatMatters.MOD_ID) init { registrar.register("insert") { InsertAction.Companion } @@ -116,11 +112,10 @@ abstract class AbstractRegistryAction( internal fun register(bus: IEventBus) { registrar.register(bus) - bus.addListener(registryDelegate::build) } val CODEC: Codec by lazy { - registry.byNameCodec().dispatch({ it.type }, { it.codec }) + MBuiltInRegistries.MATTER_REGISTRY_ACTION.byNameCodec().dispatch({ it.type }, { it.codec }) } } } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/matter/IMatterFunction.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/matter/IMatterFunction.kt index b7e64a2d0..69a634136 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/matter/IMatterFunction.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/matter/IMatterFunction.kt @@ -7,7 +7,7 @@ import ru.dbotthepony.mc.otm.matter.SimpleMatterFunction.DecimalFunction import ru.dbotthepony.mc.otm.matter.SimpleMatterFunction.DoubleFunction import ru.dbotthepony.mc.otm.matter.SimpleMatterFunction.IntFunction import ru.dbotthepony.mc.otm.registry.MDeferredRegister -import ru.dbotthepony.mc.otm.registry.RegistryDelegate +import ru.dbotthepony.mc.otm.registry.MRegistries interface IMatterFunction { fun updateValue(self: Int, other: Int): Int @@ -15,12 +15,7 @@ interface IMatterFunction { fun updateValue(self: Double, other: Double): Double companion object : IMatterFunction { - private val registryDelegate = RegistryDelegate("matter_function") { sync(false) } - - val registryKey get() = registryDelegate.key - val registry by registryDelegate - - private val registrar = MDeferredRegister(registryKey, OverdriveThatMatters.MOD_ID) + private val registrar = MDeferredRegister(MRegistries.MATTER_FUNCTION, OverdriveThatMatters.MOD_ID) init { registrar.register("noop") { this } @@ -38,7 +33,6 @@ interface IMatterFunction { internal fun register(bus: IEventBus) { registrar.register(bus) - bus.addListener(registryDelegate::build) } override fun updateValue(self: Int, other: Int): Int { diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/matter/MatterManager.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/matter/MatterManager.kt index 828868a1f..32ae1bd51 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/matter/MatterManager.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/matter/MatterManager.kt @@ -102,8 +102,9 @@ import ru.dbotthepony.mc.otm.core.writeItemType import ru.dbotthepony.mc.otm.matter.MatterManager.Finder import ru.dbotthepony.mc.otm.milliTime import ru.dbotthepony.mc.otm.onceServer +import ru.dbotthepony.mc.otm.registry.MBuiltInRegistries import ru.dbotthepony.mc.otm.registry.MDeferredRegister -import ru.dbotthepony.mc.otm.registry.RegistryDelegate +import ru.dbotthepony.mc.otm.registry.MRegistries import ru.dbotthepony.mc.otm.secondTime import ru.dbotthepony.mc.otm.storage.ItemStorageStack import ru.dbotthepony.mc.otm.storage.StorageStack @@ -397,12 +398,10 @@ object MatterManager { } private object Resolver : SimpleJsonResourceReloadListener(GsonBuilder().setPrettyPrinting().disableHtmlEscaping().create(), FINDER_DIRECTORY) { - val delegate = RegistryDelegate("recipe_finder") { sync(false) } - var ready = false private set - val registrar = MDeferredRegister(delegate.key, OverdriveThatMatters.MOD_ID) + val registrar = MDeferredRegister(MRegistries.RECIPE_FINDER, OverdriveThatMatters.MOD_ID) init { registrar.register("simple") { @@ -639,11 +638,11 @@ object MatterManager { val location = (json["type"] ?: throw JsonSyntaxException("Missing resolver type")).let { ResourceLocation.tryParse(it.asString) } ?: throw JsonSyntaxException("Invalid resolver type: ${json["type"]}") - if (!recipeFinders.containsKey(location)) { + if (!MBuiltInRegistries.RECIPE_FINDER.containsKey(location)) { throw JsonParseException("Resolver type $location does not exist (in $key)") } - val resolver = recipeFinders.get(location) ?: throw ConcurrentModificationException() + val resolver = MBuiltInRegistries.RECIPE_FINDER.get(location) ?: throw ConcurrentModificationException() builder.put(key, resolver to json) } @@ -1495,20 +1494,6 @@ object MatterManager { return Registry.direct(value) } - /** - * Access recipe finders registry - * - * @throws IllegalStateException if calling too early - */ - @JvmStatic val recipeFinders get() = Resolver.delegate.get() - - /** - * Access recipe finders registry key - * - * Use this with your [DeferredRegister] - */ - @JvmStatic val recipeFindersKey get() = Resolver.delegate.key - private val commentary = Reference2ObjectOpenHashMap>() @JvmStatic @@ -1533,7 +1518,6 @@ object MatterManager { } internal fun initialize(bus: IEventBus) { - bus.addListener(Resolver.delegate::build) Resolver.registrar.register(bus) } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/player/android/AndroidResearchDescription.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/player/android/AndroidResearchDescription.kt index b1774f198..4b9e51cce 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/player/android/AndroidResearchDescription.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/player/android/AndroidResearchDescription.kt @@ -13,11 +13,12 @@ import ru.dbotthepony.mc.otm.config.PlayerConfig import ru.dbotthepony.mc.otm.core.TextComponent import ru.dbotthepony.mc.otm.core.TranslatableComponent import ru.dbotthepony.mc.otm.core.util.formatPower +import ru.dbotthepony.mc.otm.registry.MBuiltInRegistries import ru.dbotthepony.mc.otm.registry.MDeferredRegister -import ru.dbotthepony.mc.otm.registry.RegistryDelegate +import ru.dbotthepony.mc.otm.registry.MRegistries object AndroidResearchDescriptions { - private val registrar = MDeferredRegister(AndroidResearchDescription.registryKey, OverdriveThatMatters.MOD_ID) + private val registrar = MDeferredRegister(MRegistries.ANDROID_RESEARCH_DESCRIPTION, OverdriveThatMatters.MOD_ID) init { registrar.register("plain") { PlainAndroidResearchDescription } @@ -140,17 +141,8 @@ interface AndroidResearchDescription { val type: Type<*> companion object { - private val delegate = RegistryDelegate>("android_research_description") {} - - val registry by delegate - val registryKey get() = delegate.key - val CODEC: Codec by lazy { - registry.byNameCodec().dispatch({ it.type }, { it.codec }) - } - - internal fun register(bus: IEventBus) { - bus.addListener(delegate::build) + MBuiltInRegistries.ANDROID_RESEARCH_DESCRIPTION.byNameCodec().dispatch({ it.type }, { it.codec }) } fun singleton(callback: (research: AndroidResearch) -> Component): Singleton { diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/player/android/AndroidResearchResult.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/player/android/AndroidResearchResult.kt index 6e908a33f..0ff3eaae1 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/player/android/AndroidResearchResult.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/player/android/AndroidResearchResult.kt @@ -7,13 +7,14 @@ import net.minecraft.resources.ResourceLocation import net.neoforged.bus.api.IEventBus import org.apache.logging.log4j.LogManager import ru.dbotthepony.mc.otm.OverdriveThatMatters +import ru.dbotthepony.mc.otm.registry.MBuiltInRegistries import ru.dbotthepony.mc.otm.registry.game.AndroidFeatures import ru.dbotthepony.mc.otm.registry.MDeferredRegister +import ru.dbotthepony.mc.otm.registry.MRegistries import ru.dbotthepony.mc.otm.registry.MRegistry -import ru.dbotthepony.mc.otm.registry.RegistryDelegate object AndroidResearchResults { - private val registrar = MDeferredRegister(AndroidResearchResult.registryKey, OverdriveThatMatters.MOD_ID) + private val registrar = MDeferredRegister(MRegistries.ANDROID_RESEARCH_RESULT, OverdriveThatMatters.MOD_ID) init { registrar.register("feature") { AndroidResearchResult.Feature } @@ -71,7 +72,7 @@ interface AndroidResearchResult { * Adds specific android feature [id] to target, does nothing if target already has specified feature */ class Feature(val id: ResourceLocation, val optional: Boolean = false) : AndroidResearchResult { - val feature = MRegistry.ANDROID_FEATURES.get(id) ?: if (optional) null else throw NoSuchElementException("Unknown android feature $id") + val feature = MBuiltInRegistries.ANDROID_FEATURE.get(id) ?: if (optional) null else throw NoSuchElementException("Unknown android feature $id") override val type: Type<*> get() = Companion @@ -101,7 +102,7 @@ interface AndroidResearchResult { */ class FeatureLevel(val id: ResourceLocation, val optional: Boolean = false, val levels: Int = 1) : AndroidResearchResult { - val feature = MRegistry.ANDROID_FEATURES.get(id) ?: if (optional) null else throw NoSuchElementException("Unknown android feature $id") + val feature = MBuiltInRegistries.ANDROID_FEATURE.get(id) ?: if (optional) null else throw NoSuchElementException("Unknown android feature $id") override val type: Type<*> get() = Companion @@ -153,17 +154,9 @@ interface AndroidResearchResult { companion object { private val LOGGER = LogManager.getLogger() - private val delegate = RegistryDelegate>("android_research_result") {} - - val registry by delegate - val registryKey get() = delegate.key val CODEC: Codec by lazy { - registry.byNameCodec().dispatch({ it.type }, { it.codec }) - } - - internal fun register(bus: IEventBus) { - bus.addListener(delegate::build) + MBuiltInRegistries.ANDROID_RESEARCH_RESULT.byNameCodec().dispatch({ it.type }, { it.codec }) } } } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/registry/MBuiltInRegistries.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/registry/MBuiltInRegistries.kt new file mode 100644 index 000000000..462770f23 --- /dev/null +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/registry/MBuiltInRegistries.kt @@ -0,0 +1,57 @@ +package ru.dbotthepony.mc.otm.registry + +import net.minecraft.core.Registry +import net.minecraft.resources.ResourceKey +import net.neoforged.bus.api.IEventBus +import net.neoforged.neoforge.registries.NewRegistryEvent +import net.neoforged.neoforge.registries.RegistryBuilder +import ru.dbotthepony.mc.otm.OverdriveThatMatters +import ru.dbotthepony.mc.otm.core.ResourceLocation +import kotlin.reflect.KProperty + +object MBuiltInRegistries { + private val delegates = ArrayList>() + + private class Delegate(private val key: ResourceKey>, private val configurator: RegistryBuilder.() -> Unit = {}) { + init { + delegates.add(this) + } + + private var _value: Registry? = null + + operator fun getValue(thisRef: Any, property: KProperty<*>): Registry { + return _value ?: throw IllegalStateException("Tried to access uninitialized registry ${key.location()}") + } + + fun build(event: NewRegistryEvent) { + if (_value != null) { + throw IllegalStateException("Already created registry ${key.location()}!") + } + + _value = RegistryBuilder(key).let { + configurator.invoke(it) + event.create(it) + } + } + } + + val DECIMAL_PROVIDER_TYPE by Delegate(MRegistries.DECIMAL_PROVIDER_TYPE) { + defaultKey(ResourceLocation(OverdriveThatMatters.MOD_ID, "zero")) + } + + val MATTER_REGISTRY_ACTION by Delegate(MRegistries.MATTER_REGISTRY_ACTION) + + val MATTER_FUNCTION by Delegate(MRegistries.MATTER_FUNCTION) { + defaultKey(ResourceLocation(OverdriveThatMatters.MOD_ID, "noop")) + } + + val RECIPE_FINDER by Delegate(MRegistries.RECIPE_FINDER) + val ANDROID_RESEARCH_DESCRIPTION by Delegate(MRegistries.ANDROID_RESEARCH_DESCRIPTION) + val ANDROID_RESEARCH_RESULT by Delegate(MRegistries.ANDROID_RESEARCH_RESULT) + val ANDROID_FEATURE by Delegate(MRegistries.ANDROID_FEATURE) { sync(true) } + val STACK_TYPE by Delegate(MRegistries.STACK_TYPE) + + internal fun register(bus: IEventBus) { + delegates.forEach { bus.addListener(it::build) } + } +} diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/registry/MRegistries.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/registry/MRegistries.kt new file mode 100644 index 000000000..5533b8ead --- /dev/null +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/registry/MRegistries.kt @@ -0,0 +1,29 @@ +package ru.dbotthepony.mc.otm.registry + +import net.minecraft.core.Registry +import net.minecraft.resources.ResourceKey +import ru.dbotthepony.mc.otm.OverdriveThatMatters +import ru.dbotthepony.mc.otm.core.ResourceLocation +import ru.dbotthepony.mc.otm.data.world.DecimalProvider +import ru.dbotthepony.mc.otm.matter.AbstractRegistryAction +import ru.dbotthepony.mc.otm.matter.IMatterFunction +import ru.dbotthepony.mc.otm.matter.MatterManager +import ru.dbotthepony.mc.otm.player.android.AndroidFeatureType +import ru.dbotthepony.mc.otm.player.android.AndroidResearchDescription +import ru.dbotthepony.mc.otm.player.android.AndroidResearchResult +import ru.dbotthepony.mc.otm.storage.StorageStack + +object MRegistries { + private fun k(name: String): ResourceKey> { + return ResourceKey.createRegistryKey(ResourceLocation(OverdriveThatMatters.MOD_ID, name)) + } + + val DECIMAL_PROVIDER_TYPE = k>("decimal_provider_type") + val MATTER_REGISTRY_ACTION = k>("matter_registry_action") + val MATTER_FUNCTION = k("matter_function") + val RECIPE_FINDER = k("recipe_finder") + val ANDROID_RESEARCH_DESCRIPTION = k>("android_research_description") + val ANDROID_RESEARCH_RESULT = k>("android_research_result") + val ANDROID_FEATURE = k>("android_feature") + val STACK_TYPE = k>("stack_type") +} diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/registry/MRegistry.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/registry/MRegistry.kt index 719d54efe..c15342aa9 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/registry/MRegistry.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/registry/MRegistry.kt @@ -53,11 +53,6 @@ import ru.dbotthepony.mc.otm.registry.objects.IBlockItemRegistryAcceptor import ru.dbotthepony.mc.otm.registry.objects.StripedColoredDecorativeBlock object MRegistry : IBlockItemRegistryAcceptor { - private val features = RegistryDelegate>("android_features") { sync(true) } - val ANDROID_FEATURES by features - val ANDROID_FEATURES_LOCATION get() = features.location - val ANDROID_FEATURES_KEY get() = features.key - val DYE_ORDER: ImmutableList = ImmutableList.of( DyeColor.BLACK, DyeColor.BLUE, @@ -251,7 +246,6 @@ object MRegistry : IBlockItemRegistryAcceptor { } internal fun initialize(bus: IEventBus) { - bus.addListener(features::build) bus.addListener(this::initializeClient) bus.addListener(this::initializeCommon) bus.addListener(MStats::registerVanilla) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/registry/RegistryDelegate.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/registry/RegistryDelegate.kt deleted file mode 100644 index fc412a415..000000000 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/registry/RegistryDelegate.kt +++ /dev/null @@ -1,45 +0,0 @@ -package ru.dbotthepony.mc.otm.registry - -import net.minecraft.core.Registry -import net.minecraft.resources.ResourceKey -import net.neoforged.neoforge.registries.NewRegistryEvent -import net.neoforged.neoforge.registries.RegistryBuilder -import ru.dbotthepony.mc.otm.OverdriveThatMatters -import ru.dbotthepony.mc.otm.core.ResourceLocation -import java.util.function.Supplier -import kotlin.properties.ReadOnlyProperty -import kotlin.reflect.KProperty - -class RegistryDelegate(key: String, private val configurator: RegistryBuilder.() -> Unit = {}) : ReadOnlyProperty>, Supplier>, Lazy> { - private var _value: Registry? = null - - override val value: Registry - get() = get() - - override fun isInitialized(): Boolean { - return _value != null - } - - val location = ResourceLocation(OverdriveThatMatters.MOD_ID, key) - val key: ResourceKey> = ResourceKey.createRegistryKey(location) - - override fun get(): Registry { - val value = _value ?: throw IllegalStateException("Tried to access uninitialized registry $location") - return value - } - - override fun getValue(thisRef: Any, property: KProperty<*>): Registry { - return get() - } - - fun build(event: NewRegistryEvent) { - if (_value != null) { - throw IllegalStateException("Already built registry $location!") - } - - _value = RegistryBuilder(key).let { - configurator.invoke(it) - event.create(it) - } - } -} diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/registry/game/AndroidFeatures.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/registry/game/AndroidFeatures.kt index 9e1c1d460..b548a39ff 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/registry/game/AndroidFeatures.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/registry/game/AndroidFeatures.kt @@ -18,10 +18,11 @@ import ru.dbotthepony.mc.otm.player.android.feature.StepAssistFeature import ru.dbotthepony.mc.otm.player.android.feature.SwimBoostersFeature import ru.dbotthepony.mc.otm.registry.MDeferredRegister import ru.dbotthepony.mc.otm.registry.MNames +import ru.dbotthepony.mc.otm.registry.MRegistries import ru.dbotthepony.mc.otm.registry.MRegistry object AndroidFeatures { - private val registry = MDeferredRegister(MRegistry.ANDROID_FEATURES_KEY) + private val registry = MDeferredRegister(MRegistries.ANDROID_FEATURE) val AIR_BAGS by registry.register(MNames.AIR_BAGS) { AndroidFeatureType(::DummyAndroidFeature) } val STEP_ASSIST by registry.register(MNames.STEP_ASSIST) { AndroidFeatureType(::StepAssistFeature) } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/storage/StorageStack.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/storage/StorageStack.kt index 0dfd65e2d..ddf49249b 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/storage/StorageStack.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/storage/StorageStack.kt @@ -5,14 +5,13 @@ import net.minecraft.network.RegistryFriendlyByteBuf import net.minecraft.world.item.ItemStack import net.neoforged.bus.api.IEventBus import ru.dbotthepony.mc.otm.OverdriveThatMatters -import ru.dbotthepony.mc.otm.core.getValue import ru.dbotthepony.mc.otm.core.math.Decimal import ru.dbotthepony.mc.otm.core.readBigInteger import ru.dbotthepony.mc.otm.core.readItem import ru.dbotthepony.mc.otm.core.writeBigInteger import ru.dbotthepony.mc.otm.core.writeItem import ru.dbotthepony.mc.otm.registry.MDeferredRegister -import ru.dbotthepony.mc.otm.registry.RegistryDelegate +import ru.dbotthepony.mc.otm.registry.MRegistries import java.math.BigInteger abstract class StorageStack>(val count: BigInteger) { @@ -110,11 +109,7 @@ abstract class StorageStack>(val count: BigInteger) { return o?.hashCodeWithoutCount() ?: 0 } - private val delegate = RegistryDelegate>("stack_type") {} - val REGISTRY by delegate - val REGISTRY_KEY by delegate::key - - private val registrar = MDeferredRegister(REGISTRY_KEY, OverdriveThatMatters.MOD_ID) + private val registrar = MDeferredRegister(MRegistries.STACK_TYPE, OverdriveThatMatters.MOD_ID) val ITEMS: Type by registrar.register("items") { SimpleType( @@ -131,7 +126,6 @@ abstract class StorageStack>(val count: BigInteger) { } internal fun register(bus: IEventBus) { - bus.addListener(delegate::build) registrar.register(bus) } }