Advertisement
Florian86

lochchest

May 24th, 2015
293
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 8.25 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. function truhesetzen()
  283.     truhe=SucheItem("IronChest:BlockIronChest")
  284.     print("MUESSTE STOPPEN...")
  285.     if truhe == false then
  286.         truhe=SucheItem("minecraft:chest")
  287.     end
  288.    
  289.     if truhe ~= false then
  290.         turtle.select(truhe)
  291.         turtle.turnLeft()
  292.         turtle.turnLeft()
  293.         turtle.place()
  294.         for i=1,16 do
  295.             turtle.select(i)
  296.             local data = turtle.getItemDetail(i)
  297.             if data then
  298.               print("Item name ",i," :", data.name)
  299.               --print("Item damage value: ", data.damage)
  300.               --print("Item count: ", data.count)
  301.               if data.name ~= "IronChest:BlockIronChest" and  data.name ~= "minecraft:bucket" and  data.name ~= "minecraft:chest" then
  302.                 turtle.drop()
  303.               end
  304.             end
  305.         end
  306.         turtle.turnLeft()
  307.         turtle.turnLeft()
  308.     else
  309.     print("KEINE TRUHE GEFUNDEN!")
  310.     end
  311. end
  312.  
  313. ------------------------------------------------------
  314.  
  315. term.clear()
  316. print("#-----------------------#")
  317. print("# LOCH-BUDDEL-PROGRAMM  #")
  318. print("# Einlegbare nuetzliche #")
  319. print("# Items sind: Eimer und #")
  320. print("# Cobble... KEIN MUSS!  #")
  321. print("#-----------------------#")
  322. print(" ")
  323.  
  324. term.write("Wie breit? ")
  325. a = tonumber(read())
  326. breiteeingabe=a
  327. term.write("Wie weit? ")
  328. b = tonumber(read())
  329. weiteeingabe=b
  330. b = b-1
  331. term.write("Wie tief? ")
  332. c = tonumber(read())
  333. tiefeeingabe=c
  334. c=c+1
  335.  
  336. richtung=false
  337. temp=false
  338. if a>1 then
  339.     while temp == false do
  340.         term.write("Welche Richtung? (l/r) ")
  341.         richtung = read()
  342.         if richtung == "l" then
  343.             richtung = "rechts"
  344.             temp = true
  345.         end
  346.         if richtung == "r" then
  347.             richtung = "links"
  348.             temp = true
  349.         end
  350.     end
  351. else
  352.     richtung="links"
  353. end
  354.  
  355. SeheUndMache()
  356.  
  357. itemzaehler=0
  358. richtungsumkehrer=0
  359.  
  360. for i=1,c do            --c TIEFE
  361.     if i>1 then
  362.         --print("drehen 305")
  363.         RichtigDrehen(richtung, a+richtungsumkehrer)
  364.         GrabeRunter()
  365.         FahreRunter()
  366.     end
  367.     if a % 2 == 0 and i>1 and i % 2 == 0 then
  368.         richtungsumkehrer=1
  369.     else
  370.         richtungsumkehrer=0
  371.     end
  372.     --print("Tiefe i: ",i)
  373.     for k=1,a do        --a BREITE
  374.     --print("Breite a: ",a)
  375.         for m=1,b do    --b WEITE
  376.         --print("Weite b: ",b)
  377.             if turtle.detect()==true then
  378.                 GrabeVor()
  379.                 itemzaehler=itemzaehler+1
  380.             end
  381.             FahreVor()
  382.             if itemzaehler > 8 then
  383.                 if IstInvVoll() == true then
  384.                     --Aufraeumen()
  385.                     truhesetzen()
  386.                 end
  387.                 itemzaehler=0
  388.             end
  389.         end
  390.        
  391.         --print("drehen 323")
  392.         RichtigDrehen(richtung, k+richtungsumkehrer)
  393.        
  394.         if k < a then  
  395.             if turtle.detect()==true then
  396.                 GrabeVor()
  397.                 itemzaehler=itemzaehler+1
  398.             end
  399.             FahreVor()
  400.             if itemzaehler > 8 then
  401.                 if IstInvVoll() == true then
  402.                     --Aufraeumen()
  403.                     --if IstInvVoll() == true then
  404.                     truhesetzen()
  405.                     --end
  406.                 end
  407.                 itemzaehler=0
  408.             end
  409.             --print("drehen 336")
  410.             RichtigDrehen(richtung, k+richtungsumkehrer)
  411.         end
  412.     end
  413. end
  414. for i=1,c-1 do
  415.   FahreHoch()
  416. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement