mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-19 04:06:43 -04:00
moved some more stuff from case to computer superclass
This commit is contained in:
parent
34a927059f
commit
5faedd2525
@ -57,7 +57,7 @@ class PacketHandler extends CommonPacketHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
def onComputerStateResponse(p: PacketParser) =
|
def onComputerStateResponse(p: PacketParser) =
|
||||||
p.readTileEntity[Case]() match {
|
p.readTileEntity[Computer]() match {
|
||||||
case Some(t) => t.isOn = p.readBoolean()
|
case Some(t) => t.isOn = p.readBoolean()
|
||||||
case _ => // Invalid packet.
|
case _ => // Invalid packet.
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,7 @@ import li.cil.oc.common.PacketType
|
|||||||
import li.cil.oc.common.tileentity._
|
import li.cil.oc.common.tileentity._
|
||||||
|
|
||||||
object PacketSender {
|
object PacketSender {
|
||||||
def sendComputerStateRequest(t: Case) {
|
def sendComputerStateRequest(t: Computer) {
|
||||||
val pb = new PacketBuilder(PacketType.ComputerStateRequest)
|
val pb = new PacketBuilder(PacketType.ComputerStateRequest)
|
||||||
|
|
||||||
pb.writeTileEntity(t)
|
pb.writeTileEntity(t)
|
||||||
|
@ -2,67 +2,22 @@ package li.cil.oc.common.tileentity
|
|||||||
|
|
||||||
import li.cil.oc.Config
|
import li.cil.oc.Config
|
||||||
import li.cil.oc.api.driver.Slot
|
import li.cil.oc.api.driver.Slot
|
||||||
import li.cil.oc.client.{PacketSender => ClientPacketSender}
|
|
||||||
import li.cil.oc.server.component
|
import li.cil.oc.server.component
|
||||||
import li.cil.oc.server.driver
|
|
||||||
import li.cil.oc.server.driver.Registry
|
import li.cil.oc.server.driver.Registry
|
||||||
import li.cil.oc.server.{PacketSender => ServerPacketSender}
|
|
||||||
import net.minecraft.item.ItemStack
|
import net.minecraft.item.ItemStack
|
||||||
import net.minecraft.nbt.NBTTagCompound
|
|
||||||
import net.minecraftforge.common.ForgeDirection
|
import net.minecraftforge.common.ForgeDirection
|
||||||
|
|
||||||
class Case(isClient: Boolean) extends Computer with ComponentInventory with Rotatable with Redstone {
|
class Case(isClient: Boolean) extends Computer {
|
||||||
def this() = this(false)
|
def this() = this(false)
|
||||||
|
|
||||||
// ----------------------------------------------------------------------- //
|
// ----------------------------------------------------------------------- //
|
||||||
|
|
||||||
val instance = if (isClient) null else new component.Computer(this)
|
val instance = if (isClient) null else new component.Computer(this)
|
||||||
|
|
||||||
private var isRunning = false
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------- //
|
|
||||||
|
|
||||||
def isOn = isRunning
|
|
||||||
|
|
||||||
def isOn_=(value: Boolean) = {
|
|
||||||
isRunning = value
|
|
||||||
world.markBlockForRenderUpdate(x, y, z)
|
|
||||||
this
|
|
||||||
}
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------- //
|
// ----------------------------------------------------------------------- //
|
||||||
|
|
||||||
override def updateEntity() {
|
override def updateEntity() {
|
||||||
super.updateEntity()
|
super.updateEntity()
|
||||||
if (isServer) {
|
|
||||||
if (isRunning != instance.isRunning) {
|
|
||||||
isOutputEnabled = hasRedstoneCard && instance.isRunning
|
|
||||||
ServerPacketSender.sendComputerState(this, instance.isRunning)
|
|
||||||
}
|
|
||||||
isRunning = instance.isRunning
|
|
||||||
updateRedstoneInput()
|
|
||||||
}
|
|
||||||
|
|
||||||
for (component <- components) component match {
|
|
||||||
case Some(environment) => environment.update()
|
|
||||||
case _ => // Empty.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override def validate() = {
|
|
||||||
super.validate()
|
|
||||||
if (isClient) {
|
|
||||||
ClientPacketSender.sendRotatableStateRequest(this)
|
|
||||||
ClientPacketSender.sendComputerStateRequest(this)
|
|
||||||
ClientPacketSender.sendRedstoneStateRequest(this)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------- //
|
|
||||||
|
|
||||||
override def readFromNBT(nbt: NBTTagCompound) {
|
|
||||||
super.readFromNBT(nbt)
|
|
||||||
instance.recomputeMemory()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------- //
|
// ----------------------------------------------------------------------- //
|
||||||
@ -80,27 +35,7 @@ class Case(isClient: Boolean) extends Computer with ComponentInventory with Rota
|
|||||||
case _ => false // Invalid slot.
|
case _ => false // Invalid slot.
|
||||||
}
|
}
|
||||||
|
|
||||||
override def onInventoryChanged() {
|
|
||||||
super.onInventoryChanged()
|
|
||||||
if (isServer) {
|
|
||||||
instance.recomputeMemory()
|
|
||||||
isOutputEnabled = hasRedstoneCard && instance.isRunning
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------- //
|
// ----------------------------------------------------------------------- //
|
||||||
|
|
||||||
def canConnectRedstone(side: ForgeDirection) = isOutputEnabled
|
def canConnectRedstone(side: ForgeDirection) = isOutputEnabled
|
||||||
|
|
||||||
override protected def onRedstoneInputChanged(side: ForgeDirection) {
|
|
||||||
super.onRedstoneInputChanged(side)
|
|
||||||
if (isServer) {
|
|
||||||
instance.signal("redstone_changed", side.ordinal())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private def hasRedstoneCard = items.exists {
|
|
||||||
case Some(item) => driver.item.RedstoneCard.worksWith(item)
|
|
||||||
case _ => false
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -1,13 +1,15 @@
|
|||||||
package li.cil.oc.common.tileentity
|
package li.cil.oc.common.tileentity
|
||||||
|
|
||||||
import li.cil.oc.api.network._
|
import li.cil.oc.api.network._
|
||||||
import li.cil.oc.server.component
|
import li.cil.oc.client.{PacketSender => ClientPacketSender}
|
||||||
|
import li.cil.oc.server.{PacketSender => ServerPacketSender, driver, component}
|
||||||
import li.cil.oc.{Config, api}
|
import li.cil.oc.{Config, api}
|
||||||
import net.minecraft.entity.player.EntityPlayer
|
import net.minecraft.entity.player.EntityPlayer
|
||||||
import net.minecraft.nbt.NBTTagCompound
|
import net.minecraft.nbt.NBTTagCompound
|
||||||
|
import net.minecraftforge.common.ForgeDirection
|
||||||
import scala.Some
|
import scala.Some
|
||||||
|
|
||||||
abstract class Computer extends Environment with Context with Analyzable {
|
abstract class Computer extends Environment with ComponentInventory with Rotatable with Redstone with Context with Analyzable {
|
||||||
val node = api.Network.newNode(this, Visibility.Network).
|
val node = api.Network.newNode(this, Visibility.Network).
|
||||||
withComponent("computer", Visibility.Neighbors).
|
withComponent("computer", Visibility.Neighbors).
|
||||||
withConnector().
|
withConnector().
|
||||||
@ -15,22 +17,36 @@ abstract class Computer extends Environment with Context with Analyzable {
|
|||||||
|
|
||||||
val instance: component.Computer
|
val instance: component.Computer
|
||||||
|
|
||||||
def installedMemory: Int
|
private var isRunning = false
|
||||||
|
|
||||||
// ----------------------------------------------------------------------- //
|
|
||||||
|
|
||||||
private var hasChanged = false
|
private var hasChanged = false
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------- //
|
||||||
|
|
||||||
|
def isOn = isRunning
|
||||||
|
|
||||||
|
def isOn_=(value: Boolean) = {
|
||||||
|
isRunning = value
|
||||||
|
world.markBlockForRenderUpdate(x, y, z)
|
||||||
|
this
|
||||||
|
}
|
||||||
|
|
||||||
def markAsChanged() = hasChanged = true
|
def markAsChanged() = hasChanged = true
|
||||||
|
|
||||||
|
def hasRedstoneCard = items.exists {
|
||||||
|
case Some(item) => driver.item.RedstoneCard.worksWith(item)
|
||||||
|
case _ => false
|
||||||
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------- //
|
// ----------------------------------------------------------------------- //
|
||||||
|
|
||||||
override def updateEntity() {
|
override def updateEntity() {
|
||||||
|
if (isServer) {
|
||||||
// If we're not yet in a network we were just loaded from disk. We skip
|
// If we're not yet in a network we were just loaded from disk. We skip
|
||||||
// the update this round to allow other tile entities to join the network,
|
// the update this round to allow other tile entities to join the network,
|
||||||
// too, avoiding issues of missing nodes (e.g. in the GPU which would
|
// too, avoiding issues of missing nodes (e.g. in the GPU which would
|
||||||
// otherwise loose track of its screen).
|
// otherwise loose track of its screen).
|
||||||
if (isServer && node != null && node.network != null) {
|
if (node != null && node.network != null) {
|
||||||
if (instance.isRunning && !node.changeBuffer(-Config.computerCost)) {
|
if (instance.isRunning && !node.changeBuffer(-Config.computerCost)) {
|
||||||
instance.lastError = "not enough energy"
|
instance.lastError = "not enough energy"
|
||||||
instance.stop()
|
instance.stop()
|
||||||
@ -43,14 +59,38 @@ abstract class Computer extends Environment with Context with Analyzable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isRunning != instance.isRunning) {
|
||||||
|
isOutputEnabled = hasRedstoneCard && instance.isRunning
|
||||||
|
ServerPacketSender.sendComputerState(this, instance.isRunning)
|
||||||
|
}
|
||||||
|
isRunning = instance.isRunning
|
||||||
|
|
||||||
|
updateRedstoneInput()
|
||||||
|
|
||||||
|
for (component <- components) component match {
|
||||||
|
case Some(environment) => environment.update()
|
||||||
|
case _ => // Empty.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
super.updateEntity()
|
super.updateEntity()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override def validate() = {
|
||||||
|
super.validate()
|
||||||
|
if (isClient) {
|
||||||
|
ClientPacketSender.sendRotatableStateRequest(this)
|
||||||
|
ClientPacketSender.sendComputerStateRequest(this)
|
||||||
|
ClientPacketSender.sendRedstoneStateRequest(this)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------- //
|
// ----------------------------------------------------------------------- //
|
||||||
|
|
||||||
override def readFromNBT(nbt: NBTTagCompound) {
|
override def readFromNBT(nbt: NBTTagCompound) {
|
||||||
super.readFromNBT(nbt)
|
super.readFromNBT(nbt)
|
||||||
if (instance != null) instance.load(nbt)
|
if (instance != null) instance.load(nbt)
|
||||||
|
// instance.recomputeMemory()
|
||||||
}
|
}
|
||||||
|
|
||||||
override def writeToNBT(nbt: NBTTagCompound) {
|
override def writeToNBT(nbt: NBTTagCompound) {
|
||||||
@ -78,6 +118,21 @@ abstract class Computer extends Environment with Context with Analyzable {
|
|||||||
this
|
this
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override def onInventoryChanged() {
|
||||||
|
super.onInventoryChanged()
|
||||||
|
if (isServer) {
|
||||||
|
instance.recomputeMemory()
|
||||||
|
isOutputEnabled = hasRedstoneCard && instance.isRunning
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override protected def onRedstoneInputChanged(side: ForgeDirection) {
|
||||||
|
super.onRedstoneInputChanged(side)
|
||||||
|
if (isServer) {
|
||||||
|
instance.signal("redstone_changed", side.ordinal())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------- //
|
// ----------------------------------------------------------------------- //
|
||||||
|
|
||||||
@LuaCallback("start")
|
@LuaCallback("start")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user