Advertisement
Guest User

Untitled

a guest
Dec 9th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.09 KB | None | 0 0
  1. local os = require("os")
  2. local robot = require("robot")
  3. local sides = require("sides")
  4. local component = require("component")
  5. local geolyzer = component.geolyzer
  6. local computer = require("computer")
  7.  
  8. local FLOOR_COUNT = 2
  9. local FLOOR_HEIGHT = 3
  10. local FLOOR_WIDTH = 7
  11. local FLOOR_DEPTH = 15
  12. local FLOOR_ENTRY = 2
  13.  
  14.  
  15. function checkBeginningPos()
  16. --sprawdzanie lampy redstonowej
  17. local lamp = geloyzer.analyze(sides.bottom).name
  18. if lamp~="minecraft:lit_redstone_lamp"
  19. and lamp~="minecraft:redstone_lamp" then
  20. return false, "nie ma lampy kontrolnej pod robotem"
  21. end
  22.  
  23. --sprawdzanie piecyka
  24. for i=1,4 do
  25. local smelter = geolyzer.analyze(sides.front).properties
  26. if smelter.recipe == "smelting" then break end
  27. if i==4 then return false, "nie ma stacji przepalającej" end
  28. robot.turnLeft()
  29. end
  30.  
  31. --sprawdzanie chargera
  32. local charger = geolyzer.analyze(sides.left).name
  33. if charger.name ~= "opencomputers:charger" then
  34. return false, "nie ma chargera"
  35. end
  36.  
  37. return true
  38. end
  39.  
  40.  
  41. function checkControlLamp()
  42. local lamp = geloyzer.analyze(sides.bottom).name
  43. return lamp=="minecraft:lit_redstone_lamp"
  44. end
  45.  
  46.  
  47. function moveMultiple(side, number)
  48. for i=1,number do
  49. component.robot.move(side)
  50. end
  51. end
  52.  
  53.  
  54. function doFloor()
  55. moveMultiple(sides.back, FLOOR_ENTRY-1)
  56. for r=1,FLOOR_DEPTH do
  57. robot.back()
  58. if r%2==0 then robot.turnRight() else robot.turnLeft() end
  59. for c=1,FLOOR_WIDTH do
  60. checkZiemniok()
  61. robot.forward()
  62. end
  63. checkZiemniok()
  64. if r%2==0 then robot.turnLeft() else robot.turnRight() end
  65. end
  66. if FLOOR_DEPTH%2==1 then
  67. robot.turnLeft()
  68. moveMultiple(sides.forward,FLOOR_WIDTH-1)
  69. robot.turnRight()
  70. end
  71. moveMultiple(sides.forward,FLOOR_DEPTH+FLOOR_ENTRY-1)
  72. end
  73.  
  74.  
  75. function checkZiemniok()
  76. local ziemniok = geolyzer.analyze(sides.bottom)
  77. if ziemniok.name == "minecraft:air" then
  78. robot.placeDown()
  79. elseif ziemniok.name == "minecraft:potatoes" then
  80. if ziemniok.properties.age==7 then
  81. robot.swingDown()
  82. robot.placeDown()
  83. end
  84. end
  85. end
  86.  
  87.  
  88. function depositZiemnioki()
  89. for i=16,1 do
  90. robot.select(i)
  91. robot.drop()
  92. end
  93. end
  94.  
  95.  
  96. function waitForRecharge()
  97. while computer.energy()/computer.maxEnergy()<0.99 do
  98. os.sleep(0.25)
  99. end
  100. end
  101.  
  102.  
  103.  
  104.  
  105. local goodStart, err = checkBeginningPos()
  106.  
  107. if not goodStart then print("Nieprawidłowa strefa startu: "..err)
  108. else
  109. while checkControlLamp() do
  110. for f=1,FLOOR_COUNT do
  111. if f>1 then moveMultiple(sides.up, FLOOR_HEIGHT) end
  112. doFloor()
  113. print("Ukończono piętro "..f)
  114. end
  115. moveMultiple(sides.down, FLOOR_HEIGHT * (FLOOR_COUNT-1))
  116. print("Wypierdalanie ziemnioków...")
  117. depositZiemnioki()
  118. print("Czekanie na naładowanie baterii")
  119. waitForRecharge()
  120. end
  121. print("Działanie zakończone przez użytkownika.")
  122. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement