From c95196df0e2ee03ff041490c2c86ab06ab530d95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20N=C3=BCcke?= Date: Mon, 5 Jan 2015 22:14:04 +0100 Subject: [PATCH] Unified tooltips of items with builtin components a little. --- .../scala/li/cil/oc/common/item/Server.scala | 25 +++++++++++-------- .../scala/li/cil/oc/common/item/Tablet.scala | 9 +++++-- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/src/main/scala/li/cil/oc/common/item/Server.scala b/src/main/scala/li/cil/oc/common/item/Server.scala index 5c0c15c1d..4b469af56 100644 --- a/src/main/scala/li/cil/oc/common/item/Server.scala +++ b/src/main/scala/li/cil/oc/common/item/Server.scala @@ -4,6 +4,7 @@ import java.util import li.cil.oc.OpenComputers import li.cil.oc.Settings +import li.cil.oc.client.KeyBindings import li.cil.oc.common.GuiType import li.cil.oc.common.Tier import li.cil.oc.common.inventory.ServerInventory @@ -34,17 +35,19 @@ class Server(val parent: Delegator, val tier: Int) extends Delegate { override protected def tooltipExtended(stack: ItemStack, tooltip: util.List[String]) { super.tooltipExtended(stack, tooltip) - HelperInventory.container = stack - HelperInventory.reinitialize() - val items = mutable.Map.empty[String, Int] - for (item <- (0 until HelperInventory.getSizeInventory).map(HelperInventory.getStackInSlot) if item != null) { - val itemName = item.getDisplayName - items += itemName -> (if (items.contains(itemName)) items(itemName) + 1 else 1) - } - if (items.size > 0) { - tooltip.addAll(Tooltip.get("Server.Components")) - for (itemName <- items.keys.toArray.sorted) { - tooltip.add("- " + items(itemName) + "x " + itemName) + if (KeyBindings.showExtendedTooltips) { + HelperInventory.container = stack + HelperInventory.reinitialize() + val items = mutable.Map.empty[String, Int] + for (item <- (0 until HelperInventory.getSizeInventory).map(HelperInventory.getStackInSlot) if item != null) { + val itemName = item.getDisplayName + items += itemName -> (if (items.contains(itemName)) items(itemName) + 1 else 1) + } + if (items.size > 0) { + tooltip.addAll(Tooltip.get("Server.Components")) + for (itemName <- items.keys.toArray.sorted) { + tooltip.add("- " + items(itemName) + "x " + itemName) + } } } } diff --git a/src/main/scala/li/cil/oc/common/item/Tablet.scala b/src/main/scala/li/cil/oc/common/item/Tablet.scala index 1d377e222..414b3f9a5 100644 --- a/src/main/scala/li/cil/oc/common/item/Tablet.scala +++ b/src/main/scala/li/cil/oc/common/item/Tablet.scala @@ -34,6 +34,7 @@ import li.cil.oc.util.ExtendedNBT._ import li.cil.oc.util.ItemUtils import li.cil.oc.util.ItemUtils.TabletData import li.cil.oc.util.RotationHelper +import li.cil.oc.util.Tooltip import net.minecraft.entity.Entity import net.minecraft.entity.player.EntityPlayer import net.minecraft.item.ItemStack @@ -75,8 +76,12 @@ class Tablet(val parent: Delegator) extends Delegate { if (KeyBindings.showExtendedTooltips) { val info = new ItemUtils.TabletData(stack) // Ignore/hide the screen. - info.items.drop(1).collect { - case Some(component) => tooltip.add("- " + component.getDisplayName) + val components = info.items.drop(1) + if (components.length > 1) { + tooltip.addAll(Tooltip.get("Server.Components")) + components.collect { + case Some(component) => tooltip.add("- " + component.getDisplayName) + } } } }