Declare redstone control as abstract class, not interface
to further enforce composition usage of this class
This commit is contained in:
parent
1bedd960da
commit
f742d6d819
@ -27,7 +27,7 @@ abstract class MatteryBlockEntity(
|
||||
p_155230_: BlockState
|
||||
) : SynchronizedBlockEntity(p_155228_, p_155229_, p_155230_), MenuProvider, IRedstoneControlProvider {
|
||||
var customDisplayName: Component? = null
|
||||
override val redstoneControl: IRedstoneControl = RedstoneControl(::redstoneStatusUpdated)
|
||||
override val redstoneControl: AbstractRedstoneControl = RedstoneControl(::redstoneStatusUpdated)
|
||||
|
||||
protected open val defaultDisplayName: Component
|
||||
get() = level?.getBlockState(blockPos)?.block?.name ?: TextComponent("null at $blockPos")
|
||||
|
@ -7,12 +7,12 @@ import ru.dbotthepony.mc.otm.core.nbt.set
|
||||
import ru.dbotthepony.mc.otm.network.FieldSynchronizer
|
||||
|
||||
interface IRedstoneControlProvider {
|
||||
val redstoneControl: IRedstoneControl
|
||||
val redstoneControl: AbstractRedstoneControl
|
||||
}
|
||||
|
||||
interface IRedstoneControl : INBTSerializable<CompoundTag> {
|
||||
var redstoneSetting: RedstoneSetting
|
||||
var redstoneSignal: Int
|
||||
abstract class AbstractRedstoneControl : INBTSerializable<CompoundTag> {
|
||||
abstract var redstoneSetting: RedstoneSetting
|
||||
abstract var redstoneSignal: Int
|
||||
|
||||
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
|
||||
set(level) {
|
||||
val old = isBlockedByRedstone
|
||||
@ -66,7 +66,7 @@ class RedstoneControl(private val valueChanges: (new: Boolean, old: Boolean) ->
|
||||
class SynchronizedRedstoneControl(
|
||||
synchronizer: FieldSynchronizer,
|
||||
private val valueChanges: (new: Boolean, old: Boolean) -> Unit
|
||||
) : IRedstoneControl {
|
||||
) : AbstractRedstoneControl() {
|
||||
override var redstoneSetting: RedstoneSetting by synchronizer.enum(RedstoneSetting.LOW, setter = { value, access, setByRemote ->
|
||||
if (setByRemote) {
|
||||
access.write(value)
|
||||
|
Loading…
Reference in New Issue
Block a user