Advertisement
Guest User

superdig.lua

a guest
Aug 25th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.48 KB | None | 0 0
  1. function forward(stp)
  2.   if stp == 0 then
  3.     do return end
  4.   end
  5.   for c=1,stp do
  6.     while turtle.detect() do
  7.       turtle.dig()
  8.       sleep(1)
  9.     end
  10.     turtle.forward()
  11.     turtle.digUp()
  12.     turtle.digDown()
  13.   end
  14. end
  15.  
  16. function digroom(dimx, dimy)
  17.   --We start from the middle, return to the middle, and resume our facing.
  18.   --We can make halls with digroom, (1x2, 99x1 , etc)
  19.   -- but please don't make 1x1 rooms. That's silly.
  20.   --ALSO: No 0x0 or 0x3 etc rooms. That's not a room.
  21.   if dimx == 1 then
  22.     topleft = 0
  23.   elseif dimx % 2 == 1 then
  24.     topleft = (dimx - 1) / 2
  25.   else
  26.     topleft = dimx / 2
  27.   if dimy == 1 then
  28.     upmoves = 0
  29.   elseif dimy % 2 == 1 then
  30.     topup = (dimy -1) / 2
  31.   else
  32.     topup = dimy / 2
  33.   end
  34.   xmoves=dimx - 1
  35.   forward(topup)
  36.   turtle.turnLeft()
  37.   forward(topleft)
  38.   turtle.turnRight()
  39.   --We are now in the "top-left" corner, and facing "north"
  40.   for c=1,dimy do
  41.     turtle.turnRight()
  42.     forward(xmoves)
  43.     turtle.turnLeft()
  44.     turtle.turnLeft()
  45.     forward(xmoves)
  46.     if c < dimy then
  47.       turtle.turnLeft()
  48.       forward(1)
  49.       turtle.turnRight()
  50.     end
  51.     turtle.turnRight()
  52.   end
  53.  end
  54.     -- We are now in the "bottom-left" corner, facing "north"
  55.   -- Return to center.
  56.   turtle.turnRight()
  57.   forward(topleft)
  58.   turtle.turnLeft()
  59.   forward(topup)
  60.   -- We are now in the middle, facing "north", and done.
  61. end
  62.  
  63. function DigGrid(roomx, roomy, sizex, sizey)
  64.   --We dig X rooms by Y rooms, of sizex by sizey. We start in the middle, facing "north"
  65.   -- This assumes an odd number of rooms on both axis.
  66.   if roomx % 2 == 0 then
  67.     do return end
  68.   elseif roomy %2 == 0 then
  69.     do return end
  70.   end
  71.   midleft = sizex + 1
  72.   midup = sizey + 1
  73.   if roomy > 2 then
  74.     roomup = (roomy - 1) / 2
  75.     for ru=1,roomup do
  76.       forward(midup)
  77.     end
  78.   end
  79.   turtle.turnLeft()
  80.   if roomx > 2 then
  81.     roomleft = (roomx - 1) / 2
  82.     for rl=1,roomleft do
  83.       forward(midleft)
  84.     end
  85.   end
  86.   turtle.turnRight()
  87.   for ry=1,roomy do
  88.     turtle.turnRight()
  89.     for rx=1,roomx do
  90.       digroom(sizex, sizey)
  91.       if rx < roomx then
  92.         forward(midleft)
  93.       end
  94.     end
  95.     turtle.turnLeft()
  96.     turtle.turnLeft()
  97.     for rtx=1,roomx do
  98.       if rtx < roomx then
  99.         forward(midleft)
  100.       end
  101.     end
  102.     if ry < roomy then
  103.       turtle.turnLeft()
  104.       turtle.turnLeft()
  105.       forward(midup)
  106.       turtle.turnLeft()
  107.       turtle.turnLeft()
  108.     end
  109.   end
  110. end
  111.  
  112. DigGrid(5, 5, 5, 5)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement