Advertisement
Blackhome

collectLava

Jan 6th, 2025 (edited)
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.74 KB | None | 0 0
  1. bucketList = {"minecraft:bucket", "minecraft:lava_bucket"}
  2.  
  3. -- selects slot with bucket
  4. local function selectBucket()
  5.     local item = turtle.getItemDetail()
  6.     if item then
  7.         if (item.name == bucketList[1]) then
  8.             return true
  9.         end
  10.         if (item.name == bucketList[2]) then
  11.             return true
  12.         end
  13.     end
  14.  
  15.     for i=1, 16, 1 do
  16.         turtle.select(i)
  17.         item = turtle.getItemDetail()
  18.         if item then
  19.             if (item.name == bucketList[1]) then
  20.                 return true
  21.             end
  22.             if (item.name == bucketList[2]) then
  23.                 return true
  24.             end
  25.         end
  26.     end
  27.     return false
  28. end
  29.  
  30. --Returns bool bFullTank and bBucketIsEmpty (if fuel is maximum and if bucket contains nothing)
  31. local function getBucketAndFuelData()
  32.     local fuelLevel = turtle.getFuelLevel()
  33.     local maxFuelLevel = turtle.getFuelLimit()
  34.     local bFullTank = (fuelLevel == maxFuelLevel)
  35.  
  36.     local bBucketIsEmpty = true
  37.     local item = turtle.getItemDetail()
  38.  
  39.     if item then
  40.         if (item.name == bucketList[1]) then
  41.             bBucketIsEmpty = true
  42.         end
  43.         if (item.name == bucketList[2]) then
  44.             bBucketIsEmpty = false
  45.         end
  46.     end
  47.     return bFullTank, bBucketIsEmpty
  48. end
  49.  
  50. --collects lava in this direction (tries to use it)
  51. local function Front(lavaCnt)
  52.     local bFullTank, bEmptyBucket = getBucketAndFuelData()
  53.     local bRefueld = false
  54.  
  55.     if bEmptyBucket then
  56.         turtle.place()
  57.     end
  58.     if not bFullTank then
  59.         turtle.refuel()
  60.         bRefueld = true
  61.     end
  62.     if not bEmptyBucket then
  63.         turtle.place()
  64.         if not bRefueld then
  65.             turtle.place()
  66.         end
  67.     end
  68.     lavaCnt[1] = lavaCnt[1] + 1
  69. end
  70.  
  71. local function Top(lavaCnt)
  72.     local bFullTank, bEmptyBucket = getBucketAndFuelData()
  73.     local bRefueld = false
  74.  
  75.     if bEmptyBucket then
  76.         turtle.placeUp()
  77.     end
  78.     if not bFullTank then
  79.         turtle.refuel()
  80.         bRefueld = true
  81.     end
  82.     if not bEmptyBucket then
  83.         turtle.placeUp()
  84.         if not bRefueld then
  85.             turtle.placeUp()
  86.         end
  87.     end
  88.     lavaCnt[1] = lavaCnt[1] + 1
  89. end
  90.  
  91. local function Bottom(lavaCnt)
  92.     local bFullTank, bEmptyBucket = getBucketAndFuelData()
  93.     local bRefueld = false
  94.  
  95.     if bEmptyBucket then
  96.         turtle.placeDown()
  97.     end
  98.     if not bFullTank then
  99.         turtle.refuel()
  100.         bRefueld = true
  101.     end
  102.     if not bEmptyBucket then
  103.         turtle.placeDown()
  104.         if not bRefueld then
  105.             turtle.placeDown()
  106.         end
  107.     end
  108.     lavaCnt[1] = lavaCnt[1] + 1
  109. end
  110.  
  111. return { selectBucket = selectBucket, Front = Front, Top = Top, Bottom = Bottom}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement