local stand="front"
local standRed="front"
local monitor="top"
local mfe="mfe_3"

local armors={
["empty"]={name="Empty",power=false},
--Nanosuit
[30178]={name="NanoSuit Helmet",power=true,slot=1},
[30177]={name="NanoSuit Bodyarmor",power=true,slot=2},
[30176]={name="NanoSuit Leggings",power=true,slot=3},
[30175]={name="NanoSuit Boots",power=true,slot=4},
--Jetpack
[30209]={name="Jetpack",power=true,slot=2},
}


local function wrapAll()
stand=peripheral.wrap(stand)
if not stand then error("Wrong stand side ") end
monitor=peripheral.wrap(monitor)
if not monitor then error("Wrong monitor side ") end
mfe=peripheral.wrap(mfe)
if not mfe then error("Wrong mfe side ") end
end

local function charge(A)
mfe.pullItemIntoSlot("up",A,1,1)
local tar=mfe.getStackInSlot(1)
if tar then
	repeat
	tar=mfe.getStackInSlot(1)
	sleep(1)
	until tar.dmg<=1
end
mfe.pushItemIntoSlot("up",1,1,A)
end

local function ready(A)
monitor.setBackgroundColor(monitor.isColor() and (A and colors.lime or colors.red) or (A and colors.white or colors.black))
monitor.clear()
end

wrapAll()

if standRed then redstone.setOutput(standRed,true) end

if mfe.getStackInSlot(1) then
local target=mfe.getStackInSlot(1)
local armor=armors[target.id]
	if armor then 
		mfe.pushItemIntoSlot("up",1,1,armor.slot)
	else
		print("Undefined item in charging mfe") return
	end
end 

while true do
for i=1,4 do
local item=stand.getStackInSlot(i)
	if item then
		local armor=armors[item.id]
			if armor and armor.power and item.dmg>1 then 
				ready(false)
				charge(i)		
			end
	end
end
ready(true)

sleep(5)
end