Advertisement
Guest User

superdig.lua

a guest
Aug 25th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.47 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.   -- We are now in the "bottom-left" corner, facing "north"
  54.   -- Return to center.
  55.   turtle.turnRight()
  56.   forward(topleft)
  57.   turtle.turnLeft()
  58.   forward(topup)
  59.   -- We are now in the middle, facing "north", and done.
  60. end
  61.  
  62. function DigGrid(roomx, roomy, sizex, sizey)
  63.   --We dig X rooms by Y rooms, of sizex by sizey. We start in the middle, facing "north"
  64.   -- This assumes an odd number of rooms on both axis.
  65.   if roomx % 2 == 0 then
  66.     do return end
  67.   elseif roomy %2 == 0 then
  68.     do return end
  69.   end
  70.   midleft = sizex + 1
  71.   midup = sizey + 1
  72.   if roomy > 2 then
  73.     roomup = (roomy - 1) / 2
  74.     for ru=1,roomup do
  75.       forward(midup)
  76.     end
  77.   end
  78.   turtle.turnLeft()
  79.   if roomx > 2 then
  80.     roomleft = (roomx - 1) / 2
  81.     for rl=1,roomleft do
  82.       forward(midleft)
  83.     end
  84.   end
  85.   turtle.turnRight()
  86.   for ry=1,roomy do
  87.     turtle.turnRight()
  88.     for rx=1,roomx do
  89.       digroom(sizex, sizey)
  90.       if rx < roomx then
  91.         forward(midleft)
  92.       end
  93.     end
  94.     turtle.turnLeft()
  95.     turtle.turnLeft()
  96.     for rtx=1,roomx do
  97.       if rtx < roomx then
  98.         forward(midleft)
  99.       end
  100.     end
  101.     if ry < roomy then
  102.       turtle.turnLeft()
  103.       turtle.turnLeft()
  104.       forward(midup)
  105.       turtle.turnLeft()
  106.       turtle.turnLeft()
  107.     end
  108.   end
  109. end
  110.  
  111. DigGrid(5, 5, 5, 5)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement