diff --git a/src/main/scala/li/cil/oc/common/inventory/ItemStackInventory.scala b/src/main/scala/li/cil/oc/common/inventory/ItemStackInventory.scala index 626afc3f1..1c04f22fd 100644 --- a/src/main/scala/li/cil/oc/common/inventory/ItemStackInventory.scala +++ b/src/main/scala/li/cil/oc/common/inventory/ItemStackInventory.scala @@ -12,8 +12,11 @@ trait ItemStackInventory extends Inventory { override def items = inventory // Initialize the list automatically if we have a container. - if (!container.isEmpty) { - reinitialize() + { + val _container = container + if (_container != null && !_container.isEmpty) { + reinitialize() + } } // Load items from tag. 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 fe2383869..b52465460 100644 --- a/src/main/scala/li/cil/oc/server/agent/Player.scala +++ b/src/main/scala/li/cil/oc/server/agent/Player.scala @@ -213,12 +213,22 @@ class Player(val agent: internal.Agent) extends FakePlayer(agent.world.asInstanc private var offHand: (IInventory, Int) = _ override def setItemStackToSlot(slotIn: EntityEquipmentSlot, stack: ItemStack): Unit = { + var superCall: () => Unit = () => super.setItemStackToSlot(slotIn, stack) if (slotIn == EntityEquipmentSlot.MAINHAND) { agent.equipmentInventory.setInventorySlotContents(0, stack) + superCall = () => { + val slot = inventory.currentItem + // So, if we're not in the main inventory, currentItem is set to -1 + // for compatibility with mods that try accessing the inv directly + // using inventory.currentItem. See li.cil.oc.server.agent.Inventory + if(inventory.currentItem < 0) inventory.currentItem = ~inventory.currentItem + super.setItemStackToSlot(slotIn, stack) + inventory.currentItem = slot + } } else if(slotIn == EntityEquipmentSlot.OFFHAND && offHand != null) { offHand._1.setInventorySlotContents(offHand._2, stack) } - super.setItemStackToSlot(slotIn, stack) + superCall() } override def getItemStackFromSlot(slotIn: EntityEquipmentSlot): ItemStack = {