blob: 11a8d785472ebb245bea7826f938b6ff2c75fcae [file] [log] [blame] [raw]
package li.cil.oc.common
import cpw.mods.fml.common.ICraftingHandler
import net.minecraft.entity.player.EntityPlayer
import net.minecraft.inventory.IInventory
import net.minecraft.item.ItemStack
import li.cil.oc.{Settings, api}
object CraftingHandler extends ICraftingHandler {
lazy val navigationUpgrade = api.Items.get("navigationUpgrade")
override def onCrafting(player: EntityPlayer, craftedStack: ItemStack, inventory: IInventory) = {
if (api.Items.get(craftedStack) == navigationUpgrade) {
Option(api.Driver.driverFor(craftedStack)).foreach(driver =>
for (i <- 0 until inventory.getSizeInventory) {
val stack = inventory.getStackInSlot(i)
if (stack != null && api.Items.get(stack) == navigationUpgrade) {
// Restore the map currently used in the upgrade.
val nbt = driver.dataTag(stack)
val map = ItemStack.loadItemStackFromNBT(nbt.getCompoundTag(Settings.namespace + "map"))
if (!player.inventory.addItemStackToInventory(map)) {
player.dropPlayerItemWithRandomChoice(map, false)
}
}
})
}
}
override def onSmelting(player: EntityPlayer, item: ItemStack) {}
}