From 772e98bb28a74bd20abcc3e29f874eaddf07f5de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20N=C3=BCcke?= Date: Sat, 19 Sep 2015 14:56:24 +0200 Subject: [PATCH] Replace all uses of `getCurrentEquippedItem` with `getHeldItem`. Technically the same, but more generic. --- src/main/scala/li/cil/oc/client/GuiHandler.scala | 14 +++++++------- src/main/scala/li/cil/oc/common/GuiHandler.scala | 8 ++++---- .../scala/li/cil/oc/common/block/DiskDrive.scala | 2 +- .../scala/li/cil/oc/common/block/RobotProxy.scala | 2 +- .../li/cil/oc/common/component/Terminal.scala | 2 +- src/main/scala/li/cil/oc/common/entity/Drone.scala | 2 +- .../provider/DisintegrationProvider.scala | 4 ++-- .../buildcraft/tools/EventHandlerBuildCraft.scala | 2 +- .../integration/cofh/item/EventHandlerCoFH.scala | 2 +- .../ic2/EventHandlerIndustrialCraft2.scala | 2 +- .../opencomputers/ModOpenComputers.scala | 2 +- .../railcraft/EventHandlerRailcraft.scala | 2 +- .../scala/li/cil/oc/integration/util/Wrench.scala | 4 ++-- .../scala/li/cil/oc/server/PacketHandler.scala | 6 +++--- src/main/scala/li/cil/oc/server/agent/Player.scala | 4 ++-- 15 files changed, 29 insertions(+), 29 deletions(-) diff --git a/src/main/scala/li/cil/oc/client/GuiHandler.scala b/src/main/scala/li/cil/oc/client/GuiHandler.scala index 08882733e..eb5219efc 100644 --- a/src/main/scala/li/cil/oc/client/GuiHandler.scala +++ b/src/main/scala/li/cil/oc/client/GuiHandler.scala @@ -57,14 +57,14 @@ object GuiHandler extends CommonGuiHandler { case _ => null } case Some(GuiType.Category.Item) => - Delegator.subItem(player.getCurrentEquippedItem) match { + Delegator.subItem(player.getHeldItem) match { case Some(drive: item.traits.FileSystemLike) if id == GuiType.Drive.id => - new gui.Drive(player.inventory, () => player.getCurrentEquippedItem) + new gui.Drive(player.inventory, () => player.getHeldItem) case Some(database: item.UpgradeDatabase) if id == GuiType.Database.id => new gui.Database(player.inventory, new DatabaseInventory { override def tier = database.tier - override def container = player.getCurrentEquippedItem + override def container = player.getHeldItem override def isUseableByPlayer(player: EntityPlayer) = player == player }) @@ -72,12 +72,12 @@ object GuiHandler extends CommonGuiHandler { new gui.Server(player.inventory, new ServerInventory { override def tier = server.tier - override def container = player.getCurrentEquippedItem + override def container = player.getHeldItem override def isUseableByPlayer(player: EntityPlayer) = player == player }) case Some(tablet: item.Tablet) if id == GuiType.Tablet.id => - val stack = player.getCurrentEquippedItem + val stack = player.getHeldItem if (stack.hasTagCompound) { item.Tablet.get(stack, player).components.collect { case Some(buffer: TextBuffer) => buffer @@ -88,13 +88,13 @@ object GuiHandler extends CommonGuiHandler { } else null case Some(tablet: item.Tablet) if id == GuiType.TabletInner.id => - val stack = player.getCurrentEquippedItem + val stack = player.getHeldItem if (stack.hasTagCompound) { new gui.Tablet(player.inventory, item.Tablet.get(stack, player)) } else null case Some(terminal: item.Terminal) if id == GuiType.Terminal.id => - val stack = player.getCurrentEquippedItem + val stack = player.getHeldItem if (stack.hasTagCompound) { val address = stack.getTagCompound.getString(Settings.namespace + "server") val key = stack.getTagCompound.getString(Settings.namespace + "key") diff --git a/src/main/scala/li/cil/oc/common/GuiHandler.scala b/src/main/scala/li/cil/oc/common/GuiHandler.scala index 6ce0419bd..5790b0641 100644 --- a/src/main/scala/li/cil/oc/common/GuiHandler.scala +++ b/src/main/scala/li/cil/oc/common/GuiHandler.scala @@ -45,12 +45,12 @@ abstract class GuiHandler extends IGuiHandler { case _ => null } case Some(GuiType.Category.Item) => - Delegator.subItem(player.getCurrentEquippedItem) match { + Delegator.subItem(player.getHeldItem) match { case Some(database: item.UpgradeDatabase) if id == GuiType.Database.id => new container.Database(player.inventory, new DatabaseInventory { override def tier = database.tier - override def container = player.getCurrentEquippedItem + override def container = player.getHeldItem override def isUseableByPlayer(player: EntityPlayer) = player == player }) @@ -58,12 +58,12 @@ abstract class GuiHandler extends IGuiHandler { new container.Server(player.inventory, new ServerInventory { override def tier = server.tier - override def container = player.getCurrentEquippedItem + override def container = player.getHeldItem override def isUseableByPlayer(player: EntityPlayer) = player == player }) case Some(tablet: item.Tablet) if id == GuiType.TabletInner.id => - val stack = player.getCurrentEquippedItem + val stack = player.getHeldItem if (stack.hasTagCompound) new container.Tablet(player.inventory, item.Tablet.get(stack, player)) else diff --git a/src/main/scala/li/cil/oc/common/block/DiskDrive.scala b/src/main/scala/li/cil/oc/common/block/DiskDrive.scala index 358a1297f..57401b997 100644 --- a/src/main/scala/li/cil/oc/common/block/DiskDrive.scala +++ b/src/main/scala/li/cil/oc/common/block/DiskDrive.scala @@ -54,7 +54,7 @@ class DiskDrive extends SimpleBlock with traits.GUI { if (player.isSneaking) world.getTileEntity(x, y, z) match { case drive: tileentity.DiskDrive => val isDiskInDrive = drive.getStackInSlot(0) != null - val isHoldingDisk = drive.isItemValidForSlot(0, player.getCurrentEquippedItem) + val isHoldingDisk = drive.isItemValidForSlot(0, player.getHeldItem) if (isDiskInDrive) { if (!world.isRemote) { drive.dropSlot(0, 1, Option(drive.facing)) diff --git a/src/main/scala/li/cil/oc/common/block/RobotProxy.scala b/src/main/scala/li/cil/oc/common/block/RobotProxy.scala index 274f0fcd2..ace38be4d 100644 --- a/src/main/scala/li/cil/oc/common/block/RobotProxy.scala +++ b/src/main/scala/li/cil/oc/common/block/RobotProxy.scala @@ -210,7 +210,7 @@ class RobotProxy extends RedstoneAware with traits.SpecialBlock with traits.Stat } true } - else if (player.getCurrentEquippedItem == null) { + else if (player.getHeldItem == null) { if (!world.isRemote) { world.getTileEntity(x, y, z) match { case proxy: tileentity.RobotProxy if !proxy.machine.isRunning && proxy.isUseableByPlayer(player) => proxy.machine.start() diff --git a/src/main/scala/li/cil/oc/common/component/Terminal.scala b/src/main/scala/li/cil/oc/common/component/Terminal.scala index 249d03358..235f449b9 100644 --- a/src/main/scala/li/cil/oc/common/component/Terminal.scala +++ b/src/main/scala/li/cil/oc/common/component/Terminal.scala @@ -36,7 +36,7 @@ class Terminal(val rack: tileentity.ServerRack, val number: Int) { val keyboard = api.Driver.driverFor(keyboardItem, rack.getClass).createEnvironment(keyboardItem, rack).asInstanceOf[api.component.Keyboard] keyboard.setUsableOverride(new UsabilityChecker { override def isUsableByPlayer(keyboard: api.component.Keyboard, player: EntityPlayer) = { - val stack = player.getCurrentEquippedItem + val stack = player.getHeldItem Delegator.subItem(stack) match { case Some(t: item.Terminal) if stack.hasTagCompound => keys.contains(stack.getTagCompound.getString(Settings.namespace + "key")) case _ => false diff --git a/src/main/scala/li/cil/oc/common/entity/Drone.scala b/src/main/scala/li/cil/oc/common/entity/Drone.scala index 1b4071d57..80f9cf94a 100644 --- a/src/main/scala/li/cil/oc/common/entity/Drone.scala +++ b/src/main/scala/li/cil/oc/common/entity/Drone.scala @@ -464,7 +464,7 @@ class Drone(val world: World) extends Entity(world) with MachineHost with intern override def interactFirst(player: EntityPlayer) = { if (player.isSneaking) { - if (Wrench.isWrench(player.getCurrentEquippedItem)) { + if (Wrench.isWrench(player.getHeldItem)) { kill() } else if (!world.isRemote && !machine.isRunning) { diff --git a/src/main/scala/li/cil/oc/common/nanomachines/provider/DisintegrationProvider.scala b/src/main/scala/li/cil/oc/common/nanomachines/provider/DisintegrationProvider.scala index 1ee8861b2..3c3642ffc 100644 --- a/src/main/scala/li/cil/oc/common/nanomachines/provider/DisintegrationProvider.scala +++ b/src/main/scala/li/cil/oc/common/nanomachines/provider/DisintegrationProvider.scala @@ -65,7 +65,7 @@ object DisintegrationProvider extends ScalaProvider("c4e7e3c2-8069-4fbb-b08e-74b val timeToBreak = (1 / hardness).toInt if (timeToBreak < 20 * 30) { val meta = world.getBlockMetadata(pos) - val info = new SlowBreakInfo(now, now + timeToBreak, pos, Option(player.getCurrentEquippedItem).map(_.copy()), block, meta) + val info = new SlowBreakInfo(now, now + timeToBreak, pos, Option(player.getHeldItem).map(_.copy()), block, meta) world.destroyBlockInWorldPartially(pos.hashCode(), pos, 0) breakingMapNew += pos -> info } @@ -101,7 +101,7 @@ object DisintegrationProvider extends ScalaProvider("c4e7e3c2-8069-4fbb-b08e-74b var lastDamageSent = 0 def checkTool(player: EntityPlayer): Boolean = { - val currentTool = Option(player.getCurrentEquippedItem).map(_.copy()) + val currentTool = Option(player.getHeldItem).map(_.copy()) (currentTool, originalTool) match { case (Some(stackA), Some(stackB)) => stackA.getItem == stackB.getItem && (stackA.isItemStackDamageable || stackA.getItemDamage == stackB.getItemDamage) case (None, None) => true diff --git a/src/main/scala/li/cil/oc/integration/buildcraft/tools/EventHandlerBuildCraft.scala b/src/main/scala/li/cil/oc/integration/buildcraft/tools/EventHandlerBuildCraft.scala index f1fc2e64d..785c9f7ec 100644 --- a/src/main/scala/li/cil/oc/integration/buildcraft/tools/EventHandlerBuildCraft.scala +++ b/src/main/scala/li/cil/oc/integration/buildcraft/tools/EventHandlerBuildCraft.scala @@ -6,7 +6,7 @@ import net.minecraft.item.ItemStack object EventHandlerBuildCraft { def useWrench(player: EntityPlayer, x: Int, y: Int, z: Int, changeDurability: Boolean): Boolean = { - player.getCurrentEquippedItem.getItem match { + player.getHeldItem.getItem match { case wrench: IToolWrench => if (changeDurability) { wrench.wrenchUsed(player, x, y, z) diff --git a/src/main/scala/li/cil/oc/integration/cofh/item/EventHandlerCoFH.scala b/src/main/scala/li/cil/oc/integration/cofh/item/EventHandlerCoFH.scala index b1d9c0233..dad8f739f 100644 --- a/src/main/scala/li/cil/oc/integration/cofh/item/EventHandlerCoFH.scala +++ b/src/main/scala/li/cil/oc/integration/cofh/item/EventHandlerCoFH.scala @@ -6,7 +6,7 @@ import net.minecraft.item.ItemStack object EventHandlerCoFH { def useWrench(player: EntityPlayer, x: Int, y: Int, z: Int, changeDurability: Boolean): Boolean = { - player.getCurrentEquippedItem.getItem match { + player.getHeldItem.getItem match { case wrench: IToolHammer => if (changeDurability) { wrench.toolUsed(player.getHeldItem, player, x, y, z) diff --git a/src/main/scala/li/cil/oc/integration/ic2/EventHandlerIndustrialCraft2.scala b/src/main/scala/li/cil/oc/integration/ic2/EventHandlerIndustrialCraft2.scala index e72e63b32..2ac2ad42f 100644 --- a/src/main/scala/li/cil/oc/integration/ic2/EventHandlerIndustrialCraft2.scala +++ b/src/main/scala/li/cil/oc/integration/ic2/EventHandlerIndustrialCraft2.scala @@ -48,7 +48,7 @@ object EventHandlerIndustrialCraft2 { } def useWrench(player: EntityPlayer, x: Int, y: Int, z: Int, changeDurability: Boolean): Boolean = { - player.getCurrentEquippedItem.getItem match { + player.getHeldItem.getItem match { case wrench: ItemToolWrench => if (changeDurability) { wrench.damage(player.getHeldItem, 1, player) diff --git a/src/main/scala/li/cil/oc/integration/opencomputers/ModOpenComputers.scala b/src/main/scala/li/cil/oc/integration/opencomputers/ModOpenComputers.scala index f55106f09..c61061474 100644 --- a/src/main/scala/li/cil/oc/integration/opencomputers/ModOpenComputers.scala +++ b/src/main/scala/li/cil/oc/integration/opencomputers/ModOpenComputers.scala @@ -268,7 +268,7 @@ object ModOpenComputers extends ModProxy { } def useWrench(player: EntityPlayer, x: Int, y: Int, z: Int, changeDurability: Boolean): Boolean = { - player.getCurrentEquippedItem.getItem match { + player.getHeldItem.getItem match { case wrench: Wrench => wrench.useWrenchOnBlock(player, player.getEntityWorld, x, y, z, !changeDurability) case _ => false } diff --git a/src/main/scala/li/cil/oc/integration/railcraft/EventHandlerRailcraft.scala b/src/main/scala/li/cil/oc/integration/railcraft/EventHandlerRailcraft.scala index 27ee23120..17cb23e4d 100644 --- a/src/main/scala/li/cil/oc/integration/railcraft/EventHandlerRailcraft.scala +++ b/src/main/scala/li/cil/oc/integration/railcraft/EventHandlerRailcraft.scala @@ -6,7 +6,7 @@ import net.minecraft.item.ItemStack object EventHandlerRailcraft { def useWrench(player: EntityPlayer, x: Int, y: Int, z: Int, changeDurability: Boolean): Boolean = { - player.getCurrentEquippedItem.getItem match { + player.getHeldItem.getItem match { case wrench: IToolCrowbar => if (changeDurability) { wrench.onWhack(player, player.getHeldItem, x, y, z) diff --git a/src/main/scala/li/cil/oc/integration/util/Wrench.scala b/src/main/scala/li/cil/oc/integration/util/Wrench.scala index 893aaafde..0698abf51 100644 --- a/src/main/scala/li/cil/oc/integration/util/Wrench.scala +++ b/src/main/scala/li/cil/oc/integration/util/Wrench.scala @@ -20,8 +20,8 @@ object Wrench { def isWrench(stack: ItemStack): Boolean = stack != null && checks.exists(IMC.tryInvokeStatic(_, stack)(false)) def holdsApplicableWrench(player: EntityPlayer, position: BlockPosition): Boolean = - player.getCurrentEquippedItem != null && usages.exists(IMC.tryInvokeStatic(_, player, int2Integer(position.x), int2Integer(position.y), int2Integer(position.z), boolean2Boolean(false))(false)) + player.getHeldItem != null && usages.exists(IMC.tryInvokeStatic(_, player, int2Integer(position.x), int2Integer(position.y), int2Integer(position.z), boolean2Boolean(false))(false)) def wrenchUsed(player: EntityPlayer, position: BlockPosition): Unit = - if (player.getCurrentEquippedItem != null) usages.foreach(IMC.tryInvokeStaticVoid(_, player, int2Integer(position.x), int2Integer(position.y), int2Integer(position.z), boolean2Boolean(true))) + if (player.getHeldItem != null) usages.foreach(IMC.tryInvokeStaticVoid(_, player, int2Integer(position.x), int2Integer(position.y), int2Integer(position.z), boolean2Boolean(true))) } diff --git a/src/main/scala/li/cil/oc/server/PacketHandler.scala b/src/main/scala/li/cil/oc/server/PacketHandler.scala index 45d948126..6558c5c48 100644 --- a/src/main/scala/li/cil/oc/server/PacketHandler.scala +++ b/src/main/scala/li/cil/oc/server/PacketHandler.scala @@ -83,11 +83,11 @@ object PacketHandler extends CommonPacketHandler { def onDriveMode(p: PacketParser) = p.player match { case player: EntityPlayerMP => - Delegator.subItem(player.getCurrentEquippedItem) match { + Delegator.subItem(player.getHeldItem) match { case Some(drive: FileSystemLike) => - val data = new DriveData(player.getCurrentEquippedItem) + val data = new DriveData(player.getHeldItem) data.isUnmanaged = p.readBoolean() - data.save(player.getCurrentEquippedItem) + data.save(player.getHeldItem) case _ => // Invalid packet. } case _ => // Invalid packet. diff --git a/src/main/scala/li/cil/oc/server/agent/Player.scala b/src/main/scala/li/cil/oc/server/agent/Player.scala index d268cb4dc..ba9f1a581 100644 --- a/src/main/scala/li/cil/oc/server/agent/Player.scala +++ b/src/main/scala/li/cil/oc/server/agent/Player.scala @@ -176,10 +176,10 @@ class Player(val agent: internal.Agent) extends FakePlayer(agent.world.asInstanc } !cancel && callUsingItemInSlot(agent.equipmentInventory, 0, stack => { val result = isItemUseAllowed(stack) && (entity.interactFirst(this) || (entity match { - case living: EntityLivingBase if getCurrentEquippedItem != null => getCurrentEquippedItem.interactWithEntity(this, living) + case living: EntityLivingBase if getHeldItem != null => getHeldItem.interactWithEntity(this, living) case _ => false })) - if (getCurrentEquippedItem != null && getCurrentEquippedItem.stackSize <= 0) { + if (getHeldItem != null && getHeldItem.stackSize <= 0) { destroyCurrentEquippedItem() } result