Caching default blockRotation implementation
This commit is contained in:
parent
91ccd0af16
commit
8c257db68f
@ -51,6 +51,7 @@ import ru.dbotthepony.mc.otm.core.math.plus
|
|||||||
import ru.dbotthepony.mc.otm.core.util.IntCounter
|
import ru.dbotthepony.mc.otm.core.util.IntCounter
|
||||||
import ru.dbotthepony.mc.otm.core.util.Savetables
|
import ru.dbotthepony.mc.otm.core.util.Savetables
|
||||||
import ru.dbotthepony.mc.otm.core.util.TickList
|
import ru.dbotthepony.mc.otm.core.util.TickList
|
||||||
|
import ru.dbotthepony.mc.otm.core.util.countingLazy
|
||||||
import ru.dbotthepony.mc.otm.network.BlockEntitySyncPacket
|
import ru.dbotthepony.mc.otm.network.BlockEntitySyncPacket
|
||||||
import ru.dbotthepony.mc.otm.network.GenericNetworkChannel
|
import ru.dbotthepony.mc.otm.network.GenericNetworkChannel
|
||||||
import ru.dbotthepony.mc.otm.network.synchronizer.FieldSynchronizer
|
import ru.dbotthepony.mc.otm.network.synchronizer.FieldSynchronizer
|
||||||
@ -73,20 +74,39 @@ import kotlin.reflect.KProperty
|
|||||||
abstract class MatteryBlockEntity(p_155228_: BlockEntityType<*>, p_155229_: BlockPos, p_155230_: BlockState) : BlockEntity(p_155228_, p_155229_, p_155230_), INeighbourChangeListener {
|
abstract class MatteryBlockEntity(p_155228_: BlockEntityType<*>, p_155229_: BlockPos, p_155230_: BlockState) : BlockEntity(p_155228_, p_155229_, p_155230_), INeighbourChangeListener {
|
||||||
private var isSynchronizing = false
|
private var isSynchronizing = false
|
||||||
|
|
||||||
/**
|
private val sidelessCaps = Reference2ObjectOpenHashMap<Capability<*>, SidelessCap<*>>()
|
||||||
* "shortcut" for getting [BlockRotation]
|
protected val tickList = TickList()
|
||||||
*
|
protected val blockStateChangesCounter = IntCounter()
|
||||||
* if block has no rotation, returns [BlockRotation.NORTH]
|
protected val dirtyListeners = ISubscriptable.Impl<Unit>()
|
||||||
*/
|
private val waitForServerLevel = ArrayList<() -> Unit>()
|
||||||
open val blockRotation: BlockRotation get() {
|
|
||||||
return blockState[(blockState.block as? RotatableMatteryBlock ?: return BlockRotation.NORTH).rotationProperty]
|
|
||||||
}
|
|
||||||
|
|
||||||
private val _droppableContainers = ObjectArraySet<Container>()
|
private val _droppableContainers = ObjectArraySet<Container>()
|
||||||
private val _neighbourChangeListeners = ObjectArraySet<INeighbourChangeListener>()
|
private val _neighbourChangeListeners = ObjectArraySet<INeighbourChangeListener>()
|
||||||
val droppableContainers: Set<Container> = Collections.unmodifiableSet(_droppableContainers)
|
val droppableContainers: Set<Container> = Collections.unmodifiableSet(_droppableContainers)
|
||||||
val neighbourChangeListeners: Set<INeighbourChangeListener> = Collections.unmodifiableSet(_neighbourChangeListeners)
|
val neighbourChangeListeners: Set<INeighbourChangeListener> = Collections.unmodifiableSet(_neighbourChangeListeners)
|
||||||
|
|
||||||
|
private val _sides = EnumMap<RelativeSide, Side>(RelativeSide::class.java)
|
||||||
|
val sides: Map<RelativeSide, Side> = Collections.unmodifiableMap(_sides)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shared savetables, written both to level storage and to item tag
|
||||||
|
*/
|
||||||
|
protected val savetables = Savetables()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Level-only savetables, written only to level storage
|
||||||
|
*/
|
||||||
|
protected val savetablesLevel = Savetables()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* "shortcut" for getting [BlockRotation]
|
||||||
|
*
|
||||||
|
* if block has no rotation, returns [BlockRotation.NORTH]
|
||||||
|
*/
|
||||||
|
open val blockRotation: BlockRotation by countingLazy(blockStateChangesCounter) {
|
||||||
|
blockState[(blockState.block as? RotatableMatteryBlock ?: return@countingLazy BlockRotation.NORTH).rotationProperty]
|
||||||
|
}
|
||||||
|
|
||||||
protected fun addDroppableContainer(container: Container) {
|
protected fun addDroppableContainer(container: Container) {
|
||||||
_droppableContainers.add(container)
|
_droppableContainers.add(container)
|
||||||
}
|
}
|
||||||
@ -101,27 +121,9 @@ abstract class MatteryBlockEntity(p_155228_: BlockEntityType<*>, p_155229_: Bloc
|
|||||||
open fun beforeDroppingItems(oldBlockState: BlockState, level: Level, blockPos: BlockPos, newBlockState: BlockState, movedByPiston: Boolean) {}
|
open fun beforeDroppingItems(oldBlockState: BlockState, level: Level, blockPos: BlockPos, newBlockState: BlockState, movedByPiston: Boolean) {}
|
||||||
open fun beforeDestroyedByPlayer(level: Level, blockPos: BlockPos, blockState: BlockState, player: Player) {}
|
open fun beforeDestroyedByPlayer(level: Level, blockPos: BlockPos, blockState: BlockState, player: Player) {}
|
||||||
|
|
||||||
private val _sides = EnumMap<RelativeSide, Side>(RelativeSide::class.java)
|
|
||||||
val sides: Map<RelativeSide, Side> = Collections.unmodifiableMap(_sides)
|
|
||||||
|
|
||||||
fun side(side: RelativeSide) = sides[side]!!
|
fun side(side: RelativeSide) = sides[side]!!
|
||||||
|
|
||||||
private data class SidelessCap<T : Any>(val cap: T, var optional: LazyOptional<T>)
|
private data class SidelessCap<T : Any>(val cap: T, var optional: LazyOptional<T>)
|
||||||
private val sidelessCaps = Reference2ObjectOpenHashMap<Capability<*>, SidelessCap<*>>()
|
|
||||||
protected val tickList = TickList()
|
|
||||||
protected val blockStateChangesCounter = IntCounter()
|
|
||||||
protected val dirtyListeners = ISubscriptable.Impl<Unit>()
|
|
||||||
private val waitForServerLevel = ArrayList<() -> Unit>()
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Shared savetables, written both to level storage and to item tag
|
|
||||||
*/
|
|
||||||
protected val savetables = Savetables()
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Level-only savetables, written only to level storage
|
|
||||||
*/
|
|
||||||
protected val savetablesLevel = Savetables()
|
|
||||||
|
|
||||||
open fun tick() {
|
open fun tick() {
|
||||||
tickList.tick()
|
tickList.tick()
|
||||||
@ -441,8 +443,8 @@ abstract class MatteryBlockEntity(p_155228_: BlockEntityType<*>, p_155229_: Bloc
|
|||||||
|
|
||||||
@Suppress("OVERRIDE_DEPRECATION")
|
@Suppress("OVERRIDE_DEPRECATION")
|
||||||
override fun setBlockState(pBlockState: BlockState) {
|
override fun setBlockState(pBlockState: BlockState) {
|
||||||
blockStateChangesCounter.increment()
|
|
||||||
val old = blockRotation
|
val old = blockRotation
|
||||||
|
blockStateChangesCounter.increment()
|
||||||
@Suppress("DEPRECATION")
|
@Suppress("DEPRECATION")
|
||||||
super.setBlockState(pBlockState)
|
super.setBlockState(pBlockState)
|
||||||
val new = blockRotation
|
val new = blockRotation
|
||||||
|
@ -22,6 +22,7 @@ import ru.dbotthepony.mc.otm.core.nbt.getByteArrayList
|
|||||||
import ru.dbotthepony.mc.otm.core.nbt.map
|
import ru.dbotthepony.mc.otm.core.nbt.map
|
||||||
import ru.dbotthepony.mc.otm.core.nbt.mapPresent
|
import ru.dbotthepony.mc.otm.core.nbt.mapPresent
|
||||||
import ru.dbotthepony.mc.otm.core.nbt.set
|
import ru.dbotthepony.mc.otm.core.nbt.set
|
||||||
|
import ru.dbotthepony.mc.otm.core.util.countingLazy
|
||||||
import ru.dbotthepony.mc.otm.menu.tech.EnergyCounterMenu
|
import ru.dbotthepony.mc.otm.menu.tech.EnergyCounterMenu
|
||||||
import ru.dbotthepony.mc.otm.registry.MBlockEntities
|
import ru.dbotthepony.mc.otm.registry.MBlockEntities
|
||||||
import java.util.*
|
import java.util.*
|
||||||
@ -29,8 +30,8 @@ import java.util.*
|
|||||||
class EnergyCounterBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : MatteryDeviceBlockEntity(MBlockEntities.ENERGY_COUNTER, p_155229_, p_155230_) {
|
class EnergyCounterBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : MatteryDeviceBlockEntity(MBlockEntities.ENERGY_COUNTER, p_155229_, p_155230_) {
|
||||||
var passed by synchronizer.decimal()
|
var passed by synchronizer.decimal()
|
||||||
|
|
||||||
override val blockRotation: BlockRotation get() {
|
override val blockRotation: BlockRotation by countingLazy(blockStateChangesCounter) {
|
||||||
return BlockRotation.of(blockState[EnergyCounterBlock.INPUT_DIRECTION])
|
BlockRotation.of(blockState[EnergyCounterBlock.INPUT_DIRECTION])
|
||||||
}
|
}
|
||||||
|
|
||||||
private val history = Array(10 * 20) { Decimal.ZERO }
|
private val history = Array(10 * 20) { Decimal.ZERO }
|
||||||
|
Loading…
Reference in New Issue
Block a user