Advertisement
Blackhome

BucketLavaCollector

Jan 10th, 2025 (edited)
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.54 KB | Gaming | 0 0
  1.  
  2. local move = require("move")
  3. local inspect = require("inspect")
  4. local collectLava = require("collectLava")
  5.  
  6.  
  7.  
  8. function saveData(fileName, data)
  9.     local file = fs.open(fileName, "w") -- Datei im Schreibmodus öffnen
  10.     if file then
  11.         file.write(textutils.serialize(data)) -- Tabelle in die Datei schreiben
  12.         file.close()
  13.         print("Daten gespeichert in:", fileName)
  14.     else
  15.         print("Fehler beim Speichern der Daten.")
  16.     end
  17. end
  18.  
  19. function loadData(fileName)
  20.     if fs.exists(fileName) then
  21.         local file = fs.open(fileName, "r") -- Datei im Lesemodus öffnen
  22.         if file then
  23.             local content = file.readAll()
  24.             file.close()
  25.             return textutils.unserialize(content) -- String in Tabelle umwandeln
  26.         end
  27.     else
  28.         print("Datei nicht gefunden:", fileName)
  29.     end
  30.     return nil -- Standardwert, wenn Datei nicht existiert
  31. end
  32.  
  33. local function selectBucket()
  34.     for i=1, 16, 1 do
  35.         local count = turtle.getItemCount(i)
  36.         if count > 0 then
  37.             turtle.select(i)
  38.             local itemDetail = turtle.getItemDetail()
  39.             if itemDetail then
  40.                 if itemDetail.name == "minecraft:bucket" then
  41.                     return true
  42.                 end
  43.             end
  44.         end
  45.     end
  46.     return false
  47. end
  48.  
  49. local function moreEmpty()
  50.     for i=1, 16, 1 do
  51.         local count = turtle.getItemCount(i)
  52.         if count == 0 then
  53.             return true
  54.         end
  55.     end
  56.     return false
  57. end
  58.  
  59. local function tryOffloadItems()
  60.     local bChest = inspect.Forward({"minecraft:chest"})
  61.     if not bChest then
  62.         return
  63.     end
  64.     for i=1, 16, 1 do
  65.         local numItems = turtle.getItemCount(i)
  66.         if numItems > 0 then
  67.             turtle.select(i)
  68.             local itemDetail = turtle.getItemDetail()
  69.  
  70.             if itemDetail then
  71.                 if not (itemDetail.name == "minecraft:bucket") then
  72.                     turtle.drop()
  73.                 end
  74.             end
  75.         end
  76.     end
  77. end
  78.  
  79. function LavaTilBottom()
  80.     local cnt = 0
  81.     local bFull = false
  82.     while not turtle.detectDown() do
  83.         if not moreEmpty() then
  84.             if selectBucket() then
  85.                 if not (turtle.getItemCount(turtle.getSelectedSlot()) == 1) then
  86.                     bFull = true
  87.                     break
  88.                 end
  89.             else
  90.                 bFull = true
  91.                 break
  92.             end
  93.         end
  94.  
  95.         if selectBucket() then
  96.             turtle.placeDown()
  97.             move.Down()
  98.             cnt = cnt + 1
  99.         else
  100.             bFull = true
  101.             break
  102.         end
  103.     end
  104.  
  105.     while cnt > 0 do
  106.         move.Up()
  107.         cnt = cnt - 1
  108.     end
  109.     return bFull
  110. end
  111.  
  112. local maxDistance = 28
  113. local cnt = 0
  114. local loadedData = loadData("lastPosition.txt")
  115. if loadedData then
  116.     while cnt < tonumber(loadedData.lastPosition) do
  117.         turtle.forward()
  118.         cnt = cnt + 1
  119.     end
  120. end
  121. local bFinishedLine = false
  122.  
  123. while (not LavaTilBottom()) and maxDistance > cnt do
  124.     if turtle.forward() then
  125.         cnt = cnt + 1
  126.     else
  127.         local dataToSave = { lastPosition = 0 }
  128.         saveData("lastPosition.txt", dataToSave)
  129.         break
  130.     end
  131. end
  132. if not bFinishedLine then
  133.     local dataToSave = { lastPosition = cnt }
  134.     saveData("lastPosition.txt", dataToSave)
  135. end
  136.  
  137. turtle.turnLeft()
  138. turtle.turnLeft()
  139.  
  140. while cnt > 0 do
  141.     turtle.forward()
  142.     cnt = cnt - 1
  143. end
  144.  
  145. tryOffloadItems()
  146. turtle.turnLeft()
  147. turtle.turnLeft()
  148.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement