Advertisement
bcash8

Stoneblock Wall

Dec 30th, 2022 (edited)
1,211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.49 KB | None | 0 0
  1.  
  2. local coalChest = "minecraft:chest"
  3. local dir = 1
  4. local coalDir = 1
  5. local chestDirs = {["minecraft:iron_block"]=4, ["minecraft:redstone"]=2, ["minecraft:ender_pearl"]=3}
  6.  
  7.  
  8. function findCoalChest()
  9.     for i = 1,4 do
  10.         local block, data = turtle.inspect()
  11.         if block then
  12.             if data.name == coalChest then
  13.                 dir = 1
  14.                 return
  15.             end
  16.         end
  17.         turtle.turnRight()
  18.     end
  19. end
  20.  
  21. function right()
  22.     turtle.turnRight()
  23.  
  24.     dir = dir+1
  25.     if dir > 4 then
  26.         dir = 1
  27.     end
  28. end
  29.  
  30. function left()
  31.     turtle.turnLeft()
  32.  
  33.     dir = dir-1
  34.     if dir < 1 then
  35.         dir = 4
  36.     end
  37. end
  38.  
  39. function setDir(d)
  40.     if dir == 1 and d == 4 then
  41.         left()
  42.     elseif dir == 4 and d == 1 then
  43.         right()
  44.     end
  45.  
  46.     while d > dir do
  47.         right()
  48.     end
  49.  
  50.     while d < dir do
  51.         left()
  52.     end
  53. end
  54.  
  55. function fillInv()
  56.     while turtle.detectUp() == false do
  57.         turtle.up()
  58.     end
  59.  
  60.     if turtle.getFuelLevel() < 1000 then
  61.         setDir(1)
  62.         turtle.select(16)
  63.         turtle.suck(10)
  64.         turtle.refuel(64)
  65.     end
  66.     local invDef = {[1]="minecraft:iron_block", [2]="minecraft:redstone", [3]="minecraft:ender_pearl"}
  67.     local invLayout =  {1, 1, 2, 2,
  68.                         3, 3, 3, 3,
  69.                         3, 3, 3, 3}
  70.  
  71.     for i = 1, 12 do
  72.         local item = invDef[invLayout[i]]
  73.         local count = 64
  74.         if item == "minecraft:ender_pearl" then
  75.             count = 16
  76.         end
  77.         if turtle.getItemCount(i) < count then
  78.             setDir(chestDirs[item])
  79.             turtle.select(i)
  80.             turtle.suck(count - turtle.getItemCount())
  81.         end
  82.     end
  83.  
  84. end
  85.  
  86. function pick(item)
  87.     for i = 1,12 do
  88.         turtle.select(i)
  89.         local data = turtle.getItemDetail()
  90.         if data then
  91.             if data.name == item then
  92.                 return
  93.             end
  94.         end
  95.     end
  96.  
  97.     --If no items were found then go fill up
  98.     fillInv()
  99.     pick(item)
  100.     turtle.down()
  101.     turtle.down()
  102. end
  103.  
  104. function makeWall()
  105.     while turtle.detectUp() == false do
  106.         turtle.up()
  107.     end
  108.  
  109.     turtle.down()
  110.     turtle.down()
  111.  
  112.     pick("minecraft:iron_block")
  113.     turtle.placeDown()
  114.    
  115.     turtle.up()
  116.     pick("minecraft:redstone")
  117.     turtle.placeDown()
  118.  
  119.     turtle.up()
  120.     pick("minecraft:ender_pearl")
  121.     turtle.dropDown(1)
  122. end
  123.  
  124. findCoalChest()
  125.  
  126.  
  127. while true do
  128.     makeWall()
  129.     sleep(12)
  130. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement