Thor_s_Crafter

terraTurtle

May 24th, 2016
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.84 KB | None | 0 0
  1. -- Terraformingprogramm --
  2. -- von Thor_s_Crafter --
  3. -- Version 1.0 --
  4.  
  5. t = turtle
  6. local currSlot = 1
  7. local currDir = 1
  8.  
  9. local x = 0
  10. local y = 0
  11. local z = 0
  12.  
  13. local counterX = 0
  14. local counterY = 0
  15. local counterZ = 0
  16.  
  17. local function getNumber(text)
  18.   local input
  19.   while tonumber(input) == nil do
  20.      term.clear()
  21.      term.setCursorPos(1,1)
  22.      write(text)
  23.      input = read()
  24.      if tonumber(input) == nil then
  25.       print("Ungueltige Eingabe!")
  26.      end
  27.   end
  28.   return tonumber(input)
  29. end
  30.  
  31. local function getFuel()
  32.   term.clear()
  33.   while t.getFuelLevel() < x*y*z do
  34.     term.setCursorPos(1,1)
  35.     print("Bitte Kohle in Slot 1 legen!")
  36.     print("Aktuelles FuelLevel: "..t.getFuelLevel().."   ")
  37.     print("Benoetigtes FuelLevel: "..x*y*z.."   ")
  38.     t.refuel()
  39.   end
  40. end
  41.  
  42. function userInput()
  43.   term.clear()
  44.   term.setCursorPos(1,1)
  45.   print("Dieses Programm ebnet eine Flaeche!")
  46.   print("Bitte dazu die Laenge,Breite und Hoehe")
  47.   print("der zu ebnenden Flaeche eingeben!")
  48.   print("Bitte Enter druecken...")
  49.   read()
  50.   x = getNumber("Laenge eingeben: ")
  51.   y = getNumber("Breite eingeben: ")
  52.   z = getNumber("Hoehe eingeben: ")
  53.   getFuel()
  54. end
  55.  
  56. function changeDir(dir)
  57.   if dir == "-" then
  58.     if currDir == 1 then
  59.       currDir = 4
  60.     else
  61.       currDir = currDir - 1
  62.     end    
  63.   elseif dir == "+" then
  64.     if currDir == 4 then
  65.       currDir = 1
  66.     else
  67.       currDir = currDir + 1
  68.     end
  69.   end  
  70. end
  71.  
  72. function getBack()
  73.   while not currDir == 1 do
  74.     t.turnLeft()
  75.     changeDir("-")
  76.   end
  77.   for i=1, counterZ do
  78.     t.down()
  79.   end  
  80.   t.turnLeft()
  81.   for i=1,counterY do    
  82.     t.back()
  83.   end
  84.   t.turnRight()
  85.   for i=1,counterX do
  86.     t.back()
  87.   end
  88.  
  89.   t.turnLeft()
  90.   t.turnLeft()
  91. end
  92.  
  93. function dropAll()
  94.   for i=1,16 do
  95.     t.select(i)
  96.     t.drop(64)
  97.   end
  98. end
  99.  
  100. function dropItems()
  101.   local currDirTemp = currDir
  102.  
  103.   getBack()
  104.  
  105.   dropAll()
  106.   t.turnLeft()
  107.   t.turnLeft()
  108.  
  109.   for i=1,counterX do
  110.     t.forward()
  111.   end
  112.   t.turnLeft()  
  113.   for i=1,counterY do
  114.     t.forward()
  115.   end
  116.   t.turnRight()
  117.   for i=1,counterZ do
  118.     t.up()
  119.   end
  120.   while not currDir == currDirTemp do
  121.     t.turnLeft()
  122.     changeDir("-")
  123.   end
  124. end
  125.  
  126. function setSlot()
  127.   while t.getItemCount() == 64 do
  128.     if currSlot == 16 then
  129.       dropItems()
  130.       currSlot = 1
  131.     else
  132.       currSlot = currSlot + 1
  133.     end
  134.     t.select(currSlot)
  135.   end
  136. end
  137.  
  138. function digX(dir)
  139.   for i=1,x do
  140.     term.clear()
  141.     term.setCursorPos(1,1)
  142.     print("x: "..x)
  143.     print("y: "..y)
  144.     print("z: "..z)
  145.     print()
  146.     print("counterX: "..counterX)
  147.     print("counterY: "..counterY)
  148.     print("counterZ: "..counterZ)    
  149.  
  150.     setSlot()
  151.     t.dig()
  152.     t.forward()  
  153.     if dir == "+" then
  154.       counterX = counterX + 1
  155.     elseif dir == "-" then
  156.       counterX = counterX - 1
  157.     end
  158.   end
  159.   t.dig()
  160.   t.forward()
  161. end
  162.  
  163. function digAll()
  164.   term.clear()
  165.   term.setCursorPos(1,1)
  166.  
  167.   local forY = 0
  168.   if math.floor(tonumber(y/2))*2 then
  169.     forY = math.floor(tonumber(y/2))+1
  170.     y = math.floor(tonumber(y/2))+1
  171.   else
  172.     forY = tonumber(y/2)
  173.     y = tonumber(y/2)
  174.   end
  175.  
  176.   term.clear()
  177.   for i=1,z do
  178.     for i=1,forY do
  179.       digX("+")
  180.       t.turnLeft()
  181.       changeDir("-")
  182.       t.dig()
  183.       t.forward()
  184.       t.turnLeft()
  185.       changeDir("-")
  186.       counterY = counterY + 1
  187.       digX("-")
  188.       t.turnRight()
  189.       changeDir("+")
  190.       t.dig()
  191.       t.forward()
  192.       t.turnRight()
  193.       changeDir("+")
  194.       counterY = counterY + 1
  195.     end
  196.     getBack()
  197.     t.turnLeft()
  198.     t.turnLeft()
  199.     counterX = 0
  200.     counterY = 0
  201.     counterZ = counterZ + 1
  202.     for i=1,counterZ do
  203.       t.up()
  204.     end
  205.   end
  206.   for i=1,counterZ do
  207.     t.down()
  208.   end
  209. end
  210.  
  211.  
  212. userInput()
  213. digAll()
  214. term.clear()
  215. term.setCursorPos(1,1)
  216. print("Programm beendet!")
Advertisement
Add Comment
Please, Sign In to add comment