Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[ Simple Flint Farming Bot
- This program will process all gravel blocks in its inventory in to flint.
- --]]
- -- Clear the terminal, write startup message
- term.clear()
- term.setCursorPos(1, 1)
- print ("Starting gravel program.")
- -- Variable and function declarations
- -- Main loop control variable
- local running = true
- -- A function that cycles through the entire inventory to select any gravel we still have. If none is found, ends the main loop
- local function select_gravel()
- -- For each of the 16 inventory spaces
- for slot = 1, 16, 1 do
- -- if there is an item in that slot
- if turtle.getItemCount(slot) > 0 then
- -- if that item is a stack of gravel
- if turtle.getItemDetail(slot).name == "minecraft:gravel" then
- -- Select that slot
- turtle.select(slot)
- -- Break out of the for loop to stop selecting
- break
- end
- end
- -- If we made it this far, and we are on the last inventory spot, we are out of gravel
- if slot == 16 then
- -- End the main loop
- running = false
- print("Out of gravel, ending the program.")
- end
- end
- end
- -- Start of main program loop
- -- Make sure we are selecting a stack of gravel
- select_gravel()
- -- Main Loop
- while running do
- -- Detect if there is a block in front of us
- local has_block, block = turtle.inspect()
- -- If there is a block in front of us
- if has_block then
- -- If that block is a piece of gravel
- if block.name == "minecraft:gravel" then
- -- Dig it baby
- turtle.dig()
- else
- -- If we have anything other than gravel, end the program without digging
- running = false
- print("Block other than gravel detected, ending the program.")
- end
- else -- No Block in front of us, attempt to place a piece of gravel
- -- If we have an item in the selected inventory slot and that item is gravel
- if turtle.getItemCount(turtle.getSelectedSlot()) > 0 and turtle.getItemDetail(turtle.getSelectedSlot()).name == "minecraft:gravel" then
- -- Place the piece of gravel in front of us
- turtle.place()
- else -- Else the selected inventory slot is empty or does not contain gravel
- -- Search the inventory for more gravel
- select_gravel()
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement