Advertisement
Jfqs6m

Computercraft Flint Farming Bot

Oct 1st, 2022 (edited)
311
1
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.56 KB | Source Code | 1 0
  1. --[[            Simple Flint Farming Bot
  2.  
  3.     This program will process all gravel blocks in its inventory in to flint.
  4.  
  5. --]]
  6.  
  7. -- Clear the terminal, write startup message
  8. term.clear()
  9. term.setCursorPos(1, 1)
  10. print ("Starting gravel program.")
  11.  
  12.  
  13.  
  14. --                  Variable and function declarations
  15.  
  16. -- Main loop control variable
  17. local running = true
  18.  
  19. -- A function that cycles through the entire inventory to select any gravel we still have. If none is found, ends the main loop
  20. local function select_gravel()
  21.    
  22.     -- For each of the 16 inventory spaces
  23.     for slot = 1, 16, 1 do
  24.  
  25.         -- if there is an item in that slot
  26.         if turtle.getItemCount(slot) > 0 then
  27.  
  28.             -- if that item is a stack of gravel
  29.             if turtle.getItemDetail(slot).name == "minecraft:gravel" then
  30.  
  31.                 -- Select that slot
  32.                 turtle.select(slot)
  33.  
  34.                 -- Break out of the for loop to stop selecting
  35.                 break
  36.             end
  37.         end
  38.        
  39.         -- If we made it this far, and we are on the last inventory spot, we are out of gravel
  40.         if slot == 16 then
  41.  
  42.             -- End the main loop
  43.             running = false
  44.  
  45.             print("Out of gravel, ending the program.")
  46.  
  47.         end
  48.     end
  49. end
  50.  
  51.  
  52.  
  53. --                  Start of main program loop
  54.  
  55. -- Make sure we are selecting a stack of gravel
  56. select_gravel()
  57.  
  58. -- Main Loop
  59. while running do
  60.  
  61.     -- Detect if there is a block in front of us
  62.     local has_block, block = turtle.inspect()
  63.  
  64.     -- If there is a block in front of us
  65.     if has_block then
  66.  
  67.         -- If that block is a piece of gravel
  68.         if block.name == "minecraft:gravel" then
  69.  
  70.             -- Dig it baby
  71.             turtle.dig()
  72.        
  73.         else
  74.  
  75.             -- If we have anything other than gravel, end the program without digging
  76.             running = false
  77.  
  78.             print("Block other than gravel detected, ending the program.")
  79.  
  80.         end
  81.  
  82.     else -- No Block in front of us, attempt to place a piece of gravel
  83.  
  84.         -- If we have an item in the selected inventory slot and that item is gravel
  85.         if turtle.getItemCount(turtle.getSelectedSlot()) > 0 and turtle.getItemDetail(turtle.getSelectedSlot()).name == "minecraft:gravel" then
  86.  
  87.             -- Place the piece of gravel in front of us
  88.             turtle.place()
  89.  
  90.         else -- Else the selected inventory slot is empty or does not contain gravel
  91.  
  92.             -- Search the inventory for more gravel
  93.             select_gravel()
  94.  
  95.         end
  96.     end
  97. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement