mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-17 03:05:30 -04:00
Merge branch 'master-MC1.7.10' of github.com:MightyPirates/OpenComputers into 1.4
Conflicts: src/main/scala/li/cil/oc/common/Slot.scala src/main/scala/li/cil/oc/common/tileentity/Charger.scala src/main/scala/li/cil/oc/server/driver/item/Tablet.scala
This commit is contained in:
commit
7a29055c26
BIN
assets/items.psd
BIN
assets/items.psd
Binary file not shown.
@ -2,6 +2,7 @@ package li.cil.oc.api.detail;
|
||||
|
||||
import li.cil.oc.api.driver.Block;
|
||||
import li.cil.oc.api.driver.Converter;
|
||||
import li.cil.oc.api.driver.EnvironmentHost;
|
||||
import li.cil.oc.api.driver.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.World;
|
||||
@ -72,7 +73,8 @@ public interface DriverAPI {
|
||||
* will be used.
|
||||
*
|
||||
* @param stack the item stack to get a driver for.
|
||||
* @param host the object that will host the environment created by returned driver.
|
||||
* @return a driver for the item, or <tt>null</tt> if there is none.
|
||||
*/
|
||||
Item driverFor(ItemStack stack);
|
||||
Item driverFor(ItemStack stack, EnvironmentHost host);
|
||||
}
|
||||
|
Binary file not shown.
After Width: | Height: | Size: 270 B |
@ -11,8 +11,9 @@ object Slot {
|
||||
val Floppy = "floppy"
|
||||
val HDD = "hdd"
|
||||
val Memory = "memory"
|
||||
val Tablet = "tablet"
|
||||
val Tool = "tool"
|
||||
val Upgrade = "upgrade"
|
||||
|
||||
val All = Array(Card, ComponentBus, Container, CPU, Floppy, HDD, Memory, Tool, Upgrade)
|
||||
val All = Array(Card, ComponentBus, Container, CPU, Floppy, HDD, Memory, Tablet, Tool, Upgrade)
|
||||
}
|
||||
|
@ -1,8 +1,10 @@
|
||||
package li.cil.oc.common.tileentity
|
||||
|
||||
import cpw.mods.fml.relauncher.{Side, SideOnly}
|
||||
import li.cil.oc.api.network.{Node, Visibility}
|
||||
import li.cil.oc.api.Driver
|
||||
import li.cil.oc.api.network.{Component, Node, Visibility}
|
||||
import li.cil.oc.api.tileentity.Analyzable
|
||||
import li.cil.oc.common.Slot
|
||||
import li.cil.oc.common.item.Tablet
|
||||
import li.cil.oc.server.{PacketSender => ServerPacketSender}
|
||||
import li.cil.oc.util.ItemUtils
|
||||
@ -12,7 +14,7 @@ import net.minecraft.item.ItemStack
|
||||
import net.minecraft.nbt.NBTTagCompound
|
||||
import net.minecraftforge.common.util.ForgeDirection
|
||||
|
||||
class Charger extends traits.Environment with traits.PowerAcceptor with traits.RedstoneAware with traits.Rotatable with traits.Inventory with Analyzable {
|
||||
class Charger extends traits.Environment with traits.PowerAcceptor with traits.RedstoneAware with traits.Rotatable with traits.ComponentInventory with Analyzable {
|
||||
val node = api.Network.newNode(this, Visibility.None).
|
||||
withConnector(Settings.get.bufferConverter).
|
||||
create()
|
||||
@ -138,10 +140,20 @@ class Charger extends traits.Environment with traits.PowerAcceptor with traits.R
|
||||
|
||||
override def getSizeInventory = 1
|
||||
|
||||
override def getInventoryStackLimit = 1
|
||||
override def isItemValidForSlot(slot: Int, stack: ItemStack) = (slot, Option(Driver.driverFor(stack))) match {
|
||||
case (0, Some(driver)) => driver.slot(stack) == Slot.Tablet
|
||||
case _ => false
|
||||
}
|
||||
|
||||
override def isItemValidForSlot(slot: Int, stack: ItemStack) =
|
||||
slot == 0 && api.Items.get(stack) == api.Items.get("tablet")
|
||||
override protected def onItemAdded(slot: Int, stack: ItemStack) {
|
||||
super.onItemAdded(slot, stack)
|
||||
components(slot) match {
|
||||
case Some(environment) => environment.node match {
|
||||
case component: Component => component.setVisibility(Visibility.Network)
|
||||
}
|
||||
case _ =>
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------- //
|
||||
|
||||
|
@ -537,7 +537,7 @@ class Robot extends traits.Computer with traits.PowerInformation with tileentity
|
||||
|
||||
override def componentSlot(address: String) = components.indexWhere(_.exists(env => env.node != null && env.node.address == address))
|
||||
|
||||
override def hasRedstoneCard = (containerSlots ++ componentSlots).exists(slot => Option(getStackInSlot(slot)).fold(false)(driver.item.RedstoneCard.worksWith))
|
||||
override def hasRedstoneCard = (containerSlots ++ componentSlots).exists(slot => Option(getStackInSlot(slot)).fold(false)(driver.item.RedstoneCard.worksWith(_, host)))
|
||||
|
||||
private def computeInventorySize() = math.min(maxInventorySize, (containerSlots ++ componentSlots).foldLeft(0)((acc, slot) => acc + (Option(getStackInSlot(slot)) match {
|
||||
case Some(stack) => Option(Driver.driverFor(stack)) match {
|
||||
|
@ -93,7 +93,7 @@ class ServerRack extends traits.PowerAcceptor with traits.Hub with traits.PowerB
|
||||
|
||||
def hasAbstractBusCard = servers exists {
|
||||
case Some(server) => server.machine.isRunning && server.inventory.items.exists {
|
||||
case Some(stack) => driver.item.AbstractBusCard.worksWith(stack)
|
||||
case Some(stack) => driver.item.AbstractBusCard.worksWith(stack, server.inventory.host)
|
||||
case _ => false
|
||||
}
|
||||
case _ => false
|
||||
@ -101,7 +101,7 @@ class ServerRack extends traits.PowerAcceptor with traits.Hub with traits.PowerB
|
||||
|
||||
def hasRedstoneCard = servers exists {
|
||||
case Some(server) => server.machine.isRunning && server.inventory.items.exists {
|
||||
case Some(stack) => driver.item.RedstoneCard.worksWith(stack)
|
||||
case Some(stack) => driver.item.RedstoneCard.worksWith(stack, server.inventory.host)
|
||||
case _ => false
|
||||
}
|
||||
case _ => false
|
||||
|
@ -84,12 +84,12 @@ trait Computer extends Environment with ComponentInventory with Rotatable with B
|
||||
override def onMachineDisconnect(node: Node) = this.onDisconnect(node)
|
||||
|
||||
def hasAbstractBusCard = items.exists {
|
||||
case Some(item) => machine.isRunning && driver.item.AbstractBusCard.worksWith(item)
|
||||
case Some(item) => machine.isRunning && driver.item.AbstractBusCard.worksWith(item, host)
|
||||
case _ => false
|
||||
}
|
||||
|
||||
def hasRedstoneCard = items.exists {
|
||||
case Some(item) => machine.isRunning && driver.item.RedstoneCard.worksWith(item)
|
||||
case Some(item) => machine.isRunning && driver.item.RedstoneCard.worksWith(item, host)
|
||||
case _ => false
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,7 @@ package li.cil.oc.server.driver
|
||||
|
||||
import java.util
|
||||
|
||||
import li.cil.oc.api.driver.Converter
|
||||
import li.cil.oc.api.driver.{EnvironmentHost, Converter}
|
||||
import li.cil.oc.api.machine.Value
|
||||
import li.cil.oc.{OpenComputers, api}
|
||||
import net.minecraft.item.ItemStack
|
||||
@ -57,8 +57,8 @@ private[oc] object Registry extends api.detail.DriverAPI {
|
||||
case _ => null
|
||||
}
|
||||
|
||||
def driverFor(stack: ItemStack) =
|
||||
if (stack != null) items.find(_.worksWith(stack)).orNull
|
||||
def driverFor(stack: ItemStack, host: EnvironmentHost) =
|
||||
if (stack != null) items.find(_.worksWith(stack, host)).orNull
|
||||
else null
|
||||
|
||||
def convert(value: Array[AnyRef]) = if (value != null) value.map(arg => convertRecursively(arg, new util.IdentityHashMap())) else null
|
||||
|
@ -10,7 +10,7 @@ import net.minecraft.item.ItemStack
|
||||
import net.minecraft.nbt.NBTTagCompound
|
||||
|
||||
object ComputerCraftMedia extends Item {
|
||||
override def slot(stack: ItemStack, host: EnvironmentHost) = Slot.Floppy
|
||||
override def slot(stack: ItemStack) = Slot.Floppy
|
||||
|
||||
override def createEnvironment(stack: ItemStack, host: EnvironmentHost) =
|
||||
if (Mods.ComputerCraft.isAvailable && ComputerCraft.isDisk(stack) && host != null) {
|
||||
@ -25,7 +25,7 @@ object ComputerCraftMedia extends Item {
|
||||
}
|
||||
else null
|
||||
|
||||
override def worksWith(stack: ItemStack) = Mods.ComputerCraft.isAvailable && ComputerCraft.isDisk(stack)
|
||||
override def worksWith(stack: ItemStack, host: EnvironmentHost) = Mods.ComputerCraft.isAvailable && ComputerCraft.isDisk(stack)
|
||||
|
||||
private def addressFromTag(tag: NBTTagCompound) =
|
||||
if (tag.hasKey("node") && tag.getCompoundTag("node").hasKey("address")) {
|
||||
|
@ -6,7 +6,7 @@ import li.cil.oc.common.{Slot, component, tileentity}
|
||||
import net.minecraft.item.ItemStack
|
||||
|
||||
object Screen extends Item {
|
||||
override def worksWith(stack: ItemStack) =
|
||||
override def worksWith(stack: ItemStack, host: EnvironmentHost) =
|
||||
isOneOf(stack, api.Items.get("screen1")) && !isTablet(host)
|
||||
|
||||
override def createEnvironment(stack: ItemStack, host: EnvironmentHost) = host match {
|
||||
|
@ -14,7 +14,7 @@ object Tablet extends Item {
|
||||
override def createEnvironment(stack: ItemStack, host: EnvironmentHost) = {
|
||||
val data = new ItemUtils.TabletData(stack)
|
||||
data.items.collect {
|
||||
case Some(fs) if FileSystem.worksWith(fs) => fs
|
||||
case Some(fs) if FileSystem.worksWith(fs, host) => fs
|
||||
}.headOption.map(FileSystem.createEnvironment(_, host)).orNull
|
||||
}
|
||||
|
||||
@ -23,7 +23,7 @@ object Tablet extends Item {
|
||||
override def dataTag(stack: ItemStack) = {
|
||||
val data = new ItemUtils.TabletData(stack)
|
||||
val index = data.items.indexWhere {
|
||||
case Some(fs) => FileSystem.worksWith(fs)
|
||||
case Some(fs) => FileSystem.worksWith(fs, null) // This is only safe because we know fs doesn't touch the host parameter.
|
||||
case _ => false
|
||||
}
|
||||
if (index >= 0 && stack.hasTagCompound && stack.getTagCompound.hasKey(Settings.namespace + "items")) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user