diff --git a/src/main/scala/li/cil/oc/client/renderer/tileentity/RobotRenderer.scala b/src/main/scala/li/cil/oc/client/renderer/tileentity/RobotRenderer.scala index a149c89c4..8aefcf5ed 100644 --- a/src/main/scala/li/cil/oc/client/renderer/tileentity/RobotRenderer.scala +++ b/src/main/scala/li/cil/oc/client/renderer/tileentity/RobotRenderer.scala @@ -11,6 +11,8 @@ import li.cil.oc.client.Textures import li.cil.oc.common.EventHandler import li.cil.oc.common.tileentity import li.cil.oc.util.RenderState +import li.cil.oc.util.StackOption +import li.cil.oc.util.StackOption._ import net.minecraft.client.Minecraft import net.minecraft.client.renderer._ import net.minecraft.client.renderer.block.model.ItemCameraTransforms.TransformType @@ -343,8 +345,8 @@ object RobotRenderer extends TileEntitySpecialRenderer[tileentity.RobotProxy] { if (MinecraftForgeClient.getRenderPass == 0 && !robot.renderingErrored && x * x + y * y + z * z < 24 * 24) { val itemRenderer = Minecraft.getMinecraft.getItemRenderer - Option(robot.getStackInSlot(0)) match { - case Some(stack) => + StackOption(robot.getStackInSlot(0)) match { + case SomeStack(stack) => RenderState.pushAttrib() GlStateManager.pushMatrix() diff --git a/src/main/scala/li/cil/oc/common/template/Template.scala b/src/main/scala/li/cil/oc/common/template/Template.scala index 80b3e495a..e237af2a8 100644 --- a/src/main/scala/li/cil/oc/common/template/Template.scala +++ b/src/main/scala/li/cil/oc/common/template/Template.scala @@ -6,6 +6,8 @@ import li.cil.oc.Settings import li.cil.oc.api import li.cil.oc.common.Slot import li.cil.oc.common.Tier +import li.cil.oc.util.StackOption +import li.cil.oc.util.StackOption._ import net.minecraft.inventory.IInventory import net.minecraft.item.ItemStack import net.minecraft.util.text.ITextComponent @@ -60,8 +62,8 @@ abstract class Template { } protected def exists(inventory: IInventory, p: ItemStack => Boolean) = { - (0 until inventory.getSizeInventory).exists(slot => Option(inventory.getStackInSlot(slot)) match { - case Some(stack) => p(stack) + (0 until inventory.getSizeInventory).exists(slot => StackOption(inventory.getStackInSlot(slot)) match { + case SomeStack(stack) => p(stack) case _ => false }) } diff --git a/src/main/scala/li/cil/oc/common/tileentity/Robot.scala b/src/main/scala/li/cil/oc/common/tileentity/Robot.scala index 27dc8908f..381cf52f4 100644 --- a/src/main/scala/li/cil/oc/common/tileentity/Robot.scala +++ b/src/main/scala/li/cil/oc/common/tileentity/Robot.scala @@ -29,6 +29,8 @@ import li.cil.oc.util.BlockPosition import li.cil.oc.util.ExtendedNBT._ import li.cil.oc.util.ExtendedWorld._ import li.cil.oc.util.InventoryUtils +import li.cil.oc.util.StackOption +import li.cil.oc.util.StackOption._ import net.minecraft.block.Block import net.minecraft.block.BlockLiquid import net.minecraft.client.Minecraft @@ -357,8 +359,8 @@ class Robot extends traits.Computer with traits.PowerInformation with traits.Rot } if (!appliedToolEnchantments) { appliedToolEnchantments = true - Option(getStackInSlot(0)) match { - case Some(item) => player_.getAttributeMap.applyAttributeModifiers(item.getAttributeModifiers(EntityEquipmentSlot.MAINHAND)) + StackOption(getStackInSlot(0)) match { + case SomeStack(item) => player_.getAttributeMap.applyAttributeModifiers(item.getAttributeModifiers(EntityEquipmentSlot.MAINHAND)) case _ => } } @@ -578,10 +580,10 @@ class Robot extends traits.Computer with traits.PowerInformation with traits.Rot if (isServer) { if (isToolSlot(slot)) { player_.getAttributeMap.removeAttributeModifiers(stack.getAttributeModifiers(EntityEquipmentSlot.MAINHAND)) - ServerPacketSender.sendRobotInventory(this, slot, null) + ServerPacketSender.sendRobotInventory(this, slot, ItemStack.EMPTY) } if (isUpgradeSlot(slot)) { - ServerPacketSender.sendRobotInventory(this, slot, null) + ServerPacketSender.sendRobotInventory(this, slot, ItemStack.EMPTY) } if (isFloppySlot(slot)) { common.Sound.playDiskEject(this) @@ -675,10 +677,10 @@ class Robot extends traits.Computer with traits.PowerInformation with traits.Rot override def componentSlot(address: String): Int = components.indexWhere(_.exists(env => env.node != null && env.node.address == address)) - override def hasRedstoneCard: Boolean = (containerSlots ++ componentSlots).exists(slot => Option(getStackInSlot(slot)).fold(false)(DriverRedstoneCard.worksWith(_, getClass))) + override def hasRedstoneCard: Boolean = (containerSlots ++ componentSlots).exists(slot => StackOption(getStackInSlot(slot)).fold(false)(DriverRedstoneCard.worksWith(_, getClass))) - private def computeInventorySize() = math.min(maxInventorySize, (containerSlots ++ componentSlots).foldLeft(0)((acc, slot) => acc + (Option(getStackInSlot(slot)) match { - case Some(stack) => Option(Driver.driverFor(stack, getClass)) match { + private def computeInventorySize() = math.min(maxInventorySize, (containerSlots ++ componentSlots).foldLeft(0)((acc, slot) => acc + (StackOption(getStackInSlot(slot)) match { + case SomeStack(stack) => Option(Driver.driverFor(stack, getClass)) match { case Some(driver: item.Inventory) => driver.inventoryCapacity(stack) case _ => 0 } diff --git a/src/main/scala/li/cil/oc/server/agent/Inventory.scala b/src/main/scala/li/cil/oc/server/agent/Inventory.scala index a7b8c0522..bbb41ad04 100644 --- a/src/main/scala/li/cil/oc/server/agent/Inventory.scala +++ b/src/main/scala/li/cil/oc/server/agent/Inventory.scala @@ -3,6 +3,8 @@ package li.cil.oc.server.agent import li.cil.oc.api.internal import li.cil.oc.util.ExtendedInventory._ import li.cil.oc.util.InventoryUtils +import li.cil.oc.util.StackOption +import li.cil.oc.util.StackOption._ import net.minecraft.entity.player.EntityPlayer import net.minecraft.entity.player.InventoryPlayer import net.minecraft.item.Item @@ -32,8 +34,8 @@ class Inventory(val agent: internal.Agent) extends InventoryPlayer(null) { override def decrementAnimations() { for (slot <- 0 until getSizeInventory) { - Option(getStackInSlot(slot)) match { - case Some(stack) => try stack.updateAnimation(agent.world, if (!agent.world.isRemote) agent.player else null, slot, slot == 0) catch { + StackOption(getStackInSlot(slot)) match { + case SomeStack(stack) => try stack.updateAnimation(agent.world, if (!agent.world.isRemote) agent.player else null, slot, slot == 0) catch { case ignored: NullPointerException => // Client side item updates that need a player instance... } case _ =>