blob: 778f0a1c7349399a098e1069ab69527eb301bd4f [file] [log] [blame] [raw]
package li.cil.oc.common.container
import li.cil.oc.api
import net.minecraft.inventory.{Slot, IInventory}
import net.minecraft.item.ItemStack
import li.cil.oc.client.gui.Icons
import li.cil.oc.common.InventorySlots.InventorySlot
class DynamicComponentSlot(inventory: IInventory, index: Int, x: Int, y: Int, val info: Array[Array[InventorySlot]], val tierGetter: () => Int) extends Slot(inventory, index, x, y) with ComponentSlot {
override def tier = {
val mainTier = tierGetter()
if (mainTier >= 0) info(mainTier)(slotNumber).tier
else mainTier
}
def tierIcon = Icons.get(tier)
def slot = {
val mainTier = tierGetter()
if (mainTier >= 0) info(tierGetter())(slotNumber).slot
else api.driver.Slot.None
}
override def getBackgroundIconIndex = Icons.get(slot)
override def getSlotStackLimit =
slot match {
case api.driver.Slot.Tool | api.driver.Slot.None => super.getSlotStackLimit
case _ => 1
}
override def isItemValid(stack: ItemStack) = {
inventory.isItemValidForSlot(index, stack)
}
}