Advertisement
Florian86

loch

May 12th, 2015
273
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.40 KB | None | 0 0
  1. function compactInv()
  2.     for checkSlot = 1, 16 do
  3.         if turtle.getItemCount(checkSlot) > 0 then
  4.             turtle.select(checkSlot)
  5.             for testSlot = checkSlot, 16 do
  6.                 if turtle.compareTo(testSlot) then
  7.                     turtle.select(testSlot)
  8.                     turtle.transferTo(checkSlot, turtle.getItemCount(testSlot))
  9.                     turtle.select(checkSlot)
  10.                 end
  11.             end
  12.         end
  13.     end
  14. end
  15.  
  16. function cleanUp()
  17.     for checkSlot = 16, 1, -1 do
  18.         while turtle.getItemCount(checkSlot) > 0 do
  19.             moveSlot = 16
  20.             turtle.select(checkSlot)
  21.             while not turtle.transferTo(moveSlot, turtle.getItemCount(checkSlot)) do
  22.                 moveSlot = moveSlot - 1
  23.             end
  24.             if moveSlot == checkSlot then
  25.                 break
  26.             end
  27.         end
  28.     end
  29. end
  30.  
  31. function sortInv()
  32.     for checkSlot = 16, 1, -1 do
  33.         if turtle.getItemCount(checkSlot) > 0 then
  34.             turtle.select(checkSlot)
  35.             moveSlot = 1
  36.             while not turtle.transferTo(moveSlot, turtle.getItemCount(checkSlot)) do
  37.                 moveSlot = moveSlot + 1
  38.             end
  39.             turtle.select(moveSlot)
  40.             for testSlot = 16, 1, -1 do
  41.                 moveSlot2 = moveSlot
  42.                 if testSlot > moveSlot2 then
  43.                     if turtle.getItemCount(testSlot) > 0 then
  44.                         if turtle.compareTo(testSlot) then
  45.                             turtle.select(testSlot)
  46.                             while not turtle.transferTo(moveSlot2, turtle.getItemCount(testSlot)) do
  47.                                 moveSlot2 = moveSlot2 + 1
  48.                             end
  49.                             turtle.select(moveSlot)
  50.                         end
  51.                     end
  52.                 end
  53.             end
  54.         end
  55.     end
  56. end
  57.  
  58. function Aufraeumen()
  59.   compactInv()
  60.   cleanUp()
  61.   sortInv()
  62. end
  63.  
  64. function SucheItem(VollerItemname)
  65.     for p=1,16 do
  66.         if turtle.getItemCount(p) > 0 then
  67.             turtle.select(p)
  68.             data=turtle.getItemDetail()
  69.             --print("data: ",data)
  70.             --print("data.name: ",data.name)
  71.             --print("VollerItemname: ",VollerItemname)
  72.             --print("Slot: ", p)
  73.             if data ~= false then
  74.                 if data.name == VollerItemname then
  75.                     --print("Hat geklappt")
  76.                     found=true
  77.                     slot=tonumber(p)
  78.                     return slot
  79.                 end
  80.                 if data.name == "minecraft:"..VollerItemname then
  81.                     --print("Hat geklappt")
  82.                     found=true
  83.                     slot=tonumber(p)
  84.                     return slot
  85.                 end
  86.             end
  87.         end
  88.     end
  89.     return false
  90. end
  91.  
  92. function BlockVorTurtle()
  93.     success, data = turtle.inspect()
  94.     if success==true then
  95.       --print("Block name: ", data.name)
  96.       --print("Block metadata: ", data.metadata)
  97.       return data.name
  98.     else
  99.       return false
  100.     end
  101. end
  102.  
  103. function BlockUnterTurtle()
  104.     success, data = turtle.inspectDown()
  105.     if success==true then
  106.       --print("Block name: ", data.name)
  107.       --print("Block metadata: ", data.metadata)
  108.       return data.name
  109.     else
  110.       return false
  111.     end
  112. end
  113.  
  114. function BlockUeberTurtle()
  115.     success, data = turtle.inspectUp()
  116.     if success==true then
  117.       --print("Block name: ", data.name)
  118.       --print("Block metadata: ", data.metadata)
  119.       return data.name
  120.     else
  121.       return false
  122.     end
  123. end
  124.  
  125. function SeheUndMache()
  126.     vort=BlockVorTurtle()
  127.     untert=BlockUnterTurtle()
  128.     uebert=BlockUeberTurtle()
  129.    
  130.     if  vort~= false then
  131.         if vort == "minecraft:lava" then
  132.             EntferneLava("Vor")
  133.         end
  134.     end
  135.    
  136.     if  untert~= false then
  137.         if untert == "minecraft:lava" then
  138.             EntferneLava("Unten")
  139.         end
  140.     end
  141.    
  142.     if uebert~= false then
  143.         if uebert == "minecraft:lava" then
  144.             EntferneLava("Oben")
  145.         end
  146.     end
  147. end
  148.  
  149. function FahreVor()
  150.     SeheUndMache()
  151.     while not turtle.forward() do
  152.         sleep(1)
  153.     end
  154. end
  155.  
  156. function FahreZurueck()
  157.     SeheUndMache()
  158.     while not turtle.back() do
  159.         sleep(1)
  160.     end
  161. end
  162.  
  163. function FahreHoch()
  164.     SeheUndMache()
  165.     while not turtle.up() do
  166.         sleep(1)
  167.     end
  168. end
  169.  
  170. function FahreRunter()
  171.     SeheUndMache()
  172.     while not turtle.down() do
  173.         sleep(1)
  174.     end
  175. end
  176.  
  177. function GrabeVor()
  178.     while turtle.detect()==true do
  179.         turtle.dig()
  180.         os.sleep(0.5)
  181.     end
  182. end
  183.  
  184. function GrabeRunter()
  185.     turtle.digDown()
  186. end
  187.  
  188. function GrabeHoch()
  189.     while turtle.detectUp()==true do
  190.         turtle.digUp()
  191.         os.sleep(0.5)
  192.     end
  193. end
  194.  
  195. function SucheBauMaterial()
  196.     matz={"dirt", "cobblestone", "limestone", "netherrack", "soulsand", "netherbrick"}
  197.     for i=1, #matz do
  198.         test=SucheItem(matz[i])
  199.         if test ~= false then
  200.             if test > 0 and test < 17 then
  201.                 return test
  202.             end
  203.         end
  204.     end
  205.     return false
  206. end
  207.  
  208. function EntferneLava(wo)
  209.     sleep(0.5)
  210.     lavaeimer=SucheItem("lava_bucket")
  211.     if lavaeimer ~= false then
  212.         if lavaeimer > 0 and lavaeimer < 17 then
  213.             turtle.select(lavaeimer)
  214.             turtle.refuel()
  215.         end
  216.     end
  217.    
  218.     eimer=SucheItem("bucket")
  219.     if eimer ~= false then
  220.         if eimer > 0 and eimer < 17 then
  221.             turtle.select(eimer)
  222.             if wo == "Vor" then
  223.                 turtle.place()
  224.             elseif wo == "Oben" then
  225.                 turtle.placeUp()
  226.             elseif wo == "Unten" then
  227.                 turtle.placeDown()
  228.             end
  229.             sleep(0.5)
  230.             lavaeimer=SucheItem("lava_bucket")
  231.             if lavaeimer ~= false then
  232.                 if lavaeimer > 0 and lavaeimer < 17 then
  233.                     turtle.select(lavaeimer)
  234.                     turtle.refuel()
  235.                 end
  236.             end
  237.         end
  238.     else
  239.         materialslot=SucheBauMaterial()
  240.         if materialslot ~= false then
  241.             turtle.select(materialslot)
  242.             if wo == "Vor" then
  243.                 turtle.place()
  244.                 GrabeVor()
  245.             elseif wo == "Oben" then
  246.                 turtle.placeUp()
  247.                 GrabeHoch()
  248.             elseif wo == "Unten" then
  249.                 turtle.placeDown()
  250.                 GrabeRunter()
  251.             end
  252.         end
  253.     end
  254. end
  255.  
  256. function RichtigDrehen(richtung, durchlauf)
  257.     if durchlauf % 2 == 0 then
  258.         if richtung == "links" then
  259.             turtle.turnLeft()
  260.         else
  261.             turtle.turnRight()
  262.         end
  263.     else
  264.         if richtung == "links" then
  265.             turtle.turnRight()
  266.         else
  267.             turtle.turnLeft()
  268.         end
  269.     end
  270. end
  271.  
  272. function IstInvVoll()
  273.     for slot=1,16 do
  274.         if turtle.getItemCount(slot)<1 then
  275.             return false
  276.         end
  277.     end
  278.     return true
  279. end
  280.  
  281. ------------------------------------------------------
  282.  
  283. term.clear()
  284. print("#-----------------------#")
  285. print("# LOCH-BUDDEL-PROGRAMM  #")
  286. print("# Einlegbare nuetzliche #")
  287. print("# Items sind: Eimer und #")
  288. print("# Cobble... KEIN MUSS!  #")
  289. print("#-----------------------#")
  290. print(" ")
  291.  
  292. term.write("Wie breit? ")
  293. a = tonumber(read())
  294. breiteeingabe=a
  295. term.write("Wie weit? ")
  296. b = tonumber(read())
  297. weiteeingabe=b
  298. b = b-1
  299. term.write("Wie tief? ")
  300. c = tonumber(read())
  301. tiefeeingabe=c
  302. c=c+1
  303.  
  304. richtung=false
  305. temp=false
  306. if a>1 then
  307.     while temp == false do
  308.         term.write("Welche Richtung? (l/r) ")
  309.         richtung = read()
  310.         if richtung == "l" then
  311.             richtung = "rechts"
  312.             temp = true
  313.         end
  314.         if richtung == "r" then
  315.             richtung = "links"
  316.             temp = true
  317.         end
  318.     end
  319. else
  320.     richtung="links"
  321. end
  322.  
  323. SeheUndMache()
  324.  
  325. itemzaehler=0
  326. richtungsumkehrer=0
  327.  
  328. for i=1,c do            --c TIEFE
  329.     if i>1 then
  330.         --print("drehen 305")
  331.         RichtigDrehen(richtung, a+richtungsumkehrer)
  332.         GrabeRunter()
  333.         FahreRunter()
  334.     end
  335.     if a % 2 == 0 and i>1 and i % 2 == 0 then
  336.         richtungsumkehrer=1
  337.     else
  338.         richtungsumkehrer=0
  339.     end
  340.     --print("Tiefe i: ",i)
  341.     for k=1,a do        --a BREITE
  342.     --print("Breite a: ",a)
  343.         for m=1,b do    --b WEITE
  344.         --print("Weite b: ",b)
  345.             if turtle.detect()==true then
  346.                 GrabeVor()
  347.                 itemzaehler=itemzaehler+1
  348.             end
  349.             FahreVor()
  350.             if itemzaehler > 8 then
  351.                 if IstInvVoll() == true then
  352.                     Aufraeumen()
  353.                 end
  354.                 itemzaehler=0
  355.             end
  356.         end
  357.        
  358.         --print("drehen 323")
  359.         RichtigDrehen(richtung, k+richtungsumkehrer)
  360.        
  361.         if k < a then  
  362.             if turtle.detect()==true then
  363.                 GrabeVor()
  364.                 itemzaehler=itemzaehler+1
  365.             end
  366.             FahreVor()
  367.             if itemzaehler > 8 then
  368.                 if IstInvVoll() == true then
  369.                     Aufraeumen()
  370.                 end
  371.                 itemzaehler=0
  372.             end
  373.             --print("drehen 336")
  374.             RichtigDrehen(richtung, k+richtungsumkehrer)
  375.         end
  376.     end
  377. end
  378. for i=1,c-1 do
  379.   FahreHoch()
  380. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement