Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.loadAPI("ocs/apis/sensor")
- heatSensor = sensor.wrap("left")
- inventorySensor = sensor.wrap("back")
- function distance(pos)
- return math.sqrt(pos.X * pos.X + pos.Y * pos.Y + pos.Z * pos.Z)
- end
- function findNearest(sensor, name)
- local blocks = sensor.getTargets()
- local nearest = nil
- for k, v in pairs(blocks) do
- if v.Name == name then
- if nearest == nil then
- nearest = k
- else
- if distance((blocks[nearest]).Position) > distance(v.Position) then
- nearest = k
- end
- end
- end
- end
- return nearest
- end
- keyHS = findNearest(heatSensor, "Nuclear Reactor")
- keyIS = findNearest(inventorySensor, "Nuclear Reactor")
- enabled = true
- maxT = 92
- minT = 90
- function redstoneRegulator()
- while true do
- details = heatSensor.getTargetDetails(keyHS)
- print(details.Heat)
- if (details.HeatPercentage < maxT) and enabled then
- rs.setOutput("right", true)
- else
- rs.setOutput("right", false)
- end
- sleep(0.1)
- end
- end
- function checkRoads()
- slots = inventorySensor.getTargetDetails(keyIS).Slots
- flag = true
- for _, i in pairs({2, 10, 11, 12, 20}) do
- flag = flag and slots[i].Name ~= "empty"
- end
- return flag
- end
- function heatWentRegulator()
- while true do
- heat = heatSensor.getTargetDetails(keyHS).HeatPercentage
- if heat > minT and checkRoads() then
- rs.setOutput("bottom", true)
- sleep(0.1)
- rs.setOutput("bottom", false)
- sleep (0.2)
- elseif heat <= minT then
- rs.setOutput("front", true)
- sleep(0.1)
- rs.setOutput("front", false)
- sleep (0.2)
- else
- sleep(0.1)
- end
- end
- end
- parallel.waitForAny(
- redstoneRegulator,
- heatWentRegulator,
- function ()
- read()
- end)
- rs.setOutput("right", false)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement