Advertisement
Guest User

Untitled

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