diff --git a/li/cil/oc/client/renderer/tileentity/ScreenRenderer.scala b/li/cil/oc/client/renderer/tileentity/ScreenRenderer.scala index 6b715d969..aa5627068 100644 --- a/li/cil/oc/client/renderer/tileentity/ScreenRenderer.scala +++ b/li/cil/oc/client/renderer/tileentity/ScreenRenderer.scala @@ -24,7 +24,6 @@ object ScreenRenderer extends TileEntitySpecialRenderer with Callable[Int] with /** We cache the display lists for the screens we render for performance. */ val cache = com.google.common.cache.CacheBuilder.newBuilder(). - weakKeys(). expireAfterAccess(5, TimeUnit.SECONDS). removalListener(this). asInstanceOf[CacheBuilder[Screen, Int]].build[Screen, Int]() diff --git a/li/cil/oc/common/block/Delegator.scala b/li/cil/oc/common/block/Delegator.scala index d6046f334..0324b4254 100644 --- a/li/cil/oc/common/block/Delegator.scala +++ b/li/cil/oc/common/block/Delegator.scala @@ -4,8 +4,7 @@ import cpw.mods.fml.common.registry.GameRegistry import java.util import li.cil.oc.Config import li.cil.oc.CreativeTab -import li.cil.oc.api.Network -import li.cil.oc.api.network.{Environment, Node} +import li.cil.oc.api.network.Environment import li.cil.oc.common.tileentity.Rotatable import net.minecraft.block.Block import net.minecraft.block.material.Material @@ -290,13 +289,7 @@ class Delegator[Child <: Delegate](id: Int) extends Block(id, Material.iron) { override def onBlockAdded(world: World, x: Int, y: Int, z: Int) = subBlock(world, x, y, z) match { - case Some(subBlock) => { - world.getBlockTileEntity(x, y, z) match { - case _: Environment => Network.joinOrCreateNetwork(world, x, y, z) - case _ => // Nothing special to do. - } - subBlock.onBlockAdded(world, x, y, z) - } + case Some(subBlock) => subBlock.onBlockAdded(world, x, y, z) case _ => // Invalid but avoid match error. } diff --git a/li/cil/oc/common/tileentity/Adapter.scala b/li/cil/oc/common/tileentity/Adapter.scala index 7192a0f93..1ffca083b 100644 --- a/li/cil/oc/common/tileentity/Adapter.scala +++ b/li/cil/oc/common/tileentity/Adapter.scala @@ -2,6 +2,7 @@ package li.cil.oc.common.tileentity import dan200.computer.api.{ILuaContext, IComputerAccess, IPeripheral} import li.cil.oc.api +import li.cil.oc.api.Network import li.cil.oc.api.network._ import li.cil.oc.server import li.cil.oc.server.driver @@ -25,6 +26,10 @@ class Adapter extends Rotatable with Environment with IPeripheral { // ----------------------------------------------------------------------- // override def updateEntity() { + super.updateEntity() + if (node != null && node.network == null) { + Network.joinOrCreateNetwork(worldObj, xCoord, yCoord, zCoord) + } for (block <- blocks) block match { case Some((environment, _)) => environment.update() case _ => // Empty. diff --git a/li/cil/oc/common/tileentity/Computer.scala b/li/cil/oc/common/tileentity/Computer.scala index 88eb13aae..1393ea241 100644 --- a/li/cil/oc/common/tileentity/Computer.scala +++ b/li/cil/oc/common/tileentity/Computer.scala @@ -1,6 +1,7 @@ package li.cil.oc.common.tileentity import java.util.concurrent.atomic.AtomicBoolean +import li.cil.oc.api.Network import li.cil.oc.api.driver.Slot import li.cil.oc.client.{PacketSender => ClientPacketSender} import li.cil.oc.server.component @@ -60,14 +61,24 @@ class Computer(isClient: Boolean) extends Rotatable with ComputerEnvironment wit // ----------------------------------------------------------------------- // - override def updateEntity() = if (!worldObj.isRemote) { - instance.update() - updateRedstoneInput() - if (hasChanged.get) - worldObj.markTileEntityChunkModified(xCoord, yCoord, zCoord, this) - if (isRunning != instance.isRunning) - ServerPacketSender.sendComputerState(this, instance.isRunning) - isRunning = instance.isRunning + override def updateEntity() { + super.updateEntity() + if (node != null && node.network == null) { + Network.joinOrCreateNetwork(worldObj, xCoord, yCoord, zCoord) + } + else if (!worldObj.isRemote) { + // If we just joined a network we were just loaded from disk. We skip 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 + // otherwise loose track of its screen). + instance.update() + updateRedstoneInput() + if (hasChanged.get) + worldObj.markTileEntityChunkModified(xCoord, yCoord, zCoord, this) + if (isRunning != instance.isRunning) + ServerPacketSender.sendComputerState(this, instance.isRunning) + isRunning = instance.isRunning + } for (component <- components) component match { case Some(environment) => environment.update() @@ -75,7 +86,7 @@ class Computer(isClient: Boolean) extends Rotatable with ComputerEnvironment wit } } - override def validate() = { + override def validate() { super.validate() if (worldObj.isRemote) { ClientPacketSender.sendComputerStateRequest(this) diff --git a/li/cil/oc/common/tileentity/DiskDrive.scala b/li/cil/oc/common/tileentity/DiskDrive.scala index 77fc69573..5d99de482 100644 --- a/li/cil/oc/common/tileentity/DiskDrive.scala +++ b/li/cil/oc/common/tileentity/DiskDrive.scala @@ -1,6 +1,7 @@ package li.cil.oc.common.tileentity import li.cil.oc.api +import li.cil.oc.api.Network import li.cil.oc.api.driver.Slot import li.cil.oc.api.network.{Component, Visibility} import li.cil.oc.server.driver.Registry @@ -15,6 +16,15 @@ class DiskDrive extends Rotatable with Environment with ComponentInventory { // ----------------------------------------------------------------------- // + override def updateEntity() { + super.updateEntity() + if (node != null && node.network == null) { + Network.joinOrCreateNetwork(worldObj, xCoord, yCoord, zCoord) + } + } + + // ----------------------------------------------------------------------- // + override def readFromNBT(nbt: NBTTagCompound) { super.readFromNBT(nbt) if (node != null) node.load(nbt) diff --git a/li/cil/oc/common/tileentity/Keyboard.scala b/li/cil/oc/common/tileentity/Keyboard.scala index 3c45e95de..0c95f1f8f 100644 --- a/li/cil/oc/common/tileentity/Keyboard.scala +++ b/li/cil/oc/common/tileentity/Keyboard.scala @@ -2,6 +2,7 @@ package li.cil.oc.common.tileentity import cpw.mods.fml.common.network.Player import li.cil.oc.api +import li.cil.oc.api.Network import li.cil.oc.api.network.{Visibility, Message} import net.minecraft.entity.player.EntityPlayer import net.minecraft.nbt.NBTTagCompound @@ -11,6 +12,16 @@ class Keyboard extends Rotatable with Environment { withComponent("keyboard"). create() + // ----------------------------------------------------------------------- // + + override def updateEntity() { + if (node != null && node.network == null) { + Network.joinOrCreateNetwork(worldObj, xCoord, yCoord, zCoord) + } + } + + // ----------------------------------------------------------------------- // + override def readFromNBT(nbt: NBTTagCompound) { super.readFromNBT(nbt) node.load(nbt) @@ -21,6 +32,8 @@ class Keyboard extends Rotatable with Environment { node.save(nbt) } + // ----------------------------------------------------------------------- // + override def onMessage(message: Message) = { message.data match { case Array(p: Player, char: Character, code: Integer) if message.name == "keyboard.keyDown" => @@ -37,6 +50,8 @@ class Keyboard extends Rotatable with Environment { super.onMessage(message) } + // ----------------------------------------------------------------------- // + def isUseableByPlayer(p: Player) = worldObj.getBlockTileEntity(xCoord, yCoord, zCoord) == this && p.asInstanceOf[EntityPlayer].getDistanceSq(xCoord + 0.5, yCoord + 0.5, zCoord + 0.5) < 64 } \ No newline at end of file diff --git a/li/cil/oc/common/tileentity/PowerConverter.scala b/li/cil/oc/common/tileentity/PowerConverter.scala index b27477745..5dbf4d547 100644 --- a/li/cil/oc/common/tileentity/PowerConverter.scala +++ b/li/cil/oc/common/tileentity/PowerConverter.scala @@ -4,6 +4,7 @@ import buildcraft.api.power.{PowerHandler, IPowerReceptor} import ic2.api.energy.event.{EnergyTileLoadEvent, EnergyTileUnloadEvent} import ic2.api.energy.tile.IEnergySink import li.cil.oc.api +import li.cil.oc.api.Network import li.cil.oc.api.network._ import net.minecraft.nbt.NBTTagCompound import net.minecraft.tileentity.TileEntity @@ -37,6 +38,9 @@ class PowerConverter extends Rotatable with Environment with IEnergySink with IP override def updateEntity() { super.updateEntity() + if (node != null && node.network == null) { + Network.joinOrCreateNetwork(worldObj, xCoord, yCoord, zCoord) + } if (!worldObj.isRemote) { if (!addedToEnet) { MinecraftForge.EVENT_BUS.post(new EnergyTileLoadEvent(this)) @@ -62,14 +66,14 @@ class PowerConverter extends Rotatable with Environment with IEnergySink with IP // ----------------------------------------------------------------------- // - override def readFromNBT(nbt: NBTTagCompound) = { + override def readFromNBT(nbt: NBTTagCompound) { super.readFromNBT(nbt) node.load(nbt) getPowerProvider.readFromNBT(nbt) } - override def writeToNBT(nbt: NBTTagCompound) = { + override def writeToNBT(nbt: NBTTagCompound) { super.writeToNBT(nbt) node.save(nbt) getPowerProvider.writeToNBT(nbt) diff --git a/li/cil/oc/common/tileentity/PowerDistributor.scala b/li/cil/oc/common/tileentity/PowerDistributor.scala index e542792e7..46a0cd5df 100644 --- a/li/cil/oc/common/tileentity/PowerDistributor.scala +++ b/li/cil/oc/common/tileentity/PowerDistributor.scala @@ -1,6 +1,7 @@ package li.cil.oc.common.tileentity import li.cil.oc.api +import li.cil.oc.api.Network import li.cil.oc.api.network._ import li.cil.oc.client.{PacketSender => ClientPacketSender} import li.cil.oc.server.network.Connector @@ -23,6 +24,10 @@ class PowerDistributor extends Rotatable with Environment { // ----------------------------------------------------------------------- // override def updateEntity() { + super.updateEntity() + if (node != null && node.network == null) { + Network.joinOrCreateNetwork(worldObj, xCoord, yCoord, zCoord) + } if (!worldObj.isRemote && connectors.exists(_.dirty) && computeAverage()) { // Adjust buffer fill ratio for all buffers to average. connectors.foreach(c => c.buffer = c.bufferSize * average) diff --git a/li/cil/oc/common/tileentity/Screen.scala b/li/cil/oc/common/tileentity/Screen.scala index 29194fa6a..cea20f5b5 100644 --- a/li/cil/oc/common/tileentity/Screen.scala +++ b/li/cil/oc/common/tileentity/Screen.scala @@ -1,10 +1,11 @@ package li.cil.oc.common.tileentity import li.cil.oc.Config +import li.cil.oc.api.Network import li.cil.oc.api.network.Visibility import li.cil.oc.client.gui import li.cil.oc.client.{PacketSender => ClientPacketSender} -import li.cil.oc.common.component +import li.cil.oc.common.component.Screen.{Environment => ScreenEnvironment} import li.cil.oc.server.{PacketSender => ServerPacketSender} import net.minecraft.nbt.NBTTagCompound import net.minecraft.util.AxisAlignedBB @@ -23,7 +24,7 @@ class ScreenTier3 extends Screen { protected def maxResolution = Config.screenResolutionsByTier(2) } -abstract class Screen extends Rotatable with component.Screen.Environment { +abstract class Screen extends Rotatable with ScreenEnvironment { var currentGui: Option[gui.Screen] = None /** @@ -75,7 +76,7 @@ abstract class Screen extends Rotatable with component.Screen.Environment { super.save(nbt) } - override def validate() = { + override def validate() { super.validate() if (worldObj.isRemote) ClientPacketSender.sendScreenBufferRequest(this) } @@ -89,7 +90,11 @@ abstract class Screen extends Rotatable with component.Screen.Environment { // ----------------------------------------------------------------------- // - override def updateEntity() = + override def updateEntity() { + super.updateEntity() + if (node != null && node.network == null) { + Network.joinOrCreateNetwork(worldObj, xCoord, yCoord, zCoord) + } if (shouldCheckForMultiBlock) { // Make sure we merge in a deterministic order, to avoid getting // different results on server and client due to the update order @@ -142,6 +147,7 @@ abstract class Screen extends Rotatable with component.Screen.Environment { } ) } + } def checkMultiBlock() { shouldCheckForMultiBlock = true