Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Variables
- local itemSensorPlace = "right"
- local nuclearSensorPlace = "left"
- local modemPlace = "top"
- local reactorName = "ic2.blocknuclearreactor"
- local lzhName = "item.reactorcondensatorlap"
- local cellName = "item.reactoruraniumquad"
- local cellEmptyName = "item.itemcelluranempty"
- -- Private fields
- local reactors = {}
- local turtles = {}
- turtles["-2,1,2"] = {6, "-2,0,1"}
- --[[
- 1 = LZH
- 2 = Uranium Cell
- 3 = Plating
- 4 = heat vent
- 5 = exchanger
- ]]--
- local items = {
- 1,1,1,1,1,1,1,1,1,
- 2,2,2,2,2,2,2,2,2,
- 2,2,2,2,2,2,2,2,2,
- 1,1,1,1,1,1,1,1,1,
- 3,3,3,3,3,4,5,4,5,
- 3,3,3,3,3,5,4,5,4,
- }
- --[[
- Targets table
- Key = X,Y,Z (string)
- Value = table
- ----------------
- A target table e.g. targets["2,1,-3"]
- Key = Name
- RawName
- Position
- Value = any string e.g. "Nuclear Reactor"
- any string e.g. "ic2.blocknuclearreactor"
- table
- ----------------
- A position table
- Key = X, Y, Z (a string, like "X")
- Value = 2 (a number, like -3)
- ----------------
- Sensor.getTargetDetails table
- Key = Name
- RawName
- Position
- Slots
- Value = any string e.g. "Nuclear Reactor"
- any string e.g. "ic2.blocknuclearreactor"
- table
- table
- ----------------
- Slots table
- Key = any valid number (between 1 and the number of slots)
- Value = table
- ----------------
- Item table
- Key = Size
- MaxStack
- DamageValue
- RawName
- Name
- Value = any number
- any number e.g. between 1 and 64
- any number e.g. between 1 and 9999
- any string e.g. "item.reactorcondensatorlap"
- any string e.g. "LZH-Condensator"
- ]]--
- -- Utility methods
- function split(sstr, pattern)
- local t = {}
- local fpat = "(.-)" .. pattern
- local last_end = 1
- local s, e, cap = sstr:find(fpat, 1)
- while s do
- if s ~= 1 or cap ~= "" then
- table.insert(t,cap)
- end
- last_end = e+1
- s, e, cap = sstr:find(fpat, last_end)
- end
- if last_end <= #sstr then
- cap = sstr:sub(last_end)
- table.insert(t, cap)
- end
- return t
- end
- function sendMessage(id, messageID, message)
- rednet.send(id, "RR " .. messageID .. " " .. message)
- end
- function itemName(number)
- if number == 1 then
- return lzhName
- elseif number == 2 then
- return cellName
- elseif number == 3 then
- return nil
- elseif number == 4 then
- return nil
- elseif number == 5 then
- return nil
- else
- return nil
- end
- end
- function itemCmd(reactor, cmd, slot, item)
- t = is.getTargetDetails(turtles[reactor][2])
- local slots2 = t["Slots"]
- for k = 1, #slots2, 1 do
- local it = slots2[k]
- if it["RawName"] == item then
- sendMessage(turtles[reactor][1], cmd, item .. " FROM " .. (k-1) .. " TO " .. (slot-1))
- end
- end
- end
- -- Startup
- os.loadAPI("ocs/apis/sensor")
- is = sensor.wrap(itemSensorPlace)
- targets = is.getTargets()
- rednet.open(modemPlace)
- -- Get the list of reactors
- for k,v in pairs(targets) do
- for o,p in pairs(v) do
- if o == "RawName" and p == reactorName then
- table.insert(reactors, k)
- end
- end
- end
- -- Loop foreach item in the reactor
- for i = 1, #reactors, 1 do
- key = reactors[i]
- details = is.getTargetDetails(key)
- slots = details["Slots"]
- for k = 1, #slots, 1 do
- item = slots[k]
- if item["RawName"] == lzhName then
- if item["DamageValue"] > 9900 then
- print("broken lzh")
- itemCmd(key, "REPLACE", k, lzhName)
- end
- elseif item["Name"] == "empty" then
- elseif item["RawName"] == cellEmptyName then
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement