markuszeller

Floor

Apr 26th, 2014 (edited)
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.88 KB | None | 0 0
  1. print("Floor v1.00")
  2. write("How many meters to go?: ")
  3. z = read()
  4. z = tonumber(z)
  5.  
  6. if z ~= nil and z > 0 then
  7.   write("How many blocks wide? (default=2): ")
  8.   x = read()
  9.   x = tonumber(x)
  10.  
  11.   if x == nil or x < 1 then
  12.     print("Nothing given, using default.")
  13.     x = 2
  14.   end
  15.  
  16.   slot = 1
  17.   slotMax = 16
  18.   itemsStored = 0
  19.   turtle.select(slot);
  20.  
  21.   for s = 1,16 do
  22.     itemsStored = itemsStored + turtle.getItemCount(s)
  23.   end
  24.  
  25.   work = x*z + x + z
  26.   if work > itemsStored then
  27.      stacks = math.floor(x*z / 64) + 1
  28.      if stacks > slotMax then
  29.        print("Please think smaller, more than 16 stacks are not possible.")
  30.      else
  31.        print("Not enough items in slots. Need at least " .. stacks .. " stacks")
  32.      end
  33.      return
  34.   end
  35.  
  36.   if work > turtle.getFuelLevel() then
  37.     print("Too less fuel. Please refuel.")
  38.     return
  39.   end
  40.  
  41.   print("Building floor " .. z .. "x" .. x)
  42.   turtle.forward()
  43.   turtle.up()
  44.   goRight = true
  45.   goForward = true
  46.  
  47.  for lx = 1, x do
  48.     for lz = 1, z do
  49.       while not turtle.placeDown() do
  50.         slot = slot + 1
  51.         turtle.select(slot)
  52.       end
  53.       if lz < z then
  54.         turtle.forward()
  55.       end
  56.     end
  57.     if lx < x then
  58.       if goRight then
  59.         turtle.turnRight()
  60.       else
  61.         turtle.turnLeft()
  62.       end
  63.       turtle.forward()
  64.       if goRight then
  65.         turtle.turnRight()
  66.       else
  67.         turtle.turnLeft()
  68.       end
  69.       goRight = not goRight
  70.       goForward = not goForward
  71.     end
  72.   end
  73.  
  74.   -- come home
  75.   if goForward then
  76.     for l=1, z do
  77.       turtle.back()
  78.     end
  79.     turtle.turnLeft()
  80.     for l=2, x do
  81.       turtle.forward()
  82.     end
  83.     turtle.turnRight()
  84.   else
  85.     turtle.turnRight()
  86.     for l=2, x do
  87.       turtle.forward()
  88.     end
  89.     turtle.turnRight()
  90.     turtle.back()
  91. end
  92.   turtle.down()
  93.  
  94. end
  95.  
  96. print("Done building floor.")
Add Comment
Please, Sign In to add comment