Advertisement
Inksaver

Command Computer test

Apr 23rd, 2016
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.92 KB | None | 0 0
  1. --Startup Computer 0 Commander01
  2. area =  {
  3.         {52,179},
  4.         {53,179},
  5.         {54,179},
  6.         {54,180},
  7.         {53,180},
  8.         {52,180},
  9.         {52,181},
  10.         {52,182},
  11.         {52,183},
  12.         {52,184},
  13.         {51,184},
  14.         {50,184},
  15.         {50,183},
  16.         {50,182},
  17.         {50,181},
  18.         {50,180},
  19.         {50,179},
  20.         {50,178},
  21.         {50,177},
  22.         {50,176},
  23.         {49,176},
  24.         {48,176}
  25.         }
  26.  
  27. local xHome, yHome, zHome = commands.getBlockPosition()
  28. local mineBottom = yHome - 11
  29. local mineTop = yHome - 1
  30. local mineTopEdge = xHome + 17
  31. local mineBottomEdge = xHome + 2
  32. local mineLeftEdge = zHome + 1
  33. local mineRightEdge = zHome + 8
  34.  
  35. local monitor = nil
  36. local modem = nil
  37. local termRow = 1
  38. local termCol = 1
  39. local monRow = 1
  40. local monCol = 1
  41. local page = {}
  42. local pageNo = 1
  43. local numPages = 1
  44. local numRows = 0
  45. local numCols = 0
  46. local fileName = ""
  47.  
  48. function placeWater(clear)
  49.     --for y = 56, 54, -1 do
  50.     y = 56
  51.         for i = 1, #area do
  52.             if clear then
  53.                 --if checkBlockType(area[i][1], y, area[i][2], "minecraft:water") then
  54.                     print("x="..area[i][1].."y="..y.." z="..area[i][2].." :stone")
  55.                     commands.setblock(area[i][1], y, area[i][2], "minecraft:dirt")
  56.                 --end
  57.             else
  58.                 --if checkBlockType(area[i][1], y, area[i][2], "minecraft:air") then
  59.                     print("x="..area[i][1].."y="..y.." z="..area[i][2].." :water")
  60.                     --commands.setblock(area[i][1], y, area[i][2], "minecraft:water", 0)
  61.                 --end
  62.             end
  63.         end
  64.         for i = 1, #area do
  65.             if clear then
  66.                 sleep(0.5)
  67.                 --if checkBlockType(area[i][1], y, area[i][2], "minecraft:stone") then
  68.                     print("x="..area[i][1].."y="..y.." z="..area[i][2].." :air")
  69.                     commands.setblock(area[i][1], y, area[i][2], "minecraft:air", 0)
  70.                 --end
  71.             end
  72.         end
  73.         display("both", "write", "Layer "..y.." completed")
  74.         --commands.say("Layer "..y.." completed")
  75.         sleep(0.5)
  76.     --end
  77. end
  78.  
  79. function findTurtle()
  80.     retX = 0
  81.     retY = 0
  82.     retZ = 0
  83.     for y = 56, 53, -1 do
  84.         for i = 1, #area do
  85.             if checkBlockType(area[i][1], y, area[i][2], "ComputerCraftEDU:TurtleJunior") then
  86.                 retX = area[i][1]
  87.                 retY = y
  88.                 retZ = area[i][2]
  89.                 break
  90.             end
  91.         end
  92.         if x > 0 and z > 0 then    
  93.             break
  94.         end
  95.     end
  96.     return retX, retY, retZ
  97. end
  98.  
  99. function display(device, action, text)
  100.     -- display("both", "print", text)
  101.     if action == "clear" then
  102.         if device == "term" or device == "both" then
  103.             term.clear()
  104.             term.setCursorPos(1, 1)
  105.             termRow = 1
  106.             termCol = 1
  107.         end
  108.         if device == "mon" or device == "both" then
  109.             monitor.clear()
  110.             monitor.setCursorPos(1,1)
  111.             monitor.setTextColor(colors.white)
  112.             monRow = 1
  113.             monCol = 1
  114.         end
  115.     elseif action == "print" then
  116.         if device == "term" or device == "both" then
  117.             term.write(text)
  118.             termRow = termRow + 1
  119.             term.setCursorPos(1, termRow)
  120.         end
  121.         if device == "mon" or device == "both" then
  122.             monitor.write(text)
  123.             monRow = monRow + 1
  124.             monitor.setCursorPos(1, monRow)
  125.         end
  126.         commands.say(text)
  127.     elseif action == "write" then
  128.         if device == "term" or device == "both" then
  129.             if termRow > 1 then
  130.                 termRow = termRow - 1
  131.             end
  132.             term.setCursorPos(1, termRow)
  133.             term.write("                               ")
  134.             term.setCursorPos(1, termRow)
  135.             term.write(text)
  136.             termRow = termRow + 1
  137.             term.setCursorPos(1, termRow)
  138.         end
  139.         if device == "mon" or device == "both" then
  140.             if monRow > 1 then
  141.                 monRow = monRow - 1
  142.             end
  143.             monitor.setCursorPos(1, monRow)
  144.             monitor.write("                 ")
  145.             monitor.setCursorPos(1, monRow)
  146.             monitor.write(text)
  147.             monRow = monRow + 1
  148.             monitor.setCursorPos(1, monRow)
  149.         end
  150.     end
  151. end
  152.  
  153. function checkBlockType(x, y, z, checkBlockType)
  154.     local result = false
  155.     local blockType = {}
  156.    
  157.     blockType = commands.getBlockInfo(x, y, z)
  158.     if blockType.name == checkBlockType then
  159.         result = true
  160.     end
  161.    
  162.     return result
  163. end
  164.  
  165. function getChoice()
  166.     term.clear()
  167.     term.setCursorPos(1,1)
  168.     print("Choose function:")
  169.     print()
  170.     print(" 1 - Place Water Sources")
  171.     print(" 2 - Clear Water Sources")
  172.     print(" 3 - Find Turtle Position")
  173.     print(" 4 - Retrieve Turtle")
  174.     print(" 5 - Quit")
  175.     print()
  176.     print("Enter your choice:")
  177.    
  178.     local result = read()
  179.     return result
  180. end
  181.  
  182. function getPeripheralSide(pType)
  183.     local side = ""
  184.    
  185.     for k,v in pairs(rs.getSides()) do
  186.         if peripheral.getType(v)== pType then
  187.             side = v
  188.             break
  189.         end
  190.     end
  191.    
  192.     return side
  193. end
  194.  
  195. function main()
  196.     local choice = 0
  197.     local side = ""
  198.        
  199.     side = getPeripheralSide("monitor")
  200.     if side ~= "" then
  201.         monitor = peripheral.wrap(side)
  202.         numCols, numRows = monitor.getSize()
  203.         monitor.setTextColor(colors.white)
  204.         display("both", "clear")
  205.         display("both", "print", "Submarine Controller:Waiting for modem")
  206.     end
  207.    
  208.     side = getPeripheralSide("modem")
  209.     if side ~= "" then
  210.         modem = peripheral.wrap(side)
  211.         modem.open(0)
  212.     end
  213.    
  214.     commands.gamerule("commandBlockOutput", false)
  215.    
  216.     while true do
  217.         local action = getChoice()
  218.         display("both", "clear")
  219.         if action == "1" then
  220.             display("both", "print", "Placing water sources")
  221.             sleep(0.1)
  222.             placeWater(false)
  223.             display("both", "print", "Water sources operational")
  224.         elseif action == "2" then
  225.             display("both", "print", "Clearing water sources")
  226.             sleep(0.1)
  227.             placeWater(true)
  228.             display("both", "print", "Water sources cleared")
  229.         elseif action == "3" then
  230.             display("both", "print", "Searching for Turtle")
  231.             sleep(0.1)
  232.             cfindTurtle()
  233.             display("both", "print", "Turtle found at ")
  234.         elseif action == "4" then
  235.             display("both", "print", "Retrieving Turtle")
  236.             sleep(0.1)
  237.             -- send wireless turtle to fetch CCEDU
  238.             display("both", "print", "Turtle Recovered")
  239.         elseif action == "5" then
  240.             display("both", "print", "Goodbye")
  241.             break
  242.         end
  243.     end
  244.     --[[while true do
  245.         event, p1, p2, p3, p4 = os.pullEvent()
  246.         if event == "monitor_touch" or event == "modem_message" then
  247.             if event == "monitor_touch" then
  248.                 --display("mon", "clear")
  249.                 sleep(0.5)
  250.                 display("both", "print", "Monitor Touch")
  251.                
  252.             elseif event == "modem_message" then --Advanced computer networked to allow control non-creative
  253.                 display("both", "clear")
  254.                 if p4 == "1" then
  255.                     display("both", "print", "Placing water sources")
  256.                     sleep(0.1)
  257.                     placeWater(false)
  258.                     display("both", "print", "Water sources operational")
  259.                 elseif p4 == "2" then
  260.                     display("both", "print", "Clearing water sources")
  261.                     sleep(0.1)
  262.                     placeWater(true)
  263.                     display("both", "print", "Water sources cleared")
  264.                 elseif p4 == "3" then
  265.                     display("both", "print", "Searching for Turtle")
  266.                     sleep(0.1)
  267.                     cfindTurtle()
  268.                     display("both", "print", "Turtle found at ")
  269.                 elseif p4 == "4" then
  270.                     display("both", "print", "Retrieving Turtle")
  271.                     sleep(0.1)
  272.                     -- send wireless turtle to fetch CCEDU
  273.                     display("both", "print", "Turtle Recovered")
  274.                 elseif p4 == "5" then
  275.                     display("both", "print", "Goodbye")
  276.                     break
  277.                 end
  278.             end
  279.         elseif event == "mouse_click" then
  280.             sleep(0.5)
  281.             display("both", "print", "Mouse Click")
  282.         end
  283.     end]]--
  284. end
  285.  
  286. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement