diff --git a/src/main/scala/li/cil/oc/common/block/Screen.scala b/src/main/scala/li/cil/oc/common/block/Screen.scala index a7c1704be..1d7eb9a18 100644 --- a/src/main/scala/li/cil/oc/common/block/Screen.scala +++ b/src/main/scala/li/cil/oc/common/block/Screen.scala @@ -9,7 +9,7 @@ import li.cil.oc.util.mods.{BuildCraft, Mods} import li.cil.oc.util.{Color, PackedColor, Tooltip} import li.cil.oc.{Localization, OpenComputers, Settings} import mcp.mobius.waila.api.{IWailaConfigHandler, IWailaDataAccessor} -import net.minecraft.entity.Entity +import net.minecraft.entity.{EntityLivingBase, Entity} import net.minecraft.entity.player.EntityPlayer import net.minecraft.entity.projectile.EntityArrow import net.minecraft.item.{EnumRarity, ItemStack} @@ -298,6 +298,14 @@ class Screen(val parent: SimpleDelegator, val tier: Int) extends RedstoneAware w // ----------------------------------------------------------------------- // + override def addedByEntity(world: World, x: Int, y: Int, z: Int, player: EntityLivingBase, stack: ItemStack) { + super.addedByEntity(world, x, y, z, player, stack) + world.getBlockTileEntity(x, y, z) match { + case screen: tileentity.Screen => screen.delayUntilCheckForMultiBlock = 0 + case _ => + } + } + override def rightClick(world: World, x: Int, y: Int, z: Int, player: EntityPlayer, side: ForgeDirection, hitX: Float, hitY: Float, hitZ: Float) = rightClick(world, x, y, z, player, side, hitX, hitY, hitZ, force = false) diff --git a/src/main/scala/li/cil/oc/common/tileentity/Screen.scala b/src/main/scala/li/cil/oc/common/tileentity/Screen.scala index 76edb812c..3bdbc12a8 100644 --- a/src/main/scala/li/cil/oc/common/tileentity/Screen.scala +++ b/src/main/scala/li/cil/oc/common/tileentity/Screen.scala @@ -31,6 +31,13 @@ class Screen(var tier: Int) extends traits.TextBuffer with SidedEnvironment with */ var shouldCheckForMultiBlock = true + /** + * On the client we delay connecting screens a little, to avoid glitches + * when not all tile entity data for a chunk has been received within a + * single tick (meaning some screens are still "missing"). + */ + var delayUntilCheckForMultiBlock = 40 + var width, height = 1 var origin = this @@ -149,7 +156,7 @@ class Screen(var tier: Int) extends traits.TextBuffer with SidedEnvironment with override def updateEntity() { super.updateEntity() - if (shouldCheckForMultiBlock && (isClient || isConnected)) { + if (shouldCheckForMultiBlock && ((isClient && isClientReadyForMultiBlockCheck) || (isServer && isConnected))) { // Make sure we merge in a deterministic order, to avoid getting // different results on server and client due to the update order // differing between the two. This also saves us from having to save @@ -232,6 +239,11 @@ class Screen(var tier: Int) extends traits.TextBuffer with SidedEnvironment with } } + private def isClientReadyForMultiBlockCheck = if (delayUntilCheckForMultiBlock > 0) { + delayUntilCheckForMultiBlock -= 1 + false + } else true + override def dispose() { super.dispose() screens.clone().foreach(_.checkMultiBlock())