Fixed icons for subitems with damage bar.

GUI rendering fixes.
This commit is contained in:
Florian Nücke 2015-01-08 14:20:42 +01:00
parent 17790ea156
commit 64f853d95e
8 changed files with 31 additions and 54 deletions

View File

@ -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)
}
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

View File

@ -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

View File

@ -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 {

View File

@ -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)

View File

@ -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
// ----------------------------------------------------------------------- //

View File

@ -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) =

View File

@ -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
}
// ----------------------------------------------------------------------- //

View File

@ -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
}