mariebu

16x16 Bauplatz

Mar 16th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.83 KB | None | 0 0
  1. -- Bauplatz einrichten
  2.  
  3. -- Vorgabewerte erfragen
  4. term.clear()
  5. term.setCursorPos(1,1)
  6. print("Laenge des Bauplatzes [Blickrichtung Turtle]?")
  7. lang = io.read()
  8. print("Breite des Bauplatzes [Abstand nach links oder rechts]?")
  9. breit = io.read()
  10. print("Grabungsrichtung [l]inks oder [r]echts?")
  11. grabrichtung = io.read()
  12. print("Wie viele Ebenen hoch soll abgetragen werden[mind. 2,gerade Anzahl]?")
  13. ebenen = io.read()
  14.  
  15. -- Werte anpassungen
  16. lang = lang - 1
  17. breit = breit - 1
  18. ebenen = ebenen + 0
  19. if ebenen <= 2 then
  20.   ebenen = 2
  21. else
  22.   if ebenen % 2 == 1 then
  23.     ebenen = ebenen + 1
  24.   end
  25. end
  26.  
  27. -- Brennmaterialbedarf ermitteln und befüllen
  28. function fuelCheck()
  29.   local fuelNeed = (lang+1) * (breit+1) * ebenen
  30.   local currentFuel = turtle.getFuelLevel()
  31.   if currentFuel < fuelNeed then
  32.     print("Zu wenig Treibstoff. " .. currentFuel .. "/" .. fuelNeed)
  33.     print("Bitte Slot angeben in dem der Treibstoff liegt:")
  34.     local k = io.read()
  35.     k = k + 0
  36.     turtle.select(k)
  37.     turtle.refuel()
  38.     sleep(0.5)
  39.     fuelCheck()
  40.   else
  41.     print("Treibstoffbedarf gedeckt: " .. currentFuel .. "/" .. fuelNeed)
  42.     sleep(0.5)
  43.   end
  44. end
  45.  
  46. function moveForward()
  47.   if turtle.detect() then
  48.     turtle.dig()
  49.   end
  50.   turtle.forward()
  51. end
  52.  
  53. function turnEven()
  54.   if grabrichtung == "l" then
  55.     turtle.turnLeft()
  56.   else
  57.     turtle.turnRight()
  58.   end
  59. end
  60.  
  61. function turnOdd()
  62.   if grabrichtung == "r" then
  63.     turtle.turnLeft()
  64.   else
  65.     turtle.turnRight()
  66.   end
  67. end
  68.  
  69. function doPlain()
  70.   for col = 0, breit, 1 do
  71.     for row = 0, lang, 1 do
  72.       moveForward()
  73.     end
  74.     if breit - col >= 1 then
  75.       if col % 2 == 0 then
  76.          turnEven()
  77.       else
  78.          turnOdd()
  79.       end
  80.       moveForward()
  81.       if col % 2 == 0 then
  82.          turnEven()
  83.       else
  84.          turnOdd()
  85.       end    
  86.     end
  87.   end
  88. end
  89.  
  90. function moveDown()
  91.   if turtle.detectDown() then
  92.     turtle.digDown()
  93.   end
  94.   turtle.down()
  95. end
  96.  
  97. function switchDirection()
  98.   if grabrichtung == "r" then
  99.     grabrichtung = "l"
  100.   else
  101.     grabrichtung = "r"
  102.   end
  103. end
  104.  
  105. function turnAndDown()
  106.   turtle.turnLeft()
  107.   turtle.turnLeft()
  108.   moveDown()
  109. end
  110.  
  111. -- Testausgabe
  112. print(lang .. "x" .. breit .. "x" .. ebenen .. "  Fuel: " .. turtle.getFuelLevel())
  113. fuelCheck()
  114. for i = 1, ebenen-1 do
  115.   turtle.up()
  116. end
  117. moveForward()
  118. lang = lang - 1
  119. for i = 1, ebenen, 2 do
  120.   print(lang .. "x" .. breit .. "x" .. ebenen .. "  Fuel: " .. turtle.getFuelLevel())
  121.   doPlain()
  122.   turnAndDown()
  123.   switchDirection()
  124.   print(lang .. "x" .. breit .. "x" .. ebenen .. "  Fuel: " .. turtle.getFuelLevel())
  125.   doPlain()
  126.   if ebenen-i > 1 then
  127.     print("tad")
  128.     turnAndDown()
  129.     switchDirection()    
  130.   end
  131. end
  132. print(lang .. "x" .. breit .. "x" .. ebenen .. "  Fuel: " .. turtle.getFuelLevel())
  133. moveForward()
  134. turtle.turnLeft()
  135. turtle.turnLeft()
Add Comment
Please, Sign In to add comment