SHARE
TWEET

Untitled

a guest Jul 16th, 2019 52 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. os.loadAPI("ocs/apis/sensor")
  2.  
  3. heatSensor = sensor.wrap("left")
  4. inventorySensor = sensor.wrap("back")
  5.  
  6. function distance(pos)
  7.   return math.sqrt(pos.X * pos.X + pos.Y * pos.Y + pos.Z * pos.Z)
  8. end
  9.  
  10. function findNearest(sensor, name)
  11.   local blocks = sensor.getTargets()
  12.   local nearest = nil
  13.   for k, v in pairs(blocks) do
  14.     if v.Name == name then
  15.       if nearest == nil then
  16.         nearest = k
  17.       else  
  18.         if distance((blocks[nearest]).Position) > distance(v.Position) then
  19.           nearest = k
  20.         end
  21.       end
  22.     end
  23.   end
  24.   return nearest
  25. end
  26.  
  27. keyHS = findNearest(heatSensor, "Nuclear Reactor")
  28. keyIS = findNearest(inventorySensor, "Nuclear Reactor")
  29.  
  30. enabled = true
  31. maxT = 92
  32. minT = 90
  33. function redstoneRegulator()
  34.   while true do
  35.     details = heatSensor.getTargetDetails(keyHS)
  36.     print(details.Heat)
  37.     if (details.HeatPercentage < maxT) and enabled then
  38.       rs.setOutput("right", true)
  39.     else
  40.       rs.setOutput("right", false)
  41.     end
  42.   sleep(0.1)
  43.   end
  44. end
  45.  
  46. function checkRoads()
  47.   slots = inventorySensor.getTargetDetails(keyIS).Slots
  48.   flag = true
  49.   for _, i in pairs({2, 10, 11, 12, 20}) do
  50.     flag = flag and slots[i].Name ~= "empty"
  51.   end
  52.   return flag
  53. end
  54.  
  55. function heatWentRegulator()
  56.   while true do
  57.     heat = heatSensor.getTargetDetails(keyHS).HeatPercentage
  58.     if heat > minT and checkRoads() then
  59.       rs.setOutput("bottom", true)
  60.       sleep(0.1)
  61.       rs.setOutput("bottom", false)
  62.       sleep (0.2)
  63.     elseif heat <= minT then
  64.       rs.setOutput("front", true)
  65.       sleep(0.1)
  66.       rs.setOutput("front", false)
  67.       sleep (0.2)
  68.     else
  69.       sleep(0.1)
  70.     end
  71.   end
  72. end
  73.  
  74. parallel.waitForAny(
  75.   redstoneRegulator,
  76.   heatWentRegulator,
  77.   function ()
  78.     read()
  79.    end)
  80. rs.setOutput("right", false)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top