mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-17 03:05:30 -04:00
some more fixes and adjustments; cleanup
This commit is contained in:
parent
3ff032b347
commit
d65bd29886
@ -54,7 +54,7 @@ public interface Architecture {
|
|||||||
*
|
*
|
||||||
* @return whether the architecture was initialized successfully.
|
* @return whether the architecture was initialized successfully.
|
||||||
*/
|
*/
|
||||||
boolean init();
|
boolean initialize();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when a machine stopped. Used to clean up any handles, memory and
|
* Called when a machine stopped. Used to clean up any handles, memory and
|
||||||
@ -108,7 +108,7 @@ public interface Architecture {
|
|||||||
* Called when the owning machine was connected to the component network.
|
* Called when the owning machine was connected to the component network.
|
||||||
* <p/>
|
* <p/>
|
||||||
* This can be useful for connecting custom file systems (read only memory)
|
* This can be useful for connecting custom file systems (read only memory)
|
||||||
* in case {@link #init()} was called from the machine's load logic (where
|
* in case {@link #initialize()} was called from the machine's load logic (where
|
||||||
* it was not yet connected to the network).
|
* it was not yet connected to the network).
|
||||||
*/
|
*/
|
||||||
void onConnect();
|
void onConnect();
|
||||||
|
@ -44,6 +44,19 @@ public interface Machine extends ManagedEnvironment, Context {
|
|||||||
*/
|
*/
|
||||||
Map<String, String> components();
|
Map<String, String> components();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The number of connected components.
|
||||||
|
* <p/>
|
||||||
|
* This number can differ from <tt>components().size()</tt>, since this is
|
||||||
|
* the number of actually <em>connected</em> components, which is used to
|
||||||
|
* determine whether the component limit has been exceeded, for example. It
|
||||||
|
* takes into account components added but not processed, yet (see also
|
||||||
|
* {@link #components()}).
|
||||||
|
*
|
||||||
|
* @return the number of connected components.
|
||||||
|
*/
|
||||||
|
int componentCount();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The address of the file system that holds the machine's file system for
|
* The address of the file system that holds the machine's file system for
|
||||||
* temporary files (tmpfs). This may return <tt>null</tt> if either the
|
* temporary files (tmpfs). This may return <tt>null</tt> if either the
|
||||||
@ -57,6 +70,19 @@ public interface Machine extends ManagedEnvironment, Context {
|
|||||||
*/
|
*/
|
||||||
String tmpAddress();
|
String tmpAddress();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A string with the last error message.
|
||||||
|
* <p/>
|
||||||
|
* The error string is set either when the machine crashes (see the
|
||||||
|
* {@link #crash(String)} method), or when it fails to start (which,
|
||||||
|
* technically, is also a crash).
|
||||||
|
* <p/>
|
||||||
|
* When the machine started, this is reset to <tt>null</tt>.
|
||||||
|
*
|
||||||
|
* @return the last error message, or <tt>null</tt>.
|
||||||
|
*/
|
||||||
|
String lastError();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The current world time. This is updated each tick and provides a thread
|
* The current world time. This is updated each tick and provides a thread
|
||||||
* safe way to access the world time for architectures.
|
* safe way to access the world time for architectures.
|
||||||
|
@ -4,6 +4,7 @@ import cpw.mods.fml.relauncher.{SideOnly, Side}
|
|||||||
import li.cil.oc.Settings
|
import li.cil.oc.Settings
|
||||||
import li.cil.oc.api.driver
|
import li.cil.oc.api.driver
|
||||||
import li.cil.oc.api.driver.Slot
|
import li.cil.oc.api.driver.Slot
|
||||||
|
import li.cil.oc.api.network.Connector
|
||||||
import li.cil.oc.server.driver.Registry
|
import li.cil.oc.server.driver.Registry
|
||||||
import net.minecraft.entity.player.EntityPlayer
|
import net.minecraft.entity.player.EntityPlayer
|
||||||
import net.minecraft.item.ItemStack
|
import net.minecraft.item.ItemStack
|
||||||
@ -16,7 +17,7 @@ class Case(var tier: Int, isRemote: Boolean) extends Computer(isRemote) {
|
|||||||
@SideOnly(Side.CLIENT)
|
@SideOnly(Side.CLIENT)
|
||||||
override protected def hasConnector(side: ForgeDirection) = side != facing
|
override protected def hasConnector(side: ForgeDirection) = side != facing
|
||||||
|
|
||||||
override protected def connector(side: ForgeDirection) = Option(if (side != facing && computer != null) computer.node else null)
|
override protected def connector(side: ForgeDirection) = Option(if (side != facing && computer != null) computer.node.asInstanceOf[Connector] else null)
|
||||||
|
|
||||||
var maxComponents = 0
|
var maxComponents = 0
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
package li.cil.oc.common.tileentity
|
package li.cil.oc.common.tileentity
|
||||||
|
|
||||||
import cpw.mods.fml.relauncher.{SideOnly, Side}
|
import cpw.mods.fml.relauncher.{SideOnly, Side}
|
||||||
import li.cil.oc.api.network.{Analyzable, Node, Visibility}
|
import li.cil.oc.api.network.{Connector, Analyzable, Node, Visibility}
|
||||||
import li.cil.oc.server.{PacketSender => ServerPacketSender}
|
import li.cil.oc.server.{PacketSender => ServerPacketSender}
|
||||||
import li.cil.oc.{Settings, api}
|
import li.cil.oc.{Settings, api}
|
||||||
import net.minecraft.entity.player.EntityPlayer
|
import net.minecraft.entity.player.EntityPlayer
|
||||||
@ -34,7 +34,7 @@ class Charger extends Environment with RedstoneAware with Analyzable {
|
|||||||
|
|
||||||
val charge = Settings.get.chargeRate * chargeSpeed
|
val charge = Settings.get.chargeRate * chargeSpeed
|
||||||
robots.collect {
|
robots.collect {
|
||||||
case Some(proxy) => node.changeBuffer(proxy.robot.computer.node.changeBuffer(charge + node.changeBuffer(-charge)))
|
case Some(proxy) => node.changeBuffer(proxy.robot.node.changeBuffer(charge + node.changeBuffer(-charge)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (chargeSpeed > 0 && world.getWorldInfo.getWorldTotalTime % 10 == 0) {
|
else if (chargeSpeed > 0 && world.getWorldInfo.getWorldTotalTime % 10 == 0) {
|
||||||
|
@ -180,7 +180,7 @@ abstract class Computer(isRemote: Boolean) extends Environment with ComponentInv
|
|||||||
|
|
||||||
override def onAnalyze(player: EntityPlayer, side: Int, hitX: Float, hitY: Float, hitZ: Float) = {
|
override def onAnalyze(player: EntityPlayer, side: Int, hitX: Float, hitY: Float, hitZ: Float) = {
|
||||||
computer.lastError match {
|
computer.lastError match {
|
||||||
case Some(value) =>
|
case value if value != null =>
|
||||||
player.sendChatToPlayer(ChatMessageComponent.createFromTranslationWithSubstitutions(
|
player.sendChatToPlayer(ChatMessageComponent.createFromTranslationWithSubstitutions(
|
||||||
Settings.namespace + "gui.Analyzer.LastError", ChatMessageComponent.createFromTranslationKey(value)))
|
Settings.namespace + "gui.Analyzer.LastError", ChatMessageComponent.createFromTranslationKey(value)))
|
||||||
case _ =>
|
case _ =>
|
||||||
|
@ -126,7 +126,7 @@ class Rack extends Hub with PowerBalancer with Inventory with Rotatable with Bun
|
|||||||
if (slot >= 0 && slot <= 3 && servers(slot).isDefined) {
|
if (slot >= 0 && slot <= 3 && servers(slot).isDefined) {
|
||||||
val computer = servers(slot).get.machine
|
val computer = servers(slot).get.machine
|
||||||
computer.lastError match {
|
computer.lastError match {
|
||||||
case Some(value) =>
|
case value if value != null =>
|
||||||
player.sendChatToPlayer(ChatMessageComponent.createFromTranslationWithSubstitutions(
|
player.sendChatToPlayer(ChatMessageComponent.createFromTranslationWithSubstitutions(
|
||||||
Settings.namespace + "gui.Analyzer.LastError", ChatMessageComponent.createFromTranslationKey(value)))
|
Settings.namespace + "gui.Analyzer.LastError", ChatMessageComponent.createFromTranslationKey(value)))
|
||||||
case _ =>
|
case _ =>
|
||||||
|
@ -51,7 +51,7 @@ class Robot(isRemote: Boolean) extends Computer(isRemote) with ISidedInventory w
|
|||||||
|
|
||||||
// ----------------------------------------------------------------------- //
|
// ----------------------------------------------------------------------- //
|
||||||
|
|
||||||
override def node = if (isClient) null else computer.node
|
override def node: ComponentConnector = if (isClient) null else computer.node.asInstanceOf[ComponentConnector]
|
||||||
|
|
||||||
override val _buffer = new common.component.Buffer(this) {
|
override val _buffer = new common.component.Buffer(this) {
|
||||||
override def maxResolution = (48, 14)
|
override def maxResolution = (48, 14)
|
||||||
@ -115,7 +115,7 @@ class Robot(isRemote: Boolean) extends Computer(isRemote) with ISidedInventory w
|
|||||||
// pow(xp(level) - base, 1/exp) / const = level
|
// pow(xp(level) - base, 1/exp) / const = level
|
||||||
level = math.min((Math.pow(xp - Settings.get.baseXpToLevel, 1 / Settings.get.exponentialXpGrowth) / Settings.get.constantXpGrowth).toInt, 30)
|
level = math.min((Math.pow(xp - Settings.get.baseXpToLevel, 1 / Settings.get.exponentialXpGrowth) / Settings.get.constantXpGrowth).toInt, 30)
|
||||||
if (isServer) {
|
if (isServer) {
|
||||||
computer.node.setLocalBufferSize(Settings.get.bufferRobot + Settings.get.bufferPerLevel * level)
|
node.setLocalBufferSize(Settings.get.bufferRobot + Settings.get.bufferPerLevel * level)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -209,7 +209,7 @@ class Robot(isRemote: Boolean) extends Computer(isRemote) with ISidedInventory w
|
|||||||
if (stack.hasTagCompound) {
|
if (stack.hasTagCompound) {
|
||||||
xp = stack.getTagCompound.getDouble(Settings.namespace + "xp")
|
xp = stack.getTagCompound.getDouble(Settings.namespace + "xp")
|
||||||
updateXpInfo()
|
updateXpInfo()
|
||||||
computer.node.changeBuffer(stack.getTagCompound.getInteger(Settings.namespace + "storedEnergy"))
|
node.changeBuffer(stack.getTagCompound.getInteger(Settings.namespace + "storedEnergy"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -287,8 +287,8 @@ class Robot(isRemote: Boolean) extends Computer(isRemote) with ISidedInventory w
|
|||||||
super.updateEntity()
|
super.updateEntity()
|
||||||
if (isServer) {
|
if (isServer) {
|
||||||
gpu.update()
|
gpu.update()
|
||||||
globalBuffer = computer.node.globalBuffer
|
globalBuffer = node.globalBuffer
|
||||||
globalBufferSize = computer.node.globalBufferSize
|
globalBufferSize = node.globalBufferSize
|
||||||
updatePowerInformation()
|
updatePowerInformation()
|
||||||
if (xpChanged && world.getWorldInfo.getWorldTotalTime % 200 == 0) {
|
if (xpChanged && world.getWorldInfo.getWorldTotalTime % 200 == 0) {
|
||||||
xpChanged = false
|
xpChanged = false
|
||||||
@ -418,8 +418,8 @@ class Robot(isRemote: Boolean) extends Computer(isRemote) with ISidedInventory w
|
|||||||
override def onMachineConnect(node: Node) {
|
override def onMachineConnect(node: Node) {
|
||||||
super.onConnect(node)
|
super.onConnect(node)
|
||||||
if (node == this.node) {
|
if (node == this.node) {
|
||||||
computer.node.connect(buffer.node)
|
node.connect(buffer.node)
|
||||||
computer.node.connect(gpu.node)
|
node.connect(gpu.node)
|
||||||
buffer.node.connect(keyboard.node)
|
buffer.node.connect(keyboard.node)
|
||||||
// There's a chance the server sends a robot tile entity to its clients
|
// There's a chance the server sends a robot tile entity to its clients
|
||||||
// before the tile entity's first update was called, in which case the
|
// before the tile entity's first update was called, in which case the
|
||||||
@ -438,7 +438,7 @@ class Robot(isRemote: Boolean) extends Computer(isRemote) with ISidedInventory w
|
|||||||
super.onDisconnect(node)
|
super.onDisconnect(node)
|
||||||
if (node == this.node) {
|
if (node == this.node) {
|
||||||
buffer.node.remove()
|
buffer.node.remove()
|
||||||
computer.node.remove()
|
node.remove()
|
||||||
gpu.node.remove()
|
gpu.node.remove()
|
||||||
keyboard.node.remove()
|
keyboard.node.remove()
|
||||||
}
|
}
|
||||||
|
@ -2,14 +2,14 @@ package li.cil.oc.server
|
|||||||
|
|
||||||
import cpw.mods.fml.common.network.Player
|
import cpw.mods.fml.common.network.Player
|
||||||
import li.cil.oc.Settings
|
import li.cil.oc.Settings
|
||||||
|
import li.cil.oc.api.machine.Machine
|
||||||
import li.cil.oc.common.PacketType
|
import li.cil.oc.common.PacketType
|
||||||
|
import li.cil.oc.common.multipart.EventHandler
|
||||||
import li.cil.oc.common.tileentity._
|
import li.cil.oc.common.tileentity._
|
||||||
import li.cil.oc.common.{PacketHandler => CommonPacketHandler}
|
import li.cil.oc.common.{PacketHandler => CommonPacketHandler}
|
||||||
import li.cil.oc.server.component.machine.Machine
|
|
||||||
import net.minecraft.entity.player.EntityPlayerMP
|
import net.minecraft.entity.player.EntityPlayerMP
|
||||||
import net.minecraft.util.ChatMessageComponent
|
import net.minecraft.util.ChatMessageComponent
|
||||||
import net.minecraftforge.common.{ForgeDirection, DimensionManager}
|
import net.minecraftforge.common.{ForgeDirection, DimensionManager}
|
||||||
import li.cil.oc.common.multipart.{EventHandler, MultiPart}
|
|
||||||
|
|
||||||
class PacketHandler extends CommonPacketHandler {
|
class PacketHandler extends CommonPacketHandler {
|
||||||
override protected def world(player: Player, dimension: Int) =
|
override protected def world(player: Player, dimension: Int) =
|
||||||
@ -52,7 +52,7 @@ class PacketHandler extends CommonPacketHandler {
|
|||||||
if (!computer.isPaused) {
|
if (!computer.isPaused) {
|
||||||
computer.start()
|
computer.start()
|
||||||
computer.lastError match {
|
computer.lastError match {
|
||||||
case Some(message) => player.sendChatToPlayer(ChatMessageComponent.createFromTranslationKey(message))
|
case message => player.sendChatToPlayer(ChatMessageComponent.createFromTranslationKey(message))
|
||||||
case _ =>
|
case _ =>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,7 @@ abstract class LuaArchitecture(val machine: api.machine.Machine) extends Archite
|
|||||||
val rom = Option(FileSystem.asManagedEnvironment(FileSystem.
|
val rom = Option(FileSystem.asManagedEnvironment(FileSystem.
|
||||||
fromClass(OpenComputers.getClass, Settings.resourceDomain, "lua/rom"), "rom"))
|
fromClass(OpenComputers.getClass, Settings.resourceDomain, "lua/rom"), "rom"))
|
||||||
|
|
||||||
override def init() = {
|
override def initialize() = {
|
||||||
if (machine.node.network != null) {
|
if (machine.node.network != null) {
|
||||||
rom.foreach(fs => machine.node.connect(fs.node))
|
rom.foreach(fs => machine.node.connect(fs.node))
|
||||||
}
|
}
|
||||||
|
@ -135,8 +135,8 @@ class LuaJLuaArchitecture(machine: api.machine.Machine) extends LuaArchitecture(
|
|||||||
|
|
||||||
// ----------------------------------------------------------------------- //
|
// ----------------------------------------------------------------------- //
|
||||||
|
|
||||||
override def init() = {
|
override def initialize() = {
|
||||||
super.init()
|
super.initialize()
|
||||||
|
|
||||||
lua = JsePlatform.debugGlobals()
|
lua = JsePlatform.debugGlobals()
|
||||||
lua.set("package", LuaValue.NIL)
|
lua.set("package", LuaValue.NIL)
|
||||||
|
@ -66,7 +66,7 @@ class Machine(val owner: Owner, constructor: Constructor[_ <: Architecture]) ext
|
|||||||
|
|
||||||
// ----------------------------------------------------------------------- //
|
// ----------------------------------------------------------------------- //
|
||||||
|
|
||||||
def lastError = message
|
def lastError = message.orNull
|
||||||
|
|
||||||
override def components = scala.collection.convert.WrapAsJava.mapAsJavaMap(_components)
|
override def components = scala.collection.convert.WrapAsJava.mapAsJavaMap(_components)
|
||||||
|
|
||||||
@ -643,7 +643,7 @@ class Machine(val owner: Owner, constructor: Constructor[_ <: Architecture]) ext
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return architecture.init()
|
return architecture.initialize()
|
||||||
}
|
}
|
||||||
catch {
|
catch {
|
||||||
case ex: Throwable =>
|
case ex: Throwable =>
|
||||||
|
@ -179,8 +179,8 @@ class NativeLuaArchitecture(machine: api.machine.Machine) extends LuaArchitectur
|
|||||||
|
|
||||||
// ----------------------------------------------------------------------- //
|
// ----------------------------------------------------------------------- //
|
||||||
|
|
||||||
override def init(): Boolean = {
|
override def initialize(): Boolean = {
|
||||||
super.init()
|
super.initialize()
|
||||||
|
|
||||||
// Creates a new state with all base libraries and the persistence library
|
// Creates a new state with all base libraries and the persistence library
|
||||||
// loaded into it. This means the state has much more power than it
|
// loaded into it. This means the state has much more power than it
|
||||||
|
@ -368,7 +368,7 @@ class Player(val robot: tileentity.Robot) extends EntityPlayer(robot.world, Sett
|
|||||||
|
|
||||||
override def addExhaustion(amount: Float) {
|
override def addExhaustion(amount: Float) {
|
||||||
if (Settings.get.robotExhaustionCost > 0) {
|
if (Settings.get.robotExhaustionCost > 0) {
|
||||||
robot.computer.node.changeBuffer(-Settings.get.robotExhaustionCost * amount)
|
robot.node.changeBuffer(-Settings.get.robotExhaustionCost * amount)
|
||||||
}
|
}
|
||||||
robot.addXp(Settings.get.robotExhaustionXpRate * amount)
|
robot.addXp(Settings.get.robotExhaustionXpRate * amount)
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package li.cil.oc.server.component.robot
|
package li.cil.oc.server.component.robot
|
||||||
|
|
||||||
import li.cil.oc.api
|
import li.cil.oc.api
|
||||||
import li.cil.oc.api.machine.Owner
|
|
||||||
import li.cil.oc.api.network._
|
import li.cil.oc.api.network._
|
||||||
import li.cil.oc.common.tileentity
|
import li.cil.oc.common.tileentity
|
||||||
import li.cil.oc.server.component.machine.Machine
|
import li.cil.oc.server.component.machine.Machine
|
||||||
@ -502,7 +501,7 @@ class Robot(val robot: tileentity.Robot) extends Machine(robot, api.Machine.LuaA
|
|||||||
result(Unit, what)
|
result(Unit, what)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (!robot.computer.node.tryChangeBuffer(-Settings.get.robotMoveCost)) {
|
if (!robot.node.tryChangeBuffer(-Settings.get.robotMoveCost)) {
|
||||||
result(Unit, "not enough energy")
|
result(Unit, "not enough energy")
|
||||||
}
|
}
|
||||||
else if (robot.move(direction)) {
|
else if (robot.move(direction)) {
|
||||||
@ -511,7 +510,7 @@ class Robot(val robot: tileentity.Robot) extends Machine(robot, api.Machine.LuaA
|
|||||||
result(true)
|
result(true)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
robot.computer.node.changeBuffer(Settings.get.robotMoveCost)
|
robot.node.changeBuffer(Settings.get.robotMoveCost)
|
||||||
result(Unit, "impossible move")
|
result(Unit, "impossible move")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -521,7 +520,7 @@ class Robot(val robot: tileentity.Robot) extends Machine(robot, api.Machine.LuaA
|
|||||||
@Callback
|
@Callback
|
||||||
def turn(context: Context, args: Arguments): Array[AnyRef] = {
|
def turn(context: Context, args: Arguments): Array[AnyRef] = {
|
||||||
val clockwise = args.checkBoolean(0)
|
val clockwise = args.checkBoolean(0)
|
||||||
if (robot.computer.node.tryChangeBuffer(-Settings.get.robotTurnCost)) {
|
if (robot.node.tryChangeBuffer(-Settings.get.robotTurnCost)) {
|
||||||
if (clockwise) robot.rotate(ForgeDirection.UP)
|
if (clockwise) robot.rotate(ForgeDirection.UP)
|
||||||
else robot.rotate(ForgeDirection.DOWN)
|
else robot.rotate(ForgeDirection.DOWN)
|
||||||
robot.animateTurn(clockwise, Settings.get.turnDelay)
|
robot.animateTurn(clockwise, Settings.get.turnDelay)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user