diff --git a/src/main/scala/li/cil/oc/client/gui/DynamicGuiContainer.scala b/src/main/scala/li/cil/oc/client/gui/DynamicGuiContainer.scala index 7e7a55611..318560a02 100644 --- a/src/main/scala/li/cil/oc/client/gui/DynamicGuiContainer.scala +++ b/src/main/scala/li/cil/oc/client/gui/DynamicGuiContainer.scala @@ -81,8 +81,10 @@ abstract class DynamicGuiContainer(container: Container) extends CustomGuiContai mc.getTextureManager.bindTexture(component.tierIcon) Gui.drawModalRectWithCustomSizedTexture(slot.xDisplayPosition, slot.yDisplayPosition, 0, 0, 16, 16, 16, 16) } - mc.getTextureManager.bindTexture(slot.getBackgroundLocation) - Gui.drawModalRectWithCustomSizedTexture(slot.xDisplayPosition, slot.yDisplayPosition, 0, 0, 16, 16, 16, 16) + if (component.hasBackground) { + mc.getTextureManager.bindTexture(slot.getBackgroundLocation) + Gui.drawModalRectWithCustomSizedTexture(slot.xDisplayPosition, slot.yDisplayPosition, 0, 0, 16, 16, 16, 16) + } GL11.glEnable(GL11.GL_DEPTH_TEST) case _ => } @@ -146,12 +148,6 @@ abstract class DynamicGuiContainer(container: Container) extends CustomGuiContai t.draw() } - protected override def drawGradientRect(par1: Int, par2: Int, par3: Int, par4: Int, par5: Int, par6: Int) { - super.drawGradientRect(par1, par2, par3, par4, par5, par6) - RenderState.makeItBlend() - GL11.glDisable(GL11.GL_LIGHTING) - } - private def isInPlayerInventory(slot: Slot) = container match { case player: Player => slot.inventory == player.playerInventory case _ => false diff --git a/src/main/scala/li/cil/oc/common/container/ComponentSlot.scala b/src/main/scala/li/cil/oc/common/container/ComponentSlot.scala index c5111158e..f7847bf3f 100644 --- a/src/main/scala/li/cil/oc/common/container/ComponentSlot.scala +++ b/src/main/scala/li/cil/oc/common/container/ComponentSlot.scala @@ -2,6 +2,7 @@ package li.cil.oc.common.container import li.cil.oc.common import net.minecraft.entity.player.EntityPlayer +import net.minecraft.inventory.IInventory import net.minecraft.inventory.Slot import net.minecraft.item.ItemStack import net.minecraft.util.ResourceLocation @@ -10,7 +11,7 @@ import net.minecraftforge.fml.relauncher.SideOnly import scala.collection.convert.WrapAsScala._ -trait ComponentSlot extends Slot { +abstract class ComponentSlot(inventory: IInventory, index: Int, x: Int, y: Int) extends Slot(inventory, index, x, y) { def container: Player def slot: String @@ -23,6 +24,8 @@ trait ComponentSlot extends Slot { // ----------------------------------------------------------------------- // + def hasBackground = backgroundLocation != null + @SideOnly(Side.CLIENT) override def canBeHovered = slot != common.Slot.None && tier != common.Tier.None && super.canBeHovered diff --git a/src/main/scala/li/cil/oc/common/container/DynamicComponentSlot.scala b/src/main/scala/li/cil/oc/common/container/DynamicComponentSlot.scala index 6148d03a2..c9bd38d65 100644 --- a/src/main/scala/li/cil/oc/common/container/DynamicComponentSlot.scala +++ b/src/main/scala/li/cil/oc/common/container/DynamicComponentSlot.scala @@ -6,9 +6,8 @@ import li.cil.oc.common.InventorySlots.InventorySlot import li.cil.oc.util.SideTracker import net.minecraft.entity.player.EntityPlayer import net.minecraft.inventory.IInventory -import net.minecraft.inventory.Slot -class DynamicComponentSlot(val container: Player, inventory: IInventory, index: Int, x: Int, y: Int, val info: DynamicComponentSlot => InventorySlot, val containerTierGetter: () => Int) extends Slot(inventory, index, x, y) with ComponentSlot { +class DynamicComponentSlot(val container: Player, inventory: IInventory, index: Int, x: Int, y: Int, val info: DynamicComponentSlot => InventorySlot, val containerTierGetter: () => Int) extends ComponentSlot(inventory, index, x, y) { override def tier = { val mainTier = containerTierGetter() if (mainTier >= 0) info(this).tier @@ -23,7 +22,9 @@ class DynamicComponentSlot(val container: Player, inventory: IInventory, index: else common.Slot.None } - override def getBackgroundLocation = Textures.Icons.get(slot) + override def hasBackground = Textures.Icons.get(slot) != null + + override def getBackgroundLocation = Option(Textures.Icons.get(slot)).getOrElse(super.getBackgroundLocation) override def getSlotStackLimit = slot match { diff --git a/src/main/scala/li/cil/oc/common/container/StaticComponentSlot.scala b/src/main/scala/li/cil/oc/common/container/StaticComponentSlot.scala index fd644601c..6fd943ae4 100644 --- a/src/main/scala/li/cil/oc/common/container/StaticComponentSlot.scala +++ b/src/main/scala/li/cil/oc/common/container/StaticComponentSlot.scala @@ -3,9 +3,8 @@ package li.cil.oc.common.container import li.cil.oc.client.Textures import li.cil.oc.common import net.minecraft.inventory.IInventory -import net.minecraft.inventory.Slot -class StaticComponentSlot(val container: Player, inventory: IInventory, index: Int, x: Int, y: Int, val slot: String, val tier: Int) extends Slot(inventory, index, x, y) with ComponentSlot { +class StaticComponentSlot(val container: Player, inventory: IInventory, index: Int, x: Int, y: Int, val slot: String, val tier: Int) extends ComponentSlot(inventory, index, x, y) { setBackgroundLocation(Textures.Icons.get(slot)) val tierIcon = Textures.Icons.get(tier) diff --git a/src/main/scala/li/cil/oc/common/item/Delegate.scala b/src/main/scala/li/cil/oc/common/item/Delegate.scala index a6faf290d..63e3ab24a 100644 --- a/src/main/scala/li/cil/oc/common/item/Delegate.scala +++ b/src/main/scala/li/cil/oc/common/item/Delegate.scala @@ -101,11 +101,9 @@ trait Delegate { } } - def isDamageable = false + def showDurabilityBar(stack: ItemStack) = false - def damage(stack: ItemStack) = 0 - - def maxDamage(stack: ItemStack) = 0 + def durability(stack: ItemStack) = 0.0 // ----------------------------------------------------------------------- // diff --git a/src/main/scala/li/cil/oc/common/item/Delegator.scala b/src/main/scala/li/cil/oc/common/item/Delegator.scala index 033af4026..418a532c6 100644 --- a/src/main/scala/li/cil/oc/common/item/Delegator.scala +++ b/src/main/scala/li/cil/oc/common/item/Delegator.scala @@ -147,20 +147,14 @@ class Delegator extends Item { override def getDurabilityForDisplay(stack: ItemStack) = Delegator.subItem(stack) match { - case Some(subItem) if subItem.isDamageable => subItem.damage(stack) + case Some(subItem) => subItem.durability(stack) case _ => super.getDurabilityForDisplay(stack) } - override def getMaxDamage(stack: ItemStack) = + override def showDurabilityBar(stack: ItemStack) = Delegator.subItem(stack) match { - case Some(subItem) if subItem.isDamageable => subItem.maxDamage(stack) - case _ => super.getMaxDamage(stack) - } - - override def isDamaged(stack: ItemStack) = - Delegator.subItem(stack) match { - case Some(subItem) if subItem.isDamageable => subItem.damage(stack) > 0 - case _ => false + case Some(subItem) => subItem.showDurabilityBar(stack) + case _ => super.showDurabilityBar(stack) } override def onUpdate(stack: ItemStack, world: World, player: Entity, slot: Int, selected: Boolean) = 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 4d70e5ebc..5c1fb47a3 100644 --- a/src/main/scala/li/cil/oc/common/item/Tablet.scala +++ b/src/main/scala/li/cil/oc/common/item/Tablet.scala @@ -49,26 +49,15 @@ class Tablet(val parent: Delegator) extends Delegate { // ----------------------------------------------------------------------- // - override def isDamageable = true + override def showDurabilityBar(stack: ItemStack) = true - override def damage(stack: ItemStack) = { - val nbt = stack.getTagCompound - if (nbt != null) { + override def durability(stack: ItemStack) = { + if (stack.hasTagCompound) { val data = new ItemUtils.TabletData() - data.load(nbt) - (data.maxEnergy - data.energy).toInt + data.load(stack.getTagCompound) + data.energy / data.maxEnergy } - else 100 - } - - override def maxDamage(stack: ItemStack) = { - val nbt = stack.getTagCompound - if (nbt != null) { - val data = new ItemUtils.TabletData() - data.load(nbt) - data.maxEnergy.toInt max 1 - } - else 100 + else 1.0 } // ----------------------------------------------------------------------- // diff --git a/src/main/scala/li/cil/oc/common/item/UpgradeBattery.scala b/src/main/scala/li/cil/oc/common/item/UpgradeBattery.scala index 5c3ced242..b93a97344 100644 --- a/src/main/scala/li/cil/oc/common/item/UpgradeBattery.scala +++ b/src/main/scala/li/cil/oc/common/item/UpgradeBattery.scala @@ -10,16 +10,13 @@ class UpgradeBattery(val parent: Delegator, val tier: Int) extends Delegate with override protected def tooltipData = Seq(Settings.get.bufferCapacitorUpgrades(tier).toInt) - override def isDamageable = true + override def showDurabilityBar(stack: ItemStack) = true - override def damage(stack: ItemStack) = { - val nbt = stack.getTagCompound - if (nbt != null) { - val stored = nbt.getCompoundTag(Settings.namespace + "data").getCompoundTag("node").getDouble("buffer") - ((1 - stored / Settings.get.bufferCapacitorUpgrades(tier)) * 100).toInt + override def durability(stack: ItemStack) = { + if (stack.hasTagCompound) { + val stored = stack.getTagCompound.getCompoundTag(Settings.namespace + "data").getCompoundTag("node").getDouble("buffer") + 1 - stored / Settings.get.bufferCapacitorUpgrades(tier) } - else 100 + else 1.0 } - - override def maxDamage(stack: ItemStack) = 100 }