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
|
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")
|
||||||
|
@ -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)
|
||||||
|
Loading…
Reference in New Issue
Block a user