better stuff
This commit is contained in:
@@ -31,13 +31,15 @@ import org.neoflock.neocomputers.sounds.ComputerRunningSoundInstance
|
|||||||
import org.neoflock.neocomputers.sounds.Sounds
|
import org.neoflock.neocomputers.sounds.Sounds
|
||||||
import org.neoflock.neocomputers.utils.GenericContainer
|
import org.neoflock.neocomputers.utils.GenericContainer
|
||||||
import java.time.Duration
|
import java.time.Duration
|
||||||
|
import kotlin.math.max
|
||||||
import kotlin.math.min
|
import kotlin.math.min
|
||||||
|
|
||||||
class CaseBlockEntity(blockPos: BlockPos, blockState: BlockState): NodeBlockEntity(BlockEntities.CASE_ENTITY.get(), blockPos, blockState), MachineEntity, GenericContainer, MenuProvider {
|
class CaseBlockEntity(blockPos: BlockPos, blockState: BlockState): NodeBlockEntity(BlockEntities.CASE_ENTITY.get(), blockPos, blockState), MachineEntity, GenericContainer, MenuProvider {
|
||||||
val stacks: NonNullList<ItemStack> = NonNullList<ItemStack>.withSize(7, ItemStack.EMPTY)
|
val stacks: NonNullList<ItemStack> = NonNullList<ItemStack>.withSize(7, ItemStack.EMPTY)
|
||||||
|
|
||||||
var isOn = false
|
var isOn = false
|
||||||
var isDisking = false // TOOD: writing writers and reading readers
|
var diskActivityTime = 0 // TOOD: writing writers and reading readers
|
||||||
|
var networkActivityTime = 0
|
||||||
var err: String? = null
|
var err: String? = null
|
||||||
var arch = "Lua 5.3"
|
var arch = "Lua 5.3"
|
||||||
var soundInstance: SoundInstance? = null
|
var soundInstance: SoundInstance? = null
|
||||||
@@ -50,14 +52,16 @@ class CaseBlockEntity(blockPos: BlockPos, blockState: BlockState): NodeBlockEnti
|
|||||||
override fun encodeDownstreamData(packet: FriendlyByteBuf) {
|
override fun encodeDownstreamData(packet: FriendlyByteBuf) {
|
||||||
super.encodeDownstreamData(packet)
|
super.encodeDownstreamData(packet)
|
||||||
packet.writeBoolean(isOn)
|
packet.writeBoolean(isOn)
|
||||||
packet.writeBoolean(isDisking)
|
packet.writeVarInt(diskActivityTime)
|
||||||
|
packet.writeVarInt(networkActivityTime)
|
||||||
packet.writeUtf(err ?: "")
|
packet.writeUtf(err ?: "")
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun syncWithUpstream(packet: FriendlyByteBuf) {
|
override fun syncWithUpstream(packet: FriendlyByteBuf) {
|
||||||
super.syncWithUpstream(packet)
|
super.syncWithUpstream(packet)
|
||||||
setRunning(packet.readBoolean())
|
setRunning(packet.readBoolean())
|
||||||
isDisking = packet.readBoolean()
|
diskActivityTime = packet.readVarInt()
|
||||||
|
networkActivityTime = packet.readVarInt()
|
||||||
err = packet.readUtf().ifEmpty { null }
|
err = packet.readUtf().ifEmpty { null }
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -219,6 +223,14 @@ class CaseBlockEntity(blockPos: BlockPos, blockState: BlockState): NodeBlockEnti
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun signalDiskActivity(delay: Int) {
|
||||||
|
diskActivityTime = max(delay, diskActivityTime)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun signalNetworkActivity(delay: Int) {
|
||||||
|
networkActivityTime = max(delay, networkActivityTime)
|
||||||
|
}
|
||||||
|
|
||||||
override fun getMachineMemoryTotal(): Long = stacks.mapNotNull { (it.item as? ComponentItem)?.getMemoryCapacity(it) }.sum().toLong()
|
override fun getMachineMemoryTotal(): Long = stacks.mapNotNull { (it.item as? ComponentItem)?.getMemoryCapacity(it) }.sum().toLong()
|
||||||
override fun getMachineMemoryUsed(): Long = 0
|
override fun getMachineMemoryUsed(): Long = 0
|
||||||
override fun getMachineComponentsUsed(): Long = node.getReachable().size.toLong()
|
override fun getMachineComponentsUsed(): Long = node.getReachable().size.toLong()
|
||||||
@@ -264,6 +276,8 @@ class CaseBlockEntity(blockPos: BlockPos, blockState: BlockState): NodeBlockEnti
|
|||||||
super.tickNode(level)
|
super.tickNode(level)
|
||||||
if(!level.isClientSide) {
|
if(!level.isClientSide) {
|
||||||
if (isRunning()) {
|
if (isRunning()) {
|
||||||
|
if(diskActivityTime > 0) diskActivityTime--
|
||||||
|
if(networkActivityTime > 0) networkActivityTime--
|
||||||
if(getMachineComponentsUsed() > getMachineComponentsTotal()) {
|
if(getMachineComponentsUsed() > getMachineComponentsTotal()) {
|
||||||
crash("too many components")
|
crash("too many components")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,6 +28,10 @@ interface MachineEntity {
|
|||||||
// the duration is doubled.
|
// the duration is doubled.
|
||||||
// Architectures should only use short ones.
|
// Architectures should only use short ones.
|
||||||
fun beepAsync(pattern: String, frequency: Int = 1000, duration: Duration = Duration.ofMillis(200), volume: Double = 1.0): Boolean
|
fun beepAsync(pattern: String, frequency: Int = 1000, duration: Duration = Duration.ofMillis(200), volume: Double = 1.0): Boolean
|
||||||
|
// Signals that disk activity is happening for at least that delay
|
||||||
|
fun signalDiskActivity(delay: Int)
|
||||||
|
// signal network activity to a machine
|
||||||
|
fun signalNetworkActivity(delay: Int)
|
||||||
|
|
||||||
fun isRunning(): Boolean
|
fun isRunning(): Boolean
|
||||||
fun start(): Boolean
|
fun start(): Boolean
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ class CaseEntityRenderer(private val context: BlockEntityRendererProvider.Contex
|
|||||||
} else drawLED(buffer, mat.last(), 3F, OFF)
|
} else drawLED(buffer, mat.last(), 3F, OFF)
|
||||||
|
|
||||||
mat.translate(6/16F, 0F, 0F)
|
mat.translate(6/16F, 0F, 0F)
|
||||||
drawLED(buffer, mat.last(), 2F, if (ent.isDisking) GREEN else OFF)
|
drawLED(buffer, mat.last(), 2F, if (ent.diskActivityTime > 0) GREEN else OFF)
|
||||||
|
|
||||||
mat.popPose()
|
mat.popPose()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user