Advertisement
feline-dis

Untitled

Dec 24th, 2020 (edited)
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.70 KB | None | 0 0
  1. local slotCount = 16
  2. local width = 25
  3. local length = 25
  4. local height = 3
  5.  
  6. if (arg[1] ~= nil) then
  7.     width = arg[1]
  8.     length = arg[1]
  9. end
  10.  
  11. local trash = {
  12.     "minecraft:cobblestone", "minecraft:stone", "minecraft:andesite",
  13.     "minecraft:diorite", "minecraft:clay_ball", "minecraft:sand",
  14.     "minecraft:sandstone", "minecraft:limestone", "minecraft:dirt",
  15.     "quark:limestone", "minecraft:flint", "rustic:slate", "chisel:limestone2",
  16.     "chisel:limestone", "minecraft:gravel", "minecraft:redstone",
  17.     "minecraft:torch"
  18. }
  19.  
  20. function checkFuel()
  21.     print('Checking fuel...')
  22.     local refueled = false
  23.     if (turtle.getFuelLevel() < 3000) then
  24.         for slot = 1, slotCount, 1 do
  25.             local item = turtle.getItemDetail(slot)
  26.             if (item ~= nil) then
  27.                 if (item.name == "minecraft:coal" or item.name ==
  28.                     "minecraft:coal_block") then
  29.                     print('Attemping to refuel with %d', item.name)
  30.  
  31.                     turtle.select(slot)
  32.  
  33.                     local result = turtle.refuel()
  34.  
  35.                     refueled = true
  36.                     print('Turtle refueled...')
  37.  
  38.                     break
  39.                 end
  40.             end
  41.         end
  42.         if (refueled == false) then
  43.             print('Did not find coal in inventory.. going to power down soon D:')
  44.         end
  45.         return false
  46.     end
  47. end
  48.  
  49. function stackItems()
  50.     local inventory = {}
  51.  
  52.     for slot = 1, slotCount, 1 do
  53.         local item = turtle.getItemDetail(slot)
  54.  
  55.         for invSlot = 1, slotCount, 1 do
  56.             local checking = turtle.getItemDetail(invSlot)
  57.             if (checking ~= nil) then print(checking.name) end
  58.         end
  59.     end
  60.  
  61. end
  62.  
  63. function flip()
  64.     turtle.turnLeft()
  65.     turtle.turnLeft()
  66. end
  67.  
  68. function emptyToChest()
  69.     for slot = 1, slotCount, 1 do
  70.         local item = turtle.getItemDetail(slot)
  71.  
  72.         if (item ~= nil) then
  73.             if (item.name == "minecraft:oak_chest") then
  74.                 turtle.select(slot)
  75.                 turtle.placeUp()
  76.                 print('chest placed')
  77.             end
  78.         end
  79.     end
  80.  
  81.     for itemSlot = 1, slotCount, 1 do
  82.         local item = turtle.getItemDetail(itemSlot)
  83.  
  84.         if (item ~= nil) then
  85.             if (item.name ~= "minecraft:coal" or item.name ==
  86.                 "minecraft:coal_block" or item.name == "minecraft:oak_chest") then
  87.                 turtle.select(itemSlot)
  88.                 turtle.dropUp()
  89.             end
  90.  
  91.         end
  92.     end
  93. end
  94.  
  95. function checkIfFullInventory()
  96.     local emptySlot = true
  97.     for slot = 1, slotCount, 1 do
  98.         local item = turtle.getItemDetail(slot)
  99.  
  100.         if (item == nil) then emptySlot = false end
  101.     end
  102.  
  103.     if (emptySlot == false) then return true end
  104.  
  105.     return false
  106. end
  107.  
  108. function manageInventory()
  109.     purgeTrash()
  110.     if (checkIfFullInventory() == true) then emptyToChest() end
  111. end
  112.  
  113. function digColumn()
  114.     turtle.dig()
  115.     turtle.forward()
  116.     turtle.digUp()
  117.     turtle.digDown()
  118. end
  119.  
  120. function purgeTrash()
  121.     for slot = 1, slotCount, 1 do
  122.         local item = turtle.getItemDetail(slot)
  123.  
  124.         if (item ~= nil) then
  125.             for key, value in pairs(trash) do
  126.                 if (value == item.name) then
  127.                     print("found trash:", item.name)
  128.                     print('trash in slot:', slot)
  129.                     turtle.select(slot)
  130.                     turtle.drop()
  131.                     break
  132.                 end
  133.             end
  134.         end
  135.  
  136.     end
  137. end
  138.  
  139. function turnAround(dir)
  140.     print("turning around...")
  141.     if dir == "right" then turtle.turnRight() end
  142.     if dir == "left" then turtle.turnLeft() end
  143.  
  144.     digColumn()
  145.  
  146.     if dir == "right" then turtle.turnRight() end
  147.     if dir == "left" then turtle.turnLeft() end
  148. end
  149.  
  150. function checkIfGravel()
  151.     local success, item = turtle.inspect()
  152.  
  153.     if (success) then
  154.         print(item.name)
  155.         if (item.name == "minecraft:gravel") then return true end
  156.     end
  157.     return false
  158. end
  159.  
  160. function digBlock()
  161.     while turtle.detect() == false do turtle.forward() end
  162.     for row = 1, width, 1 do
  163.         for col = 1, length, 1 do
  164.             checkFuel()
  165.             digColumn()
  166.             if (checkIfGravel() == true) then
  167.                 print("found gravel, extending col")
  168.                 length = length + 1
  169.             end
  170.             print("col:", col)
  171.             print("length:", length)
  172.             if (col == length) then
  173.                 print('i should probably turn around')
  174.             end
  175.         end
  176.         purgeTrash()
  177.         if row % 2 == 1 then turnAround("right") end
  178.         if row % 2 == 0 then turnAround("left") end
  179.     end
  180. end
  181.  
  182. digBlock()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement