Split field synchronizer into its own package
This commit is contained in:
parent
48a156cd9a
commit
3672b9c3ac
@ -6,7 +6,7 @@ import net.minecraftforge.common.util.INBTSerializable
|
||||
import net.minecraftforge.event.entity.living.LivingHurtEvent
|
||||
import ru.dbotthepony.mc.otm.capability.MatteryPlayerCapability
|
||||
import ru.dbotthepony.mc.otm.core.nbt.set
|
||||
import ru.dbotthepony.mc.otm.network.FieldSynchronizer
|
||||
import ru.dbotthepony.mc.otm.network.synchronizer.FieldSynchronizer
|
||||
import java.io.InputStream
|
||||
|
||||
abstract class AndroidFeature(val type: AndroidFeatureType<*>, val android: MatteryPlayerCapability) : INBTSerializable<CompoundTag> {
|
||||
|
@ -20,7 +20,7 @@ import ru.dbotthepony.mc.otm.core.nbt.getCompoundList
|
||||
import ru.dbotthepony.mc.otm.core.registryName
|
||||
import ru.dbotthepony.mc.otm.core.nbt.set
|
||||
import ru.dbotthepony.mc.otm.milliTime
|
||||
import ru.dbotthepony.mc.otm.network.FieldSynchronizer
|
||||
import ru.dbotthepony.mc.otm.network.synchronizer.FieldSynchronizer
|
||||
import ru.dbotthepony.mc.otm.registry.MRegistry
|
||||
import ru.dbotthepony.mc.otm.triggers.AndroidResearchTrigger
|
||||
import java.io.InputStream
|
||||
|
@ -53,7 +53,7 @@ import ru.dbotthepony.mc.otm.core.math.plus
|
||||
import ru.dbotthepony.mc.otm.core.util.Savetables
|
||||
import ru.dbotthepony.mc.otm.core.util.TickList
|
||||
import ru.dbotthepony.mc.otm.network.BlockEntitySyncPacket
|
||||
import ru.dbotthepony.mc.otm.network.FieldSynchronizer
|
||||
import ru.dbotthepony.mc.otm.network.synchronizer.FieldSynchronizer
|
||||
import ru.dbotthepony.mc.otm.network.WorldNetworkChannel
|
||||
import ru.dbotthepony.mc.otm.once
|
||||
import ru.dbotthepony.mc.otm.onceServer
|
||||
|
@ -4,7 +4,7 @@ import net.minecraft.nbt.CompoundTag
|
||||
import net.minecraftforge.common.util.INBTSerializable
|
||||
import ru.dbotthepony.mc.otm.core.nbt.mapString
|
||||
import ru.dbotthepony.mc.otm.core.nbt.set
|
||||
import ru.dbotthepony.mc.otm.network.FieldSynchronizer
|
||||
import ru.dbotthepony.mc.otm.network.synchronizer.FieldSynchronizer
|
||||
|
||||
interface IRedstoneControlled {
|
||||
val redstoneControl: AbstractRedstoneControl
|
||||
|
@ -68,6 +68,7 @@ import ru.dbotthepony.mc.otm.core.util.TickList
|
||||
import ru.dbotthepony.mc.otm.core.util.UUIDValueCodec
|
||||
import ru.dbotthepony.mc.otm.menu.ExoPackInventoryMenu
|
||||
import ru.dbotthepony.mc.otm.network.*
|
||||
import ru.dbotthepony.mc.otm.network.synchronizer.FieldSynchronizer
|
||||
import ru.dbotthepony.mc.otm.registry.AndroidFeatures
|
||||
import ru.dbotthepony.mc.otm.registry.MRegistry
|
||||
import ru.dbotthepony.mc.otm.triggers.AndroidResearchTrigger
|
||||
|
@ -14,7 +14,7 @@ import ru.dbotthepony.mc.otm.core.math.getDecimal
|
||||
import ru.dbotthepony.mc.otm.core.nbt.getItemStack
|
||||
import ru.dbotthepony.mc.otm.core.ifPresentK
|
||||
import ru.dbotthepony.mc.otm.core.nbt.set
|
||||
import ru.dbotthepony.mc.otm.network.FieldSynchronizer
|
||||
import ru.dbotthepony.mc.otm.network.synchronizer.FieldSynchronizer
|
||||
import ru.dbotthepony.mc.otm.registry.StatNames
|
||||
import ru.dbotthepony.mc.otm.triggers.AndroidBatteryTrigger
|
||||
|
||||
|
@ -14,17 +14,15 @@ import net.minecraft.world.item.Item
|
||||
import net.minecraft.world.item.Items
|
||||
import net.minecraftforge.common.util.INBTSerializable
|
||||
import net.minecraftforge.registries.ForgeRegistries
|
||||
import ru.dbotthepony.mc.otm.core.forValidRefs
|
||||
import ru.dbotthepony.mc.otm.core.nbt.map
|
||||
import ru.dbotthepony.mc.otm.core.nbt.set
|
||||
import ru.dbotthepony.mc.otm.core.registryName
|
||||
import ru.dbotthepony.mc.otm.core.util.ItemValueCodec
|
||||
import ru.dbotthepony.mc.otm.core.util.VarIntValueCodec
|
||||
import ru.dbotthepony.mc.otm.network.FieldSynchronizer
|
||||
import ru.dbotthepony.mc.otm.network.IField
|
||||
import ru.dbotthepony.mc.otm.network.synchronizer.FieldSynchronizer
|
||||
import ru.dbotthepony.mc.otm.network.synchronizer.IField
|
||||
import java.lang.ref.WeakReference
|
||||
import java.util.*
|
||||
import kotlin.collections.ArrayList
|
||||
|
||||
@Suppress("UNUSED")
|
||||
open class MatteryContainer(protected val watcher: Runnable, private val size: Int) : Container, Iterable<ItemStack>, INBTSerializable<Tag?> {
|
||||
|
@ -37,8 +37,8 @@ import ru.dbotthepony.mc.otm.core.util.ItemValueCodec
|
||||
import ru.dbotthepony.mc.otm.core.util.NullValueCodec
|
||||
import ru.dbotthepony.mc.otm.core.util.VarIntValueCodec
|
||||
import ru.dbotthepony.mc.otm.menu.widget.AbstractWidget
|
||||
import ru.dbotthepony.mc.otm.network.FieldSynchronizer
|
||||
import ru.dbotthepony.mc.otm.network.IField
|
||||
import ru.dbotthepony.mc.otm.network.synchronizer.FieldSynchronizer
|
||||
import ru.dbotthepony.mc.otm.network.synchronizer.IField
|
||||
import ru.dbotthepony.mc.otm.network.MatteryPacket
|
||||
import ru.dbotthepony.mc.otm.network.MatteryPlayerNetworkChannel
|
||||
import ru.dbotthepony.mc.otm.network.MenuFieldPacket
|
||||
|
@ -0,0 +1,41 @@
|
||||
package ru.dbotthepony.mc.otm.network.synchronizer
|
||||
|
||||
interface FieldAccess<V> {
|
||||
fun read(): V
|
||||
fun write(value: V)
|
||||
}
|
||||
|
||||
interface FloatFieldAccess : FieldAccess<Float> {
|
||||
override fun write(value: Float)
|
||||
@Deprecated("Use type specific method", replaceWith = ReplaceWith("this.readFloat()"))
|
||||
override fun read() = readFloat()
|
||||
fun readFloat(): Float
|
||||
}
|
||||
|
||||
interface DoubleFieldAccess : FieldAccess<Double> {
|
||||
override fun write(value: Double)
|
||||
@Deprecated("Use type specific method", replaceWith = ReplaceWith("this.readDouble()"))
|
||||
override fun read() = readDouble()
|
||||
fun readDouble(): Double
|
||||
}
|
||||
|
||||
interface IntFieldAccess : FieldAccess<Int> {
|
||||
override fun write(value: Int)
|
||||
@Deprecated("Use type specific method", replaceWith = ReplaceWith("this.readInt()"))
|
||||
override fun read() = readInt()
|
||||
fun readInt(): Int
|
||||
}
|
||||
|
||||
interface LongFieldAccess : FieldAccess<Long> {
|
||||
override fun write(value: Long)
|
||||
@Deprecated("Use type specific method", replaceWith = ReplaceWith("this.readLong()"))
|
||||
override fun read() = readLong()
|
||||
fun readLong(): Long
|
||||
}
|
||||
|
||||
interface BooleanFieldAccess : FieldAccess<Boolean> {
|
||||
override fun write(value: Boolean)
|
||||
@Deprecated("Use type specific method", replaceWith = ReplaceWith("this.readBoolean()"))
|
||||
override fun read() = readBoolean()
|
||||
fun readBoolean(): Boolean
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
package ru.dbotthepony.mc.otm.network.synchronizer
|
||||
|
||||
fun interface FieldGetter<V> {
|
||||
fun invoke(field: FieldAccess<V>): V
|
||||
}
|
||||
|
||||
fun interface FloatFieldGetter : FieldGetter<Float> {
|
||||
fun invoke(field: FloatFieldAccess): Float
|
||||
|
||||
@Deprecated("Use type specific invoke")
|
||||
override fun invoke(field: FieldAccess<Float>): Float {
|
||||
return invoke(field as FloatFieldAccess)
|
||||
}
|
||||
}
|
||||
|
||||
fun interface DoubleFieldGetter : FieldGetter<Double> {
|
||||
fun invoke(field: DoubleFieldAccess): Double
|
||||
|
||||
@Deprecated("Use type specific invoke")
|
||||
override fun invoke(field: FieldAccess<Double>): Double {
|
||||
return invoke(field as DoubleFieldAccess)
|
||||
}
|
||||
}
|
||||
|
||||
fun interface IntFieldGetter : FieldGetter<Int> {
|
||||
fun invoke(field: IntFieldAccess): Int
|
||||
|
||||
@Deprecated("Use type specific invoke")
|
||||
override fun invoke(field: FieldAccess<Int>): Int {
|
||||
return invoke(field as IntFieldAccess)
|
||||
}
|
||||
}
|
||||
|
||||
fun interface LongFieldGetter : FieldGetter<Long> {
|
||||
fun invoke(field: LongFieldAccess): Long
|
||||
|
||||
@Deprecated("Use type specific invoke")
|
||||
override fun invoke(field: FieldAccess<Long>): Long {
|
||||
return invoke(field as LongFieldAccess)
|
||||
}
|
||||
}
|
||||
|
||||
fun interface BooleanFieldGetter : FieldGetter<Boolean> {
|
||||
fun invoke(field: BooleanFieldAccess): Boolean
|
||||
|
||||
@Deprecated("Use type specific invoke")
|
||||
override fun invoke(field: FieldAccess<Boolean>): Boolean {
|
||||
return invoke(field as BooleanFieldAccess)
|
||||
}
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
package ru.dbotthepony.mc.otm.network.synchronizer
|
||||
|
||||
fun interface FieldSetter<V> {
|
||||
fun invoke(value: V, access: FieldAccess<V>, setByRemote: Boolean)
|
||||
}
|
||||
|
||||
fun interface FloatFieldSetter : FieldSetter<Float> {
|
||||
fun invoke(value: Float, access: FloatFieldAccess, setByRemote: Boolean)
|
||||
|
||||
@Deprecated("Use type specific invoke")
|
||||
override fun invoke(value: Float, access: FieldAccess<Float>, setByRemote: Boolean) {
|
||||
invoke(value, access as FloatFieldAccess, setByRemote)
|
||||
}
|
||||
}
|
||||
|
||||
fun interface DoubleFieldSetter : FieldSetter<Double> {
|
||||
fun invoke(value: Double, access: DoubleFieldAccess, setByRemote: Boolean)
|
||||
|
||||
@Deprecated("Use type specific invoke")
|
||||
override fun invoke(value: Double, access: FieldAccess<Double>, setByRemote: Boolean) {
|
||||
invoke(value, access as DoubleFieldAccess, setByRemote)
|
||||
}
|
||||
}
|
||||
|
||||
fun interface IntFieldSetter : FieldSetter<Int> {
|
||||
fun invoke(value: Int, access: IntFieldAccess, setByRemote: Boolean)
|
||||
|
||||
@Deprecated("Use type specific invoke")
|
||||
override fun invoke(value: Int, access: FieldAccess<Int>, setByRemote: Boolean) {
|
||||
invoke(value, access as IntFieldAccess, setByRemote)
|
||||
}
|
||||
}
|
||||
|
||||
fun interface LongFieldSetter : FieldSetter<Long> {
|
||||
fun invoke(value: Long, access: LongFieldAccess, setByRemote: Boolean)
|
||||
|
||||
@Deprecated("Use type specific invoke")
|
||||
override fun invoke(value: Long, access: FieldAccess<Long>, setByRemote: Boolean) {
|
||||
invoke(value, access as LongFieldAccess, setByRemote)
|
||||
}
|
||||
}
|
||||
|
||||
fun interface BooleanFieldSetter : FieldSetter<Boolean> {
|
||||
fun invoke(value: Boolean, access: BooleanFieldAccess, setByRemote: Boolean)
|
||||
|
||||
@Deprecated("Use type specific invoke")
|
||||
override fun invoke(value: Boolean, access: FieldAccess<Boolean>, setByRemote: Boolean) {
|
||||
invoke(value, access as BooleanFieldAccess, setByRemote)
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
@file:Suppress("DeprecatedCallableAddReplaceWith")
|
||||
|
||||
package ru.dbotthepony.mc.otm.network
|
||||
package ru.dbotthepony.mc.otm.network.synchronizer
|
||||
|
||||
import it.unimi.dsi.fastutil.booleans.BooleanConsumer
|
||||
import it.unimi.dsi.fastutil.floats.FloatConsumer
|
||||
@ -41,488 +41,12 @@ import java.util.function.IntSupplier
|
||||
import java.util.function.LongConsumer
|
||||
import java.util.function.LongSupplier
|
||||
import java.util.function.Supplier
|
||||
import kotlin.properties.ReadOnlyProperty
|
||||
import kotlin.reflect.KMutableProperty0
|
||||
import kotlin.reflect.KProperty
|
||||
import kotlin.reflect.KProperty0
|
||||
|
||||
interface FieldAccess<V> {
|
||||
fun read(): V
|
||||
fun write(value: V)
|
||||
}
|
||||
|
||||
interface FloatFieldAccess : FieldAccess<Float> {
|
||||
override fun write(value: Float)
|
||||
@Deprecated("Use type specific method", replaceWith = ReplaceWith("this.readFloat()"))
|
||||
override fun read() = readFloat()
|
||||
fun readFloat(): Float
|
||||
}
|
||||
|
||||
interface DoubleFieldAccess : FieldAccess<Double> {
|
||||
override fun write(value: Double)
|
||||
@Deprecated("Use type specific method", replaceWith = ReplaceWith("this.readDouble()"))
|
||||
override fun read() = readDouble()
|
||||
fun readDouble(): Double
|
||||
}
|
||||
|
||||
interface IntFieldAccess : FieldAccess<Int> {
|
||||
override fun write(value: Int)
|
||||
@Deprecated("Use type specific method", replaceWith = ReplaceWith("this.readInt()"))
|
||||
override fun read() = readInt()
|
||||
fun readInt(): Int
|
||||
}
|
||||
|
||||
interface LongFieldAccess : FieldAccess<Long> {
|
||||
override fun write(value: Long)
|
||||
@Deprecated("Use type specific method", replaceWith = ReplaceWith("this.readLong()"))
|
||||
override fun read() = readLong()
|
||||
fun readLong(): Long
|
||||
}
|
||||
|
||||
interface BooleanFieldAccess : FieldAccess<Boolean> {
|
||||
override fun write(value: Boolean)
|
||||
@Deprecated("Use type specific method", replaceWith = ReplaceWith("this.readBoolean()"))
|
||||
override fun read() = readBoolean()
|
||||
fun readBoolean(): Boolean
|
||||
}
|
||||
|
||||
fun interface FieldGetter<V> {
|
||||
fun invoke(field: FieldAccess<V>): V
|
||||
}
|
||||
|
||||
fun interface FloatFieldGetter : FieldGetter<Float> {
|
||||
fun invoke(field: FloatFieldAccess): Float
|
||||
|
||||
@Deprecated("Use type specific invoke")
|
||||
override fun invoke(field: FieldAccess<Float>): Float {
|
||||
return invoke(field as FloatFieldAccess)
|
||||
}
|
||||
}
|
||||
|
||||
fun interface DoubleFieldGetter : FieldGetter<Double> {
|
||||
fun invoke(field: DoubleFieldAccess): Double
|
||||
|
||||
@Deprecated("Use type specific invoke")
|
||||
override fun invoke(field: FieldAccess<Double>): Double {
|
||||
return invoke(field as DoubleFieldAccess)
|
||||
}
|
||||
}
|
||||
|
||||
fun interface IntFieldGetter : FieldGetter<Int> {
|
||||
fun invoke(field: IntFieldAccess): Int
|
||||
|
||||
@Deprecated("Use type specific invoke")
|
||||
override fun invoke(field: FieldAccess<Int>): Int {
|
||||
return invoke(field as IntFieldAccess)
|
||||
}
|
||||
}
|
||||
|
||||
fun interface LongFieldGetter : FieldGetter<Long> {
|
||||
fun invoke(field: LongFieldAccess): Long
|
||||
|
||||
@Deprecated("Use type specific invoke")
|
||||
override fun invoke(field: FieldAccess<Long>): Long {
|
||||
return invoke(field as LongFieldAccess)
|
||||
}
|
||||
}
|
||||
|
||||
fun interface BooleanFieldGetter : FieldGetter<Boolean> {
|
||||
fun invoke(field: BooleanFieldAccess): Boolean
|
||||
|
||||
@Deprecated("Use type specific invoke")
|
||||
override fun invoke(field: FieldAccess<Boolean>): Boolean {
|
||||
return invoke(field as BooleanFieldAccess)
|
||||
}
|
||||
}
|
||||
|
||||
fun interface FieldSetter<V> {
|
||||
fun invoke(value: V, access: FieldAccess<V>, setByRemote: Boolean)
|
||||
}
|
||||
|
||||
fun interface FloatFieldSetter : FieldSetter<Float> {
|
||||
fun invoke(value: Float, access: FloatFieldAccess, setByRemote: Boolean)
|
||||
|
||||
@Deprecated("Use type specific invoke")
|
||||
override fun invoke(value: Float, access: FieldAccess<Float>, setByRemote: Boolean) {
|
||||
invoke(value, access as FloatFieldAccess, setByRemote)
|
||||
}
|
||||
}
|
||||
|
||||
fun interface DoubleFieldSetter : FieldSetter<Double> {
|
||||
fun invoke(value: Double, access: DoubleFieldAccess, setByRemote: Boolean)
|
||||
|
||||
@Deprecated("Use type specific invoke")
|
||||
override fun invoke(value: Double, access: FieldAccess<Double>, setByRemote: Boolean) {
|
||||
invoke(value, access as DoubleFieldAccess, setByRemote)
|
||||
}
|
||||
}
|
||||
|
||||
fun interface IntFieldSetter : FieldSetter<Int> {
|
||||
fun invoke(value: Int, access: IntFieldAccess, setByRemote: Boolean)
|
||||
|
||||
@Deprecated("Use type specific invoke")
|
||||
override fun invoke(value: Int, access: FieldAccess<Int>, setByRemote: Boolean) {
|
||||
invoke(value, access as IntFieldAccess, setByRemote)
|
||||
}
|
||||
}
|
||||
|
||||
fun interface LongFieldSetter : FieldSetter<Long> {
|
||||
fun invoke(value: Long, access: LongFieldAccess, setByRemote: Boolean)
|
||||
|
||||
@Deprecated("Use type specific invoke")
|
||||
override fun invoke(value: Long, access: FieldAccess<Long>, setByRemote: Boolean) {
|
||||
invoke(value, access as LongFieldAccess, setByRemote)
|
||||
}
|
||||
}
|
||||
|
||||
fun interface BooleanFieldSetter : FieldSetter<Boolean> {
|
||||
fun invoke(value: Boolean, access: BooleanFieldAccess, setByRemote: Boolean)
|
||||
|
||||
@Deprecated("Use type specific invoke")
|
||||
override fun invoke(value: Boolean, access: FieldAccess<Boolean>, setByRemote: Boolean) {
|
||||
invoke(value, access as BooleanFieldAccess, setByRemote)
|
||||
}
|
||||
}
|
||||
|
||||
sealed interface IField<V> : ReadOnlyProperty<Any?, V>, Supplier<V>, () -> V {
|
||||
fun observe(): Boolean
|
||||
fun markDirty()
|
||||
fun markDirty(endpoint: FieldSynchronizer.Endpoint)
|
||||
val value: V
|
||||
val isRemoved: Boolean
|
||||
|
||||
fun remove()
|
||||
|
||||
fun write(stream: DataOutputStream, endpoint: FieldSynchronizer.Endpoint)
|
||||
fun read(stream: DataInputStream)
|
||||
|
||||
override fun getValue(thisRef: Any?, property: KProperty<*>): V {
|
||||
return this.value
|
||||
}
|
||||
|
||||
override fun get(): V {
|
||||
return value
|
||||
}
|
||||
|
||||
override fun invoke(): V {
|
||||
return value
|
||||
}
|
||||
}
|
||||
|
||||
interface IFloatProperty {
|
||||
operator fun getValue(thisRef: Any?, property: KProperty<*>): Float
|
||||
}
|
||||
|
||||
sealed interface IFloatField : IField<Float>, FloatSupplier {
|
||||
val float: Float
|
||||
val property: IFloatProperty
|
||||
|
||||
override val value: Float
|
||||
get() = float
|
||||
|
||||
@Deprecated("Use type specific Supplier interface")
|
||||
override fun get(): Float {
|
||||
return float
|
||||
}
|
||||
|
||||
override fun getAsFloat(): Float {
|
||||
return float
|
||||
}
|
||||
|
||||
@Deprecated("Use type specific property", replaceWith = ReplaceWith("this.property"))
|
||||
override fun getValue(thisRef: Any?, property: KProperty<*>): Float {
|
||||
return float
|
||||
}
|
||||
}
|
||||
|
||||
interface IDoubleProperty {
|
||||
operator fun getValue(thisRef: Any?, property: KProperty<*>): Double
|
||||
}
|
||||
|
||||
sealed interface IDoubleField : IField<Double>, DoubleSupplier {
|
||||
val double: Double
|
||||
val property: IDoubleProperty
|
||||
|
||||
@Deprecated("Use type specific Supplier interface")
|
||||
override fun get(): Double {
|
||||
return double
|
||||
}
|
||||
|
||||
override val value: Double
|
||||
get() = double
|
||||
|
||||
override fun getAsDouble(): Double {
|
||||
return double
|
||||
}
|
||||
|
||||
@Deprecated("Use type specific property", replaceWith = ReplaceWith("this.property"))
|
||||
override fun getValue(thisRef: Any?, property: KProperty<*>): Double {
|
||||
return double
|
||||
}
|
||||
}
|
||||
|
||||
interface IIntProperty {
|
||||
operator fun getValue(thisRef: Any?, property: KProperty<*>): Int
|
||||
}
|
||||
|
||||
sealed interface IIntField : IField<Int>, IntSupplier {
|
||||
val int: Int
|
||||
val property: IIntProperty
|
||||
|
||||
@Deprecated("Use type specific Supplier interface")
|
||||
override fun get(): Int {
|
||||
return int
|
||||
}
|
||||
|
||||
override val value: Int
|
||||
get() = int
|
||||
|
||||
override fun getAsInt(): Int {
|
||||
return int
|
||||
}
|
||||
|
||||
@Deprecated("Use type specific property", replaceWith = ReplaceWith("this.property"))
|
||||
override fun getValue(thisRef: Any?, property: KProperty<*>): Int {
|
||||
return int
|
||||
}
|
||||
}
|
||||
|
||||
interface ILongProperty {
|
||||
operator fun getValue(thisRef: Any?, property: KProperty<*>): Long
|
||||
}
|
||||
|
||||
sealed interface ILongField : IField<Long>, LongSupplier {
|
||||
val long: Long
|
||||
val property: ILongProperty
|
||||
|
||||
@Deprecated("Use type specific Supplier interface")
|
||||
override fun get(): Long {
|
||||
return long
|
||||
}
|
||||
|
||||
override val value: Long
|
||||
get() = long
|
||||
|
||||
override fun getAsLong(): Long {
|
||||
return long
|
||||
}
|
||||
|
||||
@Deprecated("Use type specific property", replaceWith = ReplaceWith("this.property"))
|
||||
override fun getValue(thisRef: Any?, property: KProperty<*>): Long {
|
||||
return long
|
||||
}
|
||||
}
|
||||
|
||||
interface IBooleanProperty {
|
||||
operator fun getValue(thisRef: Any?, property: KProperty<*>): Boolean
|
||||
}
|
||||
|
||||
sealed interface IBooleanField : IField<Boolean>, BooleanSupplier {
|
||||
val boolean: Boolean
|
||||
val property: IBooleanProperty
|
||||
|
||||
@Deprecated("Use type specific Supplier interface")
|
||||
override fun get(): Boolean {
|
||||
return boolean
|
||||
}
|
||||
|
||||
override val value: Boolean
|
||||
get() = boolean
|
||||
|
||||
override fun getAsBoolean(): Boolean {
|
||||
return boolean
|
||||
}
|
||||
|
||||
@Deprecated("Use type specific property", replaceWith = ReplaceWith("this.property"))
|
||||
override fun getValue(thisRef: Any?, property: KProperty<*>): Boolean {
|
||||
return boolean
|
||||
}
|
||||
}
|
||||
|
||||
sealed interface IMutableField<V> : IField<V>, GetterSetter<V> {
|
||||
override fun getValue(thisRef: Any?, property: KProperty<*>): V {
|
||||
return this.value
|
||||
}
|
||||
|
||||
override var value: V
|
||||
|
||||
override fun accept(t: V) {
|
||||
value = t
|
||||
}
|
||||
|
||||
override fun invoke(): V {
|
||||
return this.value
|
||||
}
|
||||
}
|
||||
|
||||
interface IMutableFloatProperty : IFloatProperty {
|
||||
operator fun setValue(thisRef: Any?, property: KProperty<*>, value: Float)
|
||||
}
|
||||
|
||||
sealed interface IMutableFloatField : IMutableField<Float>, IFloatField, FloatConsumer {
|
||||
override var float: Float
|
||||
override val property: IMutableFloatProperty
|
||||
|
||||
@Deprecated("Use type specific property", replaceWith = ReplaceWith("this.float"))
|
||||
override var value: Float
|
||||
get() = float
|
||||
set(value) { float = value }
|
||||
|
||||
override fun accept(t: Float) {
|
||||
float = t
|
||||
}
|
||||
|
||||
@Deprecated("Use type specific property", replaceWith = ReplaceWith("this.property"))
|
||||
override fun getValue(thisRef: Any?, property: KProperty<*>): Float {
|
||||
return float
|
||||
}
|
||||
|
||||
@Deprecated("Use type specific property", replaceWith = ReplaceWith("this.property"))
|
||||
override fun setValue(thisRef: Any?, property: KProperty<*>, value: Float) {
|
||||
float = value
|
||||
}
|
||||
}
|
||||
|
||||
interface IMutableDoubleProperty : IDoubleProperty {
|
||||
operator fun setValue(thisRef: Any?, property: KProperty<*>, value: Double)
|
||||
}
|
||||
|
||||
sealed interface IMutableDoubleField : IMutableField<Double>, IDoubleField, DoubleConsumer {
|
||||
override var double: Double
|
||||
override val property: IMutableDoubleProperty
|
||||
|
||||
@Deprecated("Use type specific property", replaceWith = ReplaceWith("this.double"))
|
||||
override var value: Double
|
||||
get() = double
|
||||
set(value) { double = value }
|
||||
|
||||
override fun accept(t: Double) {
|
||||
double = t
|
||||
}
|
||||
|
||||
@Deprecated("Use type specific property", replaceWith = ReplaceWith("this.property"))
|
||||
override fun getValue(thisRef: Any?, property: KProperty<*>): Double {
|
||||
return double
|
||||
}
|
||||
|
||||
@Deprecated("Use type specific property", replaceWith = ReplaceWith("this.property"))
|
||||
override fun setValue(thisRef: Any?, property: KProperty<*>, value: Double) {
|
||||
double = value
|
||||
}
|
||||
}
|
||||
|
||||
interface IMutableIntProperty : IIntProperty {
|
||||
operator fun setValue(thisRef: Any?, property: KProperty<*>, value: Int)
|
||||
}
|
||||
|
||||
sealed interface IMutableIntField : IMutableField<Int>, IIntField, IntConsumer {
|
||||
override var int: Int
|
||||
override val property: IMutableIntProperty
|
||||
|
||||
@Deprecated("Use type specific property", replaceWith = ReplaceWith("this.int"))
|
||||
override var value: Int
|
||||
get() = int
|
||||
set(value) { int = value }
|
||||
|
||||
override fun accept(t: Int) {
|
||||
int = t
|
||||
}
|
||||
|
||||
@Deprecated("Use type specific property", replaceWith = ReplaceWith("this.property"))
|
||||
override fun getValue(thisRef: Any?, property: KProperty<*>): Int {
|
||||
return int
|
||||
}
|
||||
|
||||
@Deprecated("Use type specific property", replaceWith = ReplaceWith("this.property"))
|
||||
override fun setValue(thisRef: Any?, property: KProperty<*>, value: Int) {
|
||||
int = value
|
||||
}
|
||||
}
|
||||
|
||||
interface IMutableLongProperty : ILongProperty {
|
||||
operator fun setValue(thisRef: Any?, property: KProperty<*>, value: Long)
|
||||
}
|
||||
|
||||
sealed interface IMutableLongField : IMutableField<Long>, ILongField, LongConsumer {
|
||||
override var long: Long
|
||||
override val property: IMutableLongProperty
|
||||
|
||||
@Deprecated("Use type specific property", replaceWith = ReplaceWith("this.long"))
|
||||
override var value: Long
|
||||
get() = long
|
||||
set(value) { long = value }
|
||||
|
||||
override fun accept(t: Long) {
|
||||
long = t
|
||||
}
|
||||
|
||||
@Deprecated("Use type specific property", replaceWith = ReplaceWith("this.property"))
|
||||
override fun getValue(thisRef: Any?, property: KProperty<*>): Long {
|
||||
return long
|
||||
}
|
||||
|
||||
@Deprecated("Use type specific property", replaceWith = ReplaceWith("this.property"))
|
||||
override fun setValue(thisRef: Any?, property: KProperty<*>, value: Long) {
|
||||
long = value
|
||||
}
|
||||
}
|
||||
|
||||
interface IMutableBooleanProperty : IBooleanProperty {
|
||||
operator fun setValue(thisRef: Any?, property: KProperty<*>, value: Boolean)
|
||||
}
|
||||
|
||||
sealed interface IMutableBooleanField : IMutableField<Boolean>, IBooleanField, BooleanConsumer {
|
||||
override var boolean: Boolean
|
||||
override val property: IMutableBooleanProperty
|
||||
|
||||
@Deprecated("Use type specific property", replaceWith = ReplaceWith("this.boolean"))
|
||||
override var value: Boolean
|
||||
get() = boolean
|
||||
set(value) { boolean = value }
|
||||
|
||||
override fun accept(t: Boolean) {
|
||||
boolean = t
|
||||
}
|
||||
|
||||
@Deprecated("Use type specific property", replaceWith = ReplaceWith("this.property"))
|
||||
override fun getValue(thisRef: Any?, property: KProperty<*>): Boolean {
|
||||
return boolean
|
||||
}
|
||||
|
||||
@Deprecated("Use type specific property", replaceWith = ReplaceWith("this.property"))
|
||||
override fun setValue(thisRef: Any?, property: KProperty<*>, value: Boolean) {
|
||||
boolean = value
|
||||
}
|
||||
}
|
||||
|
||||
data class MapChangeset<out K, out V>(
|
||||
val action: MapAction,
|
||||
val key: K?,
|
||||
val value: V?
|
||||
) {
|
||||
inline fun map(add: (K, V) -> Unit, remove: (K) -> Unit) {
|
||||
when (action) {
|
||||
MapAction.ADD -> add.invoke(key!!, value!!)
|
||||
MapAction.REMOVE -> remove.invoke(key!!)
|
||||
else -> {}
|
||||
}
|
||||
}
|
||||
|
||||
inline fun map(add: (K, V) -> Unit, remove: (K) -> Unit, clear: () -> Unit) {
|
||||
when (action) {
|
||||
MapAction.CLEAR -> clear.invoke()
|
||||
MapAction.ADD -> add.invoke(key!!, value!!)
|
||||
MapAction.REMOVE -> remove.invoke(key!!)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
enum class MapAction {
|
||||
CLEAR, ADD, REMOVE
|
||||
}
|
||||
|
||||
/**
|
||||
* Universal one-to-many value synchronizer, allowing to synchronize values from server to client
|
||||
* Universal, one-to-many value synchronizer, allowing to synchronize values from server to client
|
||||
* anywhere, where input/output streams are supported
|
||||
*/
|
||||
@Suppress("unused")
|
@ -0,0 +1,167 @@
|
||||
package ru.dbotthepony.mc.otm.network.synchronizer
|
||||
|
||||
import mekanism.api.functions.FloatSupplier
|
||||
import java.io.DataInputStream
|
||||
import java.io.DataOutputStream
|
||||
import java.util.function.BooleanSupplier
|
||||
import java.util.function.DoubleSupplier
|
||||
import java.util.function.IntSupplier
|
||||
import java.util.function.LongSupplier
|
||||
import java.util.function.Supplier
|
||||
import kotlin.properties.ReadOnlyProperty
|
||||
import kotlin.reflect.KProperty
|
||||
|
||||
sealed interface IField<V> : ReadOnlyProperty<Any?, V>, Supplier<V>, () -> V {
|
||||
fun observe(): Boolean
|
||||
fun markDirty()
|
||||
fun markDirty(endpoint: FieldSynchronizer.Endpoint)
|
||||
val value: V
|
||||
val isRemoved: Boolean
|
||||
|
||||
fun remove()
|
||||
|
||||
fun write(stream: DataOutputStream, endpoint: FieldSynchronizer.Endpoint)
|
||||
fun read(stream: DataInputStream)
|
||||
|
||||
override fun getValue(thisRef: Any?, property: KProperty<*>): V {
|
||||
return this.value
|
||||
}
|
||||
|
||||
override fun get(): V {
|
||||
return value
|
||||
}
|
||||
|
||||
override fun invoke(): V {
|
||||
return value
|
||||
}
|
||||
}
|
||||
|
||||
interface IFloatProperty {
|
||||
operator fun getValue(thisRef: Any?, property: KProperty<*>): Float
|
||||
}
|
||||
|
||||
sealed interface IFloatField : IField<Float>, FloatSupplier {
|
||||
val float: Float
|
||||
val property: IFloatProperty
|
||||
|
||||
override val value: Float
|
||||
get() = float
|
||||
|
||||
@Deprecated("Use type specific Supplier interface")
|
||||
override fun get(): Float {
|
||||
return float
|
||||
}
|
||||
|
||||
override fun getAsFloat(): Float {
|
||||
return float
|
||||
}
|
||||
|
||||
@Deprecated("Use type specific property", replaceWith = ReplaceWith("this.property"))
|
||||
override fun getValue(thisRef: Any?, property: KProperty<*>): Float {
|
||||
return float
|
||||
}
|
||||
}
|
||||
|
||||
interface IDoubleProperty {
|
||||
operator fun getValue(thisRef: Any?, property: KProperty<*>): Double
|
||||
}
|
||||
|
||||
sealed interface IDoubleField : IField<Double>, DoubleSupplier {
|
||||
val double: Double
|
||||
val property: IDoubleProperty
|
||||
|
||||
@Deprecated("Use type specific Supplier interface")
|
||||
override fun get(): Double {
|
||||
return double
|
||||
}
|
||||
|
||||
override val value: Double
|
||||
get() = double
|
||||
|
||||
override fun getAsDouble(): Double {
|
||||
return double
|
||||
}
|
||||
|
||||
@Deprecated("Use type specific property", replaceWith = ReplaceWith("this.property"))
|
||||
override fun getValue(thisRef: Any?, property: KProperty<*>): Double {
|
||||
return double
|
||||
}
|
||||
}
|
||||
|
||||
interface IIntProperty {
|
||||
operator fun getValue(thisRef: Any?, property: KProperty<*>): Int
|
||||
}
|
||||
|
||||
sealed interface IIntField : IField<Int>, IntSupplier {
|
||||
val int: Int
|
||||
val property: IIntProperty
|
||||
|
||||
@Deprecated("Use type specific Supplier interface")
|
||||
override fun get(): Int {
|
||||
return int
|
||||
}
|
||||
|
||||
override val value: Int
|
||||
get() = int
|
||||
|
||||
override fun getAsInt(): Int {
|
||||
return int
|
||||
}
|
||||
|
||||
@Deprecated("Use type specific property", replaceWith = ReplaceWith("this.property"))
|
||||
override fun getValue(thisRef: Any?, property: KProperty<*>): Int {
|
||||
return int
|
||||
}
|
||||
}
|
||||
|
||||
interface ILongProperty {
|
||||
operator fun getValue(thisRef: Any?, property: KProperty<*>): Long
|
||||
}
|
||||
|
||||
sealed interface ILongField : IField<Long>, LongSupplier {
|
||||
val long: Long
|
||||
val property: ILongProperty
|
||||
|
||||
@Deprecated("Use type specific Supplier interface")
|
||||
override fun get(): Long {
|
||||
return long
|
||||
}
|
||||
|
||||
override val value: Long
|
||||
get() = long
|
||||
|
||||
override fun getAsLong(): Long {
|
||||
return long
|
||||
}
|
||||
|
||||
@Deprecated("Use type specific property", replaceWith = ReplaceWith("this.property"))
|
||||
override fun getValue(thisRef: Any?, property: KProperty<*>): Long {
|
||||
return long
|
||||
}
|
||||
}
|
||||
|
||||
interface IBooleanProperty {
|
||||
operator fun getValue(thisRef: Any?, property: KProperty<*>): Boolean
|
||||
}
|
||||
|
||||
sealed interface IBooleanField : IField<Boolean>, BooleanSupplier {
|
||||
val boolean: Boolean
|
||||
val property: IBooleanProperty
|
||||
|
||||
@Deprecated("Use type specific Supplier interface")
|
||||
override fun get(): Boolean {
|
||||
return boolean
|
||||
}
|
||||
|
||||
override val value: Boolean
|
||||
get() = boolean
|
||||
|
||||
override fun getAsBoolean(): Boolean {
|
||||
return boolean
|
||||
}
|
||||
|
||||
@Deprecated("Use type specific property", replaceWith = ReplaceWith("this.property"))
|
||||
override fun getValue(thisRef: Any?, property: KProperty<*>): Boolean {
|
||||
return boolean
|
||||
}
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
package ru.dbotthepony.mc.otm.network.synchronizer
|
||||
|
||||
enum class MapAction {
|
||||
CLEAR, ADD, REMOVE
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
package ru.dbotthepony.mc.otm.network.synchronizer
|
||||
|
||||
data class MapChangeset<out K, out V>(
|
||||
val action: MapAction,
|
||||
val key: K?,
|
||||
val value: V?
|
||||
) {
|
||||
inline fun map(add: (K, V) -> Unit, remove: (K) -> Unit) {
|
||||
when (action) {
|
||||
MapAction.ADD -> add.invoke(key!!, value!!)
|
||||
MapAction.REMOVE -> remove.invoke(key!!)
|
||||
else -> {}
|
||||
}
|
||||
}
|
||||
|
||||
inline fun map(add: (K, V) -> Unit, remove: (K) -> Unit, clear: () -> Unit) {
|
||||
when (action) {
|
||||
MapAction.CLEAR -> clear.invoke()
|
||||
MapAction.ADD -> add.invoke(key!!, value!!)
|
||||
MapAction.REMOVE -> remove.invoke(key!!)
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,165 @@
|
||||
package ru.dbotthepony.mc.otm.network.synchronizer
|
||||
|
||||
import it.unimi.dsi.fastutil.booleans.BooleanConsumer
|
||||
import it.unimi.dsi.fastutil.floats.FloatConsumer
|
||||
import ru.dbotthepony.mc.otm.core.GetterSetter
|
||||
import java.util.function.DoubleConsumer
|
||||
import java.util.function.IntConsumer
|
||||
import java.util.function.LongConsumer
|
||||
import kotlin.reflect.KProperty
|
||||
|
||||
sealed interface IMutableField<V> : IField<V>, GetterSetter<V> {
|
||||
override fun getValue(thisRef: Any?, property: KProperty<*>): V {
|
||||
return this.value
|
||||
}
|
||||
|
||||
override var value: V
|
||||
|
||||
override fun accept(t: V) {
|
||||
value = t
|
||||
}
|
||||
|
||||
override fun invoke(): V {
|
||||
return this.value
|
||||
}
|
||||
}
|
||||
|
||||
interface IMutableFloatProperty : IFloatProperty {
|
||||
operator fun setValue(thisRef: Any?, property: KProperty<*>, value: Float)
|
||||
}
|
||||
|
||||
sealed interface IMutableFloatField : IMutableField<Float>, IFloatField, FloatConsumer {
|
||||
override var float: Float
|
||||
override val property: IMutableFloatProperty
|
||||
|
||||
@Deprecated("Use type specific property", replaceWith = ReplaceWith("this.float"))
|
||||
override var value: Float
|
||||
get() = float
|
||||
set(value) { float = value }
|
||||
|
||||
override fun accept(t: Float) {
|
||||
float = t
|
||||
}
|
||||
|
||||
@Deprecated("Use type specific property", replaceWith = ReplaceWith("this.property"))
|
||||
override fun getValue(thisRef: Any?, property: KProperty<*>): Float {
|
||||
return float
|
||||
}
|
||||
|
||||
@Deprecated("Use type specific property", replaceWith = ReplaceWith("this.property"))
|
||||
override fun setValue(thisRef: Any?, property: KProperty<*>, value: Float) {
|
||||
float = value
|
||||
}
|
||||
}
|
||||
|
||||
interface IMutableDoubleProperty : IDoubleProperty {
|
||||
operator fun setValue(thisRef: Any?, property: KProperty<*>, value: Double)
|
||||
}
|
||||
|
||||
sealed interface IMutableDoubleField : IMutableField<Double>, IDoubleField, DoubleConsumer {
|
||||
override var double: Double
|
||||
override val property: IMutableDoubleProperty
|
||||
|
||||
@Deprecated("Use type specific property", replaceWith = ReplaceWith("this.double"))
|
||||
override var value: Double
|
||||
get() = double
|
||||
set(value) { double = value }
|
||||
|
||||
override fun accept(t: Double) {
|
||||
double = t
|
||||
}
|
||||
|
||||
@Deprecated("Use type specific property", replaceWith = ReplaceWith("this.property"))
|
||||
override fun getValue(thisRef: Any?, property: KProperty<*>): Double {
|
||||
return double
|
||||
}
|
||||
|
||||
@Deprecated("Use type specific property", replaceWith = ReplaceWith("this.property"))
|
||||
override fun setValue(thisRef: Any?, property: KProperty<*>, value: Double) {
|
||||
double = value
|
||||
}
|
||||
}
|
||||
|
||||
interface IMutableIntProperty : IIntProperty {
|
||||
operator fun setValue(thisRef: Any?, property: KProperty<*>, value: Int)
|
||||
}
|
||||
|
||||
sealed interface IMutableIntField : IMutableField<Int>, IIntField, IntConsumer {
|
||||
override var int: Int
|
||||
override val property: IMutableIntProperty
|
||||
|
||||
@Deprecated("Use type specific property", replaceWith = ReplaceWith("this.int"))
|
||||
override var value: Int
|
||||
get() = int
|
||||
set(value) { int = value }
|
||||
|
||||
override fun accept(t: Int) {
|
||||
int = t
|
||||
}
|
||||
|
||||
@Deprecated("Use type specific property", replaceWith = ReplaceWith("this.property"))
|
||||
override fun getValue(thisRef: Any?, property: KProperty<*>): Int {
|
||||
return int
|
||||
}
|
||||
|
||||
@Deprecated("Use type specific property", replaceWith = ReplaceWith("this.property"))
|
||||
override fun setValue(thisRef: Any?, property: KProperty<*>, value: Int) {
|
||||
int = value
|
||||
}
|
||||
}
|
||||
|
||||
interface IMutableLongProperty : ILongProperty {
|
||||
operator fun setValue(thisRef: Any?, property: KProperty<*>, value: Long)
|
||||
}
|
||||
|
||||
sealed interface IMutableLongField : IMutableField<Long>, ILongField, LongConsumer {
|
||||
override var long: Long
|
||||
override val property: IMutableLongProperty
|
||||
|
||||
@Deprecated("Use type specific property", replaceWith = ReplaceWith("this.long"))
|
||||
override var value: Long
|
||||
get() = long
|
||||
set(value) { long = value }
|
||||
|
||||
override fun accept(t: Long) {
|
||||
long = t
|
||||
}
|
||||
|
||||
@Deprecated("Use type specific property", replaceWith = ReplaceWith("this.property"))
|
||||
override fun getValue(thisRef: Any?, property: KProperty<*>): Long {
|
||||
return long
|
||||
}
|
||||
|
||||
@Deprecated("Use type specific property", replaceWith = ReplaceWith("this.property"))
|
||||
override fun setValue(thisRef: Any?, property: KProperty<*>, value: Long) {
|
||||
long = value
|
||||
}
|
||||
}
|
||||
|
||||
interface IMutableBooleanProperty : IBooleanProperty {
|
||||
operator fun setValue(thisRef: Any?, property: KProperty<*>, value: Boolean)
|
||||
}
|
||||
|
||||
sealed interface IMutableBooleanField : IMutableField<Boolean>, IBooleanField, BooleanConsumer {
|
||||
override var boolean: Boolean
|
||||
override val property: IMutableBooleanProperty
|
||||
|
||||
@Deprecated("Use type specific property", replaceWith = ReplaceWith("this.boolean"))
|
||||
override var value: Boolean
|
||||
get() = boolean
|
||||
set(value) { boolean = value }
|
||||
|
||||
override fun accept(t: Boolean) {
|
||||
boolean = t
|
||||
}
|
||||
|
||||
@Deprecated("Use type specific property", replaceWith = ReplaceWith("this.property"))
|
||||
override fun getValue(thisRef: Any?, property: KProperty<*>): Boolean {
|
||||
return boolean
|
||||
}
|
||||
|
||||
@Deprecated("Use type specific property", replaceWith = ReplaceWith("this.property"))
|
||||
override fun setValue(thisRef: Any?, property: KProperty<*>, value: Boolean) {
|
||||
boolean = value
|
||||
}
|
||||
}
|
@ -3,8 +3,8 @@ package ru.dbotthepony.mc.otm.tests
|
||||
import org.junit.jupiter.api.Assertions.assertEquals
|
||||
import org.junit.jupiter.api.DisplayName
|
||||
import org.junit.jupiter.api.Test
|
||||
import ru.dbotthepony.mc.otm.network.FieldSynchronizer
|
||||
import ru.dbotthepony.mc.otm.network.IMutableField
|
||||
import ru.dbotthepony.mc.otm.network.synchronizer.FieldSynchronizer
|
||||
import ru.dbotthepony.mc.otm.network.synchronizer.IMutableField
|
||||
import java.io.ByteArrayInputStream
|
||||
|
||||
object FieldSynchronizerTests {
|
||||
|
Loading…
Reference in New Issue
Block a user