Declare redstone control as abstract class, not interface

to further enforce composition usage of this class
This commit is contained in:
DBotThePony 2023-01-29 21:54:59 +07:00
parent 1bedd960da
commit f742d6d819
Signed by: DBot
GPG Key ID: DCC23B5715498507
2 changed files with 7 additions and 7 deletions

View File

@ -27,7 +27,7 @@ abstract class MatteryBlockEntity(
p_155230_: BlockState p_155230_: BlockState
) : SynchronizedBlockEntity(p_155228_, p_155229_, p_155230_), MenuProvider, IRedstoneControlProvider { ) : SynchronizedBlockEntity(p_155228_, p_155229_, p_155230_), MenuProvider, IRedstoneControlProvider {
var customDisplayName: Component? = null var customDisplayName: Component? = null
override val redstoneControl: IRedstoneControl = RedstoneControl(::redstoneStatusUpdated) override val redstoneControl: AbstractRedstoneControl = RedstoneControl(::redstoneStatusUpdated)
protected open val defaultDisplayName: Component protected open val defaultDisplayName: Component
get() = level?.getBlockState(blockPos)?.block?.name ?: TextComponent("null at $blockPos") get() = level?.getBlockState(blockPos)?.block?.name ?: TextComponent("null at $blockPos")

View File

@ -7,12 +7,12 @@ import ru.dbotthepony.mc.otm.core.nbt.set
import ru.dbotthepony.mc.otm.network.FieldSynchronizer import ru.dbotthepony.mc.otm.network.FieldSynchronizer
interface IRedstoneControlProvider { interface IRedstoneControlProvider {
val redstoneControl: IRedstoneControl val redstoneControl: AbstractRedstoneControl
} }
interface IRedstoneControl : INBTSerializable<CompoundTag> { abstract class AbstractRedstoneControl : INBTSerializable<CompoundTag> {
var redstoneSetting: RedstoneSetting abstract var redstoneSetting: RedstoneSetting
var redstoneSignal: Int abstract var redstoneSignal: Int
val isBlockedByRedstone: Boolean get() = !redstoneSetting.test(redstoneSignal) val isBlockedByRedstone: Boolean get() = !redstoneSetting.test(redstoneSignal)
@ -40,7 +40,7 @@ interface IRedstoneControl : INBTSerializable<CompoundTag> {
} }
} }
class RedstoneControl(private val valueChanges: (new: Boolean, old: Boolean) -> Unit) : IRedstoneControl { class RedstoneControl(private val valueChanges: (new: Boolean, old: Boolean) -> Unit) : AbstractRedstoneControl() {
override var redstoneSetting: RedstoneSetting = RedstoneSetting.LOW override var redstoneSetting: RedstoneSetting = RedstoneSetting.LOW
set(level) { set(level) {
val old = isBlockedByRedstone val old = isBlockedByRedstone
@ -66,7 +66,7 @@ class RedstoneControl(private val valueChanges: (new: Boolean, old: Boolean) ->
class SynchronizedRedstoneControl( class SynchronizedRedstoneControl(
synchronizer: FieldSynchronizer, synchronizer: FieldSynchronizer,
private val valueChanges: (new: Boolean, old: Boolean) -> Unit private val valueChanges: (new: Boolean, old: Boolean) -> Unit
) : IRedstoneControl { ) : AbstractRedstoneControl() {
override var redstoneSetting: RedstoneSetting by synchronizer.enum(RedstoneSetting.LOW, setter = { value, access, setByRemote -> override var redstoneSetting: RedstoneSetting by synchronizer.enum(RedstoneSetting.LOW, setter = { value, access, setByRemote ->
if (setByRemote) { if (setByRemote) {
access.write(value) access.write(value)