Compare commits

...

4 Commits

20 changed files with 157 additions and 171 deletions

View File

@ -103,6 +103,8 @@ object OverdriveThatMatters {
fun loc(path: String): ResourceLocation = ResourceLocation.fromNamespaceAndPath(MOD_ID, path) fun loc(path: String): ResourceLocation = ResourceLocation.fromNamespaceAndPath(MOD_ID, path)
init { init {
MBuiltInRegistries.register(MOD_BUS)
MBlocks.register(MOD_BUS) MBlocks.register(MOD_BUS)
MFluids.register(MOD_BUS) MFluids.register(MOD_BUS)
MBlockEntities.register(MOD_BUS) MBlockEntities.register(MOD_BUS)
@ -133,9 +135,7 @@ object OverdriveThatMatters {
MOD_BUS.addListener(::registerNetworkPackets) MOD_BUS.addListener(::registerNetworkPackets)
DecimalProvider.register(MOD_BUS) DecimalProvider.register(MOD_BUS)
AndroidResearchDescription.register(MOD_BUS)
AndroidResearchDescriptions.register(MOD_BUS) AndroidResearchDescriptions.register(MOD_BUS)
AndroidResearchResult.register(MOD_BUS)
AndroidResearchResults.register(MOD_BUS) AndroidResearchResults.register(MOD_BUS)
AbstractRegistryAction.register(MOD_BUS) AbstractRegistryAction.register(MOD_BUS)

View File

@ -7,12 +7,12 @@ import com.mojang.serialization.codecs.RecordCodecBuilder
import net.minecraft.util.RandomSource import net.minecraft.util.RandomSource
import net.neoforged.bus.api.IEventBus import net.neoforged.bus.api.IEventBus
import ru.dbotthepony.mc.otm.OverdriveThatMatters 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.Decimal
import ru.dbotthepony.mc.otm.core.math.nextDecimal import ru.dbotthepony.mc.otm.core.math.nextDecimal
import ru.dbotthepony.mc.otm.data.codec.DecimalCodec 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.MDeferredRegister
import ru.dbotthepony.mc.otm.registry.RegistryDelegate import ru.dbotthepony.mc.otm.registry.MRegistries
fun interface SampledDecimal { fun interface SampledDecimal {
fun sample(source: RandomSource): Decimal fun sample(source: RandomSource): Decimal
@ -28,33 +28,25 @@ abstract class DecimalProvider : SampledDecimal {
abstract val type: Type<*> abstract val type: Type<*>
companion object { companion object {
private val registryHolder = RegistryDelegate<Type<*>>("decimal_provider_type") {
defaultKey(ResourceLocation(OverdriveThatMatters.MOD_ID, "zero"))
}
val CODEC: Codec<DecimalProvider> by lazy { val CODEC: Codec<DecimalProvider> by lazy {
Codec Codec
.either(DecimalCodec, registry.byNameCodec().dispatch({ it.type }, { it.codec })) .either(DecimalCodec, MBuiltInRegistries.DECIMAL_PROVIDER_TYPE.byNameCodec().dispatch({ it.type }, { it.codec }))
.xmap( .xmap(
{ c -> c.map(::ConstantDecimal, { it }) }, { c -> c.map(::ConstantDecimal, { it }) },
{ if (it.type === ConstantDecimal) Either.left(it.minValue) else Either.right(it) } { if (it.type === ConstantDecimal) Either.left(it.minValue) else Either.right(it) }
) )
} }
val registry by registryHolder private val registrar = MDeferredRegister(MRegistries.DECIMAL_PROVIDER_TYPE, OverdriveThatMatters.MOD_ID)
val registryKey get() = registryHolder.key
private val registror = MDeferredRegister(registryKey, OverdriveThatMatters.MOD_ID)
init { init {
registror.register("zero") { ConstantDecimal.Zero } registrar.register("zero") { ConstantDecimal.Zero }
registror.register("constant") { ConstantDecimal } registrar.register("constant") { ConstantDecimal }
registror.register("uniform") { UniformDecimal } registrar.register("uniform") { UniformDecimal }
} }
internal fun register(bus: IEventBus) { internal fun register(bus: IEventBus) {
bus.addListener(registryHolder::build) registrar.register(bus)
registror.register(bus)
} }
} }
} }

View File

@ -13,8 +13,9 @@ import net.minecraft.tags.TagKey
import net.minecraft.world.item.Item import net.minecraft.world.item.Item
import net.neoforged.bus.api.IEventBus import net.neoforged.bus.api.IEventBus
import ru.dbotthepony.mc.otm.OverdriveThatMatters 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.MDeferredRegister
import ru.dbotthepony.mc.otm.registry.RegistryDelegate import ru.dbotthepony.mc.otm.registry.MRegistries
import java.util.* import java.util.*
abstract class AbstractRegistryAction( abstract class AbstractRegistryAction(
@ -99,12 +100,7 @@ abstract class AbstractRegistryAction(
} }
companion object { companion object {
private val registryDelegate = RegistryDelegate<Type<*>>("matter_registry_action") { sync(false) } private val registrar = MDeferredRegister(MRegistries.MATTER_REGISTRY_ACTION, OverdriveThatMatters.MOD_ID)
val registryKey get() = registryDelegate.key
val registry by registryDelegate
private val registrar = MDeferredRegister(registryKey, OverdriveThatMatters.MOD_ID)
init { init {
registrar.register("insert") { InsertAction.Companion } registrar.register("insert") { InsertAction.Companion }
@ -116,11 +112,10 @@ abstract class AbstractRegistryAction(
internal fun register(bus: IEventBus) { internal fun register(bus: IEventBus) {
registrar.register(bus) registrar.register(bus)
bus.addListener(registryDelegate::build)
} }
val CODEC: Codec<AbstractRegistryAction> by lazy { val CODEC: Codec<AbstractRegistryAction> by lazy {
registry.byNameCodec().dispatch({ it.type }, { it.codec }) MBuiltInRegistries.MATTER_REGISTRY_ACTION.byNameCodec().dispatch({ it.type }, { it.codec })
} }
} }
} }

View File

@ -15,6 +15,7 @@ import net.minecraft.world.item.Item
import ru.dbotthepony.mc.otm.core.math.Decimal import ru.dbotthepony.mc.otm.core.math.Decimal
import ru.dbotthepony.mc.otm.data.codec.DecimalCodec import ru.dbotthepony.mc.otm.data.codec.DecimalCodec
import ru.dbotthepony.mc.otm.data.codec.PredicatedCodecList import ru.dbotthepony.mc.otm.data.codec.PredicatedCodecList
import ru.dbotthepony.mc.otm.registry.MBuiltInRegistries
import java.util.Optional import java.util.Optional
import java.util.function.Predicate import java.util.function.Predicate
@ -29,8 +30,8 @@ class ComputeAction(
it.group( it.group(
DecimalCodec.fieldOf("matter").forGetter(Constant::matter), DecimalCodec.fieldOf("matter").forGetter(Constant::matter),
Codec.DOUBLE.fieldOf("complexity").forGetter(Constant::complexity), Codec.DOUBLE.fieldOf("complexity").forGetter(Constant::complexity),
IMatterFunction.registry.byNameCodec().fieldOf("matterFunction").forGetter(Constant::matterFunction), MBuiltInRegistries.MATTER_FUNCTION.byNameCodec().fieldOf("matterFunction").forGetter(Constant::matterFunction),
IMatterFunction.registry.byNameCodec().fieldOf("complexityFunction").forGetter(Constant::complexityFunction), MBuiltInRegistries.MATTER_FUNCTION.byNameCodec().fieldOf("complexityFunction").forGetter(Constant::complexityFunction),
).apply(it, ::Constant) ).apply(it, ::Constant)
} to Predicate { true } } to Predicate { true }
} }
@ -40,7 +41,7 @@ class ComputeAction(
it.group( it.group(
DecimalCodec.fieldOf("matter").forGetter(Constant::matter), DecimalCodec.fieldOf("matter").forGetter(Constant::matter),
Codec.DOUBLE.fieldOf("complexity").forGetter(Constant::complexity), Codec.DOUBLE.fieldOf("complexity").forGetter(Constant::complexity),
IMatterFunction.registry.byNameCodec().fieldOf("function").forGetter(Constant::matterFunction), MBuiltInRegistries.MATTER_FUNCTION.byNameCodec().fieldOf("function").forGetter(Constant::matterFunction),
).apply(it) { a, b, c -> Constant(a, b, c, c) } ).apply(it) { a, b, c -> Constant(a, b, c, c) }
} to Predicate { it.matterFunction == it.complexityFunction } } to Predicate { it.matterFunction == it.complexityFunction }
} }
@ -49,8 +50,8 @@ class ComputeAction(
RecordCodecBuilder.create<Constant> { RecordCodecBuilder.create<Constant> {
it.group( it.group(
DecimalCodec.fieldOf("value").forGetter(Constant::matter), DecimalCodec.fieldOf("value").forGetter(Constant::matter),
IMatterFunction.registry.byNameCodec().fieldOf("matterFunction").forGetter(Constant::matterFunction), MBuiltInRegistries.MATTER_FUNCTION.byNameCodec().fieldOf("matterFunction").forGetter(Constant::matterFunction),
IMatterFunction.registry.byNameCodec().fieldOf("complexityFunction").forGetter(Constant::complexityFunction), MBuiltInRegistries.MATTER_FUNCTION.byNameCodec().fieldOf("complexityFunction").forGetter(Constant::complexityFunction),
).apply(it) { a, b, c -> Constant(a, a.toDouble(), b, c) } ).apply(it) { a, b, c -> Constant(a, a.toDouble(), b, c) }
} to Predicate { it.matter == Decimal(it.complexity.toString()) } } to Predicate { it.matter == Decimal(it.complexity.toString()) }
} }
@ -59,7 +60,7 @@ class ComputeAction(
RecordCodecBuilder.create<Constant> { RecordCodecBuilder.create<Constant> {
it.group( it.group(
DecimalCodec.fieldOf("value").forGetter(Constant::matter), DecimalCodec.fieldOf("value").forGetter(Constant::matter),
IMatterFunction.registry.byNameCodec().fieldOf("function").forGetter(Constant::matterFunction), MBuiltInRegistries.MATTER_FUNCTION.byNameCodec().fieldOf("function").forGetter(Constant::matterFunction),
).apply(it) { a, b -> Constant(a, a.toDouble(), b, b) } ).apply(it) { a, b -> Constant(a, a.toDouble(), b, b) }
} to Predicate { it.matter == Decimal(it.complexity.toString()) && it.matterFunction == it.complexityFunction } } to Predicate { it.matter == Decimal(it.complexity.toString()) && it.matterFunction == it.complexityFunction }
} }
@ -68,7 +69,7 @@ class ComputeAction(
RecordCodecBuilder.create<Constant> { RecordCodecBuilder.create<Constant> {
it.group( it.group(
Codec.DOUBLE.fieldOf("complexity").forGetter(Constant::complexity), Codec.DOUBLE.fieldOf("complexity").forGetter(Constant::complexity),
IMatterFunction.registry.byNameCodec().fieldOf("function").forGetter(Constant::complexityFunction), MBuiltInRegistries.MATTER_FUNCTION.byNameCodec().fieldOf("function").forGetter(Constant::complexityFunction),
).apply(it) { a, b -> Constant(Decimal.ZERO, a.toDouble(), IMatterFunction.NOOP, b) } ).apply(it) { a, b -> Constant(Decimal.ZERO, a.toDouble(), IMatterFunction.NOOP, b) }
} to Predicate { it.matterFunction == IMatterFunction.NOOP } } to Predicate { it.matterFunction == IMatterFunction.NOOP }
} }
@ -77,7 +78,7 @@ class ComputeAction(
RecordCodecBuilder.create<Constant> { RecordCodecBuilder.create<Constant> {
it.group( it.group(
Codec.DOUBLE.fieldOf("complexity").forGetter(Constant::complexity), Codec.DOUBLE.fieldOf("complexity").forGetter(Constant::complexity),
IMatterFunction.registry.byNameCodec().fieldOf("complexityFunction").forGetter(Constant::complexityFunction), MBuiltInRegistries.MATTER_FUNCTION.byNameCodec().fieldOf("complexityFunction").forGetter(Constant::complexityFunction),
).apply(it) { a, b -> Constant(Decimal.ZERO, a.toDouble(), IMatterFunction.NOOP, b) } ).apply(it) { a, b -> Constant(Decimal.ZERO, a.toDouble(), IMatterFunction.NOOP, b) }
} to Predicate { it.matterFunction == IMatterFunction.NOOP } } to Predicate { it.matterFunction == IMatterFunction.NOOP }
} }
@ -86,7 +87,7 @@ class ComputeAction(
RecordCodecBuilder.create<Constant> { RecordCodecBuilder.create<Constant> {
it.group( it.group(
DecimalCodec.fieldOf("matter").forGetter(Constant::matter), DecimalCodec.fieldOf("matter").forGetter(Constant::matter),
IMatterFunction.registry.byNameCodec().fieldOf("function").forGetter(Constant::matterFunction), MBuiltInRegistries.MATTER_FUNCTION.byNameCodec().fieldOf("function").forGetter(Constant::matterFunction),
).apply(it) { a, b -> Constant(a, 0.0, b, IMatterFunction.NOOP) } ).apply(it) { a, b -> Constant(a, 0.0, b, IMatterFunction.NOOP) }
} to Predicate { it.complexityFunction == IMatterFunction.NOOP } } to Predicate { it.complexityFunction == IMatterFunction.NOOP }
} }
@ -95,7 +96,7 @@ class ComputeAction(
RecordCodecBuilder.create<Constant> { RecordCodecBuilder.create<Constant> {
it.group( it.group(
DecimalCodec.fieldOf("matter").forGetter(Constant::matter), DecimalCodec.fieldOf("matter").forGetter(Constant::matter),
IMatterFunction.registry.byNameCodec().fieldOf("matterFunction").forGetter(Constant::matterFunction), MBuiltInRegistries.MATTER_FUNCTION.byNameCodec().fieldOf("matterFunction").forGetter(Constant::matterFunction),
).apply(it) { a, b -> Constant(a, 0.0, b, IMatterFunction.NOOP) } ).apply(it) { a, b -> Constant(a, 0.0, b, IMatterFunction.NOOP) }
} to Predicate { it.complexityFunction == IMatterFunction.NOOP } } to Predicate { it.complexityFunction == IMatterFunction.NOOP }
} }
@ -182,7 +183,7 @@ class ComputeAction(
RecordCodecBuilder.create { RecordCodecBuilder.create {
it.group( it.group(
TargetCodec.fieldOf("id").forGetter(Value::id), TargetCodec.fieldOf("id").forGetter(Value::id),
IMatterFunction.registry.byNameCodec().fieldOf("function").forGetter(Value::matterFunction), MBuiltInRegistries.MATTER_FUNCTION.byNameCodec().fieldOf("function").forGetter(Value::matterFunction),
).apply(it, ::Value) ).apply(it, ::Value)
} }
} }
@ -191,8 +192,8 @@ class ComputeAction(
RecordCodecBuilder.create { RecordCodecBuilder.create {
it.group( it.group(
TargetCodec.fieldOf("id").forGetter(Value::id), TargetCodec.fieldOf("id").forGetter(Value::id),
IMatterFunction.registry.byNameCodec().fieldOf("matterFunction").forGetter(Value::matterFunction), MBuiltInRegistries.MATTER_FUNCTION.byNameCodec().fieldOf("matterFunction").forGetter(Value::matterFunction),
IMatterFunction.registry.byNameCodec().fieldOf("complexityFunction").forGetter(Value::complexityFunction), MBuiltInRegistries.MATTER_FUNCTION.byNameCodec().fieldOf("complexityFunction").forGetter(Value::complexityFunction),
).apply(it, ::Value) ).apply(it, ::Value)
} }
} }

View File

@ -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.DoubleFunction
import ru.dbotthepony.mc.otm.matter.SimpleMatterFunction.IntFunction import ru.dbotthepony.mc.otm.matter.SimpleMatterFunction.IntFunction
import ru.dbotthepony.mc.otm.registry.MDeferredRegister import ru.dbotthepony.mc.otm.registry.MDeferredRegister
import ru.dbotthepony.mc.otm.registry.RegistryDelegate import ru.dbotthepony.mc.otm.registry.MRegistries
interface IMatterFunction { interface IMatterFunction {
fun updateValue(self: Int, other: Int): Int fun updateValue(self: Int, other: Int): Int
@ -15,12 +15,7 @@ interface IMatterFunction {
fun updateValue(self: Double, other: Double): Double fun updateValue(self: Double, other: Double): Double
companion object : IMatterFunction { companion object : IMatterFunction {
private val registryDelegate = RegistryDelegate<IMatterFunction>("matter_function") { sync(false) } private val registrar = MDeferredRegister(MRegistries.MATTER_FUNCTION, OverdriveThatMatters.MOD_ID)
val registryKey get() = registryDelegate.key
val registry by registryDelegate
private val registrar = MDeferredRegister(registryKey, OverdriveThatMatters.MOD_ID)
init { init {
registrar.register("noop") { this } registrar.register("noop") { this }
@ -38,7 +33,6 @@ interface IMatterFunction {
internal fun register(bus: IEventBus) { internal fun register(bus: IEventBus) {
registrar.register(bus) registrar.register(bus)
bus.addListener(registryDelegate::build)
} }
override fun updateValue(self: Int, other: Int): Int { override fun updateValue(self: Int, other: Int): Int {

View File

@ -102,8 +102,9 @@ import ru.dbotthepony.mc.otm.core.writeItemType
import ru.dbotthepony.mc.otm.matter.MatterManager.Finder import ru.dbotthepony.mc.otm.matter.MatterManager.Finder
import ru.dbotthepony.mc.otm.milliTime import ru.dbotthepony.mc.otm.milliTime
import ru.dbotthepony.mc.otm.onceServer 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.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.secondTime
import ru.dbotthepony.mc.otm.storage.ItemStorageStack import ru.dbotthepony.mc.otm.storage.ItemStorageStack
import ru.dbotthepony.mc.otm.storage.StorageStack import ru.dbotthepony.mc.otm.storage.StorageStack
@ -397,12 +398,10 @@ object MatterManager {
} }
private object Resolver : SimpleJsonResourceReloadListener(GsonBuilder().setPrettyPrinting().disableHtmlEscaping().create(), FINDER_DIRECTORY) { private object Resolver : SimpleJsonResourceReloadListener(GsonBuilder().setPrettyPrinting().disableHtmlEscaping().create(), FINDER_DIRECTORY) {
val delegate = RegistryDelegate<Finder>("recipe_finder") { sync(false) }
var ready = false var ready = false
private set private set
val registrar = MDeferredRegister(delegate.key, OverdriveThatMatters.MOD_ID) val registrar = MDeferredRegister(MRegistries.RECIPE_FINDER, OverdriveThatMatters.MOD_ID)
init { init {
registrar.register("simple") { 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"]}") 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)") 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) builder.put(key, resolver to json)
} }
@ -1495,20 +1494,6 @@ object MatterManager {
return Registry.direct(value) 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<Item, ArrayList<Component>>() private val commentary = Reference2ObjectOpenHashMap<Item, ArrayList<Component>>()
@JvmStatic @JvmStatic
@ -1533,7 +1518,6 @@ object MatterManager {
} }
internal fun initialize(bus: IEventBus) { internal fun initialize(bus: IEventBus) {
bus.addListener(Resolver.delegate::build)
Resolver.registrar.register(bus) Resolver.registrar.register(bus)
} }

View File

@ -11,6 +11,7 @@ import net.minecraft.world.item.Item
import ru.dbotthepony.mc.otm.core.math.Decimal import ru.dbotthepony.mc.otm.core.math.Decimal
import ru.dbotthepony.mc.otm.data.codec.DecimalCodec import ru.dbotthepony.mc.otm.data.codec.DecimalCodec
import ru.dbotthepony.mc.otm.data.codec.simpleCodec import ru.dbotthepony.mc.otm.data.codec.simpleCodec
import ru.dbotthepony.mc.otm.registry.MBuiltInRegistries
class UpdateAction( class UpdateAction(
id: Either<ResourceLocation, TagKey<Item>>, id: Either<ResourceLocation, TagKey<Item>>,
@ -22,7 +23,7 @@ class UpdateAction(
data class MatterFunction(val function: IMatterFunction, val value: Decimal) { data class MatterFunction(val function: IMatterFunction, val value: Decimal) {
companion object { companion object {
val CODEC: Codec<MatterFunction> by lazy { val CODEC: Codec<MatterFunction> by lazy {
simpleCodec(::MatterFunction, MatterFunction::function, IMatterFunction.registry.byNameCodec(), MatterFunction::value, DecimalCodec) simpleCodec(::MatterFunction, MatterFunction::function, MBuiltInRegistries.MATTER_FUNCTION.byNameCodec(), MatterFunction::value, DecimalCodec)
} }
} }
} }
@ -30,7 +31,7 @@ class UpdateAction(
data class ComplexityFunction(val function: IMatterFunction, val value: Double) { data class ComplexityFunction(val function: IMatterFunction, val value: Double) {
companion object { companion object {
val CODEC: Codec<ComplexityFunction> by lazy { val CODEC: Codec<ComplexityFunction> by lazy {
simpleCodec(::ComplexityFunction, ComplexityFunction::function, IMatterFunction.registry.byNameCodec(), ComplexityFunction::value, Codec.DOUBLE) simpleCodec(::ComplexityFunction, ComplexityFunction::function, MBuiltInRegistries.MATTER_FUNCTION.byNameCodec(), ComplexityFunction::value, Codec.DOUBLE)
} }
} }
} }
@ -38,7 +39,7 @@ class UpdateAction(
data class PriorityFunction(val function: IMatterFunction, val value: Int) { data class PriorityFunction(val function: IMatterFunction, val value: Int) {
companion object { companion object {
val CODEC: Codec<PriorityFunction> by lazy { val CODEC: Codec<PriorityFunction> by lazy {
simpleCodec(::PriorityFunction, PriorityFunction::function, IMatterFunction.registry.byNameCodec(), PriorityFunction::value, Codec.INT) simpleCodec(::PriorityFunction, PriorityFunction::function, MBuiltInRegistries.MATTER_FUNCTION.byNameCodec(), PriorityFunction::value, Codec.INT)
} }
} }
} }

View File

@ -26,13 +26,14 @@ import ru.dbotthepony.mc.otm.core.readComponent
import ru.dbotthepony.mc.otm.core.writeComponent import ru.dbotthepony.mc.otm.core.writeComponent
import ru.dbotthepony.mc.otm.menu.tech.AndroidStationMenu import ru.dbotthepony.mc.otm.menu.tech.AndroidStationMenu
import ru.dbotthepony.mc.otm.onceServer import ru.dbotthepony.mc.otm.onceServer
import ru.dbotthepony.mc.otm.registry.MBuiltInRegistries
import ru.dbotthepony.mc.otm.registry.game.AndroidFeatures import ru.dbotthepony.mc.otm.registry.game.AndroidFeatures
import ru.dbotthepony.mc.otm.registry.MRegistry import ru.dbotthepony.mc.otm.registry.MRegistry
import ru.dbotthepony.mc.otm.registry.game.MSoundEvents import ru.dbotthepony.mc.otm.registry.game.MSoundEvents
class AndroidFeatureSyncPacket(val type: AndroidFeatureType<*>, val data: ByteArrayList) : CustomPacketPayload { class AndroidFeatureSyncPacket(val type: AndroidFeatureType<*>, val data: ByteArrayList) : CustomPacketPayload {
fun write(buff: RegistryFriendlyByteBuf) { fun write(buff: RegistryFriendlyByteBuf) {
buff.writeInt(MRegistry.ANDROID_FEATURES.getId(type)) buff.writeInt(MBuiltInRegistries.ANDROID_FEATURE.getId(type))
buff.writeBytes(data.elements(), 0, data.size) buff.writeBytes(data.elements(), 0, data.size)
} }
@ -58,7 +59,7 @@ class AndroidFeatureSyncPacket(val type: AndroidFeatureType<*>, val data: ByteAr
fun read(buff: RegistryFriendlyByteBuf): AndroidFeatureSyncPacket { fun read(buff: RegistryFriendlyByteBuf): AndroidFeatureSyncPacket {
return AndroidFeatureSyncPacket( return AndroidFeatureSyncPacket(
MRegistry.ANDROID_FEATURES.byIdOrThrow(buff.readInt()), MBuiltInRegistries.ANDROID_FEATURE.byIdOrThrow(buff.readInt()),
ByteArrayList.wrap(ByteArray(buff.readableBytes()).also { buff.readBytes(it) }) ByteArrayList.wrap(ByteArray(buff.readableBytes()).also { buff.readBytes(it) })
) )
} }
@ -140,7 +141,7 @@ class AndroidResearchRequestPacket(val type: AndroidResearchType) : CustomPacket
class AndroidFeatureRemovePacket(val type: AndroidFeatureType<*>) : CustomPacketPayload { class AndroidFeatureRemovePacket(val type: AndroidFeatureType<*>) : CustomPacketPayload {
fun write(buff: FriendlyByteBuf) { fun write(buff: FriendlyByteBuf) {
buff.writeInt(MRegistry.ANDROID_FEATURES.getId(type)) buff.writeInt(MBuiltInRegistries.ANDROID_FEATURE.getId(type))
} }
fun play(context: IPayloadContext) { fun play(context: IPayloadContext) {
@ -164,7 +165,7 @@ class AndroidFeatureRemovePacket(val type: AndroidFeatureType<*>) : CustomPacket
StreamCodec.ofMember(AndroidFeatureRemovePacket::write, ::read) StreamCodec.ofMember(AndroidFeatureRemovePacket::write, ::read)
fun read(buff: FriendlyByteBuf): AndroidFeatureRemovePacket { fun read(buff: FriendlyByteBuf): AndroidFeatureRemovePacket {
return AndroidFeatureRemovePacket(MRegistry.ANDROID_FEATURES.byIdOrThrow(buff.readInt())) return AndroidFeatureRemovePacket(MBuiltInRegistries.ANDROID_FEATURE.byIdOrThrow(buff.readInt()))
} }
} }
} }
@ -219,7 +220,7 @@ class PlayerIterationPacket(val iteration: Int, val deathLog: List<Pair<Int, Com
class SwitchAndroidFeaturePacket(val type: AndroidFeatureType<*>, val newState: Boolean) : CustomPacketPayload { class SwitchAndroidFeaturePacket(val type: AndroidFeatureType<*>, val newState: Boolean) : CustomPacketPayload {
fun write(buff: FriendlyByteBuf) { fun write(buff: FriendlyByteBuf) {
buff.writeInt(MRegistry.ANDROID_FEATURES.getId(type)) buff.writeInt(MBuiltInRegistries.ANDROID_FEATURE.getId(type))
buff.writeBoolean(newState) buff.writeBoolean(newState)
} }
@ -259,14 +260,14 @@ class SwitchAndroidFeaturePacket(val type: AndroidFeatureType<*>, val newState:
StreamCodec.ofMember(SwitchAndroidFeaturePacket::write, ::read) StreamCodec.ofMember(SwitchAndroidFeaturePacket::write, ::read)
fun read(buff: FriendlyByteBuf): SwitchAndroidFeaturePacket { fun read(buff: FriendlyByteBuf): SwitchAndroidFeaturePacket {
return SwitchAndroidFeaturePacket(MRegistry.ANDROID_FEATURES.byIdOrThrow(buff.readInt()), buff.readBoolean()) return SwitchAndroidFeaturePacket(MBuiltInRegistries.ANDROID_FEATURE.byIdOrThrow(buff.readInt()), buff.readBoolean())
} }
} }
} }
class ActivateAndroidFeaturePacket(val type: AndroidFeatureType<*>) : CustomPacketPayload { class ActivateAndroidFeaturePacket(val type: AndroidFeatureType<*>) : CustomPacketPayload {
fun write(buff: FriendlyByteBuf) { fun write(buff: FriendlyByteBuf) {
buff.writeInt(MRegistry.ANDROID_FEATURES.getId(type)) buff.writeInt(MBuiltInRegistries.ANDROID_FEATURE.getId(type))
} }
fun play(context: IPayloadContext) { fun play(context: IPayloadContext) {
@ -298,7 +299,7 @@ class ActivateAndroidFeaturePacket(val type: AndroidFeatureType<*>) : CustomPack
StreamCodec.ofMember(ActivateAndroidFeaturePacket::write, ::read) StreamCodec.ofMember(ActivateAndroidFeaturePacket::write, ::read)
fun read(buff: FriendlyByteBuf): ActivateAndroidFeaturePacket { fun read(buff: FriendlyByteBuf): ActivateAndroidFeaturePacket {
return ActivateAndroidFeaturePacket(MRegistry.ANDROID_FEATURES.byIdOrThrow(buff.readInt())) return ActivateAndroidFeaturePacket(MBuiltInRegistries.ANDROID_FEATURE.byIdOrThrow(buff.readInt()))
} }
} }
} }

View File

@ -97,6 +97,7 @@ import ru.dbotthepony.mc.otm.menu.ExopackInventoryMenu
import ru.dbotthepony.mc.otm.menu.IItemStackSortingSettings import ru.dbotthepony.mc.otm.menu.IItemStackSortingSettings
import ru.dbotthepony.mc.otm.network.* import ru.dbotthepony.mc.otm.network.*
import ru.dbotthepony.mc.otm.network.SmokeParticlesPacket.Companion.makeSmoke import ru.dbotthepony.mc.otm.network.SmokeParticlesPacket.Companion.makeSmoke
import ru.dbotthepony.mc.otm.registry.MBuiltInRegistries
import ru.dbotthepony.mc.otm.registry.game.AndroidFeatures import ru.dbotthepony.mc.otm.registry.game.AndroidFeatures
import ru.dbotthepony.mc.otm.registry.MDamageTypes import ru.dbotthepony.mc.otm.registry.MDamageTypes
import ru.dbotthepony.mc.otm.registry.game.MItems import ru.dbotthepony.mc.otm.registry.game.MItems
@ -1004,7 +1005,7 @@ class MatteryPlayer(val ply: Player) {
research.clear() research.clear()
for (featureTag in tag.getCompoundList("features")) { for (featureTag in tag.getCompoundList("features")) {
val feature = MRegistry.ANDROID_FEATURES.get(ResourceLocation.parse(featureTag.getString("id"))) val feature = MBuiltInRegistries.ANDROID_FEATURE.get(ResourceLocation.parse(featureTag.getString("id")))
if (feature?.isApplicable(this) == true) { if (feature?.isApplicable(this) == true) {
val instance = feature.create(this) val instance = feature.create(this)

View File

@ -6,6 +6,7 @@ import net.minecraft.network.chat.MutableComponent
import net.minecraft.network.chat.contents.TranslatableContents import net.minecraft.network.chat.contents.TranslatableContents
import ru.dbotthepony.mc.otm.player.MatteryPlayer import ru.dbotthepony.mc.otm.player.MatteryPlayer
import ru.dbotthepony.mc.otm.core.getKeyNullable import ru.dbotthepony.mc.otm.core.getKeyNullable
import ru.dbotthepony.mc.otm.registry.MBuiltInRegistries
import ru.dbotthepony.mc.otm.registry.MRegistry import ru.dbotthepony.mc.otm.registry.MRegistry
open class AndroidFeatureType<T : AndroidFeature> { open class AndroidFeatureType<T : AndroidFeature> {
@ -26,7 +27,7 @@ open class AndroidFeatureType<T : AndroidFeature> {
open fun isApplicable(android: MatteryPlayer) = true open fun isApplicable(android: MatteryPlayer) = true
val registryName by lazy { val registryName by lazy {
MRegistry.ANDROID_FEATURES.getKeyNullable(this) MBuiltInRegistries.ANDROID_FEATURE.getKeyNullable(this)
} }
open val displayContents: ComponentContents by lazy { open val displayContents: ComponentContents by lazy {

View File

@ -13,11 +13,12 @@ import ru.dbotthepony.mc.otm.config.PlayerConfig
import ru.dbotthepony.mc.otm.core.TextComponent import ru.dbotthepony.mc.otm.core.TextComponent
import ru.dbotthepony.mc.otm.core.TranslatableComponent import ru.dbotthepony.mc.otm.core.TranslatableComponent
import ru.dbotthepony.mc.otm.core.util.formatPower 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.MDeferredRegister
import ru.dbotthepony.mc.otm.registry.RegistryDelegate import ru.dbotthepony.mc.otm.registry.MRegistries
object AndroidResearchDescriptions { object AndroidResearchDescriptions {
private val registrar = MDeferredRegister(AndroidResearchDescription.registryKey, OverdriveThatMatters.MOD_ID) private val registrar = MDeferredRegister(MRegistries.ANDROID_RESEARCH_DESCRIPTION, OverdriveThatMatters.MOD_ID)
init { init {
registrar.register("plain") { PlainAndroidResearchDescription } registrar.register("plain") { PlainAndroidResearchDescription }
@ -140,17 +141,8 @@ interface AndroidResearchDescription {
val type: Type<*> val type: Type<*>
companion object { companion object {
private val delegate = RegistryDelegate<Type<*>>("android_research_description") {}
val registry by delegate
val registryKey get() = delegate.key
val CODEC: Codec<AndroidResearchDescription> by lazy { val CODEC: Codec<AndroidResearchDescription> by lazy {
registry.byNameCodec().dispatch({ it.type }, { it.codec }) MBuiltInRegistries.ANDROID_RESEARCH_DESCRIPTION.byNameCodec().dispatch({ it.type }, { it.codec })
}
internal fun register(bus: IEventBus) {
bus.addListener(delegate::build)
} }
fun singleton(callback: (research: AndroidResearch) -> Component): Singleton { fun singleton(callback: (research: AndroidResearch) -> Component): Singleton {

View File

@ -7,13 +7,14 @@ import net.minecraft.resources.ResourceLocation
import net.neoforged.bus.api.IEventBus import net.neoforged.bus.api.IEventBus
import org.apache.logging.log4j.LogManager import org.apache.logging.log4j.LogManager
import ru.dbotthepony.mc.otm.OverdriveThatMatters 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.game.AndroidFeatures
import ru.dbotthepony.mc.otm.registry.MDeferredRegister 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.MRegistry
import ru.dbotthepony.mc.otm.registry.RegistryDelegate
object AndroidResearchResults { object AndroidResearchResults {
private val registrar = MDeferredRegister(AndroidResearchResult.registryKey, OverdriveThatMatters.MOD_ID) private val registrar = MDeferredRegister(MRegistries.ANDROID_RESEARCH_RESULT, OverdriveThatMatters.MOD_ID)
init { init {
registrar.register("feature") { AndroidResearchResult.Feature } 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 * 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 { 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<*> override val type: Type<*>
get() = Companion get() = Companion
@ -101,7 +102,7 @@ interface AndroidResearchResult {
*/ */
class FeatureLevel(val id: ResourceLocation, val optional: Boolean = false, val levels: Int = 1) : class FeatureLevel(val id: ResourceLocation, val optional: Boolean = false, val levels: Int = 1) :
AndroidResearchResult { 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<*> override val type: Type<*>
get() = Companion get() = Companion
@ -153,17 +154,9 @@ interface AndroidResearchResult {
companion object { companion object {
private val LOGGER = LogManager.getLogger() private val LOGGER = LogManager.getLogger()
private val delegate = RegistryDelegate<Type<*>>("android_research_result") {}
val registry by delegate
val registryKey get() = delegate.key
val CODEC: Codec<AndroidResearchResult> by lazy { val CODEC: Codec<AndroidResearchResult> by lazy {
registry.byNameCodec().dispatch({ it.type }, { it.codec }) MBuiltInRegistries.ANDROID_RESEARCH_RESULT.byNameCodec().dispatch({ it.type }, { it.codec })
}
internal fun register(bus: IEventBus) {
bus.addListener(delegate::build)
} }
} }
} }

View File

@ -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<Delegate<*>>()
private class Delegate<T : Any>(private val key: ResourceKey<Registry<T>>, private val configurator: RegistryBuilder<T>.() -> Unit = {}) {
init {
delegates.add(this)
}
private var _value: Registry<T>? = null
operator fun getValue(thisRef: Any, property: KProperty<*>): Registry<T> {
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) }
}
}

View File

@ -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 <T> k(name: String): ResourceKey<Registry<T>> {
return ResourceKey.createRegistryKey(ResourceLocation(OverdriveThatMatters.MOD_ID, name))
}
val DECIMAL_PROVIDER_TYPE = k<DecimalProvider.Type<*>>("decimal_provider_type")
val MATTER_REGISTRY_ACTION = k<AbstractRegistryAction.Type<*>>("matter_registry_action")
val MATTER_FUNCTION = k<IMatterFunction>("matter_function")
val RECIPE_FINDER = k<MatterManager.Finder>("recipe_finder")
val ANDROID_RESEARCH_DESCRIPTION = k<AndroidResearchDescription.Type<*>>("android_research_description")
val ANDROID_RESEARCH_RESULT = k<AndroidResearchResult.Type<*>>("android_research_result")
val ANDROID_FEATURE = k<AndroidFeatureType<*>>("android_feature")
val STACK_TYPE = k<StorageStack.Type<*>>("stack_type")
}

View File

@ -53,11 +53,6 @@ import ru.dbotthepony.mc.otm.registry.objects.IBlockItemRegistryAcceptor
import ru.dbotthepony.mc.otm.registry.objects.StripedColoredDecorativeBlock import ru.dbotthepony.mc.otm.registry.objects.StripedColoredDecorativeBlock
object MRegistry : IBlockItemRegistryAcceptor { object MRegistry : IBlockItemRegistryAcceptor {
private val features = RegistryDelegate<AndroidFeatureType<*>>("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<DyeColor> = ImmutableList.of( val DYE_ORDER: ImmutableList<DyeColor> = ImmutableList.of(
DyeColor.BLACK, DyeColor.BLACK,
DyeColor.BLUE, DyeColor.BLUE,
@ -251,7 +246,6 @@ object MRegistry : IBlockItemRegistryAcceptor {
} }
internal fun initialize(bus: IEventBus) { internal fun initialize(bus: IEventBus) {
bus.addListener(features::build)
bus.addListener(this::initializeClient) bus.addListener(this::initializeClient)
bus.addListener(this::initializeCommon) bus.addListener(this::initializeCommon)
bus.addListener(MStats::registerVanilla) bus.addListener(MStats::registerVanilla)

View File

@ -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<T>(key: String, private val configurator: RegistryBuilder<T>.() -> Unit = {}) : ReadOnlyProperty<Any, Registry<T>>, Supplier<Registry<T>>, Lazy<Registry<T>> {
private var _value: Registry<T>? = null
override val value: Registry<T>
get() = get()
override fun isInitialized(): Boolean {
return _value != null
}
val location = ResourceLocation(OverdriveThatMatters.MOD_ID, key)
val key: ResourceKey<Registry<T>> = ResourceKey.createRegistryKey(location)
override fun get(): Registry<T> {
val value = _value ?: throw IllegalStateException("Tried to access uninitialized registry $location")
return value
}
override fun getValue(thisRef: Any, property: KProperty<*>): Registry<T> {
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)
}
}
}

View File

@ -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.player.android.feature.SwimBoostersFeature
import ru.dbotthepony.mc.otm.registry.MDeferredRegister import ru.dbotthepony.mc.otm.registry.MDeferredRegister
import ru.dbotthepony.mc.otm.registry.MNames import ru.dbotthepony.mc.otm.registry.MNames
import ru.dbotthepony.mc.otm.registry.MRegistries
import ru.dbotthepony.mc.otm.registry.MRegistry import ru.dbotthepony.mc.otm.registry.MRegistry
object AndroidFeatures { 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 AIR_BAGS by registry.register(MNames.AIR_BAGS) { AndroidFeatureType(::DummyAndroidFeature) }
val STEP_ASSIST by registry.register(MNames.STEP_ASSIST) { AndroidFeatureType(::StepAssistFeature) } val STEP_ASSIST by registry.register(MNames.STEP_ASSIST) { AndroidFeatureType(::StepAssistFeature) }

View File

@ -5,14 +5,13 @@ import net.minecraft.network.RegistryFriendlyByteBuf
import net.minecraft.world.item.ItemStack import net.minecraft.world.item.ItemStack
import net.neoforged.bus.api.IEventBus import net.neoforged.bus.api.IEventBus
import ru.dbotthepony.mc.otm.OverdriveThatMatters 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.math.Decimal
import ru.dbotthepony.mc.otm.core.readBigInteger import ru.dbotthepony.mc.otm.core.readBigInteger
import ru.dbotthepony.mc.otm.core.readItem import ru.dbotthepony.mc.otm.core.readItem
import ru.dbotthepony.mc.otm.core.writeBigInteger import ru.dbotthepony.mc.otm.core.writeBigInteger
import ru.dbotthepony.mc.otm.core.writeItem import ru.dbotthepony.mc.otm.core.writeItem
import ru.dbotthepony.mc.otm.registry.MDeferredRegister 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 import java.math.BigInteger
abstract class StorageStack<S : StorageStack<S>>(val count: BigInteger) { abstract class StorageStack<S : StorageStack<S>>(val count: BigInteger) {
@ -110,11 +109,7 @@ abstract class StorageStack<S : StorageStack<S>>(val count: BigInteger) {
return o?.hashCodeWithoutCount() ?: 0 return o?.hashCodeWithoutCount() ?: 0
} }
private val delegate = RegistryDelegate<Type<*>>("stack_type") {} private val registrar = MDeferredRegister(MRegistries.STACK_TYPE, OverdriveThatMatters.MOD_ID)
val REGISTRY by delegate
val REGISTRY_KEY by delegate::key
private val registrar = MDeferredRegister(REGISTRY_KEY, OverdriveThatMatters.MOD_ID)
val ITEMS: Type<ItemStorageStack> by registrar.register("items") { val ITEMS: Type<ItemStorageStack> by registrar.register("items") {
SimpleType( SimpleType(
@ -131,7 +126,6 @@ abstract class StorageStack<S : StorageStack<S>>(val count: BigInteger) {
} }
internal fun register(bus: IEventBus) { internal fun register(bus: IEventBus) {
bus.addListener(delegate::build)
registrar.register(bus) registrar.register(bus)
} }
} }

View File

@ -15,6 +15,7 @@ import ru.dbotthepony.mc.otm.player.MatteryPlayer
import ru.dbotthepony.mc.otm.player.matteryPlayer import ru.dbotthepony.mc.otm.player.matteryPlayer
import ru.dbotthepony.mc.otm.core.ResourceLocation import ru.dbotthepony.mc.otm.core.ResourceLocation
import ru.dbotthepony.mc.otm.data.codec.SingletonCodec import ru.dbotthepony.mc.otm.data.codec.SingletonCodec
import ru.dbotthepony.mc.otm.registry.MBuiltInRegistries
import ru.dbotthepony.mc.otm.registry.MRegistry import ru.dbotthepony.mc.otm.registry.MRegistry
import java.util.Optional import java.util.Optional
import java.util.function.Predicate import java.util.function.Predicate
@ -76,7 +77,7 @@ object KillAsAndroidTrigger : MCriterionTrigger<KillAsAndroidTrigger.Instance>(R
} }
class Has(val name: ResourceLocation) : FeaturePredicate() { class Has(val name: ResourceLocation) : FeaturePredicate() {
private val resolved by lazy { MRegistry.ANDROID_FEATURES.get(name) } private val resolved by lazy { MBuiltInRegistries.ANDROID_FEATURE.get(name) }
override val type: PredicateType override val type: PredicateType
get() = PredicateType.HAS get() = PredicateType.HAS

View File

@ -18,7 +18,7 @@ function initializeCoreMod() {
if (insn.getOpcode() == Opcodes.BIPUSH) { if (insn.getOpcode() == Opcodes.BIPUSH) {
node.instructions.insert(insn, new MethodInsnNode( node.instructions.insert(insn, new MethodInsnNode(
Opcodes.INVOKESTATIC, Opcodes.INVOKESTATIC,
'ru/dbotthepony/mc/otm/android/feature/LimbOverclockingFeature', 'ru/dbotthepony/mc/otm/player/android/feature/LimbOverclockingFeature',
'getBrushCooldown', 'getBrushCooldown',
'(Lnet/minecraft/world/entity/LivingEntity;)I' '(Lnet/minecraft/world/entity/LivingEntity;)I'
)) ))
@ -31,7 +31,7 @@ function initializeCoreMod() {
if (insn.getOpcode() == Opcodes.ICONST_5) { if (insn.getOpcode() == Opcodes.ICONST_5) {
node.instructions.insert(insn, new MethodInsnNode( node.instructions.insert(insn, new MethodInsnNode(
Opcodes.INVOKESTATIC, Opcodes.INVOKESTATIC,
'ru/dbotthepony/mc/otm/android/feature/LimbOverclockingFeature', 'ru/dbotthepony/mc/otm/player/android/feature/LimbOverclockingFeature',
'getBrushTick', 'getBrushTick',
'(Lnet/minecraft/world/entity/LivingEntity;)I' '(Lnet/minecraft/world/entity/LivingEntity;)I'
)) ))
@ -59,7 +59,7 @@ function initializeCoreMod() {
if (insn.getOpcode() == Opcodes.LDC && insn.cst == 10) { if (insn.getOpcode() == Opcodes.LDC && insn.cst == 10) {
node.instructions.insert(insn, new MethodInsnNode( node.instructions.insert(insn, new MethodInsnNode(
Opcodes.INVOKESTATIC, Opcodes.INVOKESTATIC,
'ru/dbotthepony/mc/otm/android/feature/LimbOverclockingFeature', 'ru/dbotthepony/mc/otm/player/android/feature/LimbOverclockingFeature',
'getBrushableBlockCooldown', 'getBrushableBlockCooldown',
'(Lnet/minecraft/world/entity/player/Player;)J' '(Lnet/minecraft/world/entity/player/Player;)J'
)) ))