Trying to get rid of FMLCommonHandler.instance.getEffectiveSide where possible, since it can apparently fail in some scenarios.

This commit is contained in:
Florian Nücke 2014-07-17 15:15:26 +02:00
parent c1d5371738
commit b3813bc4f5
54 changed files with 104 additions and 83 deletions

View File

@ -1,6 +1,5 @@
package li.cil.oc.common.asm;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.ITickHandler;
import cpw.mods.fml.common.TickType;
import li.cil.oc.api.Network;
@ -20,7 +19,7 @@ public final class SimpleComponentTickHandler implements ITickHandler {
}
public static void schedule(final TileEntity tileEntity) {
if (FMLCommonHandler.instance().getEffectiveSide().isServer()) {
if (tileEntity.hasWorldObj() && !tileEntity.getWorldObj().isRemote) {
synchronized (pending) {
pending.add(new Runnable() {
@Override

View File

@ -235,6 +235,7 @@ object Settings {
val hologramMaxScaleByTier = Array(3, 4)
val robotComplexityByTier = Array(12, 24, 32, 9001)
var rTreeDebugRenderer = false
var blockRenderId = -1
// Power conversion values. These are the same values used by Universal
// Electricity to provide global power support.

View File

@ -12,7 +12,7 @@ import li.cil.oc.client.renderer.{PetRenderer, TextBufferRenderCache, WirelessNe
import li.cil.oc.common.component.TextBuffer
import li.cil.oc.common.tileentity.Rack
import li.cil.oc.common.{tileentity, Proxy => CommonProxy}
import li.cil.oc.{Items, OpenComputers}
import li.cil.oc.{Settings, Items, OpenComputers}
import net.minecraft.client.Minecraft
import net.minecraft.client.resources.ReloadableResourceManager
import net.minecraftforge.client.MinecraftForgeClient
@ -30,7 +30,7 @@ private[oc] class Proxy extends CommonProxy {
NetworkRegistry.instance.registerGuiHandler(OpenComputers, GuiHandler)
BlockRenderer.getRenderId = RenderingRegistry.getNextAvailableRenderId
Settings.blockRenderId = RenderingRegistry.getNextAvailableRenderId
RenderingRegistry.registerBlockHandler(BlockRenderer)
ClientRegistry.bindTileEntitySpecialRenderer(classOf[tileentity.Cable], CableRenderer)

View File

@ -1,6 +1,7 @@
package li.cil.oc.client.renderer.block
import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler
import li.cil.oc.Settings
import li.cil.oc.client.Textures
import li.cil.oc.client.renderer.tileentity.{CableRenderer, RobotRenderer}
import li.cil.oc.common.block._
@ -13,7 +14,7 @@ import net.minecraftforge.common.ForgeDirection
import org.lwjgl.opengl.GL11
object BlockRenderer extends ISimpleBlockRenderingHandler {
var getRenderId = -1
def getRenderId = Settings.blockRenderId
override def shouldRender3DInInventory() = true

View File

@ -13,8 +13,8 @@ import li.cil.oc.client.renderer.PetRenderer
import li.cil.oc.client.{PacketSender => ClientPacketSender}
import li.cil.oc.common.tileentity.traits.power
import li.cil.oc.server.{PacketSender => ServerPacketSender}
import li.cil.oc.util.{LuaStateFactory, mods}
import li.cil.oc.util.mods.Mods
import li.cil.oc.util.{LuaStateFactory, mods}
import net.minecraft.client.Minecraft
import net.minecraft.entity.player.{EntityPlayer, EntityPlayerMP}
import net.minecraft.inventory.IInventory
@ -31,18 +31,18 @@ object EventHandler extends ITickHandler with IConnectionHandler with ICraftingH
val pending = mutable.Buffer.empty[() => Unit]
def schedule(tileEntity: TileEntity) =
if (FMLCommonHandler.instance.getEffectiveSide.isServer) pending.synchronized {
if (tileEntity.hasWorldObj && !tileEntity.getWorldObj.isRemote) pending.synchronized {
pending += (() => Network.joinOrCreateNetwork(tileEntity))
}
@Optional.Method(modid = "ForgeMultipart")
def schedule(part: TMultiPart) =
if (FMLCommonHandler.instance.getEffectiveSide.isServer) pending.synchronized {
if (part.world != null && !part.world.isRemote) pending.synchronized {
pending += (() => Network.joinOrCreateNetwork(part.tile))
}
@Optional.Method(modid = "IC2")
def scheduleIC2Add(tileEntity: power.IndustrialCraft2) = if (FMLCommonHandler.instance.getEffectiveSide.isServer) pending.synchronized {
def scheduleIC2Add(tileEntity: power.IndustrialCraft2) = if (tileEntity.hasWorldObj && !tileEntity.getWorldObj.isRemote) pending.synchronized {
pending += (() => if (!tileEntity.addedToPowerGrid && !tileEntity.isInvalid) {
MinecraftForge.EVENT_BUS.post(new EnergyTileLoadEvent(tileEntity))
tileEntity.addedToPowerGrid = true
@ -50,14 +50,14 @@ object EventHandler extends ITickHandler with IConnectionHandler with ICraftingH
}
@Optional.Method(modid = "IC2")
def scheduleIC2Remove(tileEntity: power.IndustrialCraft2) = if (FMLCommonHandler.instance.getEffectiveSide.isServer) pending.synchronized {
def scheduleIC2Remove(tileEntity: power.IndustrialCraft2) = if (tileEntity.hasWorldObj && !tileEntity.getWorldObj.isRemote) pending.synchronized {
pending += (() => if (tileEntity.addedToPowerGrid) {
MinecraftForge.EVENT_BUS.post(new EnergyTileUnloadEvent(tileEntity))
tileEntity.addedToPowerGrid = false
})
}
def scheduleWirelessRedstone(rs: server.component.RedstoneWireless) = if (FMLCommonHandler.instance.getEffectiveSide.isServer) pending.synchronized {
def scheduleWirelessRedstone(rs: server.component.RedstoneWireless) = if (rs.owner.isServer) pending.synchronized {
pending += (() => if (!rs.owner.isInvalid) {
mods.WirelessRedstone.addReceiver(rs)
mods.WirelessRedstone.updateOutput(rs)

View File

@ -54,5 +54,5 @@ class AccessPoint(val parent: SimpleDelegator) extends SimpleDelegate {
override def hasTileEntity = true
override def createTileEntity(world: World) = Some(new tileentity.WirelessRouter)
override def createTileEntity(world: World) = Some(new tileentity.WirelessRouter(world.isRemote))
}

View File

@ -39,7 +39,7 @@ class Adapter(val parent: SimpleDelegator) extends SimpleDelegate {
override def hasTileEntity = true
override def createTileEntity(world: World) = Some(new tileentity.Adapter)
override def createTileEntity(world: World) = Some(new tileentity.Adapter(world.isRemote))
// ----------------------------------------------------------------------- //

View File

@ -43,7 +43,7 @@ class Cable(val parent: SpecialDelegator) extends SpecialDelegate {
override def hasTileEntity = true
override def createTileEntity(world: World) = Some(new tileentity.Cable)
override def createTileEntity(world: World) = Some(new tileentity.Cable(world.isRemote))
// ----------------------------------------------------------------------- //

View File

@ -51,7 +51,7 @@ class Capacitor(val parent: SimpleDelegator) extends SimpleDelegate {
override def hasTileEntity = true
override def createTileEntity(world: World) = Some(new tileentity.Capacitor)
override def createTileEntity(world: World) = Some(new tileentity.Capacitor(world.isRemote))
// ----------------------------------------------------------------------- //

View File

@ -82,7 +82,7 @@ abstract class Case(val parent: SimpleDelegator) extends RedstoneAware with Simp
// ----------------------------------------------------------------------- //
override def createTileEntity(world: World) = Some(new tileentity.Case(tier, world.isRemote))
override def createTileEntity(world: World) = Some(new tileentity.Case(world.isRemote, tier))
// ----------------------------------------------------------------------- //

View File

@ -54,7 +54,7 @@ class Charger(val parent: SimpleDelegator) extends RedstoneAware with SimpleDele
Textures.Charger.iconSideCharging = iconRegister.registerIcon(Settings.resourceDomain + ":charger_side_on")
}
override def createTileEntity(world: World) = Some(new tileentity.Charger())
override def createTileEntity(world: World) = Some(new tileentity.Charger(world.isRemote))
override def canConnectToRedstone(world: IBlockAccess, x: Int, y: Int, z: Int, side: ForgeDirection) = true

View File

@ -3,10 +3,9 @@ package li.cil.oc.common.block
import java.util
import java.util.Random
import cpw.mods.fml.common.{FMLCommonHandler, Optional}
import cpw.mods.fml.common.Optional
import cpw.mods.fml.relauncher.{Side, SideOnly}
import li.cil.oc.client.KeyBindings
import li.cil.oc.client.renderer.block.BlockRenderer
import li.cil.oc.common.tileentity.traits.{BundledRedstoneAware, Colored, Rotatable}
import li.cil.oc.util.mods.Mods
import li.cil.oc.util.{Color, ItemCosts}
@ -344,7 +343,7 @@ class Delegator[Child <: Delegate](id: Int) extends Block(id, Material.iron) {
}
}
override def getRenderType = if (FMLCommonHandler.instance.getEffectiveSide.isClient) BlockRenderer.getRenderId else -1
override def getRenderType = Settings.blockRenderId
override def getLightOpacity(world: World, x: Int, y: Int, z: Int) =
subBlock(world, x, y, z) match {

View File

@ -43,7 +43,7 @@ class Disassembler(val parent: SimpleDelegator) extends SimpleDelegate {
override def hasTileEntity = true
override def createTileEntity(world: World) = Some(new tileentity.Disassembler)
override def createTileEntity(world: World) = Some(new tileentity.Disassembler(world.isRemote))
// ----------------------------------------------------------------------- //

View File

@ -61,7 +61,7 @@ class DiskDrive(val parent: SimpleDelegator) extends SimpleDelegate {
override def hasTileEntity = true
override def createTileEntity(world: World) = Some(new tileentity.DiskDrive)
override def createTileEntity(world: World) = Some(new tileentity.DiskDrive(world.isRemote))
// ----------------------------------------------------------------------- //

View File

@ -44,6 +44,6 @@ class Geolyzer(val parent: SimpleDelegator) extends SimpleDelegate {
override def hasTileEntity = true
override def createTileEntity(world: World) = Some(new tileentity.Geolyzer)
override def createTileEntity(world: World) = Some(new tileentity.Geolyzer(world.isRemote))
}

View File

@ -68,7 +68,7 @@ abstract class Hologram(val parent: SpecialDelegator) extends SpecialDelegate {
override def hasTileEntity = true
override def createTileEntity(world: World) = Some(new tileentity.Hologram(tier))
override def createTileEntity(world: World) = Some(new tileentity.Hologram(world.isRemote, tier))
}
object Hologram {

View File

@ -68,5 +68,5 @@ class PowerConverter(val parent: SimpleDelegator) extends SimpleDelegate {
override def hasTileEntity = true
override def createTileEntity(world: World) = Some(new tileentity.PowerConverter)
override def createTileEntity(world: World) = Some(new tileentity.PowerConverter(world.isRemote))
}

View File

@ -45,6 +45,6 @@ class PowerDistributor(val parent: SimpleDelegator) extends SimpleDelegate {
override def hasTileEntity = true
override def createTileEntity(world: World) = Some(new tileentity.PowerDistributor)
override def createTileEntity(world: World) = Some(new tileentity.PowerDistributor(world.isRemote))
}

View File

@ -51,7 +51,7 @@ class Rack(val parent: SpecialDelegator) extends RedstoneAware with SpecialDeleg
override def hasTileEntity = true
override def createTileEntity(world: World) = Some(new tileentity.Rack)
override def createTileEntity(world: World) = Some(new tileentity.Rack(world.isRemote))
// ----------------------------------------------------------------------- //

View File

@ -40,5 +40,5 @@ class Redstone(val parent: SimpleDelegator) extends RedstoneAware with SimpleDel
icons(ForgeDirection.EAST.ordinal) = icons(ForgeDirection.NORTH.ordinal)
}
override def createTileEntity(world: World) = Some(new tileentity.Redstone())
override def createTileEntity(world: World) = Some(new tileentity.Redstone(world.isRemote))
}

View File

@ -48,7 +48,7 @@ class RobotAssembler(val parent: SpecialDelegator) extends SpecialDelegate {
override def hasTileEntity = true
override def createTileEntity(world: World) = Some(new tileentity.RobotAssembler)
override def createTileEntity(world: World) = Some(new tileentity.RobotAssembler(world.isRemote))
// ----------------------------------------------------------------------- //

View File

@ -87,8 +87,8 @@ class RobotProxy(val parent: SpecialDelegator) extends RedstoneAware with Specia
override def createTileEntity(world: World) = {
moving.get match {
case Some(robot) => Some(new tileentity.RobotProxy(robot))
case _ => Some(new tileentity.RobotProxy(new tileentity.Robot(world.isRemote)))
case Some(robot) => Some(new tileentity.RobotProxy(world.isRemote, robot))
case _ => Some(new tileentity.RobotProxy(world.isRemote, new tileentity.Robot(world.isRemote)))
}
}

View File

@ -299,7 +299,7 @@ abstract class Screen(val parent: SimpleDelegator) extends RedstoneAware with Si
override def hasTileEntity = true
override def createTileEntity(world: World) = Some(new tileentity.Screen(tier))
override def createTileEntity(world: World) = Some(new tileentity.Screen(world.isRemote, tier))
// ----------------------------------------------------------------------- //

View File

@ -42,5 +42,5 @@ class Switch(val parent: SimpleDelegator) extends SimpleDelegate {
override def hasTileEntity = true
override def createTileEntity(world: World) = Some(new tileentity.Router)
override def createTileEntity(world: World) = Some(new tileentity.Router(world.isRemote))
}

View File

@ -1,7 +1,6 @@
package li.cil.oc.common.component
import com.google.common.base.Strings
import cpw.mods.fml.common.FMLCommonHandler
import cpw.mods.fml.relauncher.{Side, SideOnly}
import li.cil.oc.api.component.TextBuffer.ColorDepth
import li.cil.oc.api.driver.Container
@ -58,8 +57,8 @@ class TextBuffer(val owner: Container) extends ManagedComponent with api.compone
powerConsumptionPerTick * (mw * mh) / (w * h)
}
val proxy =
if (FMLCommonHandler.instance.getEffectiveSide.isClient) new TextBuffer.ClientProxy(this)
lazy val proxy =
if (owner.world.isRemote) new TextBuffer.ClientProxy(this)
else new TextBuffer.ServerProxy(this)
val data = new util.TextBuffer(maxResolution, PackedColor.Depth.format(maxDepth))
@ -350,7 +349,8 @@ class TextBuffer(val owner: Container) extends ManagedComponent with api.compone
override def load(nbt: NBTTagCompound) {
super.load(nbt)
if (FMLCommonHandler.instance.getEffectiveSide.isClient) {
// World will be null on the server and set on the client.
if (owner.world != null) {
if (!Strings.isNullOrEmpty(proxy.nodeAddress)) return // Only load once.
proxy.nodeAddress = nbt.getCompoundTag("node").getString("address")
TextBuffer.registerClientBuffer(this)

View File

@ -1,6 +1,5 @@
package li.cil.oc.common.container
import cpw.mods.fml.common.FMLCommonHandler
import cpw.mods.fml.relauncher.{Side, SideOnly}
import li.cil.oc.common.tileentity
import net.minecraft.entity.player.InventoryPlayer
@ -21,7 +20,7 @@ class Disassembler(playerInventory: InventoryPlayer, disassembler: tileentity.Di
override def detectAndSendChanges() {
super.detectAndSendChanges()
if (FMLCommonHandler.instance.getEffectiveSide.isServer) {
if (!disassembler.world.isRemote) {
if (math.abs(disassembler.progress - disassemblyProgress) > 0.2) {
disassemblyProgress = disassembler.progress
sendProgressBarUpdate(0, (disassemblyProgress * 5).toInt)

View File

@ -1,6 +1,5 @@
package li.cil.oc.common.container
import cpw.mods.fml.common.FMLCommonHandler
import li.cil.oc.api
import li.cil.oc.client.gui.Icons
import li.cil.oc.common.InventorySlots.InventorySlot
@ -31,7 +30,7 @@ class DynamicComponentSlot(val container: Player, inventory: IInventory, index:
}
override protected def clearIfInvalid(player: EntityPlayer) {
if (FMLCommonHandler.instance.getEffectiveSide.isServer && getHasStack && !isItemValid(getStack)) {
if (player.getEntityWorld != null && !player.getEntityWorld.isRemote && getHasStack && !isItemValid(getStack)) {
val stack = getStack
putStack(null)
player.inventory.addItemStackToInventory(stack)

View File

@ -23,7 +23,7 @@ abstract class Player(val playerInventory: InventoryPlayer, val otherInventory:
override def slotClick(slot: Int, mouseClick: Int, holdingShift: Int, player: EntityPlayer) = {
val result = super.slotClick(slot, mouseClick, holdingShift, player)
if (FMLCommonHandler.instance.getEffectiveSide.isServer) {
if (player.getEntityWorld != null && !player.getEntityWorld.isRemote) {
detectAndSendChanges() // We have to enforce this more than MC does itself
// because stacks can change their... "character" just by being inserted in
// certain containers - by being assigned an address.
@ -36,7 +36,7 @@ abstract class Player(val playerInventory: InventoryPlayer, val otherInventory:
val slot = Option(inventorySlots.get(index)).map(_.asInstanceOf[Slot]).orNull
if (slot != null && slot.getHasStack) {
tryTransferStackInSlot(slot, slot.inventory == otherInventory)
if (FMLCommonHandler.instance.getEffectiveSide.isServer) {
if (player.getEntityWorld != null && !player.getEntityWorld.isRemote) {
detectAndSendChanges()
}
}

View File

@ -59,7 +59,7 @@ class Robot(playerInventory: InventoryPlayer, robot: tileentity.Robot) extends P
override def detectAndSendChanges() {
super.detectAndSendChanges()
if (FMLCommonHandler.instance.getEffectiveSide.isServer) {
if (robot.isServer) {
val currentBuffer = robot.globalBuffer.toInt / factor
if (currentBuffer != lastSentBuffer) {
lastSentBuffer = currentBuffer

View File

@ -77,7 +77,7 @@ class RobotAssembler(playerInventory: InventoryPlayer, val assembler: tileentity
override def detectAndSendChanges() {
super.detectAndSendChanges()
if (FMLCommonHandler.instance.getEffectiveSide.isServer) {
if (assembler.isServer) {
if (isAssembling != assembler.isAssembling) {
isAssembling = assembler.isAssembling
sendProgressBarUpdate(0, if (isAssembling) 1 else 0)

View File

@ -8,7 +8,9 @@ import net.minecraftforge.common.ForgeDirection
import scala.collection.mutable
class Adapter extends traits.Environment with Analyzable {
class Adapter(val isClient: Boolean) extends traits.Environment with Analyzable {
def this() = this(false)
val node = api.Network.newNode(this, Visibility.Network).create()
private val blocks = Array.fill[Option[(ManagedEnvironment, api.driver.Block)]](6)(None)

View File

@ -3,7 +3,9 @@ package li.cil.oc.common.tileentity
import li.cil.oc.api.network.Visibility
import li.cil.oc.{api, common}
class Cable extends traits.Environment with traits.NotAnalyzable {
class Cable(val isClient: Boolean) extends traits.Environment with traits.NotAnalyzable {
def this() = this(false)
val node = api.Network.newNode(this, Visibility.None).create()
override def canUpdate = false

View File

@ -4,7 +4,9 @@ import li.cil.oc.api.network.{Node, Visibility}
import li.cil.oc.{Settings, api}
import net.minecraftforge.common.ForgeDirection
class Capacitor extends traits.Environment {
class Capacitor(val isClient: Boolean) extends traits.Environment {
def this() = this(false)
// Start with maximum theoretical capacity, gets reduced after validation.
// This is done so that we don't lose energy while loading.
val node = api.Network.newNode(this, Visibility.Network).

View File

@ -12,8 +12,8 @@ import net.minecraft.item.ItemStack
import net.minecraft.nbt.NBTTagCompound
import net.minecraftforge.common.ForgeDirection
class Case(var tier: Int, val isRemote: Boolean) extends traits.PowerAcceptor with traits.Computer with traits.Colored {
def this() = this(0, false)
class Case(val isClient: Boolean, var tier: Int) extends traits.PowerAcceptor with traits.Computer with traits.Colored {
def this() = this(false, 0)
color = Color.byTier(tier)

View File

@ -8,7 +8,9 @@ import net.minecraft.entity.player.EntityPlayer
import net.minecraft.nbt.NBTTagCompound
import net.minecraftforge.common.ForgeDirection
class Charger extends traits.Environment with traits.PowerAcceptor with traits.RedstoneAware with traits.Rotatable with Analyzable {
class Charger(val isClient: Boolean) extends traits.Environment with traits.PowerAcceptor with traits.RedstoneAware with traits.Rotatable with Analyzable {
def this() = this(false)
val node = api.Network.newNode(this, Visibility.None).
withConnector(Settings.get.bufferConverter).
create()

View File

@ -19,7 +19,9 @@ import net.minecraftforge.oredict.{ShapedOreRecipe, ShapelessOreRecipe}
import scala.collection.convert.WrapAsScala._
import scala.collection.mutable
class Disassembler extends traits.Environment with traits.PowerAcceptor with traits.Inventory {
class Disassembler(val isClient: Boolean) extends traits.Environment with traits.PowerAcceptor with traits.Inventory {
def this() = this(false)
val node = api.Network.newNode(this, Visibility.None).
withConnector(Settings.get.bufferConverter).
create()

View File

@ -8,7 +8,9 @@ import li.cil.oc.{Settings, api}
import net.minecraft.entity.player.EntityPlayer
import net.minecraft.item.ItemStack
class DiskDrive extends traits.Environment with traits.ComponentInventory with traits.Rotatable with Analyzable {
class DiskDrive(val isClient: Boolean) extends traits.Environment with traits.ComponentInventory with traits.Rotatable with Analyzable {
def this() = this(false)
val node = api.Network.newNode(this, Visibility.None).create()
// ----------------------------------------------------------------------- //

View File

@ -5,7 +5,9 @@ import li.cil.oc.{Settings, api}
import net.minecraft.block.{Block, BlockFluid}
import net.minecraftforge.fluids.FluidRegistry
class Geolyzer extends traits.Environment {
class Geolyzer(val isClient: Boolean) extends traits.Environment {
def this() = this(false)
val node = api.Network.newNode(this, Visibility.Network).
withComponent("geolyzer").
withConnector().

View File

@ -9,8 +9,8 @@ import net.minecraft.nbt.NBTTagCompound
import net.minecraft.util.AxisAlignedBB
import net.minecraftforge.common.ForgeDirection
class Hologram(var tier: Int) extends traits.Environment with SidedEnvironment with Analyzable {
def this() = this(0)
class Hologram(val isClient: Boolean, var tier: Int) extends traits.Environment with SidedEnvironment with Analyzable {
def this() = this(false, 0)
val node = api.Network.newNode(this, Visibility.Network).
withComponent("hologram").

View File

@ -8,7 +8,7 @@ import net.minecraft.entity.player.EntityPlayer
import net.minecraft.nbt.NBTTagCompound
import net.minecraftforge.common.ForgeDirection
class Keyboard(isRemote: Boolean) extends traits.Environment with traits.Rotatable with SidedEnvironment with Analyzable {
class Keyboard(val isClient: Boolean) extends traits.Environment with traits.Rotatable with SidedEnvironment with Analyzable {
def this() = this(false)
override def validFacings = ForgeDirection.VALID_DIRECTIONS

View File

@ -5,7 +5,9 @@ import li.cil.oc.api.network._
import li.cil.oc.{Settings, api}
import net.minecraftforge.common.ForgeDirection
class PowerConverter extends traits.PowerAcceptor with traits.Environment with traits.NotAnalyzable {
class PowerConverter(val isClient: Boolean) extends traits.PowerAcceptor with traits.Environment with traits.NotAnalyzable {
def this() = this(false)
val node = api.Network.newNode(this, Visibility.Network).
withConnector(Settings.get.bufferConverter).
create()

View File

@ -7,7 +7,9 @@ import li.cil.oc.{Settings, api}
import net.minecraft.nbt.NBTTagCompound
import net.minecraftforge.common.ForgeDirection
class PowerDistributor extends traits.Environment with traits.PowerBalancer with traits.NotAnalyzable {
class PowerDistributor(val isClient: Boolean) extends traits.Environment with traits.PowerBalancer with traits.NotAnalyzable {
def this() = this(false)
val node = null
private val nodes = Array.fill(6)(api.Network.newNode(this, Visibility.Network).

View File

@ -22,13 +22,15 @@ import scala.collection.mutable
// See AbstractBusAware as to why we have to define the IBusDevice here.
@Optional.Interface(iface = "stargatetech2.api.bus.IBusDevice", modid = "StargateTech2")
class Rack extends traits.PowerAcceptor with traits.Hub with traits.PowerBalancer with traits.Inventory with traits.Rotatable with traits.BundledRedstoneAware with traits.AbstractBusAware with Analyzable with IBusDevice {
class Rack(val isClient: Boolean) extends traits.PowerAcceptor with traits.Hub with traits.PowerBalancer with traits.Inventory with traits.Rotatable with traits.BundledRedstoneAware with traits.AbstractBusAware with Analyzable with IBusDevice {
def this() = this(false)
val servers = Array.fill(getSizeInventory)(None: Option[component.Server])
val sides = Seq(ForgeDirection.UP, ForgeDirection.EAST, ForgeDirection.WEST, ForgeDirection.DOWN).
padTo(servers.length, ForgeDirection.UNKNOWN).toArray
val terminals = (0 until servers.length).map(new common.component.Terminal(this, _)).toArray
lazy val terminals = (0 until servers.length).map(new common.component.Terminal(this, _)).toArray
var range = 16

View File

@ -9,7 +9,9 @@ import li.cil.oc.util.mods.BundledRedstone
import net.minecraft.nbt.NBTTagCompound
import net.minecraftforge.common.ForgeDirection
class Redstone extends Environment with BundledRedstoneAware {
class Redstone(val isClient: Boolean) extends Environment with BundledRedstoneAware {
def this() = this(false)
val instance = if (BundledRedstone.isAvailable) new component.Redstone[BundledRedstoneAware](this) with component.RedstoneBundled else new component.Redstone(this)
val node = instance.node
if (node != null) {

View File

@ -30,7 +30,7 @@ import scala.collection.mutable
// robot moves we only create a new proxy tile entity, hook the instance of this
// class that was held by the old proxy to it and can then safely forget the
// old proxy, which will be cleaned up by Minecraft like any other tile entity.
class Robot(val isRemote: Boolean) extends traits.Computer with traits.PowerInformation with api.machine.Robot {
class Robot(val isClient: Boolean) extends traits.Computer with traits.PowerInformation with api.machine.Robot {
def this() = this(false)
var proxy: RobotProxy = _

View File

@ -14,7 +14,9 @@ import net.minecraft.item.ItemStack
import net.minecraft.nbt.NBTTagCompound
import net.minecraftforge.common.ForgeDirection
class RobotAssembler extends traits.Environment with traits.PowerAcceptor with traits.Inventory with traits.Rotatable with SidedEnvironment {
class RobotAssembler(val isClient: Boolean) extends traits.Environment with traits.PowerAcceptor with traits.Inventory with traits.Rotatable with SidedEnvironment {
def this() = this(false)
val node = api.Network.newNode(this, Visibility.None).
withConnector(Settings.get.bufferConverter).
create()

View File

@ -12,10 +12,8 @@ import net.minecraft.item.ItemStack
import net.minecraft.nbt.NBTTagCompound
import net.minecraftforge.common.ForgeDirection
class RobotProxy(val robot: Robot) extends traits.Computer with traits.PowerInformation with api.machine.Robot with ISidedInventory {
def this() = this(new Robot(false))
override def isRemote = robot.isClient
class RobotProxy(val isClient: Boolean, val robot: Robot) extends traits.Computer with traits.PowerInformation with api.machine.Robot with ISidedInventory {
def this() = this(false, new Robot(false))
// ----------------------------------------------------------------------- //

View File

@ -24,7 +24,9 @@ import scala.collection.mutable
// old API, so there should be no ClassNotFoundExceptions anyway.
@Optional.Interface(iface = "dan200.computer.api.IPeripheral", modid = "ComputerCraft")
class Router extends traits.Hub with traits.NotAnalyzable with IPeripheral {
class Router(val isClient: Boolean) extends traits.Hub with traits.NotAnalyzable with IPeripheral {
def this() = this(false)
var lastMessage = 0L
val computers = mutable.Map.empty[AnyRef, ComputerWrapper]

View File

@ -15,8 +15,8 @@ import net.minecraftforge.common.ForgeDirection
import scala.collection.mutable
import scala.language.postfixOps
class Screen(var tier: Int) extends traits.TextBuffer with SidedEnvironment with traits.Rotatable with traits.RedstoneAware with traits.Colored with Analyzable with Ordered[Screen] {
def this() = this(0)
class Screen(val isClient: Boolean, var tier: Int) extends traits.TextBuffer with SidedEnvironment with traits.Rotatable with traits.RedstoneAware with traits.Colored with Analyzable with Ordered[Screen] {
def this() = this(false, 0)
// Enable redstone functionality.
_isOutputEnabled = true

View File

@ -10,7 +10,9 @@ import net.minecraftforge.common.ForgeDirection
import scala.collection.convert.WrapAsScala._
class WirelessRouter extends Router with WirelessEndpoint {
class WirelessRouter(isClient: Boolean) extends Router(isClient) with WirelessEndpoint {
def this() = this(false)
var strength = Settings.get.maxWirelessRange
val componentNodes = Array.fill(6)(api.Network.newNode(this, Visibility.Network).withComponent("access_point").create())

View File

@ -21,9 +21,7 @@ import scala.collection.mutable
// See AbstractBusAware as to why we have to define the IBusDevice here.
@Optional.Interface(iface = "stargatetech2.api.bus.IBusDevice", modid = "StargateTech2")
trait Computer extends Environment with ComponentInventory with Rotatable with BundledRedstoneAware with AbstractBusAware with IBusDevice with Analyzable with Owner {
def isRemote: Boolean
private lazy val _computer = if (isRemote) null else Machine.create(this)
private lazy val _computer = if (isClient) null else Machine.create(this)
def computer = _computer

View File

@ -2,7 +2,6 @@ package li.cil.oc.common.tileentity.traits
import java.util.logging.Level
import cpw.mods.fml.common.FMLCommonHandler
import cpw.mods.fml.relauncher.{Side, SideOnly}
import li.cil.oc.OpenComputers
import li.cil.oc.client.Sound
@ -21,9 +20,9 @@ trait TileEntity extends net.minecraft.tileentity.TileEntity {
def block = getBlockType
def isClient = FMLCommonHandler.instance.getEffectiveSide.isClient
def isClient: Boolean
def isServer = FMLCommonHandler.instance.getEffectiveSide.isServer
def isServer = !isClient
// ----------------------------------------------------------------------- //

View File

@ -52,7 +52,7 @@ trait Component extends network.Component with Node {
throw new IllegalArgumentException("Trying to set computer visibility to '" + value + "' on a '" + name +
"' node with reachability '" + reachability + "'. It will be limited to the node's reachability.")
}
if (FMLCommonHandler.instance.getEffectiveSide == Side.SERVER) {
if (FMLCommonHandler.instance.getEffectiveSide.isServer) {
if (network != null) _visibility match {
case Visibility.Neighbors => value match {
case Visibility.Network => addTo(reachableNodes)

View File

@ -504,7 +504,7 @@ object Network extends api.detail.NetworkAPI {
def withConnector() = withConnector(0)
def create() = if (FMLCommonHandler.instance.getEffectiveSide == Side.SERVER) new MutableNode with NodeVarargPart {
def create() = if (FMLCommonHandler.instance.getEffectiveSide.isServer) new MutableNode with NodeVarargPart {
val host = _host
val reachability = _reachability
}
@ -516,7 +516,7 @@ object Network extends api.detail.NetworkAPI {
def withConnector() = withConnector(0)
def create() = if (FMLCommonHandler.instance.getEffectiveSide == Side.SERVER) new Component with NodeVarargPart {
def create() = if (FMLCommonHandler.instance.getEffectiveSide.isServer) new Component with NodeVarargPart {
val host = _host
val reachability = _reachability
val name = _name
@ -530,7 +530,7 @@ object Network extends api.detail.NetworkAPI {
def withComponent(name: String) = withComponent(name, _reachability)
def create() = if (FMLCommonHandler.instance.getEffectiveSide == Side.SERVER) new Connector with NodeVarargPart {
def create() = if (FMLCommonHandler.instance.getEffectiveSide.isServer) new Connector with NodeVarargPart {
val host = _host
val reachability = _reachability
var localBufferSize = _bufferSize
@ -539,7 +539,7 @@ object Network extends api.detail.NetworkAPI {
}
class ComponentConnectorBuilder(val _host: Environment, val _reachability: Visibility, val _name: String, val _visibility: Visibility, val _bufferSize: Double) extends api.detail.Builder.ComponentConnectorBuilder {
def create() = if (FMLCommonHandler.instance.getEffectiveSide == Side.SERVER) new ComponentConnector with NodeVarargPart {
def create() = if (FMLCommonHandler.instance.getEffectiveSide.isServer) new ComponentConnector with NodeVarargPart {
val host = _host
val reachability = _reachability
val name = _name