alesandreo

right_branch.lua

May 28th, 2020 (edited)
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.38 KB | None | 0 0
  1. --
  2. -- Created by IntelliJ IDEA.
  3. -- User: amcconaughey
  4. -- Date: 4/3/20
  5. -- Time: 4:07 PM
  6. -- To change this template use File | Settings | File Templates.
  7. --
  8. if not fs.exists("t.lua") then
  9.     shell.run("pastebin get Gg3PGyUn t.lua")
  10. end
  11.  
  12. dofile("t.lua")
  13.  
  14. trunk_length = 27
  15. branch_length = 15
  16. mine_height = 5
  17.  
  18. chest_active = false
  19.  
  20. directionAction = "turnLeft"
  21.  
  22. --flag_whitelist["minecraft:emerald_ore"] = true
  23. --flag_whitelist["minecraft:diamond_ore"] = true
  24.  
  25. function createDropPoint()
  26.     local og_slot = turtle.getSelectedSlot()
  27.     down(false)
  28.     down(false)
  29.     processLavaDown()
  30.     processLava()
  31.     turnLeft(false)
  32.     processLava()
  33.     turnLeft(false)
  34.     processLava()
  35.     turnLeft(false)
  36.     processLava()
  37.     turnLeft(false)
  38.     up(false)
  39.     turtle.select(CHEST_SLOT)
  40.     turtle.placeDown()
  41.     up(false)
  42.     savePosition("active_chest")
  43.     chest_active = true
  44.     turtle.select(og_slot)
  45. end
  46.  
  47. function dumpInventory()
  48.     local og_slot = turtle.getSelectedSlot()
  49.     down(false)
  50.     for slot=1,12 do
  51.         turtle.select(slot)
  52.         if not turtle.dropDown() then
  53.             chest_active = false
  54.             deletePosition("active_chest")
  55.         end
  56.     end
  57.     up(false)
  58.     turtle.select(og_slot)
  59. end
  60.  
  61. function cleanUpInventory()
  62.     while processInventory() do
  63.         if chest_active then
  64.             savePosition("cleanup_resume")
  65.             repeat
  66.                 rewind()
  67.             until (( not chest_active) or comparePositions(turtle_pos, getPosition("active_chest")))
  68.             dumpInventory()
  69.             repeat
  70.                 redo()
  71.             until (comparePositions(turtle_pos, getPosition("cleanup_resume")))
  72.             deletePosition("cleanup_resume")
  73.         else
  74.             createDropPoint()
  75.             dumpInventory()
  76.         end
  77.     end
  78. end
  79.  
  80. function trunk(count, action)
  81.     count = count or 1
  82.     local counter=0
  83.     repeat
  84.         counter = counter+1
  85.         forward()
  86.         down(false)
  87.         processBlockDown()
  88.         doAction(action, false)
  89.         processBlock()
  90.         for i=1,mine_height do
  91.             up(false)
  92.             processBlock()
  93.         end
  94.         processBlockUp()
  95.         for i=1,mine_height do
  96.             down(false)
  97.         end
  98.         processBlockDown()
  99.         undoAction(action, false)
  100.         up(false)
  101.     until (counter >= count)
  102. end
  103.  
  104. function processBranchInventory()
  105.     if processInventory() then
  106.         if getPosition("main_branch_point") then
  107.             savePosition("process_branch_inventory_resume")
  108.             rewindToPosition(getPosition("main_branch_point"))
  109.             cleanUpInventory()
  110.             resumeToPosition(getPosition("process_branch_inventory_resume"))
  111.             deletePosition("process_branch_inventory_resume")
  112.         else
  113.             cleanUpInventory()
  114.         end
  115.     end
  116. end
  117.  
  118. function mineBranch(length, refill)
  119.     length = length or branch_length
  120.     if refill == nil then refill = false end
  121.     savePosition("branch_point")
  122.     for space=1,length do
  123.         mine()
  124.         if space % 4 == 0 then
  125.             processBranchInventory()
  126.         end
  127.         if space % 8 == 4 then
  128.             turnRight(false)
  129.             placeTorchUp()
  130.             turnLeft(false)
  131.             restockFillMaterial()
  132.         elseif space % 8 == 5 then
  133.             cleanUpInventory()
  134.         end
  135.     end
  136.     repeat
  137.         if refill then
  138.             fill()
  139.             fillUp()
  140.             turtle.digDown()
  141.             fillDown()
  142.         end
  143.         rewind(1, false)
  144.     until (comparePositions(turtle_pos, getPosition("branch_point")))
  145.     deletePosition("branch_point")
  146.     return true
  147. end
  148.  
  149. function mineUpperBranch(length, refill)
  150.     if length <= 0 then
  151.         return true
  152.     end
  153.     forward()
  154.     up() -- 13
  155.     up() -- 14
  156.     up() -- 15
  157.     processLevel()
  158.     up() -- 16
  159.     processLevel()
  160.     up() -- 17
  161.     processLevel()
  162.     mineBranch(length, refill)
  163.     rewind(4, false) -- 16 --> 15 --> 14 --> 13
  164.     fillUp()
  165.     rewindToPosition(getPosition("main_branch_point"), false)
  166. end
  167.  
  168. function mineLowerBranch(length, refill)
  169.     if length <= 0 then
  170.         return true
  171.     end
  172.     forward()
  173.     down() -- 11
  174.     down() -- 10
  175.     down() -- 9
  176.     processLevel()
  177.     down() --8
  178.     processLevel()
  179.     down() -- 7
  180.     mineBranch(length, refill)
  181.     rewind(4, false) --8 --> 9 --> 10 --> 11
  182.     fillDown()
  183.     rewindToPosition(getPosition("main_branch_point"), false)
  184. end
  185.  
  186. function mineFullBranch(length, refill)
  187.     mineBranch(length, refill)
  188.     mineUpperBranch(length-1, refill)
  189.     mineLowerBranch(length-1, refill)
  190.     if checkOreFlag() then
  191.         placeTorchDown()
  192.         clearOreFlag()
  193.     end
  194. end
  195.  
  196. function mineApporpriateBranch(length, refill)
  197.     length = length or branch_length
  198.     doAction(directionAction)
  199.     savePosition("main_branch_point")
  200.     mineFullBranch(length, refill)
  201.     rewindToPosition(getPosition("main_branch_point"), false)
  202.     deletePosition("main_branch_point")
  203. end
  204.  
  205. savePosition("start")
  206. createDropPoint()
  207.  
  208.  
  209. repeat
  210.     trunk(3, directionAction)
  211.     if turtle_pos["x"] % 8 == 3 and string.lower(directionAction) == "turnright" then
  212.         turnRight(false)
  213.         placeTorchUp()
  214.         turnLeft(false)
  215.     end
  216.     trunk(1, directionAction)
  217.     mineApporpriateBranch(branch_length, false)
  218.     cleanUpInventory()
  219. until ( turtle_pos["x"] > trunk_length )
Add Comment
Please, Sign In to add comment