OpenPeripheralModDepletedFuelRodReplacer

Mirror of http://pastebin.com/7wBQiF98

--#########
--IC2 Reactor depleted fuel rod replacer
--Requires the OpenPeripherals mod! //Cragrim
--#########

--  EDIT THE FOLLOWING

--Direction of the MEInterface from reactor
--Use up, down, north, west, east, south
storeDir = "down"

--Redstone input that starts the replacement
redstoneSide = "top"

--MEInterface depleted uranium inv slot
meSlotOld = 2
--MEInterface fuel rod inv slot
meSlotNew = 1

--Direction of the reactor from the computer
using = peripheral.wrap("right")

--  DONT EDIT THE FOLLOWING

newItem = "ic2.reactorUraniumSimple"
oldItem = "ic2.reactorUraniumSimpledepleted"

function errType(number)
  number = tonumber(number)
  if type(number) ~= "number" then
    return false
  else
    return true
  end
end

function getName(peripheral,slot)
  --check for integer
  if errType(slot) == false then
    return ""
  else
    if peripheral ~= nil then
      item = peripheral.getStackInSlot(slot)
      if item ~= nil then
        return item["name"]
      else
        return ""
      end
    end
  end
end

while true do
  print("Waiting for redstone signal from "..redstoneSide..".")
  os.pullEvent("redstone")
  if rs.getInput(redstoneSide) or rs.getBundledInput(redstoneSide, colors.white) then
    print("Searching for ".. oldItem.." to replace with "..newItem..".")
    count = 0
    for i=1,54 do
      if getName(using,i) == oldItem then
        count = count + 1
        using.pushItem(storeDir,i,1,meSlotOld)
        using.pullItem(storeDir,meSlotNew,1,i)
      end            
    end
    print("Replaced "..count.." items.")
    os.sleep(10)
  end
end
Advertisements