From f1474819005b947fbc4ff13ba87d27a4d57a5b22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20N=C3=BCcke?= Date: Mon, 22 Dec 2014 16:57:53 +0100 Subject: [PATCH] Better Waila support for servers. --- build.properties | 2 +- .../cil/oc/common/tileentity/ServerRack.scala | 42 +++++++++++-------- .../integration/waila/BlockDataProvider.scala | 15 +++++++ 3 files changed, 41 insertions(+), 18 deletions(-) diff --git a/build.properties b/build.properties index dd3dec520..4f087c4ef 100644 --- a/build.properties +++ b/build.properties @@ -32,7 +32,7 @@ redlogic.version=59.0.3 rotc.version=1 tmech.version=75.0afb56c re.version=3.0.0.342 -waila.version=1.5.6a +waila.version=1.5.7 wrcbe.version=1.4.1.2 maven.url=file:///var/www/users/fnuecke/maven.cil.li \ No newline at end of file diff --git a/src/main/scala/li/cil/oc/common/tileentity/ServerRack.scala b/src/main/scala/li/cil/oc/common/tileentity/ServerRack.scala index 9edf884bc..fbf5f040a 100644 --- a/src/main/scala/li/cil/oc/common/tileentity/ServerRack.scala +++ b/src/main/scala/li/cil/oc/common/tileentity/ServerRack.scala @@ -200,27 +200,35 @@ class ServerRack extends traits.PowerAcceptor with traits.Hub with traits.PowerB // ----------------------------------------------------------------------- // override def onAnalyze(player: EntityPlayer, side: Int, hitX: Float, hitY: Float, hitZ: Float) = { - if (side == facing.ordinal) { + slotAt(ForgeDirection.getOrientation(side), hitX, hitY, hitZ) match { + case Some(slot) => servers(slot) match { + case Some(server) => + val computer = server.machine + computer.lastError match { + case value if value != null => + player.addChatMessage(Localization.Analyzer.LastError(value)) + case _ => + } + player.addChatMessage(Localization.Analyzer.Components(computer.componentCount, servers(slot).get.maxComponents)) + val list = computer.users + if (list.size > 0) { + player.addChatMessage(Localization.Analyzer.Users(list)) + } + Array(computer.node) + case _ => null + } + case _ => Array(sidedNode(ForgeDirection.getOrientation(side))) + } + } + + def slotAt(side: ForgeDirection, hitX: Float, hitY: Float, hitZ: Float) = { + if (side == facing) { val l = 2 / 16.0 val h = 14 / 16.0 val slot = (((1 - hitY) - l) / (h - l) * 4).toInt - if (slot >= 0 && slot <= 3 && servers(slot).isDefined) { - val computer = servers(slot).get.machine - computer.lastError match { - case value if value != null => - player.addChatMessage(Localization.Analyzer.LastError(value)) - case _ => - } - player.addChatMessage(Localization.Analyzer.Components(computer.componentCount, servers(slot).get.maxComponents)) - val list = computer.users - if (list.size > 0) { - player.addChatMessage(Localization.Analyzer.Users(list)) - } - Array(computer.node) - } - else null + Some(math.max(0, math.min(servers.length, slot))) } - else Array(sidedNode(ForgeDirection.getOrientation(side))) + else None } // ----------------------------------------------------------------------- // diff --git a/src/main/scala/li/cil/oc/integration/waila/BlockDataProvider.scala b/src/main/scala/li/cil/oc/integration/waila/BlockDataProvider.scala index 91cb2d29a..b75716c73 100644 --- a/src/main/scala/li/cil/oc/integration/waila/BlockDataProvider.scala +++ b/src/main/scala/li/cil/oc/integration/waila/BlockDataProvider.scala @@ -16,6 +16,7 @@ import mcp.mobius.waila.api.IWailaDataProvider import mcp.mobius.waila.api.IWailaRegistrar import net.minecraft.item.ItemStack import net.minecraft.nbt.NBTTagCompound +import net.minecraft.nbt.NBTTagString import net.minecraft.tileentity.TileEntity import net.minecraft.world.World import net.minecraftforge.common.util.Constants.NBT @@ -90,6 +91,10 @@ object BlockDataProvider extends IWailaDataProvider { case te: tileentity.Hologram => ignoreSidedness(te.node) case te: tileentity.Keyboard => ignoreSidedness(te.node) case te: tileentity.Screen => ignoreSidedness(te.node) + case te: tileentity.ServerRack => + tag.removeTag("nodes") + tag.setNewTagList("servers", stringIterableToNbt(te.servers.map(_.fold("")(_.node.address)))) + tag.setByteArray("sideIndexes", ForgeDirection.VALID_DIRECTIONS.map(te.sides.indexOf).map(_.toByte)) case _ => } @@ -117,6 +122,16 @@ object BlockDataProvider extends IWailaDataProvider { case _: tileentity.Charger => val chargeSpeed = tag.getDouble("chargeSpeed") tooltip.add(Localization.Analyzer.ChargerSpeed(chargeSpeed).getUnformattedText) + case te: tileentity.ServerRack => + val servers = tag.getTagList("servers", NBT.TAG_STRING).map((t: NBTTagString) => t.func_150285_a_()).toArray + val hitPos = accessor.getPosition.hitVec + val address = te.slotAt(accessor.getSide, (hitPos.xCoord - accessor.getPosition.blockX).toFloat, (hitPos.yCoord - accessor.getPosition.blockY).toFloat, (hitPos.zCoord - accessor.getPosition.blockZ).toFloat) match { + case Some(slot) => servers(slot) + case _ => tag.getByteArray("sideIndexes").map(index => if (index >= 0) servers(index) else "").apply(te.toLocal(accessor.getSide).ordinal) + } + if (address.nonEmpty) { + tooltip.add(Localization.Analyzer.Address(address).getUnformattedText) + } case _ => }