Advertisement
Inksaver

cobble.lua (For use in the cobble generator)

Mar 19th, 2022
1,093
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.13 KB | None | 0 0
  1. local function getCobble(digDirection)
  2.     if digDirection == "up" then -- dig 64 cobble then exit
  3.         local count = 0
  4.         while count < 64 do
  5.             if turtle.detectUp() then
  6.                 turtle.digUp()
  7.                 count = count + 1
  8.             end
  9.         end
  10.     else
  11.         for i = 1, 4 do         -- dig 4 cobble then exit
  12.             turtle.dig()
  13.             turtle.turnRight()
  14.         end
  15.     end
  16. end
  17.  
  18. local function getInventoryCount()
  19.     local count = 0
  20.     for i = 1, 16 do
  21.         count = count + turtle.getItemCount(i)
  22.     end
  23.     return count
  24. end
  25.  
  26. local function emptyTurtle(chestDirection)
  27.     local function empty(Drop)
  28.         for i = 1, 16 do
  29.             turtle.select(i)
  30.             if turtle.getItemCount(i) > 0 then
  31.                 if not Drop() then
  32.                     turtle.select(1)
  33.                     return false
  34.                 end
  35.             end
  36.         end
  37.         turtle.select(1)
  38.         return true
  39.     end
  40.    
  41.     local Drop = turtle.drop
  42.     if chestDirection == "down" then
  43.         Drop = turtle.dropDown
  44.         return empty(Drop)
  45.     else -- up to 4 chests around turtle
  46.         local allFull = true
  47.         local success, data = turtle.inspect()
  48.         for j = 1, 4 do
  49.             if data.name == "minecraft:chest" then
  50.                 if empty(Drop) then
  51.                     allFull = false
  52.                 end
  53.             end
  54.             turtle.turnRight()
  55.             success, data = turtle.inspect()
  56.         end
  57.         return allFull
  58.     end
  59. end
  60.  
  61. local function main()
  62.     --[[ everything runs from here ]]
  63.     local chestDirection = "forward"            -- assume chest(s) in front
  64.     local digDirection = "up"                   -- assume stone formed above
  65.     local success, data = turtle.inspectDown()  -- is there a chest below?
  66.     if data.name == "minecraft:chest" then      -- yes
  67.         chestDirection = "down"                 -- change chestDirection
  68.         digDirection = "forward"                -- change dig direction
  69.     end
  70.     while true do                               -- run forever
  71.         if emptyTurtle(chestDirection) then     -- successfully emptied turtle
  72.             for i = 1, 16 do                    -- get 64 more cobble
  73.                 getCobble(digDirection)         -- 4 cobble per rotation = 64
  74.             end
  75.         else                                    -- chest full, now fill turtle
  76.             if getInventoryCount() < 1024 then  -- still some space in the turtle
  77.                 getCobble(digDirection)         -- 4 cobble only
  78.             else
  79.                 print("Inventory full. Waiting for Player")
  80.                 sleep(10)                       -- allows time for player to remove cobble
  81.             end
  82.         end
  83.     end
  84. end
  85.  
  86. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement