Advertisement
Guest User

ausheben

a guest
Apr 5th, 2020
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.77 KB | None | 0 0
  1. local breite = nil
  2. local hoehe = nil
  3. local tiefe = nil
  4.  
  5. local x = nil -- Breite
  6. local y = nil -- Hoehe
  7. local z = nil -- Tiefe
  8.  
  9. local richtung = nil
  10. local ou = nil
  11.  
  12. local tSaveBlock ={}
  13.  
  14.  
  15. local gemined = 0
  16. local sz = 3
  17.  
  18. -- Funktionen --
  19.  
  20. local function ausgabe()
  21.  local prozent = math.floor((gemined*100)/(breite*hoehe*tiefe))
  22.  
  23.  shell.run("clear")
  24.  
  25.  term.setTextColor(colors.white)
  26.  print("Der Turtle arbeitet: ")
  27.  
  28.  term.setTextColor(colors.blue)
  29.  print("Breite ", breite)
  30.  
  31.  term.setTextColor(colors.green)
  32.  print("Hoehe ", hoehe)
  33.  
  34.  term.setTextColor(colors.yellow)
  35.  print("Tiefe ", tiefe)
  36.  
  37.  if #tSaveBlock > 0 then
  38.   term.setTextColor(colors.pink)
  39.   print("Es werden folgende Bloecke gesichert:")
  40.   for i, v in ipairs(tSaveBlock) do
  41.    print(" "..i..". "..v)
  42.   end
  43.  end
  44.  
  45.  term.setTextColor(colors.red)
  46.  if prozent >= 100 then
  47.   print("Der Turtle ist fertig")
  48.  else
  49.   print("... "..prozent.."%")
  50.  end
  51. end
  52.  
  53. --
  54. local function oboun(obenunten)
  55.  myApi.graben(obenunten)
  56.  gemined = gemined + 1
  57. end
  58. local function obenuntenGerade()
  59.  myApi.graben()
  60.  myApi.graben("hoch")
  61.  myApi.graben("runter")
  62.  gemined = gemined + 3
  63. end
  64. local function untenGerade()
  65.  myApi.graben()
  66.  myApi.graben("runter")
  67.  gemined = gemined + 2
  68. end
  69. local function obenGerade()
  70.  myApi.graben()
  71.  myApi.graben("hoch")
  72.  gemined = gemined + 2
  73. end
  74.  
  75. local function waagerechtGraben(obenunten, gerade)
  76.  local abbauen =  nil
  77.  
  78.  if gerade == nil and obenunten ~= nil then
  79.   abbauen = oboun
  80.  elseif obenunten == "hoch" and gerade == "gerade" then
  81.   abbauen = obenGerade
  82.  elseif obenunten == "runter" and gerade == "gerade" then
  83.   abbauen = untenGerade
  84.  else
  85.   abbauen = obenuntenGerade
  86.  end
  87.  
  88.  x = breite
  89.  while x > 1 do
  90.   abbauen(obenunten)
  91.   if turtle.detect() then myApi.graben() end
  92. --[[  if myApi.saveBlock(tSaveBlock, 10) then
  93.    turtle.idSelect("EnderStorage:enderChest")
  94.    turtle.place()
  95.    for i = 1, 16 do
  96.     turtle.select(i)
  97.     turtle.dropDown()
  98.    end
  99.    turtle.dig()
  100.   end
  101.   ]]--
  102.   turtle.forward()
  103.   x = x - 1
  104.  
  105.   ausgabe()
  106.  end
  107.  
  108. end
  109.  
  110. ---
  111.  
  112. local function senkrechtGraben(hochrunter)
  113.  local schritte = 0
  114.  local schritt = nil
  115.  local abb = nil
  116.  
  117.  if hochrunter == "unten" then
  118.   myApi.graben("hoch")
  119.   schritt = turtle.down
  120.   abb = "runter"
  121.  elseif hochrunter == "oben" then
  122.   myApi.graben("runter")
  123.   schritt = turtle.up
  124.   abb = "hoch"
  125.  end
  126.  
  127.  gemined = gemined + 1
  128.  
  129.  while y > 2 and schritte < 3 do
  130.   myApi.graben(abb)
  131.   gemined = gemined + 1
  132.   schritt()
  133.   y = y - 1
  134.   schritte = schritte + 1
  135.  end
  136.  
  137.  turtle.turnRight()
  138.  turtle.turnRight()
  139.  return schritte
  140. end
  141.  
  142. ---
  143.  
  144. local function richtungsWechsel()
  145.  if richtung == "links" then
  146.   richtung = "rechts"
  147.  elseif richtung == "rechts" then
  148.   richtung = "links"
  149.  end
  150. end
  151.  
  152. --- Eingabe ---
  153.  
  154. shell.run("clear")
  155.  
  156. textutils.slowPrint("Bitte geben sie folgende Mase ein:\n", 15)
  157.  
  158. local function eingabe(text)
  159.  local mas = nil
  160.  while true do
  161.   local xPos, yPos = term.getCursorPos()
  162.   term.write(text.."(>=3) ")
  163.   mas = read()
  164.   if tonumber(mas) ~= nil then
  165.    if tonumber(mas) > 2 then
  166.     break
  167.    end
  168.   end
  169.   local tc = term.getTextColor()
  170.   term.setTextColor(colors.red)
  171.   print("Falsche Eingabe!")
  172.   sleep(1)
  173.   term.setCursorPos(xPos, yPos+1)
  174.   term.clearLine()
  175.   term.setTextColor(tc)
  176.   term.setCursorPos(xPos, yPos)
  177.   term.clearLine()
  178.  end
  179.  return mas
  180. end
  181. -----
  182.  
  183. term.setTextColor(colors.blue)
  184.  breite = eingabe("Breite") + 0
  185.  
  186. term.setTextColor(colors.green)
  187.  hoehe = eingabe("Hoehe") + 0
  188.  
  189. term.setTextColor(colors.yellow)
  190.  tiefe = eingabe("Tiefe") + 0
  191.  
  192. term.setTextColor(colors.purple)
  193. local xPos, yPos = term.getCursorPos()
  194.  
  195. while richtung ~= "rechts" and richtung ~= "links" do
  196.   term.setCursorPos(xPos, yPos)
  197.   term.clearLine()
  198.   term.write("Startrichtung")
  199.   term.setTextColor(colors.red)
  200.   term.write("(rechts/links) ")
  201.   term.setTextColor(colors.purple)
  202.   richtung = read()
  203. end
  204.  
  205. while ou ~= "oben" and ou ~= "unten" do
  206.   term.setCursorPos(xPos, yPos + 1)
  207.   term.clearLine()
  208.   term.write("Startrichtung")
  209.   term.setTextColor(colors.red)
  210.   term.write("(oben/unten) ")
  211.   term.setTextColor(colors.purple)
  212.   ou = read()
  213. end
  214.  
  215. term.setTextColor(colors.pink)
  216. print("Welche Bloeke sollen gesichert werden?: \n")
  217.  
  218. for id in string.gmatch(read(),"[,]*%s*([:_%/%-%.%|%w+]+)") do
  219.  table.insert(tSaveBlock, id)
  220. end
  221.  
  222. --- START ---
  223.  
  224. if ou == "oben" then
  225.  myApi.graben("hoch")
  226.  turtle.up()
  227. elseif ou == "unten" then
  228.  myApi.graben("runter")
  229.  turtle.down()
  230. end
  231.  
  232.  myApi.graben()
  233.  gemined = gemined + 1
  234.  turtle.forward()
  235.  
  236. if richtung == "rechts" then
  237.  turtle.turnRight()
  238. elseif richtung == "links" then
  239.  turtle.turnLeft()
  240. end
  241.  
  242. --- HAUPTPROGRAMM --
  243. local drehen =  nil
  244.  
  245. z = tiefe
  246. while z > 0 do
  247.  
  248.  y = hoehe - 1
  249.  while y > 2 do
  250.  
  251.   waagerechtGraben()
  252.   sz = senkrechtGraben(ou)
  253.   ausgabe()
  254.   richtungsWechsel()
  255.  end
  256.  
  257.  
  258.  if sz == 2 and ou == "unten" then
  259.   waagerechtGraben("runter", "gerade")
  260.   myApi.graben("runter")
  261.  elseif sz == 2 and ou == "oben" then
  262.   waagerechtGraben("hoch", "gerade")
  263.   myApi.graben("hoch")
  264.  elseif sz == 1 and ou == "unten" then
  265.   waagerechtGraben("runter")
  266.   myApi.graben("runter")
  267.  elseif sz == 1 and ou == "oben" then
  268.   waagerechtGraben("hoch")
  269.   myApi.graben("hoch")
  270.  else
  271.   waagerechtGraben()
  272.   myApi.graben("hoch")
  273.   myApi.graben("runter")
  274.   gemined = gemined + 1
  275.  end
  276.  
  277.  gemined = gemined + 1
  278.  
  279.  if richtung ==  "links" then
  280.   drehen = turtle.turnRight
  281.  elseif richtung == "rechts" then
  282.   drehen = turtle.turnLeft
  283.  end
  284.  
  285.  richtungsWechsel()
  286.  
  287.  drehen()
  288.  if z > 1 then
  289.   myApi.graben()
  290.   gemined = gemined + 1
  291.   turtle.forward()
  292.  end
  293.  drehen()
  294.  
  295.  ausgabe()
  296.  
  297.  if ou == "unten" then
  298.   ou = "oben"
  299.  elseif ou == "oben" then
  300.   ou = "unten"
  301.  end
  302.  
  303.  z = z - 1
  304. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement