mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-18 11:48:02 -04:00
Homogenized item data stuff a bit and trying to avoid NPEs in preconfigured item creation.
This commit is contained in:
parent
fb45881cec
commit
64d3f93177
@ -191,6 +191,8 @@ object Items extends ItemAPI {
|
||||
get(Constants.ItemName.LuaBios).createItemStack(amount)
|
||||
}
|
||||
|
||||
private def safeGetStack(name: String) = Option(get(name)).map(_.createItemStack(1)).orNull
|
||||
|
||||
def createConfiguredDrone() = {
|
||||
val data = new DroneData()
|
||||
|
||||
@ -198,18 +200,18 @@ object Items extends ItemAPI {
|
||||
data.tier = Tier.Four
|
||||
data.storedEnergy = Settings.get.bufferDrone.toInt
|
||||
data.components = Array(
|
||||
get(Constants.ItemName.InventoryUpgrade).createItemStack(1),
|
||||
get(Constants.ItemName.InventoryUpgrade).createItemStack(1),
|
||||
get(Constants.ItemName.InventoryControllerUpgrade).createItemStack(1),
|
||||
get(Constants.ItemName.TankUpgrade).createItemStack(1),
|
||||
get(Constants.ItemName.TankControllerUpgrade).createItemStack(1),
|
||||
get(Constants.ItemName.LeashUpgrade).createItemStack(1),
|
||||
safeGetStack(Constants.ItemName.InventoryUpgrade),
|
||||
safeGetStack(Constants.ItemName.InventoryUpgrade),
|
||||
safeGetStack(Constants.ItemName.InventoryControllerUpgrade),
|
||||
safeGetStack(Constants.ItemName.TankUpgrade),
|
||||
safeGetStack(Constants.ItemName.TankControllerUpgrade),
|
||||
safeGetStack(Constants.ItemName.LeashUpgrade),
|
||||
|
||||
get(Constants.ItemName.WirelessNetworkCard).createItemStack(1),
|
||||
safeGetStack(Constants.ItemName.WirelessNetworkCard),
|
||||
|
||||
get(Constants.ItemName.CPUTier3).createItemStack(1),
|
||||
get(Constants.ItemName.RAMTier6).createItemStack(1),
|
||||
get(Constants.ItemName.RAMTier6).createItemStack(1)
|
||||
safeGetStack(Constants.ItemName.CPUTier3),
|
||||
safeGetStack(Constants.ItemName.RAMTier6),
|
||||
safeGetStack(Constants.ItemName.RAMTier6)
|
||||
)
|
||||
|
||||
data.createItemStack()
|
||||
@ -221,15 +223,15 @@ object Items extends ItemAPI {
|
||||
data.tier = Tier.Four
|
||||
data.storedEnergy = Settings.get.bufferMicrocontroller.toInt
|
||||
data.components = Array(
|
||||
get(Constants.ItemName.SignUpgrade).createItemStack(1),
|
||||
get(Constants.ItemName.PistonUpgrade).createItemStack(1),
|
||||
safeGetStack(Constants.ItemName.SignUpgrade),
|
||||
safeGetStack(Constants.ItemName.PistonUpgrade),
|
||||
|
||||
get(Constants.ItemName.RedstoneCardTier2).createItemStack(1),
|
||||
get(Constants.ItemName.WirelessNetworkCard).createItemStack(1),
|
||||
safeGetStack(Constants.ItemName.RedstoneCardTier2),
|
||||
safeGetStack(Constants.ItemName.WirelessNetworkCard),
|
||||
|
||||
get(Constants.ItemName.CPUTier3).createItemStack(1),
|
||||
get(Constants.ItemName.RAMTier6).createItemStack(1),
|
||||
get(Constants.ItemName.RAMTier6).createItemStack(1)
|
||||
safeGetStack(Constants.ItemName.CPUTier3),
|
||||
safeGetStack(Constants.ItemName.RAMTier6),
|
||||
safeGetStack(Constants.ItemName.RAMTier6)
|
||||
)
|
||||
|
||||
data.createItemStack()
|
||||
@ -243,34 +245,34 @@ object Items extends ItemAPI {
|
||||
data.robotEnergy = Settings.get.bufferRobot.toInt
|
||||
data.totalEnergy = data.robotEnergy
|
||||
data.components = Array(
|
||||
get(Constants.BlockName.ScreenTier1).createItemStack(1),
|
||||
get(Constants.BlockName.Keyboard).createItemStack(1),
|
||||
get(Constants.ItemName.InventoryUpgrade).createItemStack(1),
|
||||
get(Constants.ItemName.InventoryUpgrade).createItemStack(1),
|
||||
get(Constants.ItemName.InventoryUpgrade).createItemStack(1),
|
||||
get(Constants.ItemName.InventoryUpgrade).createItemStack(1),
|
||||
get(Constants.ItemName.InventoryControllerUpgrade).createItemStack(1),
|
||||
get(Constants.ItemName.TankUpgrade).createItemStack(1),
|
||||
get(Constants.ItemName.TankControllerUpgrade).createItemStack(1),
|
||||
get(Constants.ItemName.CraftingUpgrade).createItemStack(1),
|
||||
safeGetStack(Constants.BlockName.ScreenTier1),
|
||||
safeGetStack(Constants.BlockName.Keyboard),
|
||||
safeGetStack(Constants.ItemName.InventoryUpgrade),
|
||||
safeGetStack(Constants.ItemName.InventoryUpgrade),
|
||||
safeGetStack(Constants.ItemName.InventoryUpgrade),
|
||||
safeGetStack(Constants.ItemName.InventoryUpgrade),
|
||||
safeGetStack(Constants.ItemName.InventoryControllerUpgrade),
|
||||
safeGetStack(Constants.ItemName.TankUpgrade),
|
||||
safeGetStack(Constants.ItemName.TankControllerUpgrade),
|
||||
safeGetStack(Constants.ItemName.CraftingUpgrade),
|
||||
|
||||
get(Constants.ItemName.GraphicsCardTier3).createItemStack(1),
|
||||
get(Constants.ItemName.RedstoneCardTier2).createItemStack(1),
|
||||
get(Constants.ItemName.WirelessNetworkCard).createItemStack(1),
|
||||
get(Constants.ItemName.InternetCard).createItemStack(1),
|
||||
safeGetStack(Constants.ItemName.GraphicsCardTier3),
|
||||
safeGetStack(Constants.ItemName.RedstoneCardTier2),
|
||||
safeGetStack(Constants.ItemName.WirelessNetworkCard),
|
||||
safeGetStack(Constants.ItemName.InternetCard),
|
||||
|
||||
get(Constants.ItemName.CPUTier3).createItemStack(1),
|
||||
get(Constants.ItemName.RAMTier6).createItemStack(1),
|
||||
get(Constants.ItemName.RAMTier6).createItemStack(1),
|
||||
safeGetStack(Constants.ItemName.CPUTier3),
|
||||
safeGetStack(Constants.ItemName.RAMTier6),
|
||||
safeGetStack(Constants.ItemName.RAMTier6),
|
||||
|
||||
get(Constants.ItemName.LuaBios).createItemStack(1),
|
||||
get(Constants.ItemName.OpenOS).createItemStack(1),
|
||||
get(Constants.ItemName.HDDTier3).createItemStack(1)
|
||||
safeGetStack(Constants.ItemName.LuaBios),
|
||||
safeGetStack(Constants.ItemName.OpenOS),
|
||||
safeGetStack(Constants.ItemName.HDDTier3)
|
||||
)
|
||||
data.containers = Array(
|
||||
get(Constants.ItemName.CardContainerTier3).createItemStack(1),
|
||||
get(Constants.ItemName.UpgradeContainerTier3).createItemStack(1),
|
||||
get(Constants.BlockName.DiskDrive).createItemStack(1)
|
||||
safeGetStack(Constants.ItemName.CardContainerTier3),
|
||||
safeGetStack(Constants.ItemName.UpgradeContainerTier3),
|
||||
safeGetStack(Constants.BlockName.DiskDrive)
|
||||
)
|
||||
|
||||
data.createItemStack()
|
||||
@ -283,42 +285,36 @@ object Items extends ItemAPI {
|
||||
data.energy = Settings.get.bufferTablet
|
||||
data.maxEnergy = data.energy
|
||||
data.items = Array(
|
||||
Option(get(Constants.BlockName.ScreenTier1).createItemStack(1)),
|
||||
Option(get(Constants.BlockName.Keyboard).createItemStack(1)),
|
||||
Option(safeGetStack(Constants.BlockName.ScreenTier1)),
|
||||
Option(safeGetStack(Constants.BlockName.Keyboard)),
|
||||
|
||||
Option(get(Constants.ItemName.SignUpgrade).createItemStack(1)),
|
||||
Option(get(Constants.ItemName.PistonUpgrade).createItemStack(1)),
|
||||
Option(get(Constants.BlockName.Geolyzer).createItemStack(1)),
|
||||
Option(get(Constants.ItemName.NavigationUpgrade).createItemStack(1)),
|
||||
Option(safeGetStack(Constants.ItemName.SignUpgrade)),
|
||||
Option(safeGetStack(Constants.ItemName.PistonUpgrade)),
|
||||
Option(safeGetStack(Constants.BlockName.Geolyzer)),
|
||||
Option(safeGetStack(Constants.ItemName.NavigationUpgrade)),
|
||||
|
||||
Option(get(Constants.ItemName.GraphicsCardTier2).createItemStack(1)),
|
||||
Option(get(Constants.ItemName.RedstoneCardTier2).createItemStack(1)),
|
||||
Option(get(Constants.ItemName.WirelessNetworkCard).createItemStack(1)),
|
||||
Option(safeGetStack(Constants.ItemName.GraphicsCardTier2)),
|
||||
Option(safeGetStack(Constants.ItemName.RedstoneCardTier2)),
|
||||
Option(safeGetStack(Constants.ItemName.WirelessNetworkCard)),
|
||||
|
||||
Option(get(Constants.ItemName.CPUTier3).createItemStack(1)),
|
||||
Option(get(Constants.ItemName.RAMTier6).createItemStack(1)),
|
||||
Option(get(Constants.ItemName.RAMTier6).createItemStack(1)),
|
||||
Option(safeGetStack(Constants.ItemName.CPUTier3)),
|
||||
Option(safeGetStack(Constants.ItemName.RAMTier6)),
|
||||
Option(safeGetStack(Constants.ItemName.RAMTier6)),
|
||||
|
||||
Option(get(Constants.ItemName.LuaBios).createItemStack(1)),
|
||||
Option(get(Constants.ItemName.HDDTier3).createItemStack(1))
|
||||
Option(safeGetStack(Constants.ItemName.LuaBios)),
|
||||
Option(safeGetStack(Constants.ItemName.HDDTier3))
|
||||
).padTo(32, None)
|
||||
data.items(31) = Option(get(Constants.ItemName.OpenOS).createItemStack(1))
|
||||
data.container = Option(get(Constants.BlockName.DiskDrive).createItemStack(1))
|
||||
data.items(31) = Option(safeGetStack(Constants.ItemName.OpenOS))
|
||||
data.container = Option(safeGetStack(Constants.BlockName.DiskDrive))
|
||||
|
||||
val stack = get(Constants.ItemName.Tablet).createItemStack(1)
|
||||
data.save(stack)
|
||||
|
||||
stack
|
||||
data.createItemStack()
|
||||
}
|
||||
|
||||
def createChargedHoverBoots() = {
|
||||
val data = new HoverBootsData()
|
||||
data.charge = Settings.get.bufferHoverBoots
|
||||
|
||||
val stack = get(Constants.ItemName.HoverBoots).createItemStack(1)
|
||||
data.save(stack)
|
||||
|
||||
stack
|
||||
data.createItemStack()
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------- //
|
||||
|
@ -1,10 +1,11 @@
|
||||
package li.cil.oc.common.item.data
|
||||
|
||||
import li.cil.oc.Constants
|
||||
import li.cil.oc.Settings
|
||||
import net.minecraft.item.ItemStack
|
||||
import net.minecraft.nbt.NBTTagCompound
|
||||
|
||||
class DebugCardData extends ItemData {
|
||||
class DebugCardData extends ItemData(Constants.ItemName.DebugCard) {
|
||||
def this(stack: ItemStack) {
|
||||
this()
|
||||
load(stack)
|
||||
|
@ -2,11 +2,10 @@ package li.cil.oc.common.item.data
|
||||
|
||||
import com.google.common.base.Strings
|
||||
import li.cil.oc.Constants
|
||||
import li.cil.oc.api
|
||||
import net.minecraft.item.ItemStack
|
||||
import net.minecraft.nbt.NBTTagCompound
|
||||
|
||||
class DroneData extends MicrocontrollerData {
|
||||
class DroneData extends MicrocontrollerData(Constants.ItemName.Drone) {
|
||||
def this(stack: ItemStack) = {
|
||||
this()
|
||||
load(stack)
|
||||
@ -33,10 +32,4 @@ class DroneData extends MicrocontrollerData {
|
||||
nbt.getCompoundTag("display").setString("Name", name)
|
||||
}
|
||||
}
|
||||
|
||||
override def createItemStack(): ItemStack = {
|
||||
val stack = api.Items.get(Constants.ItemName.Drone).createItemStack(1)
|
||||
save(stack)
|
||||
stack
|
||||
}
|
||||
}
|
||||
|
@ -1,10 +1,11 @@
|
||||
package li.cil.oc.common.item.data
|
||||
|
||||
import li.cil.oc.Constants
|
||||
import li.cil.oc.Settings
|
||||
import net.minecraft.item.ItemStack
|
||||
import net.minecraft.nbt.NBTTagCompound
|
||||
|
||||
class HoverBootsData extends ItemData {
|
||||
class HoverBootsData extends ItemData(Constants.ItemName.HoverBoots) {
|
||||
def this(stack: ItemStack) {
|
||||
this()
|
||||
load(stack)
|
||||
|
@ -1,10 +1,11 @@
|
||||
package li.cil.oc.common.item.data
|
||||
|
||||
import li.cil.oc.api
|
||||
import li.cil.oc.api.Persistable
|
||||
import net.minecraft.item.ItemStack
|
||||
import net.minecraft.nbt.NBTTagCompound
|
||||
|
||||
abstract class ItemData extends Persistable {
|
||||
abstract class ItemData(val itemName: String) extends Persistable {
|
||||
def load(stack: ItemStack) {
|
||||
if (stack.hasTagCompound) {
|
||||
// Because ItemStack's load function doesn't copy the compound tag,
|
||||
@ -19,4 +20,13 @@ abstract class ItemData extends Persistable {
|
||||
}
|
||||
save(stack.getTagCompound)
|
||||
}
|
||||
|
||||
def createItemStack() = {
|
||||
if (itemName == null) null
|
||||
else {
|
||||
val stack = api.Items.get(itemName).createItemStack(1)
|
||||
save(stack)
|
||||
stack
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ import net.minecraft.item.ItemStack
|
||||
import net.minecraft.nbt.NBTTagCompound
|
||||
import net.minecraftforge.common.util.Constants.NBT
|
||||
|
||||
class MicrocontrollerData extends ItemData {
|
||||
class MicrocontrollerData(itemName: String = Constants.BlockName.Microcontroller) extends ItemData(itemName) {
|
||||
def this(stack: ItemStack) {
|
||||
this()
|
||||
load(stack)
|
||||
@ -40,12 +40,6 @@ class MicrocontrollerData extends ItemData {
|
||||
nbt.setInteger(Settings.namespace + "storedEnergy", storedEnergy)
|
||||
}
|
||||
|
||||
def createItemStack() = {
|
||||
val stack = api.Items.get(Constants.BlockName.Microcontroller).createItemStack(1)
|
||||
save(stack)
|
||||
stack
|
||||
}
|
||||
|
||||
def copyItemStack() = {
|
||||
val stack = createItemStack()
|
||||
val newInfo = new MicrocontrollerData(stack)
|
||||
|
@ -1,5 +1,6 @@
|
||||
package li.cil.oc.common.item.data
|
||||
|
||||
import li.cil.oc.Constants
|
||||
import li.cil.oc.Settings
|
||||
import li.cil.oc.util.ExtendedNBT._
|
||||
import net.minecraft.item.ItemMap
|
||||
@ -7,7 +8,7 @@ import net.minecraft.item.ItemStack
|
||||
import net.minecraft.nbt.NBTTagCompound
|
||||
import net.minecraft.world.World
|
||||
|
||||
class NavigationUpgradeData extends ItemData {
|
||||
class NavigationUpgradeData extends ItemData(Constants.ItemName.NavigationUpgrade) {
|
||||
def this(stack: ItemStack) {
|
||||
this()
|
||||
load(stack)
|
||||
|
@ -6,7 +6,7 @@ import net.minecraft.item.ItemStack
|
||||
import net.minecraft.nbt.NBTTagCompound
|
||||
|
||||
// Generic one for items that are used as components; gets the items node info.
|
||||
class NodeData extends ItemData {
|
||||
class NodeData extends ItemData(null) {
|
||||
def this(stack: ItemStack) {
|
||||
this()
|
||||
load(stack)
|
||||
|
@ -15,7 +15,7 @@ import net.minecraftforge.common.util.Constants.NBT
|
||||
|
||||
import scala.collection.mutable
|
||||
|
||||
class PrintData extends ItemData {
|
||||
class PrintData extends ItemData(Constants.BlockName.Print) {
|
||||
def this(stack: ItemStack) {
|
||||
this()
|
||||
load(stack)
|
||||
@ -83,12 +83,6 @@ class PrintData extends ItemData {
|
||||
nbt.setBoolean("isBeaconBase", isBeaconBase)
|
||||
nbt.setByte("lightLevel", lightLevel.toByte)
|
||||
}
|
||||
|
||||
def createItemStack() = {
|
||||
val stack = api.Items.get(Constants.BlockName.Print).createItemStack(1)
|
||||
save(stack)
|
||||
stack
|
||||
}
|
||||
}
|
||||
|
||||
object PrintData {
|
||||
|
@ -2,13 +2,12 @@ package li.cil.oc.common.item.data
|
||||
|
||||
import li.cil.oc.Constants
|
||||
import li.cil.oc.Settings
|
||||
import li.cil.oc.api
|
||||
import li.cil.oc.util.ExtendedNBT._
|
||||
import net.minecraft.item.ItemStack
|
||||
import net.minecraft.nbt.NBTTagCompound
|
||||
import net.minecraftforge.common.util.Constants.NBT
|
||||
|
||||
class RaidData extends ItemData {
|
||||
class RaidData extends ItemData(Constants.BlockName.Raid) {
|
||||
def this(stack: ItemStack) {
|
||||
this()
|
||||
load(stack)
|
||||
@ -34,10 +33,4 @@ class RaidData extends ItemData {
|
||||
nbt.setTag(Settings.namespace + "filesystem", filesystem)
|
||||
label.foreach(nbt.setString(Settings.namespace + "label", _))
|
||||
}
|
||||
|
||||
def createItemStack() = {
|
||||
val stack = api.Items.get(Constants.BlockName.Raid).createItemStack(1)
|
||||
save(stack)
|
||||
stack
|
||||
}
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ object RobotData {
|
||||
def randomName = if (names.length > 0) names((math.random * names.length).toInt) else "Robot"
|
||||
}
|
||||
|
||||
class RobotData extends ItemData {
|
||||
class RobotData extends ItemData(Constants.BlockName.Robot) {
|
||||
def this(stack: ItemStack) {
|
||||
this()
|
||||
load(stack)
|
||||
@ -85,12 +85,6 @@ class RobotData extends ItemData {
|
||||
nbt.setInteger(Settings.namespace + "lightColor", lightColor)
|
||||
}
|
||||
|
||||
def createItemStack() = {
|
||||
val stack = api.Items.get(Constants.BlockName.Robot).createItemStack(1)
|
||||
save(stack)
|
||||
stack
|
||||
}
|
||||
|
||||
def copyItemStack() = {
|
||||
val stack = createItemStack()
|
||||
// Forget all node addresses and so on. This is used when 'picking' a
|
||||
|
@ -1,5 +1,6 @@
|
||||
package li.cil.oc.common.item.data
|
||||
|
||||
import li.cil.oc.Constants
|
||||
import li.cil.oc.Settings
|
||||
import li.cil.oc.common.Tier
|
||||
import li.cil.oc.util.ExtendedNBT._
|
||||
@ -7,7 +8,7 @@ import net.minecraft.item.ItemStack
|
||||
import net.minecraft.nbt.NBTTagCompound
|
||||
import net.minecraftforge.common.util.Constants.NBT
|
||||
|
||||
class TabletData extends ItemData {
|
||||
class TabletData extends ItemData(Constants.ItemName.Tablet) {
|
||||
def this(stack: ItemStack) {
|
||||
this()
|
||||
load(stack)
|
||||
|
@ -122,7 +122,6 @@ object RecipeHandler {
|
||||
}
|
||||
//all values required
|
||||
case _ =>
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -164,7 +163,6 @@ object RecipeHandler {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private def parseRecipe(output: ItemStack, recipe: Config) = {
|
||||
val inputs = parseIngredientList(recipe.getValue("input")).toBuffer
|
||||
output.stackSize = Recipes.tryGetCount(recipe)
|
||||
|
Loading…
x
Reference in New Issue
Block a user