Compare commits
No commits in common. "ddcfe11780f4230ae453bb541ad5654c45adef90" and "fdfc406ca67290bdce2d2412911ab1218029cc77" have entirely different histories.
ddcfe11780
...
fdfc406ca6
@ -103,8 +103,6 @@ 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)
|
||||||
@ -135,7 +133,9 @@ 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)
|
||||||
|
@ -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.MRegistries
|
import ru.dbotthepony.mc.otm.registry.RegistryDelegate
|
||||||
|
|
||||||
fun interface SampledDecimal {
|
fun interface SampledDecimal {
|
||||||
fun sample(source: RandomSource): Decimal
|
fun sample(source: RandomSource): Decimal
|
||||||
@ -28,25 +28,33 @@ 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, MBuiltInRegistries.DECIMAL_PROVIDER_TYPE.byNameCodec().dispatch({ it.type }, { it.codec }))
|
.either(DecimalCodec, registry.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) }
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private val registrar = MDeferredRegister(MRegistries.DECIMAL_PROVIDER_TYPE, OverdriveThatMatters.MOD_ID)
|
val registry by registryHolder
|
||||||
|
val registryKey get() = registryHolder.key
|
||||||
|
|
||||||
|
private val registror = MDeferredRegister(registryKey, OverdriveThatMatters.MOD_ID)
|
||||||
|
|
||||||
init {
|
init {
|
||||||
registrar.register("zero") { ConstantDecimal.Zero }
|
registror.register("zero") { ConstantDecimal.Zero }
|
||||||
registrar.register("constant") { ConstantDecimal }
|
registror.register("constant") { ConstantDecimal }
|
||||||
registrar.register("uniform") { UniformDecimal }
|
registror.register("uniform") { UniformDecimal }
|
||||||
}
|
}
|
||||||
|
|
||||||
internal fun register(bus: IEventBus) {
|
internal fun register(bus: IEventBus) {
|
||||||
registrar.register(bus)
|
bus.addListener(registryHolder::build)
|
||||||
|
registror.register(bus)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,9 +13,8 @@ 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.MRegistries
|
import ru.dbotthepony.mc.otm.registry.RegistryDelegate
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
abstract class AbstractRegistryAction(
|
abstract class AbstractRegistryAction(
|
||||||
@ -100,7 +99,12 @@ abstract class AbstractRegistryAction(
|
|||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private val registrar = MDeferredRegister(MRegistries.MATTER_REGISTRY_ACTION, OverdriveThatMatters.MOD_ID)
|
private val registryDelegate = RegistryDelegate<Type<*>>("matter_registry_action") { sync(false) }
|
||||||
|
|
||||||
|
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 }
|
||||||
@ -112,10 +116,11 @@ 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 {
|
||||||
MBuiltInRegistries.MATTER_REGISTRY_ACTION.byNameCodec().dispatch({ it.type }, { it.codec })
|
registry.byNameCodec().dispatch({ it.type }, { it.codec })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,6 @@ 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
|
||||||
|
|
||||||
@ -30,8 +29,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),
|
||||||
MBuiltInRegistries.MATTER_FUNCTION.byNameCodec().fieldOf("matterFunction").forGetter(Constant::matterFunction),
|
IMatterFunction.registry.byNameCodec().fieldOf("matterFunction").forGetter(Constant::matterFunction),
|
||||||
MBuiltInRegistries.MATTER_FUNCTION.byNameCodec().fieldOf("complexityFunction").forGetter(Constant::complexityFunction),
|
IMatterFunction.registry.byNameCodec().fieldOf("complexityFunction").forGetter(Constant::complexityFunction),
|
||||||
).apply(it, ::Constant)
|
).apply(it, ::Constant)
|
||||||
} to Predicate { true }
|
} to Predicate { true }
|
||||||
}
|
}
|
||||||
@ -41,7 +40,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),
|
||||||
MBuiltInRegistries.MATTER_FUNCTION.byNameCodec().fieldOf("function").forGetter(Constant::matterFunction),
|
IMatterFunction.registry.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 }
|
||||||
}
|
}
|
||||||
@ -50,8 +49,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),
|
||||||
MBuiltInRegistries.MATTER_FUNCTION.byNameCodec().fieldOf("matterFunction").forGetter(Constant::matterFunction),
|
IMatterFunction.registry.byNameCodec().fieldOf("matterFunction").forGetter(Constant::matterFunction),
|
||||||
MBuiltInRegistries.MATTER_FUNCTION.byNameCodec().fieldOf("complexityFunction").forGetter(Constant::complexityFunction),
|
IMatterFunction.registry.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()) }
|
||||||
}
|
}
|
||||||
@ -60,7 +59,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),
|
||||||
MBuiltInRegistries.MATTER_FUNCTION.byNameCodec().fieldOf("function").forGetter(Constant::matterFunction),
|
IMatterFunction.registry.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 }
|
||||||
}
|
}
|
||||||
@ -69,7 +68,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),
|
||||||
MBuiltInRegistries.MATTER_FUNCTION.byNameCodec().fieldOf("function").forGetter(Constant::complexityFunction),
|
IMatterFunction.registry.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 }
|
||||||
}
|
}
|
||||||
@ -78,7 +77,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),
|
||||||
MBuiltInRegistries.MATTER_FUNCTION.byNameCodec().fieldOf("complexityFunction").forGetter(Constant::complexityFunction),
|
IMatterFunction.registry.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 }
|
||||||
}
|
}
|
||||||
@ -87,7 +86,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),
|
||||||
MBuiltInRegistries.MATTER_FUNCTION.byNameCodec().fieldOf("function").forGetter(Constant::matterFunction),
|
IMatterFunction.registry.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 }
|
||||||
}
|
}
|
||||||
@ -96,7 +95,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),
|
||||||
MBuiltInRegistries.MATTER_FUNCTION.byNameCodec().fieldOf("matterFunction").forGetter(Constant::matterFunction),
|
IMatterFunction.registry.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 }
|
||||||
}
|
}
|
||||||
@ -183,7 +182,7 @@ class ComputeAction(
|
|||||||
RecordCodecBuilder.create {
|
RecordCodecBuilder.create {
|
||||||
it.group(
|
it.group(
|
||||||
TargetCodec.fieldOf("id").forGetter(Value::id),
|
TargetCodec.fieldOf("id").forGetter(Value::id),
|
||||||
MBuiltInRegistries.MATTER_FUNCTION.byNameCodec().fieldOf("function").forGetter(Value::matterFunction),
|
IMatterFunction.registry.byNameCodec().fieldOf("function").forGetter(Value::matterFunction),
|
||||||
).apply(it, ::Value)
|
).apply(it, ::Value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -192,8 +191,8 @@ class ComputeAction(
|
|||||||
RecordCodecBuilder.create {
|
RecordCodecBuilder.create {
|
||||||
it.group(
|
it.group(
|
||||||
TargetCodec.fieldOf("id").forGetter(Value::id),
|
TargetCodec.fieldOf("id").forGetter(Value::id),
|
||||||
MBuiltInRegistries.MATTER_FUNCTION.byNameCodec().fieldOf("matterFunction").forGetter(Value::matterFunction),
|
IMatterFunction.registry.byNameCodec().fieldOf("matterFunction").forGetter(Value::matterFunction),
|
||||||
MBuiltInRegistries.MATTER_FUNCTION.byNameCodec().fieldOf("complexityFunction").forGetter(Value::complexityFunction),
|
IMatterFunction.registry.byNameCodec().fieldOf("complexityFunction").forGetter(Value::complexityFunction),
|
||||||
).apply(it, ::Value)
|
).apply(it, ::Value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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.MRegistries
|
import ru.dbotthepony.mc.otm.registry.RegistryDelegate
|
||||||
|
|
||||||
interface IMatterFunction {
|
interface IMatterFunction {
|
||||||
fun updateValue(self: Int, other: Int): Int
|
fun updateValue(self: Int, other: Int): Int
|
||||||
@ -15,7 +15,12 @@ interface IMatterFunction {
|
|||||||
fun updateValue(self: Double, other: Double): Double
|
fun updateValue(self: Double, other: Double): Double
|
||||||
|
|
||||||
companion object : IMatterFunction {
|
companion object : IMatterFunction {
|
||||||
private val registrar = MDeferredRegister(MRegistries.MATTER_FUNCTION, OverdriveThatMatters.MOD_ID)
|
private val registryDelegate = RegistryDelegate<IMatterFunction>("matter_function") { sync(false) }
|
||||||
|
|
||||||
|
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 }
|
||||||
@ -33,6 +38,7 @@ 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 {
|
||||||
|
@ -102,9 +102,8 @@ 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.MRegistries
|
import ru.dbotthepony.mc.otm.registry.RegistryDelegate
|
||||||
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
|
||||||
@ -398,10 +397,12 @@ 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(MRegistries.RECIPE_FINDER, OverdriveThatMatters.MOD_ID)
|
val registrar = MDeferredRegister(delegate.key, OverdriveThatMatters.MOD_ID)
|
||||||
|
|
||||||
init {
|
init {
|
||||||
registrar.register("simple") {
|
registrar.register("simple") {
|
||||||
@ -638,11 +639,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 (!MBuiltInRegistries.RECIPE_FINDER.containsKey(location)) {
|
if (!recipeFinders.containsKey(location)) {
|
||||||
throw JsonParseException("Resolver type $location does not exist (in $key)")
|
throw JsonParseException("Resolver type $location does not exist (in $key)")
|
||||||
}
|
}
|
||||||
|
|
||||||
val resolver = MBuiltInRegistries.RECIPE_FINDER.get(location) ?: throw ConcurrentModificationException()
|
val resolver = recipeFinders.get(location) ?: throw ConcurrentModificationException()
|
||||||
builder.put(key, resolver to json)
|
builder.put(key, resolver to json)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1494,6 +1495,20 @@ 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
|
||||||
@ -1518,6 +1533,7 @@ 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)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,7 +11,6 @@ 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>>,
|
||||||
@ -23,7 +22,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, MBuiltInRegistries.MATTER_FUNCTION.byNameCodec(), MatterFunction::value, DecimalCodec)
|
simpleCodec(::MatterFunction, MatterFunction::function, IMatterFunction.registry.byNameCodec(), MatterFunction::value, DecimalCodec)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -31,7 +30,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, MBuiltInRegistries.MATTER_FUNCTION.byNameCodec(), ComplexityFunction::value, Codec.DOUBLE)
|
simpleCodec(::ComplexityFunction, ComplexityFunction::function, IMatterFunction.registry.byNameCodec(), ComplexityFunction::value, Codec.DOUBLE)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -39,7 +38,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, MBuiltInRegistries.MATTER_FUNCTION.byNameCodec(), PriorityFunction::value, Codec.INT)
|
simpleCodec(::PriorityFunction, PriorityFunction::function, IMatterFunction.registry.byNameCodec(), PriorityFunction::value, Codec.INT)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,14 +26,13 @@ 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(MBuiltInRegistries.ANDROID_FEATURE.getId(type))
|
buff.writeInt(MRegistry.ANDROID_FEATURES.getId(type))
|
||||||
buff.writeBytes(data.elements(), 0, data.size)
|
buff.writeBytes(data.elements(), 0, data.size)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,7 +58,7 @@ class AndroidFeatureSyncPacket(val type: AndroidFeatureType<*>, val data: ByteAr
|
|||||||
|
|
||||||
fun read(buff: RegistryFriendlyByteBuf): AndroidFeatureSyncPacket {
|
fun read(buff: RegistryFriendlyByteBuf): AndroidFeatureSyncPacket {
|
||||||
return AndroidFeatureSyncPacket(
|
return AndroidFeatureSyncPacket(
|
||||||
MBuiltInRegistries.ANDROID_FEATURE.byIdOrThrow(buff.readInt()),
|
MRegistry.ANDROID_FEATURES.byIdOrThrow(buff.readInt()),
|
||||||
ByteArrayList.wrap(ByteArray(buff.readableBytes()).also { buff.readBytes(it) })
|
ByteArrayList.wrap(ByteArray(buff.readableBytes()).also { buff.readBytes(it) })
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -141,7 +140,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(MBuiltInRegistries.ANDROID_FEATURE.getId(type))
|
buff.writeInt(MRegistry.ANDROID_FEATURES.getId(type))
|
||||||
}
|
}
|
||||||
|
|
||||||
fun play(context: IPayloadContext) {
|
fun play(context: IPayloadContext) {
|
||||||
@ -165,7 +164,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(MBuiltInRegistries.ANDROID_FEATURE.byIdOrThrow(buff.readInt()))
|
return AndroidFeatureRemovePacket(MRegistry.ANDROID_FEATURES.byIdOrThrow(buff.readInt()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -220,7 +219,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(MBuiltInRegistries.ANDROID_FEATURE.getId(type))
|
buff.writeInt(MRegistry.ANDROID_FEATURES.getId(type))
|
||||||
buff.writeBoolean(newState)
|
buff.writeBoolean(newState)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -260,14 +259,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(MBuiltInRegistries.ANDROID_FEATURE.byIdOrThrow(buff.readInt()), buff.readBoolean())
|
return SwitchAndroidFeaturePacket(MRegistry.ANDROID_FEATURES.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(MBuiltInRegistries.ANDROID_FEATURE.getId(type))
|
buff.writeInt(MRegistry.ANDROID_FEATURES.getId(type))
|
||||||
}
|
}
|
||||||
|
|
||||||
fun play(context: IPayloadContext) {
|
fun play(context: IPayloadContext) {
|
||||||
@ -299,7 +298,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(MBuiltInRegistries.ANDROID_FEATURE.byIdOrThrow(buff.readInt()))
|
return ActivateAndroidFeaturePacket(MRegistry.ANDROID_FEATURES.byIdOrThrow(buff.readInt()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -97,7 +97,6 @@ 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
|
||||||
@ -1005,7 +1004,7 @@ class MatteryPlayer(val ply: Player) {
|
|||||||
research.clear()
|
research.clear()
|
||||||
|
|
||||||
for (featureTag in tag.getCompoundList("features")) {
|
for (featureTag in tag.getCompoundList("features")) {
|
||||||
val feature = MBuiltInRegistries.ANDROID_FEATURE.get(ResourceLocation.parse(featureTag.getString("id")))
|
val feature = MRegistry.ANDROID_FEATURES.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)
|
||||||
|
@ -6,7 +6,6 @@ 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> {
|
||||||
@ -27,7 +26,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 {
|
||||||
MBuiltInRegistries.ANDROID_FEATURE.getKeyNullable(this)
|
MRegistry.ANDROID_FEATURES.getKeyNullable(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
open val displayContents: ComponentContents by lazy {
|
open val displayContents: ComponentContents by lazy {
|
||||||
|
@ -13,12 +13,11 @@ 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.MRegistries
|
import ru.dbotthepony.mc.otm.registry.RegistryDelegate
|
||||||
|
|
||||||
object AndroidResearchDescriptions {
|
object AndroidResearchDescriptions {
|
||||||
private val registrar = MDeferredRegister(MRegistries.ANDROID_RESEARCH_DESCRIPTION, OverdriveThatMatters.MOD_ID)
|
private val registrar = MDeferredRegister(AndroidResearchDescription.registryKey, OverdriveThatMatters.MOD_ID)
|
||||||
|
|
||||||
init {
|
init {
|
||||||
registrar.register("plain") { PlainAndroidResearchDescription }
|
registrar.register("plain") { PlainAndroidResearchDescription }
|
||||||
@ -141,8 +140,17 @@ 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 {
|
||||||
MBuiltInRegistries.ANDROID_RESEARCH_DESCRIPTION.byNameCodec().dispatch({ it.type }, { it.codec })
|
registry.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 {
|
||||||
|
@ -7,14 +7,13 @@ 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(MRegistries.ANDROID_RESEARCH_RESULT, OverdriveThatMatters.MOD_ID)
|
private val registrar = MDeferredRegister(AndroidResearchResult.registryKey, OverdriveThatMatters.MOD_ID)
|
||||||
|
|
||||||
init {
|
init {
|
||||||
registrar.register("feature") { AndroidResearchResult.Feature }
|
registrar.register("feature") { AndroidResearchResult.Feature }
|
||||||
@ -72,7 +71,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 = MBuiltInRegistries.ANDROID_FEATURE.get(id) ?: if (optional) null else throw NoSuchElementException("Unknown android feature $id")
|
val feature = MRegistry.ANDROID_FEATURES.get(id) ?: if (optional) null else throw NoSuchElementException("Unknown android feature $id")
|
||||||
|
|
||||||
override val type: Type<*>
|
override val type: Type<*>
|
||||||
get() = Companion
|
get() = Companion
|
||||||
@ -102,7 +101,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 = MBuiltInRegistries.ANDROID_FEATURE.get(id) ?: if (optional) null else throw NoSuchElementException("Unknown android feature $id")
|
val feature = MRegistry.ANDROID_FEATURES.get(id) ?: if (optional) null else throw NoSuchElementException("Unknown android feature $id")
|
||||||
|
|
||||||
override val type: Type<*>
|
override val type: Type<*>
|
||||||
get() = Companion
|
get() = Companion
|
||||||
@ -154,9 +153,17 @@ 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 {
|
||||||
MBuiltInRegistries.ANDROID_RESEARCH_RESULT.byNameCodec().dispatch({ it.type }, { it.codec })
|
registry.byNameCodec().dispatch({ it.type }, { it.codec })
|
||||||
|
}
|
||||||
|
|
||||||
|
internal fun register(bus: IEventBus) {
|
||||||
|
bus.addListener(delegate::build)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,57 +0,0 @@
|
|||||||
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) }
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,29 +0,0 @@
|
|||||||
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")
|
|
||||||
}
|
|
@ -53,6 +53,11 @@ 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,
|
||||||
@ -246,6 +251,7 @@ 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)
|
||||||
|
@ -0,0 +1,45 @@
|
|||||||
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -18,11 +18,10 @@ 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(MRegistries.ANDROID_FEATURE)
|
private val registry = MDeferredRegister(MRegistry.ANDROID_FEATURES_KEY)
|
||||||
|
|
||||||
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) }
|
||||||
|
@ -5,13 +5,14 @@ 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.MRegistries
|
import ru.dbotthepony.mc.otm.registry.RegistryDelegate
|
||||||
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) {
|
||||||
@ -109,7 +110,11 @@ abstract class StorageStack<S : StorageStack<S>>(val count: BigInteger) {
|
|||||||
return o?.hashCodeWithoutCount() ?: 0
|
return o?.hashCodeWithoutCount() ?: 0
|
||||||
}
|
}
|
||||||
|
|
||||||
private val registrar = MDeferredRegister(MRegistries.STACK_TYPE, OverdriveThatMatters.MOD_ID)
|
private val delegate = RegistryDelegate<Type<*>>("stack_type") {}
|
||||||
|
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(
|
||||||
@ -126,6 +131,7 @@ 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)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,6 @@ 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
|
||||||
@ -77,7 +76,7 @@ object KillAsAndroidTrigger : MCriterionTrigger<KillAsAndroidTrigger.Instance>(R
|
|||||||
}
|
}
|
||||||
|
|
||||||
class Has(val name: ResourceLocation) : FeaturePredicate() {
|
class Has(val name: ResourceLocation) : FeaturePredicate() {
|
||||||
private val resolved by lazy { MBuiltInRegistries.ANDROID_FEATURE.get(name) }
|
private val resolved by lazy { MRegistry.ANDROID_FEATURES.get(name) }
|
||||||
|
|
||||||
override val type: PredicateType
|
override val type: PredicateType
|
||||||
get() = PredicateType.HAS
|
get() = PredicateType.HAS
|
||||||
|
@ -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/player/android/feature/LimbOverclockingFeature',
|
'ru/dbotthepony/mc/otm/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/player/android/feature/LimbOverclockingFeature',
|
'ru/dbotthepony/mc/otm/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/player/android/feature/LimbOverclockingFeature',
|
'ru/dbotthepony/mc/otm/android/feature/LimbOverclockingFeature',
|
||||||
'getBrushableBlockCooldown',
|
'getBrushableBlockCooldown',
|
||||||
'(Lnet/minecraft/world/entity/player/Player;)J'
|
'(Lnet/minecraft/world/entity/player/Player;)J'
|
||||||
))
|
))
|
||||||
|
Loading…
Reference in New Issue
Block a user