Arphahat

BloodAltar_bot_v4

Feb 5th, 2024 (edited)
1,007
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.88 KB | Gaming | 0 0
  1. input_slot = 1      -- location in inventory that the turtle uses to grab an item to place
  2. additional_input_slot = 5 -- location in inventory of the second input to be used when the first is empty
  3. checking_slot = 15  -- locaiton in inventory that the turtle sucks an item to check if it is complete
  4. target_slot = 16    -- location in inventory that the turtle compares an item against to see if it is complete
  5. output_slot = 2     -- location in inventory that the final output is placed
  6. error_slot = 3      -- location in inventory that the final output is placed if output_slot is full of something else
  7.  
  8. function IsDone()
  9.     local done = false
  10.     if turtle.getItemCount(target_slot) > 0 then -- only compares to target_slot if something in target_slot
  11.         turtle.select(checking_slot)
  12.         turtle.suck()
  13.         if turtle.compareTo(target_slot) then -- compare the new item to the target item
  14.             -- items match, we're done
  15.             turtle.transferTo(output_slot) -- move to final location
  16.             done = true
  17.         else
  18.             -- not done, put it back in and continue
  19.             turtle.drop()          
  20.         end
  21.     else
  22.         turtle.select(output_slot)
  23.         turtle.suck()
  24.         done = true
  25.     end
  26.     return done
  27. end
  28.  
  29. -- main program
  30. local current_input_slot = input_slot
  31. turtle.select(current_input_slot)
  32. if turtle.getItemCount(current_input_slot) > 0 then
  33.     turtle.drop(1)
  34.     while true do
  35.         local lamp = rs.getAnalogInput("front")
  36.         if lamp == 15 then -- only check when done is triggered
  37.             if IsDone() then
  38.                 turtle.select(current_input_slot)
  39.                 if turtle.getItemCount() == 0 then -- if input_slot is empty, break the loop and end program.
  40.                     current_input_slot = additional_input_slot
  41.                     turtle.select(current_input_slot)
  42.                     if turtle.getItemCount() == 0 then
  43.                         break
  44.                     end
  45.                 end
  46.                 -- if slot isn't empty, insert the next one
  47.                 turtle.drop(1)
  48.             end
  49.         end
  50.         os.pullEvent("redstone")
  51.     end
  52. end
  53. write("Input slot is empty.\n")
Advertisement
Add Comment
Please, Sign In to add comment