Advertisement
Link712011

Snow

Aug 15th, 2017
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.67 KB | None | 0 0
  1. local SLEEP_BETWEEN_DIG = 0.5
  2. local SLEEP_MAIN_LOOP_WAIT = 30
  3. local SLEEP_MAIN_LOOP_ACTIVE = 1
  4. local SNOW_PER_LOOP = 32
  5. local TURTLE_INVENTORY_SIZE = 16
  6. local SNOW_STACK_SIZE = 16
  7.  
  8.  
  9. function garbage_all()
  10.     local i = TURTLE_INVENTORY_SIZE
  11.  
  12.     while i > 0 do
  13.         turtle.select(i)
  14.         turtle.drop()
  15.         i = i - 1
  16.     end
  17. end
  18.  
  19. function select_item(item)
  20.     local slot = 1
  21.  
  22.     while slot <= TURTLE_INVENTORY_SIZE do
  23.         local data = turtle.getItemDetail(slot)
  24.         if data and data.name == item then
  25.             turtle.select(slot)
  26.             return true
  27.         end
  28.         slot = slot + 1
  29.     end
  30.     return false
  31. end
  32.  
  33. function is_full()
  34.     local slot
  35.     local data
  36.     local empty
  37.  
  38.     slot = TURTLE_INVENTORY_SIZE
  39.     empty = 0
  40.     while slot > 0 do
  41.         data = turtle.getItemDetail(slot)
  42.         if not data then
  43.             empty = empty + 1
  44.         end
  45.         slot = slot - 1
  46.     end
  47.     return empty < (SNOW_PER_LOOP / SNOW_STACK_SIZE)
  48. end
  49.  
  50. function dig_snow()
  51.     local i
  52.  
  53.     i = 0
  54.     while i < SNOW_PER_LOOP do
  55.         turtle.dig()
  56.         sleep(SLEEP_BETWEEN_DIG)
  57.         i = i + 1
  58.     end
  59. end
  60.  
  61. function drop_to_chest()
  62.     while select_item('minecraft:snowball') and turtle.dropDown() do end
  63.     return select_item('minecraft:snowball')
  64. end
  65.  
  66. function core()
  67.     while true do
  68.         if not is_full() then
  69.             dig_snow()
  70.         elseif not select_item('minecraft:snowball') then
  71.             garbage_all()
  72.         end
  73.         if not drop_to_chest() then
  74.             sleep(SLEEP_MAIN_LOOP_WAIT)
  75.         else
  76.             sleep(SLEEP_MAIN_LOOP_ACTIVE)
  77.         end
  78.     end
  79. end
  80.  
  81. core()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement