Advertisement
M0n5t3r

wallMaker

Jul 2nd, 2018
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.95 KB | None | 0 0
  1. local stone_slot = 0
  2. local stone_slots = 0
  3.  
  4. local ender_chest_slot = 1
  5.  
  6. local forward_motion = 0
  7. local down_motion = 0
  8.  
  9. term.write("Insert Length: ")
  10. Length = tonumber(read()) - 1
  11. print(" ")
  12.  
  13. term.write("Insert Height: ")
  14. Height = tonumber(read())
  15. print(" ")
  16.  
  17. local Length = Length
  18. local Height = Height
  19.  
  20.  
  21. --do i need to place a block, or not...
  22. function place_or_not()
  23.     turtle.turnLeft()
  24.     local succes, t = turtle.inspect()
  25.     if succes then
  26.         if string.find(t.name, "cobble") then
  27.         else
  28.             selectStone()
  29.             while turtle.place() == false do
  30.                 turtle.dig()
  31.             end
  32.         end
  33.     end
  34.     turtle.turnRight()
  35. end
  36.  
  37. --select stone or glass, if not found (more than one) than refill
  38. function selectStone()
  39.     local is_stone = 0
  40.     for q=2,15 do
  41.         local item_detail = turtle.getItemDetail(q)
  42.         if item_detail then
  43.             if string.find(item_detail.name, "cobble") ~= nil and item_detail.count > 1 then
  44.                 is_stone = q
  45.                 break
  46.             end
  47.         end
  48.     end
  49.     if is_stone == 0 then
  50.         print("no stones found, gotte get some")
  51.         refilChest()
  52.     else
  53.         stone_slot = is_stone
  54.         turtle.select(stone_slot)
  55.         print(stone_slot)
  56.     end
  57. end
  58.  
  59. --get bricks or glass from enderchest
  60. function refilChest()
  61.     turtle.select(ender_chest_slot)
  62.     if turtle.place() then
  63.         --suck all items, than turn left  
  64.         for q=2,16 do
  65.             turtle.select(q)
  66.             local toSuck = 64 - turtle.getItemCount(q)
  67.             turtle.suck(toSuck)
  68.         end
  69.         --
  70.         turtle.select(ender_chest_slot)
  71.         if turtle.getItemCount(ender_chest_slot) == 0 then
  72.             print("Chest is right")
  73.             turtle.dig()
  74.             turtle.select(2)
  75.         else
  76.             turtle.select(ender_chest_slot)
  77.             turtle.drop(64)
  78.             turtle.dig()
  79.             turtle.select(2)
  80.         end
  81.     else
  82.         --als ik 'm niet kan plaatsten moet hij draaien ofzo
  83.         turtle.turnRight()
  84.         if turtle.place() then
  85.             --suck all items, than turn Right
  86.             for q=2,16 do
  87.                 turtle.select(q)
  88.                 local toSuck = 64 - turtle.getItemCount(q)
  89.                 turtle.suck(toSuck)
  90.             end
  91.             --
  92.             turtle.select(ender_chest_slot)
  93.             if turtle.getItemCount(ender_chest_slot) == 0 then
  94.                 print("Chest is right")
  95.                 turtle.dig()
  96.                 turtle.select(2)
  97.             else
  98.                 turtle.select(ender_chest_slot)
  99.                 turtle.drop(64)
  100.                 turtle.dig()
  101.                 turtle.select(2)
  102.             end
  103.             turtle.turnLeft()
  104.         else
  105.             while turtle.place() == false do
  106.                 turtle.dig()
  107.             end
  108.             --suck all items, than turn Right
  109.             for q=2,16 do
  110.                 turtle.select(q)
  111.                 local toSuck = 64 - turtle.getItemCount(q)
  112.                 turtle.suck(toSuck)
  113.             end
  114.  
  115.             turtle.select(ender_chest_slot)
  116.             if turtle.getItemCount(ender_chest_slot) == 0 then
  117.                 print("Chest is right")
  118.                 turtle.dig()
  119.                 turtle.select(2)
  120.             else
  121.                 turtle.select(ender_chest_slot)
  122.                 turtle.drop(64)
  123.                 turtle.dig()
  124.                 turtle.select(2)
  125.             end
  126.  
  127.             turtle.turnLeft()
  128.         end
  129.     end
  130. end
  131.  
  132. --check if everything is still correct..
  133. function empty_if_not_right()
  134.     if string.find(turtle.getItemDetail(1).name, "ender") ~= nil then
  135.         print("Chest is right")
  136.     else
  137.         print("Seem to lost my chest? ")
  138.     end
  139.  
  140.     for p=2,16 do
  141.         if string.find(turtle.getItemDetail(p).name, "cobble") ~= nil then
  142.             print("Slot: " .. p .. " has stones")
  143.         else
  144.             turtle.select(p)
  145.             turtle.turnLeft()
  146.             turtle.turnLeft()
  147.             turtle.drop(64)
  148.             turtle.turnRight()
  149.             turtle.turnRight()
  150.             print("Seem to have no stone? ")
  151.             refilChest()
  152.         end
  153.     end
  154. end
  155.  
  156. function makeLine()
  157.     place_or_not()
  158.     repeat
  159.         while turtle.forward() == false do
  160.             turtle.dig()
  161.         end
  162.         forward_motion = forward_motion + 1
  163.         place_or_not()
  164.     until forward_motion == Length
  165.     repeat
  166.         if turtle.back() then
  167.             forward_motion = forward_motion - 1
  168.         end
  169.     until forward_motion == 0
  170. end
  171.  
  172. function start()
  173.     print("Starting")
  174.     repeat
  175.         makeLine()
  176.         empty_if_not_right()
  177.         if turtle.down() then
  178.             down_motion = down_motion + 1
  179.         end
  180.     until down_motion == Height
  181.     makeLine()
  182.     repeat
  183.         if turtle.up() then
  184.             down_motion = down_motion - 1
  185.         end
  186.     until down_motion == 0
  187.     print("Done?")
  188. end
  189.  
  190. start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement