Barnet

Minecraft Turtle: BuildWall

Apr 25th, 2016 (edited)
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.02 KB | None | 0 0
  1. -----------Written by Barnet-----------
  2.  
  3. function MoveUp()
  4.   while turtle.up() == false do
  5.     if turtle.detectUp() == true then
  6.       turtle.digUp()
  7.     else
  8.       turtle.attackUp()
  9.     end
  10.   end
  11. end
  12.  
  13. function MoveDown()
  14.   while turtle.down() == false do
  15.     if turtle.detectDown() == true then
  16.       turtle.digDown()
  17.     else
  18.       turtle.attackDown()
  19.     end
  20.   end
  21. end
  22.  
  23. function CheckSlot()
  24.   Slot = turtle.getItemDetail()
  25.   if Slot.name == "" then
  26.     return true
  27.   else
  28.     return false
  29.   end
  30. end
  31.  
  32. function CheckMaterial(Material)
  33.   Item = turtle.getItemDetail()
  34.   if pcall(CheckSlot) == true then
  35.     if Item.name == Material then
  36.       return true
  37.     else
  38.       return false
  39.     end
  40.   else
  41.     return false
  42.   end
  43. end
  44.  
  45. function Refill(Material)
  46.   if CheckMaterial(Material) == false then
  47.     c = 1
  48.     while c<17 do
  49.       turtle.select(c)
  50.       c=c+1
  51.       if CheckMaterial(Material) == true then
  52.         c=17
  53.       elseif c == 17 then
  54.         turtle.select(1)
  55.         print("Missing material!")
  56.         error()
  57.       end
  58.     end
  59.   end
  60. end
  61.  
  62. function MoveForward()
  63.   while turtle.forward() == false do
  64.     if turtle.detect() == true then
  65.       turtle.dig()
  66.     else
  67.       turtle.attack()
  68.     end
  69.   end
  70. end
  71.  
  72. function BuildUp(y,Material)
  73.   x = 0
  74.   while x<y do
  75.     Refill(Material)
  76.     MoveUp()
  77.     turtle.placeDown()
  78.     x=x+1
  79.   end
  80.   MoveForward()
  81.   MoveDown()
  82.   x = 1
  83.   while x<y do
  84.     Refill(Material)
  85.     MoveDown()
  86.     turtle.placeUp()
  87.     x=x+1
  88.   end
  89.   Refill(Material)
  90.   MoveForward()
  91.   turtle.turnLeft()
  92.   turtle.turnLeft()
  93.   turtle.place()
  94.   turtle.turnLeft()
  95.   turtle.turnLeft()
  96. end
  97.  
  98. function Build(y,z,Material)
  99.   v = 1
  100.   while v<=z/2 do
  101.     BuildUp(y,Material)
  102.     v=v+1
  103.   end
  104. end
  105.  
  106. print()
  107. print("Build a Wall")
  108. print("---------------------------------------")
  109. write("Height: ")
  110. y = tonumber(read())
  111. write("Length: ")
  112. z = tonumber(read())
  113. write("Material: ")
  114. Material = read()
  115. print("Building wall....")
  116. Build(y,z,Material)
  117. print("Done!")
Add Comment
Please, Sign In to add comment