gridcaster

autoTurtle.lua

Jun 11th, 2021 (edited)
331
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.53 KB | None | 0 0
  1. --[[
  2.     Program: autoTurtle.loa
  3.     Description: A turtle automation program for farming, mining, and wood harvesting
  4.     GitHub Repository: https://github.com/dwightdurmon/ccTweaked
  5.     Pastbin Command: pastebin get U7TSCfnE autoTurtle
  6.     License: MIT
  7.     Version: 1.0
  8.  
  9.     Command Line Options
  10.     -action [farm,mine,wood]
  11.     -
  12. ]]
  13.  
  14.  
  15.  
  16.  
  17. ---------------------------------------
  18. --           DEFAULTS                --
  19. ---------------------------------------
  20. variables = {
  21.     ["offset"] = {
  22.         ["x"] = 0,
  23.         ["y"] = 0,
  24.         ["z"] = 0,
  25.         ["moves"] = 0
  26.     },
  27.     ["resourceLocation"] = {
  28.         ["fuel"] = 'left',
  29.         ["items"] = 'right',
  30.         ["furnace"] = 'top',
  31.         ["craftingTable"] = 'back',
  32.     },
  33.     ["defaultSlots"] = {
  34.         ["barrier"] = 15,
  35.         ["fuel"] = 16,
  36.     },
  37.     ["miningSlots"] = {
  38.         ['normalTorches'] = 13,
  39.         ['redstoneTorches'] = 14
  40.     },
  41.     ["miningSettings"] = {
  42.         ['mainTunnelWidth'] = 3,
  43.         ['mainTunnelHeight'] = 3,
  44.         ['mainTunnelLength'] = 30,
  45.         ['sideTunnelWidth'] = 3,
  46.         ['sideTunnelHeight'] = 3,
  47.         ['sideTunnelLength'] = 10
  48.     },
  49.     ["farmingSlots"] = {
  50.         ['boneMeal'] = 13,
  51.         ['seeds'] = 14
  52.     },
  53.     ["treeSlots"] = {
  54.         ['seeds'] = 14
  55.     },
  56.     ["treeSettings"] = {
  57.         ['spaceBetweenTrees'] = 2
  58.     },
  59.     ["autoRefuel"] = true,
  60.     ['rednetChannel'] = 4,
  61.     ['isRemoteDisplay'] = false,
  62.     ['stumpCrops'] = {'minecraft:sugar_cane','minecraft:cactus','minecraft:bamboo'}
  63.   }
  64.  
  65.  
  66. ---------------------------------------
  67. --    OS DEFAULTS (Do Not Change)    --
  68. ---------------------------------------
  69. osDefaults = {
  70.     ["turtleScreenSize"] = {
  71.         ["width"] = 51,
  72.         ["height"] = 19,
  73.     },
  74.     ["monitorScreenSize"] = {
  75.         ["width"] = 39,
  76.         ["height"] = 13,
  77.     },
  78.     ['version'] = '1.0'
  79. }
  80.  
  81. ---------------------------------------
  82. --           VARIABLES                --
  83. ---------------------------------------
  84. running=true
  85.  
  86.  
  87. ---------------------------------------
  88. -- BASIC FUNCTIONS FOR TURTLE CONTROL -
  89. ---------------------------------------
  90. local function goForward(n)
  91.     if n==nil then n=1 end
  92.     for i=1,n,1 do while not turtle.forward() do end end
  93.   end
  94.   local function goBack(n)
  95.     if n==nil then n=1 end
  96.     for i=1,n,1 do while not turtle.back() do end end
  97.   end
  98.   local function goUp(n)
  99.     if n==nil then n=1 end
  100.     for i=1,n,1 do while not turtle.up() do end end
  101.   end
  102.   local function goDown(n)
  103.     if n==nil then n=1 end
  104.     for i=1,n,1 do while not turtle.down() do end end
  105.   end
  106.   local function turnLeft(n)
  107.     if n==nil then n=1 end
  108.     for i=1,n,1 do while not turtle.turnLeft() do end end
  109.   end
  110.   local function turnRight(n)
  111.     if n==nil then n=1 end
  112.     for i=1,n,1 do while not turtle.turnRight() do end end
  113.   end
  114.   local function placeForward(n)
  115.     -- moves backwards if n>1
  116.     if n==nil then n=1 end
  117.     for i=1,n,1 do if i~=1 then goBack() end turtle.place() end
  118.   end
  119.   local function placeUp()  turtle.placeUp()    end
  120.   local function placeDown()  turtle.placeDown()  end
  121.   local function digForward()  return turtle.dig() end
  122.   local function digUp()  turtle.digUp()      end
  123.   local function digDown()  turtle.digDown()    end
  124.   local function suckForward()  turtle.suck()       end
  125.   local function suckUp()  turtle.suckUp()     end
  126.   local function suckDown(n)
  127.     if n==nil then
  128.       while turtle.suckDown() do end
  129.     else
  130.       for i=1,n do
  131.         turtle.suckDown()
  132.       end
  133.     end
  134.   end
  135.   local function dropForward()  turtle.drop()      end
  136.   local function dropUp(n) if n==nil then n=64 end turtle.dropUp(n) end
  137.   local function dropDown(n) if n==nil then n=64 end turtle.dropDown(n) end
  138.  
  139. local function termPrint(x,y,text)
  140.     term.setCursorPos(x,y)
  141.     term.write(text)
  142. end
  143.  
  144.  
  145. local function printTestTurtleScreen()
  146.     termPrint(1,1,"         1         2         3         ")
  147.     termPrint(1,2,"123456789012345678901234567890123456789")
  148.  
  149. end
  150.  
  151. local function printSeparator(x,y)
  152.     termPrint(x,y,'+-------------------------------------+')  
  153. end
  154.  
  155. local function printBorder(x,y)
  156.     termPrint(x,y,'+                                     +')
  157. end
  158.  
  159. local function printHeader()
  160.     termPrint(3,2,'AutoTurtle ver. ' .. osDefaults['version'])    
  161. end
  162.  
  163. local function screenTemplate()
  164.     term.clear()
  165.     --                                      SCREEN LOOKS LIKE THIS:
  166.     printSeparator(1,1)   -- line 1   +-------------------------------------+
  167.     printBorder(1,2)      -- line 2   +                                     +
  168.     printSeparator(1,3)   -- line 3   +-------------------------------------+
  169.     printBorder(1,4)      -- line 4   +                                     +
  170.     printBorder(1,5)      -- line 5   +                                     +
  171.     printBorder(1,6)      -- line 6   +                                     +
  172.     printBorder(1,7)      -- line 7   +                                     +
  173.     printBorder(1,8)      -- line 8   +                                     +
  174.     printBorder(1,9)      -- line 9   +                                     +
  175.     printBorder(1,10)     -- line 10  +                                     +
  176.     printBorder(1,11)     -- line 11  +                                     +
  177.     printBorder(1,12)     -- line 12  +                                     +
  178.     printSeparator(1,13)  -- line 13  +-------------------------------------+
  179. end
  180.  
  181. local function printKeyPress()
  182.     local event, key, is_held = os.pullEvent("key")
  183.     termPrint(3,4,'Key: ' .. ("%s held=%s"):format(keys.getName(key), is_held))
  184. end
  185.  
  186. local function getKey()
  187.     local event, key, is_held = os.pullEvent("key")
  188.     return keys.getName(key)
  189. end
  190.  
  191. local function keyTest ()
  192.     while true do
  193.         screenTemplate()
  194.         printHeader()
  195.         printKeyPress()
  196.         sleep(1)
  197.     end
  198. end
  199.  
  200. local function setupScreen1()
  201.     -- Lets find out the task
  202.     screenTemplate()
  203.     printHeader()
  204.     printSeparator(1,11)  -- line 13  +-------------------------------------+
  205.     termPrint(3,4,'Select a task from the items below:')
  206.     keyPressed = getKey()
  207.     while true do
  208.         if keyPressed == 'space' then
  209.             running=false
  210.         end        
  211.     end
  212.     termPrint(3,12,'Press <space> to continue')
  213.    
  214. end
  215.  
  216.  
  217.  
  218. --[[
  219. Main Function Loop
  220. ]]--
  221. function main()
  222.     printTestTurtleScreen()
  223.     sleep(2)
  224.  
  225.     while running do
  226.         setupScreen1()        
  227.     end
  228. end
  229.  
  230. --[[
  231.     Run the program!
  232. ]]--
  233. main()
Add Comment
Please, Sign In to add comment