Keystyles

Turtle - hb

Dec 28th, 2017
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.16 KB | None | 0 0
  1. --House Builder V0.1
  2. --17 Dec 28
  3. --  pastebin get vpsS85Bu hb
  4. --  delete hb
  5. --************
  6. --
  7. --Written by : Keystyles
  8. --************
  9.  
  10.  
  11. --************
  12. --Constants/Initialization
  13. --************
  14.  
  15. ----Orientation (start location = 0,0,0)
  16. local currX = 0
  17. local currY = 0
  18. local currZ = 0
  19.  
  20. local width = 15
  21.  
  22. --***********
  23. --Functions
  24. --***********
  25.  
  26. function checkJunk(name) --check the data from the inspect and return true if it's junk; add "--" before both lines to remove an entry
  27.     if name == "minecraft:stone" then
  28.         return false
  29.     elseif name == "minecraft:cobblestone" then
  30.         return false
  31.     elseif name == "minecraft:gravel" then
  32.         return false
  33.     elseif name == "minecraft:dirt" then
  34.         return false
  35.     elseif name == "minecraft:water" then
  36.         return false
  37.     elseif name == "minecraft:red_mushroom" then
  38.         return false
  39.     --elseif name == "minecraft:redstone_ore" then
  40.     --  return false
  41.     --elseif name == "minecraft:coal_ore" then
  42.     --  return false
  43.     elseif name == "ProjRed:Exploration:projectred.exploration.stone" then --Marble, need to find correct name*
  44.         return false
  45.     elseif name == "minecraft:sand" then
  46.         return false
  47.     elseif name == "minecraft:netherrack" then
  48.         return false
  49.     elseif name == "Botania:stone" then --this is all Botania stones; diorite, granite, etc
  50.         return false
  51.     elseif name == "Botania:mushroom" then  --this is all Botania stones; diorite, granite, etc
  52.         return false
  53.     elseif name == "chisel:limestone" then
  54.         return false
  55.     elseif name == "chisel:andesite" then
  56.         return false
  57.     elseif name == "chisel:diorite" then
  58.         return false
  59.     elseif name == "chisel:granite" then
  60.         return false
  61.     elseif name == "chisel:marble" then
  62.         return false
  63.     elseif name == "BiomesOPlenty:flowers" then
  64.         return false
  65.     elseif name == "BiomesOPlenty:flowers2" then
  66.         return false
  67.     else
  68.         return true
  69.     end
  70. end
  71.  
  72. function turtleUp()
  73.     x = turtle.up()
  74.     while x == false do
  75.         if turtle.digUp() then
  76.         x = turtle.up()
  77.         else
  78.             if turtle.inspectUp() then
  79.                 if turtle.digUp() then
  80.                     x=turtle.up()
  81.                 else
  82.                     return false
  83.                 end
  84.             else
  85.                 turtle.attackUp()
  86.                 x = turtle.up()
  87.             end
  88.         end
  89.     end
  90.     return true
  91. end
  92.  
  93. function turtleDown()
  94.     x = turtle.down()
  95.     while x == false do
  96.         if turtle.digDown() then
  97.             x = turtle.down()
  98.         else
  99.             if turtle.inspectDown() then
  100.                 if turtle.digDown() then
  101.                     x=turtle.down()
  102.                 else
  103.                     return false
  104.                 end
  105.             else
  106.                 turtle.attackDown()
  107.                 x = turtle.down()
  108.             end
  109.         end
  110.     end
  111.     return true
  112. end
  113.  
  114. function turtleForward()
  115.     x = turtle.forward()
  116.     while x == false do
  117.         if turtle.dig() then
  118.         x = turtle.forward()
  119.         else
  120.             if turtle.inspect() then
  121.                 if turtle.dig() then
  122.                     x=turtle.forward()
  123.                 else
  124.                     return false
  125.                 end
  126.             else
  127.                 turtle.attack()
  128.                 x = turtle.forward()
  129.             end
  130.         end
  131.     end
  132.     return true
  133. end
  134.  
  135. function checkMining()
  136.     --Check down first, dig if necessary
  137.     local success, data = turtle.inspectDown()
  138.     if success then
  139.         if checkJunk(data.name) then
  140.             if data.name == "minecraft:flowing_lava" then
  141.                 turtle.select(1)
  142.                 turtle.placeDown()
  143.                 turtle.refuel()
  144.             else
  145.                 turtle.digDown()
  146.             end
  147.         end
  148.     end
  149.     --Check up second, ...
  150.     local success, data = turtle.inspectUp()
  151.     if success then
  152.         if checkJunk(data.name) then
  153.             if data.name == "minecraft:flowing_lava" then
  154.                 turtle.select(1)
  155.                 turtle.placeUp()
  156.                 turtle.refuel()
  157.             else
  158.                 turtle.digUp()
  159.             end
  160.         end
  161.     end
  162. end
  163.  
  164. function stripMining()
  165.     --Check down first, dig if necessary
  166.     local success, data = turtle.inspectDown()
  167.     if success then
  168.         if data.name == "minecraft:flowing_lava" then
  169.             turtle.select(1)
  170.             turtle.placeDown()
  171.             turtle.refuel()
  172.         else
  173.             turtle.digDown()   
  174.         end
  175.     end
  176.     --Check up second, ...
  177.     local success, data = turtle.inspectUp()
  178.     if success then
  179.         if data.name == "minecraft:flowing_lava" then
  180.             turtle.select(1)
  181.             turtle.placeUp()
  182.             turtle.refuel()
  183.         else
  184.             turtle.digUp()
  185.         end
  186.     end
  187. end
  188.  
  189. function inventoryClear()
  190.     for i=2, 16 do
  191.         turtle.select(i)
  192.     local data = turtle.getItemDetail()
  193.         if data then
  194.             if checkJunk(data.name) == false then
  195.                 turtle.drop()
  196.         end
  197.         end
  198.     end
  199.     turtle.select(1)
  200. end
  201.  
  202. function inventoryFull()
  203.     local count = 0
  204.     for i = 1,16 do
  205.         if turtle.getItemCount(i) > 0 then
  206.             count = count + 1
  207.         end
  208.     end
  209.     if count > 8 then
  210.         return true
  211.     else
  212.         return false
  213.     end
  214. end
  215.  
  216. function inventoryUnload()
  217.     for i = 2, 16 do
  218.         turtle.select(i)
  219.         turtle.dropUp()
  220.     end
  221. end
  222.  
  223. --************
  224. --Main Loop
  225. --************
  226.  
  227. ----Fuel
  228. turtle.select(1)
  229. turtle.refuel()
  230. turtle.select(2)
  231. turtle.refuel()
  232. print(turtle.getFuelLevel())
  233.  
  234. ----Move down
  235.  
  236. for i = 1, 3 do
  237.     turtleDown()
  238.     currY = currY - 1
  239. end
  240.  
  241.  
  242. ----Mining Loop
  243. inventoryClear()
  244. while currY > -8 do  --While you are in an acceptable mining range
  245.    
  246.     for i = 1, width do     --Mine one leg
  247.         turtleForward()
  248.         stripMining()
  249.     end
  250.    
  251.     inventoryClear()
  252.     turtle.turnRight()      --Move right one
  253.     turtleForward()
  254.     currX = currX + 1
  255.     stripMining()
  256.     turtle.turnRight()
  257.    
  258.     for i = 1, width do     --Mine return leg
  259.         turtleForward()
  260.         stripMining()
  261.     end
  262.    
  263.     if currX < width then   --Move left one
  264.         inventoryClear()
  265.         turtle.turnLeft()
  266.         turtleForward()
  267.         currX = currX + 1
  268.         stripMining()
  269.         turtle.turnLeft()
  270.     else                    --or return to 0,0 if complete
  271.         turtle.turnRight()
  272.         repeat
  273.         turtleForward()
  274.         currX = currX - 1
  275.         until currX == 0
  276.         turtle.turnRight()
  277.        
  278.         inventoryClear()    --Dump junk
  279.        
  280.         if inventoryFull() then     --Return to starting level and empty cargo if necessary
  281.             y = currY
  282.             print(y)
  283.             print(turtle.getFuelLevel())
  284.             while currY < 0 do
  285.                 turtleUp()
  286.                 currY = currY + 1
  287.             end
  288.             inventoryUnload()
  289.             while currY > y do
  290.                 turtleDown()
  291.                 currY = currY - 1
  292.             end
  293.         end
  294.        
  295.         for i = 1, 3 do     --Move down three levels
  296.             turtleDown()
  297.             currY = currY - 1
  298.         end
  299.        
  300.     end
  301. end
  302.  
  303. inventoryClear()    --Dump junk
  304. while currY < 0 do
  305.     turtleUp()
  306.     currY = currY + 1
  307. end
  308. inventoryUnload()
  309. --************
  310. --Rev history
  311. --************
  312. --  v0.1 - initial posting
  313. --  v0.2 - fixed MANY issues, added inital fueling from slot2, increased inventoryClear frequency, added junk items, etc, etc, etc,
Add Comment
Please, Sign In to add comment