mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-13 01:10:19 -04:00
add address key check in item Delegator to limit max stack size to 1
closes #3226
This commit is contained in:
parent
ff3c2f51a9
commit
278e7bdbef
@ -2,7 +2,6 @@ package li.cil.oc.common.item
|
||||
|
||||
import java.util
|
||||
import java.util.Random
|
||||
|
||||
import cpw.mods.fml.relauncher.Side
|
||||
import cpw.mods.fml.relauncher.SideOnly
|
||||
import li.cil.oc.CreativeTab
|
||||
@ -13,6 +12,7 @@ import li.cil.oc.api.driver.item.Chargeable
|
||||
import li.cil.oc.api.event.RobotRenderEvent.MountPoint
|
||||
import li.cil.oc.api.internal.Robot
|
||||
import li.cil.oc.client.renderer.item.UpgradeRenderer
|
||||
import li.cil.oc.integration.opencomputers.{Item => OpenComputersItem}
|
||||
import li.cil.oc.util.BlockPosition
|
||||
import net.minecraft.client.renderer.texture.IIconRegister
|
||||
import net.minecraft.creativetab.CreativeTabs
|
||||
@ -48,9 +48,12 @@ class Delegator extends Item with driver.item.UpgradeRenderer with Chargeable {
|
||||
// SubItem
|
||||
// ----------------------------------------------------------------------- //
|
||||
|
||||
override def getItemStackLimit(stack: ItemStack) =
|
||||
override def getItemStackLimit(stack: ItemStack): Int =
|
||||
Delegator.subItem(stack) match {
|
||||
case Some(subItem) => subItem.maxStackSize
|
||||
case Some(subItem) => OpenComputersItem.address(stack) match {
|
||||
case Some(address) => 1
|
||||
case _ => subItem.maxStackSize
|
||||
}
|
||||
case _ => maxStackSize
|
||||
}
|
||||
|
||||
|
@ -4,11 +4,11 @@ import li.cil.oc.Settings
|
||||
import net.minecraft.item.ItemStack
|
||||
|
||||
class HardDiskDrive(val parent: Delegator, val tier: Int) extends traits.Delegate with traits.ItemTier with traits.FileSystemLike {
|
||||
override val unlocalizedName = super.unlocalizedName + tier
|
||||
val kiloBytes = Settings.get.hddSizes(tier)
|
||||
val platterCount = Settings.get.hddPlatterCounts(tier)
|
||||
override val unlocalizedName: String = super.unlocalizedName + tier
|
||||
val kiloBytes: Int = Settings.get.hddSizes(tier)
|
||||
val platterCount: Int = Settings.get.hddPlatterCounts(tier)
|
||||
|
||||
override def displayName(stack: ItemStack) = {
|
||||
override def displayName(stack: ItemStack): Option[String] = {
|
||||
val localizedName = parent.internalGetItemStackDisplayName(stack)
|
||||
Some(if (kiloBytes >= 1024) {
|
||||
localizedName + s" (${kiloBytes / 1024}MB)"
|
||||
|
@ -41,7 +41,7 @@ object DriveData {
|
||||
val data = new DriveData(stack)
|
||||
if (!data.isLocked) {
|
||||
data.lockInfo = key match {
|
||||
case name: String if name != null && !name.isEmpty => name
|
||||
case name: String if name != null && name.nonEmpty => name
|
||||
case _ => "notch" // meaning: "unknown"
|
||||
}
|
||||
data.save(stack)
|
||||
|
@ -1,5 +1,6 @@
|
||||
package li.cil.oc.integration.opencomputers
|
||||
|
||||
import com.google.common.base.Strings
|
||||
import li.cil.oc.Settings
|
||||
import li.cil.oc.api
|
||||
import li.cil.oc.api.driver
|
||||
@ -10,6 +11,8 @@ import li.cil.oc.server.driver.Registry
|
||||
import net.minecraft.item.ItemStack
|
||||
import net.minecraft.nbt.NBTTagCompound
|
||||
|
||||
import scala.annotation.tailrec
|
||||
|
||||
trait Item extends driver.Item {
|
||||
def worksWith(stack: ItemStack, host: Class[_ <: EnvironmentHost]): Boolean =
|
||||
worksWith(stack) && !Registry.blacklist.exists {
|
||||
@ -52,4 +55,25 @@ object Item {
|
||||
}
|
||||
nbt.getCompoundTag(Settings.namespace + "data")
|
||||
}
|
||||
|
||||
@tailrec
|
||||
private def getTag(tagCompound: NBTTagCompound, keys: Array[String]): Option[NBTTagCompound] = {
|
||||
if (keys.length == 0) Option(tagCompound)
|
||||
else if (!tagCompound.hasKey(keys(0))) None
|
||||
else getTag(tagCompound.getCompoundTag(keys(0)), keys.drop(1))
|
||||
}
|
||||
|
||||
private def getTag(stack: ItemStack, keys: Array[String]): Option[NBTTagCompound] = {
|
||||
if (stack == null || stack.stackSize == 0) None
|
||||
else if (!stack.hasTagCompound) None
|
||||
else getTag(stack.getTagCompound, keys)
|
||||
}
|
||||
|
||||
def address(stack: ItemStack): Option[String] = {
|
||||
val addressKey = "address"
|
||||
getTag(stack, Array(Settings.namespace + "data", "node")) match {
|
||||
case Some(tag) if tag.hasKey(addressKey) => Option(tag.getString(addressKey))
|
||||
case _ => None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -101,7 +101,7 @@ object FileSystem extends api.detail.FileSystemAPI {
|
||||
}
|
||||
}
|
||||
|
||||
override def fromSaveDirectory(root: String, capacity: Long, buffered: Boolean) = {
|
||||
override def fromSaveDirectory(root: String, capacity: Long, buffered: Boolean): Capacity = {
|
||||
val path = new io.File(DimensionManager.getCurrentSaveRootDirectory, Settings.savePath + root)
|
||||
if (!path.isDirectory) {
|
||||
path.delete()
|
||||
@ -200,7 +200,7 @@ object FileSystem extends api.detail.FileSystemAPI {
|
||||
extends VirtualFileSystem
|
||||
with Buffered
|
||||
with Capacity {
|
||||
protected override def segments(path: String) = {
|
||||
protected override def segments(path: String): Array[String] = {
|
||||
val parts = super.segments(path)
|
||||
if (isCaseInsensitive) toCaseInsensitive(parts) else parts
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user