Allow inserting tablets into disk drives to access their first internal drive.

This commit is contained in:
Florian Nücke 2014-09-16 18:55:46 +02:00
parent cbb08e3b1c
commit 211034bbde
2 changed files with 33 additions and 0 deletions

View File

@ -83,6 +83,7 @@ class Proxy {
api.Driver.add(driver.item.Keyboard)
api.Driver.add(driver.item.RedstoneCard)
api.Driver.add(driver.item.Screen)
api.Driver.add(driver.item.Tablet)
api.Driver.add(driver.item.UpgradeAngel)
api.Driver.add(driver.item.UpgradeBattery)
api.Driver.add(driver.item.UpgradeChunkloader)

View File

@ -0,0 +1,32 @@
package li.cil.oc.server.driver.item
import li.cil.oc.api.driver.{Container, Slot}
import li.cil.oc.util.ItemUtils
import li.cil.oc.{Settings, api}
import net.minecraft.item.ItemStack
import net.minecraft.nbt.NBTTagCompound
object Tablet extends Item {
override def worksWith(stack: ItemStack) = isOneOf(stack, api.Items.get("tablet"))
override def createEnvironment(stack: ItemStack, container: Container) = {
val data = new ItemUtils.TabletData(stack)
data.items.collect {
case Some(fs) if FileSystem.worksWith(fs) => fs
}.headOption.map(FileSystem.createEnvironment(_, container)).orNull
}
override def slot(stack: ItemStack) = Slot.Disk
override def dataTag(stack: ItemStack) = {
val data = new ItemUtils.TabletData(stack)
val index = data.items.indexWhere {
case Some(fs) => FileSystem.worksWith(fs)
case _ => false
}
if (index >= 0 && stack.hasTagCompound && stack.getTagCompound.hasKey(Settings.namespace + "items")) {
stack.getTagCompound.getTagList(Settings.namespace + "items").tagAt(index).asInstanceOf[NBTTagCompound].getCompoundTag("tag")
}
else new NBTTagCompound()
}
}