mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-12 16:57:32 -04:00
Cleaned up a bit.
This commit is contained in:
parent
f6f97e0d3f
commit
0224fa262d
@ -1,7 +1,7 @@
|
||||
package li.cil.oc.client.gui
|
||||
|
||||
import li.cil.oc.client.Textures
|
||||
import li.cil.oc.common.Tier
|
||||
import li.cil.oc.common
|
||||
import li.cil.oc.common.container.{ComponentSlot, Player}
|
||||
import li.cil.oc.util.RenderState
|
||||
import li.cil.oc.util.mods.NEI
|
||||
@ -40,7 +40,7 @@ abstract class DynamicGuiContainer(container: Container) extends CustomGuiContai
|
||||
|
||||
override def drawSlotInventory(slot: Slot) {
|
||||
slot match {
|
||||
case component: ComponentSlot if component.tier == Tier.None => // Ignore.
|
||||
case component: ComponentSlot if component.tier == common.Tier.None || component.slot == common.Slot.None => // Ignore.
|
||||
case _ =>
|
||||
if (!isInPlayerInventory(slot)) {
|
||||
GL11.glDisable(GL11.GL_DEPTH_TEST)
|
||||
|
@ -1,5 +1,8 @@
|
||||
package li.cil.oc.common
|
||||
|
||||
import li.cil.oc.api
|
||||
import net.minecraft.item.ItemStack
|
||||
|
||||
object Slot {
|
||||
val None = "none"
|
||||
|
||||
@ -15,7 +18,7 @@ object Slot {
|
||||
|
||||
val All = Array(Card, ComponentBus, Container, CPU, Floppy, HDD, Memory, Tool, Upgrade)
|
||||
|
||||
def fromApi(slotType: li.cil.oc.api.driver.Slot) = slotType match {
|
||||
def apply(driver: api.driver.Item, stack: ItemStack, f: Option[ItemStack => api.driver.Slot] = scala.None) = f.getOrElse(driver.slot _)(stack) match {
|
||||
case li.cil.oc.api.driver.Slot.Card => Card
|
||||
case li.cil.oc.api.driver.Slot.Disk => Floppy
|
||||
case li.cil.oc.api.driver.Slot.HardDiskDrive => HDD
|
||||
@ -24,6 +27,9 @@ object Slot {
|
||||
case li.cil.oc.api.driver.Slot.Tool => Tool
|
||||
case li.cil.oc.api.driver.Slot.Upgrade => Upgrade
|
||||
case li.cil.oc.api.driver.Slot.UpgradeContainer => Container
|
||||
case _ => None
|
||||
case _ =>
|
||||
val descriptor = api.Items.get(stack)
|
||||
if (descriptor == api.Items.get("componentBus1") || descriptor == api.Items.get("componentBus2") || descriptor == api.Items.get("componentBus3")) ComponentBus
|
||||
else None
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
package li.cil.oc.common.container
|
||||
|
||||
import cpw.mods.fml.relauncher.{Side, SideOnly}
|
||||
import li.cil.oc.common.Tier
|
||||
import li.cil.oc.common
|
||||
import net.minecraft.entity.player.EntityPlayer
|
||||
import net.minecraft.inventory.Slot
|
||||
import net.minecraft.item.ItemStack
|
||||
@ -21,7 +21,7 @@ trait ComponentSlot extends Slot {
|
||||
// ----------------------------------------------------------------------- //
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
override def func_111238_b() = tier != Tier.None && super.func_111238_b()
|
||||
override def func_111238_b() = slot != common.Slot.None && tier != common.Tier.None && super.func_111238_b()
|
||||
|
||||
override def isItemValid(stack: ItemStack) = inventory.isItemValidForSlot(getSlotIndex, stack)
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
package li.cil.oc.common.inventory
|
||||
|
||||
import li.cil.oc.api.{Driver, Items}
|
||||
import li.cil.oc.api.Driver
|
||||
import li.cil.oc.common.{InventorySlots, Slot}
|
||||
import net.minecraft.entity.player.EntityPlayer
|
||||
import net.minecraft.item.ItemStack
|
||||
@ -19,14 +19,6 @@ trait ServerInventory extends ItemStackInventory {
|
||||
override def isItemValidForSlot(slot: Int, stack: ItemStack) =
|
||||
Option(Driver.driverFor(stack)).fold(false)(driver => {
|
||||
val provided = InventorySlots.server(tier)(slot)
|
||||
// TODO remove special code in 1.4 when slot type API changes.
|
||||
val requiredSlot = Slot.fromApi(driver.slot(stack))
|
||||
val isComponentBus = provided.slot == Slot.ComponentBus && {
|
||||
val descriptor = Items.get(stack)
|
||||
descriptor == Items.get("componentBus1") ||
|
||||
descriptor == Items.get("componentBus2") ||
|
||||
descriptor == Items.get("componentBus3")
|
||||
}
|
||||
(requiredSlot == provided.slot || isComponentBus) && driver.tier(stack) <= provided.tier
|
||||
Slot(driver, stack) == provided.slot && driver.tier(stack) <= provided.tier
|
||||
})
|
||||
}
|
||||
|
@ -60,17 +60,15 @@ object AssemblerTemplates {
|
||||
def validate(inventory: IInventory, slot: Int, stack: ItemStack) = validator match {
|
||||
case Some(method) => tryInvokeStatic(method, inventory, slot.underlying(), stack)(false)
|
||||
case _ => Option(api.Driver.driverFor(stack)) match {
|
||||
case Some(driver) => validateInternal(stack, driver) && Slot.fromApi(driver.slot(stack)) == kind
|
||||
case Some(driver) => Slot(driver, stack) == kind && driver.tier(stack) <= tier
|
||||
case _ => false
|
||||
}
|
||||
}
|
||||
|
||||
protected def validateInternal(stack: ItemStack, driver: api.driver.Item) = driver.tier(stack) <= tier
|
||||
}
|
||||
|
||||
private def parseSlot(kindOverride: Option[String] = None)(nbt: NBTTagCompound) = {
|
||||
val kind = kindOverride.getOrElse(if (nbt.hasKey("type")) nbt.getString("type") else Slot.None)
|
||||
val tier = if (nbt.hasKey("tier")) nbt.getInteger("tier") else Tier.None
|
||||
val tier = if (nbt.hasKey("tier")) nbt.getInteger("tier") else Tier.Any
|
||||
val validator = if (nbt.hasKey("validator")) Option(getStaticMethod(nbt.getString("validator"), classOf[ItemStack], classOf[Int], classOf[ItemStack])) else None
|
||||
new Slot(kind, tier, validator)
|
||||
}
|
||||
|
@ -251,7 +251,7 @@ object RobotTemplate {
|
||||
})
|
||||
|
||||
private def hasFileSystem(inventory: IInventory) = exists(inventory, stack => Option(api.Driver.driverFor(stack)) match {
|
||||
case Some(driver) => Slot.fromApi(driver.slot(stack)) == Slot.Floppy || Slot.fromApi(driver.slot(stack)) == Slot.HDD
|
||||
case Some(driver) => Slot(driver, stack) == Slot.Floppy || Slot(driver, stack) == Slot.HDD
|
||||
case _ => false
|
||||
})
|
||||
|
||||
|
@ -60,7 +60,7 @@ class Case(var tier: Int) extends traits.PowerAcceptor with traits.Computer with
|
||||
|
||||
def hasCPU = items.exists {
|
||||
case Some(stack) => Option(Driver.driverFor(stack)) match {
|
||||
case Some(driver) => Slot.fromApi(driver.slot(stack)) == Slot.CPU
|
||||
case Some(driver) => Slot(driver, stack) == Slot.CPU
|
||||
case _ => false
|
||||
}
|
||||
case _ => false
|
||||
@ -125,6 +125,6 @@ class Case(var tier: Int) extends traits.PowerAcceptor with traits.Computer with
|
||||
override def isItemValidForSlot(slot: Int, stack: ItemStack) =
|
||||
Option(Driver.driverFor(stack)).fold(false)(driver => {
|
||||
val provided = InventorySlots.computer(tier)(slot)
|
||||
Slot.fromApi(driver.slot(stack)) == provided.slot && driver.tier(stack) <= provided.tier
|
||||
Slot(driver, stack) == provided.slot && driver.tier(stack) <= provided.tier
|
||||
})
|
||||
}
|
@ -29,7 +29,7 @@ class DiskDrive extends traits.Environment with traits.ComponentInventory with t
|
||||
override def getSizeInventory = 1
|
||||
|
||||
override def isItemValidForSlot(slot: Int, stack: ItemStack) = (slot, Option(Driver.driverFor(stack))) match {
|
||||
case (0, Some(driver)) => Slot.fromApi(driver.slot(stack)) == Slot.Floppy
|
||||
case (0, Some(driver)) => Slot(driver, stack) == Slot.Floppy
|
||||
case _ => false
|
||||
}
|
||||
|
||||
|
@ -492,7 +492,7 @@ class Robot extends traits.Computer with traits.PowerInformation with api.machin
|
||||
def containerSlotType(slot: Int) = if (containerSlots contains slot) {
|
||||
val stack = info.containers(slot - 1)
|
||||
Option(Driver.driverFor(stack)) match {
|
||||
case Some(driver: api.driver.UpgradeContainer) => Slot.fromApi(driver.providedSlot(stack))
|
||||
case Some(driver: api.driver.UpgradeContainer) => Slot(driver, stack, Some(driver.providedSlot))
|
||||
case _ => Slot.None
|
||||
}
|
||||
}
|
||||
@ -515,7 +515,7 @@ class Robot extends traits.Computer with traits.PowerInformation with api.machin
|
||||
|
||||
def isFloppySlot(slot: Int) = isComponentSlot(slot) && (Option(getStackInSlot(slot)) match {
|
||||
case Some(stack) => Option(Driver.driverFor(stack)) match {
|
||||
case Some(driver) => Slot.fromApi(driver.slot(stack)) == Slot.Floppy
|
||||
case Some(driver) => Slot(driver, stack) == Slot.Floppy
|
||||
case _ => false
|
||||
}
|
||||
case _ => false
|
||||
@ -622,7 +622,7 @@ class Robot extends traits.Computer with traits.PowerInformation with api.machin
|
||||
// logic making the differentiation of assembler and containers generic.
|
||||
driver != server.driver.item.Screen &&
|
||||
driver != server.driver.item.Keyboard &&
|
||||
Slot.fromApi(driver.slot(stack)) == containerSlotType(i) &&
|
||||
Slot(driver, stack) == containerSlotType(i) &&
|
||||
driver.tier(stack) <= containerSlotTier(i)
|
||||
case (i, _) if isInventorySlot(i) => true // Normal inventory.
|
||||
case _ => false // Invalid slot.
|
||||
|
@ -157,14 +157,14 @@ class Switch extends traits.Hub with traits.NotAnalyzable with IPeripheral with
|
||||
|
||||
private def updateLimits(slot: Int, stack: ItemStack) {
|
||||
Driver.driverFor(stack) match {
|
||||
case driver if Slot.fromApi(driver.slot(stack)) == Slot.CPU =>
|
||||
case driver if Slot(driver, stack) == Slot.CPU =>
|
||||
relayDelay = math.max(1, relayBaseDelay - ((driver.tier(stack) + 1) * relayDelayPerUpgrade))
|
||||
case driver if Slot.fromApi(driver.slot(stack)) == Slot.Memory =>
|
||||
case driver if Slot(driver, stack) == Slot.Memory =>
|
||||
relayAmount = math.max(1, relayBaseAmount + (Items.multi.subItem(stack) match {
|
||||
case Some(ram: item.Memory) => (ram.tier + 1) * relayAmountPerUpgrade
|
||||
case _ => (driver.tier(stack) + 1) * (relayAmountPerUpgrade * 2)
|
||||
}))
|
||||
case driver if Slot.fromApi(driver.slot(stack)) == Slot.HDD =>
|
||||
case driver if Slot(driver, stack) == Slot.HDD =>
|
||||
maxQueueSize = math.max(1, queueBaseSize + (driver.tier(stack) + 1) * queueSizePerUpgrade)
|
||||
}
|
||||
}
|
||||
@ -172,9 +172,9 @@ class Switch extends traits.Hub with traits.NotAnalyzable with IPeripheral with
|
||||
override protected def onItemRemoved(slot: Int, stack: ItemStack) {
|
||||
super.onItemRemoved(slot, stack)
|
||||
Driver.driverFor(stack) match {
|
||||
case driver if Slot.fromApi(driver.slot(stack)) == Slot.CPU => relayDelay = relayBaseDelay
|
||||
case driver if Slot.fromApi(driver.slot(stack)) == Slot.Memory => relayAmount = relayBaseAmount
|
||||
case driver if Slot.fromApi(driver.slot(stack)) == Slot.HDD => maxQueueSize = queueBaseSize
|
||||
case driver if Slot(driver, stack) == Slot.CPU => relayDelay = relayBaseDelay
|
||||
case driver if Slot(driver, stack) == Slot.Memory => relayAmount = relayBaseAmount
|
||||
case driver if Slot(driver, stack) == Slot.HDD => maxQueueSize = queueBaseSize
|
||||
}
|
||||
}
|
||||
|
||||
@ -183,7 +183,7 @@ class Switch extends traits.Hub with traits.NotAnalyzable with IPeripheral with
|
||||
override def isItemValidForSlot(slot: Int, stack: ItemStack) =
|
||||
Option(Driver.driverFor(stack)).fold(false)(driver => {
|
||||
val provided = InventorySlots.switch(slot)
|
||||
Slot.fromApi(driver.slot(stack)) == provided.slot && driver.tier(stack) <= provided.tier
|
||||
Slot(driver, stack) == provided.slot && driver.tier(stack) <= provided.tier
|
||||
})
|
||||
|
||||
// ----------------------------------------------------------------------- //
|
||||
|
@ -58,7 +58,7 @@ class Server(val rack: tileentity.ServerRack, val number: Int) extends Owner {
|
||||
|
||||
def hasCPU = inventory.items.exists {
|
||||
case Some(stack) => Option(Driver.driverFor(stack)) match {
|
||||
case Some(driver) => Slot.fromApi(driver.slot(stack)) == Slot.CPU
|
||||
case Some(driver) => Slot(driver, stack) == Slot.CPU
|
||||
case _ => false
|
||||
}
|
||||
case _ => false
|
||||
|
Loading…
x
Reference in New Issue
Block a user