SHARE
TWEET

Untitled

a guest Jan 17th, 2020 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Miner
  2.  
  3. local SLOT_FEUL = 1
  4.  
  5. function get_place_dig_suck_drop_in_empty_space()
  6.   local success, data = turtle.inspect()
  7.   if not success then
  8.     return turtle.place, turtle.dig, turtle.suck, turtle.drop
  9.   end
  10.  
  11.   success, data = turtle.inspectUp()
  12.   if not success then
  13.     return turtle.placeUp, turtle.digUp, turtle.suckUp, turtle.dropUp
  14.   end
  15.  
  16.   success, data = turtle.inspectDown()
  17.   if not success then
  18.     return turtle.placeDown, turtle.digDown, turtle.suckDown, turtle.dropDown
  19.   end
  20.  
  21.   error("No empty space in front, above, or below the turtle")
  22. end
  23.  
  24. function try_with_rotation(func)
  25.   for i=1,4 do
  26.     vals = {pcall(func)}
  27.     if vals[1] then
  28.       for j = 1,(i-1) do
  29.         turtle.turnRight()
  30.       end
  31.       table.remove(vals, 1)
  32.       return unpack(vals)
  33.     end
  34.     turtle.turnLeft()
  35.   end
  36.  
  37.   error("Could not execute function in any orientation")
  38. end
  39.  
  40. function refuel_from_chest(slot)
  41.   local place, dig, suck, drop = try_with_rotation(get_place_dig_suck_drop_in_empty_space)
  42.   local prev_slot = turtle.getSelectedSlot()
  43.   turtle.select(slot)
  44.   local success = place()
  45.   assert(success, "Could not place chest")
  46.   success = suck()
  47.   assert(success, "Could not obtain fuel from chest")
  48.   success = turtle.refuel()
  49.   assert(success, "Could not use item obtained from chest as fuel")
  50.   success = dig()
  51.   assert(success, "Could not remove chest")
  52.   turtle.select(prev_slot)
  53. end
  54.  
  55. refuel_from_chest(SLOT_FEUL)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top