ferreusveritas

build

Sep 11th, 2020
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 22.12 KB | None | 0 0
  1. ----------------------------------------------------------------
  2. -- TABLES                                                     --
  3. ----------------------------------------------------------------
  4.  
  5. function tableDump(t)
  6.   print(textutils.serialize(t));
  7. end
  8.  
  9. function testValues(t)
  10.   local test = {};
  11.   for i,e in pairs(t) do
  12.     test[e] = true;
  13.   end
  14.   return test;
  15. end
  16.  
  17. function fif(cond, a, b)
  18.   if cond then
  19.     return a;
  20.   else
  21.     return b;
  22.   end
  23. end
  24.  
  25. ----------------------------------------------------------------
  26. -- ERASE OR CREATE                                            --
  27. ----------------------------------------------------------------
  28.  
  29. erase = false;
  30.  
  31. function setErase(should)
  32.   erase = should;
  33. end
  34.  
  35. ----------------------------------------------------------------
  36. -- SYNC or ASYNC
  37. ----------------------------------------------------------------
  38.  
  39. sync = false;
  40.  
  41. function setSync(should)
  42.   sync = should;
  43. end
  44.  
  45. asyncCalled = false;
  46.  
  47. function wait()
  48.   os.pullEvent("task_complete");
  49. end
  50.  
  51. function waitAsync()
  52.   if asyncCalled then
  53.     wait();
  54.     asyncCalled = false;
  55.   end
  56. end
  57.  
  58. ----------------------------------------------------------------
  59. -- COORDINATES                                                --
  60. ----------------------------------------------------------------
  61.  
  62. Coord = {}
  63. Coord.__index = Coord;
  64.  
  65. function Coord:new(x, y, z)
  66.     local coord = {}             -- our new object
  67.     setmetatable(coord, Coord)  -- make Account handle lookup
  68.     -- initialize our object
  69.     coord.x = x;
  70.     coord.y = y;
  71.     coord.z = z;
  72.    return coord
  73. end
  74.  
  75. function coord(...)
  76.   if #arg == 3 then return Coord:new(arg[1], arg[2], arg[3]); end
  77.   return Coord:new(0, 0, 0);
  78. end
  79.  
  80. function Coord:__tostring()
  81.   return "coord: [" ..
  82.     self.x .. ", " ..
  83.     self.y .. ", " ..
  84.     self.z .. "]";
  85. end
  86.  
  87. function Coord:cpy()
  88.   return Coord:new(self.x, self.y, self.z);
  89. end
  90.  
  91. function Coord:scale(amount)
  92.   return Coord:new(self.x * amount, self.y * amount, self.z * amount);
  93. end
  94.  
  95. function Coord:print()
  96.   print(self);
  97.   return self;
  98. end
  99.  
  100. function Coord:get()
  101.   local x, y, z = commands.getBlockPosition();
  102.   return Coord:new(x, y, z);
  103. end
  104.  
  105. function Coord:add(c)
  106.   return Coord:new(self.x + c.x, self.y + c.y, self.z + c.z);
  107. end
  108.  
  109. function Coord:sub(c)
  110.   return Coord:new(self.x - c.x, self.y - c.y, self.z - c.z);
  111. end
  112.  
  113. function Coord:mul(c)
  114.   return Coord:new(self.x * c.x, self.y * c.y, self.z * c.z);
  115. end
  116.  
  117. function Coord:rot(qturns, a)
  118.   qturns = qturns or 1;
  119.   local c = self;
  120.   if a ~= nil then c = c:sub(a); end
  121.   qturns = qturns % 4;
  122.   if qturns == 0 then c = Coord:new( c.x, c.y,  c.z); end;
  123.   if qturns == 1 then c = Coord:new(-c.z, c.y,  c.x); end;
  124.   if qturns == 2 then c = Coord:new(-c.x, c.y, -c.z); end;
  125.   if qturns == 3 then c = Coord:new( c.z, c.y, -c.x); end;
  126.   if a ~= nil then c = c:add(a); end
  127.   return c;
  128. end
  129.  
  130. function Coord:mir(axis, a)
  131.   local c = self;
  132.   if a ~= nil then c = c:sub(a); end
  133.   if axis.x ~= 0 then c = Coord:new(-c.x,  c.y,  c.z); end
  134.   if axis.y ~= 0 then c = Coord:new( c.x, -c.y,  c.z); end
  135.   if axis.z ~= 0 then c = Coord:new( c.x,  c.y, -c.z); end
  136.   if a ~= nil then c = c:add(a); end
  137.   return c;
  138. end
  139.  
  140. function Coord:up(amount)
  141.   return self:add(Coord:new(0, amount or 1, 0));
  142. end
  143.  
  144. function Coord:dwn(amount)
  145.   amount = amount or 1;
  146.   return self:up(-amount);
  147. end
  148.  
  149. function Coord:trn(turns, mirAxis, pos)
  150.   return self:rot(turns or 0):mir(mirAxis or coord()):add(pos or coord());
  151. end
  152.  
  153. function Coord:eq(other)
  154.   return self.x == other.x and self.y == other.y and self.z == other.z;
  155. end
  156.  
  157. ----------------------------------------------------------------
  158. -- DIRECTIONS                                                 --
  159. ----------------------------------------------------------------
  160.  
  161. AXIS = {
  162.  X = Coord:new(1, 0, 0),
  163.  Y = Coord:new(0, 1, 0),
  164.  Z = Coord:new(0, 0, 1)
  165. };
  166.  
  167. DIR = {
  168.   D = {x =  0, y = -1, z =  0, n = "down", a = 'y'},
  169.   U = {x =  0, y =  1, z =  0, n = "up", a = 'y'},
  170.   N = {x =  0, y =  0, z = -1, n = "north", a = 'z'},
  171.   S = {x =  0, y =  0, z =  1, n = "south", a = 'z'},
  172.   W = {x = -1, y =  0, z =  0, n = "west", a = 'x'},
  173.   E = {x =  1, y =  0, z =  0, n = "east", a = 'x'}
  174. };
  175. DIR.HORIZONTALS = { DIR.N, DIR.S, DIR.W, DIR.E };
  176. DIR.OPPOSITES = { [DIR.N] = DIR.S, [DIR.S] = DIR.N, [DIR.W] = DIR.E, [DIR.E] = DIR.W };
  177. DIR.ROTATE = { [DIR.D] = DIR.D, [DIR.U] = DIR.U, [DIR.N] = DIR.E, [DIR.S] = DIR.W, [DIR.W] = DIR.N, [DIR.E] = DIR.S };
  178.  
  179. function dirName(dir)
  180.   return dir.n;
  181. end
  182.  
  183. function dirLetter(dir)
  184.   return string.sub(dirName(dir), 1, 1);
  185. end
  186.  
  187. function dirAxis(dir)
  188.   return dir.a;
  189. end
  190.  
  191. function dirCoord(dir)
  192.   return coord(dir.x, dir.y, dir.z);
  193. end
  194.  
  195. function dirOpposite(dir)
  196.   return DIR.OPPOSITES[dir];
  197. end
  198.  
  199. function dirOppositeTable(dir)
  200.   local r = {};
  201.   for k,v in pairs(dirs) do
  202.     r[k] = dirOpposite(v);
  203.   end
  204.   return r;
  205. end
  206.  
  207. function dirRotate(dir, qturns)
  208.   qturns = qturns or 1;
  209.   qturns = qturns % 4;
  210.   for i = 0, qturns - 1 do
  211.     dir = DIR.ROTATE[dir];
  212.   end
  213.   return dir;
  214. end
  215.  
  216. function dirRotateTable(dirs, qturns)
  217.   local r = {};
  218.   for k,v in pairs(dirs) do
  219.     r[k] = dirRotate(v, qturns);
  220.   end
  221.   return r;
  222. end
  223.  
  224. function dirMirror(dir, axis)
  225.   if dir.a == axis then return dirOpposite(dir); end
  226.   return dir;
  227. end
  228.  
  229. function dirMirrorTable(dir, axis)
  230.   local r = {};
  231.   for k,v in pairs(dir) do
  232.     r[k] = dirMirror(v, axis);
  233.   end
  234.   return r;
  235. end
  236.  
  237. function dirMap(turns)
  238.   turns = turns or 0;
  239.   return
  240.     dirRotate(DIR.D, turns),
  241.     dirRotate(DIR.U, turns),
  242.     dirRotate(DIR.N, turns),
  243.     dirRotate(DIR.S, turns),
  244.     dirRotate(DIR.W, turns),
  245.     dirRotate(DIR.E, turns);
  246. end
  247.  
  248. function Coord:off(dir, amount)
  249.   dir = dir or DIR.U;
  250.   amount = amount or 1;
  251.   return self:add(coord(dir.x * amount, dir.y * amount, dir.z * amount));
  252. end
  253.  
  254. ----------------------------------------------------------------
  255. -- BLOCKSTATES                                                --
  256. ----------------------------------------------------------------
  257.  
  258. function blockState(block, data)
  259.   local a = {};
  260.   a.block = block;
  261.   a.data = data or "";
  262.   return a;
  263. end
  264.  
  265. function makeStairs(block, fillBlock)
  266.   local s = {};
  267.   s.n = blockState(block, "half=bottom,facing=north");
  268.   s.s = blockState(block, "half=bottom,facing=south");
  269.   s.w = blockState(block, "half=bottom,facing=west");
  270.   s.e = blockState(block, "half=bottom,facing=east");
  271.   s.ni = blockState(block, "half=top,facing=north");
  272.   s.si = blockState(block, "half=top,facing=south");
  273.   s.wi = blockState(block, "half=top,facing=west");
  274.   s.ei = blockState(block, "half=top,facing=east");
  275.   s.f = fillBlock;
  276.   return s;
  277. end
  278.  
  279. function makeSolidStairs(block, fillBlock)
  280.   local s = {};
  281.   s.n = block;
  282.   s.s = block;
  283.   s.w = block;
  284.   s.e = block;
  285.   s.ni = block;
  286.   s.si = block;
  287.   s.wi = block;
  288.   s.ei = block;
  289.   s.f = fillBlock;
  290.   return s;
  291. end
  292.  
  293. function makeSlabs(block, variant)
  294.   local s = {};
  295.   s.t = blockState(block, "half=top,variant="..variant);
  296.   s.b = blockState(block, "half=bottom,variant="..variant);
  297.   return s;
  298. end
  299.  
  300. air = blockState("minecraft:air");
  301. stone = blockState("minecraft:stone", "variant=stone");
  302. stonebrick = blockState("minecraft:stonebrick", "variant=stonebrick");
  303. stoneknot = blockState("cathedral:extras_block_stone", "variant=knot");
  304. stonepaver = blockState("cathedral:extras_block_stone", "variant=paver");
  305. stonechisel = blockState("chisel:stonebrick2", "variation=7");
  306. stonecircular = blockState("chisel:stonebrick1", "variation=6");
  307. stonedent = blockState("chisel:stonebrick", "variation=11");
  308. stonerosette = blockState("minecraft:stonebrick", "variant=chiseled_stonebrick");
  309. stonewide = blockState("chisel:stonebrick", "variation=3");
  310. stonerailing = blockState("cathedral:cathedral_railing_various", "variant=stone");
  311. glass = blockState("chisel:glass", "variation=2");
  312. dirt = blockState("minecraft:dirt");
  313. water = blockState("minecraft:water");
  314. lattice = blockState("rustic:iron_lattice", "leaves=false");
  315. chain = blockState("rustic:chain");
  316.  
  317. barsornate = blockState("chisel:ironpane", "variation=6");
  318.  
  319. basaltpaver = blockState("cathedral:basalt_block_carved", "variant=paver");
  320.  
  321. cartographer = blockState("mcf:cartographer", "");
  322. terraformer = blockState("mcf:terraformer", "");
  323. sentinel = blockState("mcf:sentinel", "");
  324.  
  325. colFill = stone;
  326. colBody = stoneknot;
  327. colHead = stonerosette;
  328. colFoot = stonepaver;
  329. colBase = stonewide;
  330. colCrwn = stonechisel;
  331.  
  332. tileOdd = stonepaver;
  333. tileEven = basaltpaver;
  334.  
  335. railing = stonerailing;
  336.  
  337. roofing = makeStairs("cathedral:roofing_shingles_red", stonebrick);
  338. stairs = makeStairs("minecraft:stone_brick_stairs", stonebrick);
  339. airstairs = makeSolidStairs(air, air);
  340. slab = makeSlabs("minecraft:stone_slab", "stone_brick");
  341. smoothslab = makeSlabs("minecraft:stone_slab", "stone");
  342.  
  343.  
  344. ----------------------------------------------------------------
  345. -- CUBOIDS                                                    --
  346. ----------------------------------------------------------------
  347.  
  348. function sort(v1, v2)
  349.   if(v1 > v2) then return v2, v1; else return v1, v2; end
  350. end
  351.  
  352. Cuboid = {}
  353. Cuboid.__index = Cuboid;
  354.  
  355. function Cuboid:new(c1, c2)
  356.   local cuboid = {};             -- our new object
  357.   setmetatable(cuboid, Cuboid);  -- make handle lookup
  358.   c1 = c1:cpy();
  359.   c2 = c2:cpy();
  360.   c1.x, c2.x = sort(c1.x, c2.x);
  361.   c1.y, c2.y = sort(c1.y, c2.y);
  362.   c1.z, c2.z = sort(c1.z, c2.z);
  363.   cuboid[1] = c1;
  364.   cuboid[2] = c2;
  365.   return cuboid;
  366. end
  367.  
  368. function cuboid(...)
  369.   if #arg == 1 then return Cuboid:new(arg[1], arg[1]); end
  370.   if #arg == 2 then return Cuboid:new(arg[1], arg[2]); end
  371.   if #arg == 6 then return Cuboid:newAll(arg[1], arg[2], arg[3], arg[4], arg[5], arg[6]); end
  372.   return Cuboid:newAll(0, 0, 0, 0, 0, 0);
  373. end
  374.  
  375. function Coord:cub()
  376.   return cuboid(self);
  377. end
  378.  
  379. function Cuboid:__tostring()
  380.   return "cuboid: [" ..
  381.     self[1].x .. "," ..
  382.     self[1].y .. "," ..
  383.     self[1].z .. "," ..
  384.     self[2].x .. "," ..
  385.     self[2].y .. "," ..
  386.     self[2].z .. "]";
  387. end
  388.  
  389. function Cuboid:newAll(x1, y1, z1, x2, y2, z2)
  390.   return Cuboid:new(Coord:new(x1, y1, z1), Coord:new(x2, y2, z2));
  391. end
  392.  
  393. function Cuboid:print()
  394.   print(self);
  395.   return self;
  396. end
  397.  
  398. function Cuboid:cpy()
  399.   return Cuboid:new(self[1], self[2]);
  400. end
  401.  
  402. function Cuboid:add(o)
  403.   return Cuboid:new(self[1]:add(o), self[2]:add(o));
  404. end
  405.  
  406. function Cuboid:sub(o)
  407.   return Cuboid:new(self[1]:sub(o), self[2]:sub(o));
  408. end
  409.  
  410. function Cuboid:rot(qturns, a)
  411.   return Cuboid:new(self[1]:rot(qturns, a), self[2]:rot(qturns, a));
  412. end
  413.  
  414. function Cuboid:mir(axis, a)
  415.   return Cuboid:new(self[1]:mir(axis, a), self[2]:mir(axis, a));
  416. end
  417.  
  418. function Cuboid:miriter(axis, a)
  419.   result = {};
  420.   result[0] = self:cpy();
  421.   result[1] = mir(axis, a);
  422.   return result;
  423. end
  424.  
  425. function Cuboid:gro(dir, amount)
  426.   amount = amount or 1;
  427.   if dir == nil then
  428.     return self:gro(coord(1, 1, 1), amount):gro(coord(-1, -1, -1), amount)
  429.   end
  430.   local c = self:cpy();
  431.   if dir.x < 0 then c[1].x = c[1].x - amount; end
  432.   if dir.y < 0 then c[1].y = c[1].y - amount; end
  433.   if dir.z < 0 then c[1].z = c[1].z - amount; end
  434.   if dir.x > 0 then c[2].x = c[2].x + amount; end
  435.   if dir.y > 0 then c[2].y = c[2].y + amount; end
  436.   if dir.z > 0 then c[2].z = c[2].z + amount; end
  437.   return c;
  438. end
  439.  
  440. function Cuboid:shr(dir, amount)
  441.   amount = amount or 1;
  442.   return self:gro(dir, -amount);
  443. end
  444.  
  445. function Cuboid:off(dir, amount)
  446.   dir = dir or DIR.U;
  447.   amount = amount or 1;
  448.   return self:add(coord(dir.x * amount, dir.y * amount, dir.z * amount));
  449. end
  450.  
  451. function Cuboid:uni(c)
  452.   return Cuboid:newAll(
  453.     math.min(self[1].x, c[1].x),
  454.     math.min(self[1].y, c[1].y),
  455.     math.min(self[1].z, c[1].z),
  456.     math.max(self[2].x, c[2].x),
  457.     math.max(self[2].y, c[2].y),
  458.     math.max(self[2].z, c[2].z)
  459.   );
  460. end
  461.  
  462. function Cuboid:fac(dir)
  463.   local c = self:cpy();
  464.   if dir.x > 0 then c = Cuboid:new(coord(c[2].x, c[1].y, c[1].z), c[2]); end
  465.   if dir.y > 0 then c = Cuboid:new(coord(c[1].x, c[2].y, c[1].z), c[2]); end
  466.   if dir.z > 0 then c = Cuboid:new(coord(c[1].x, c[1].y, c[2].z), c[2]); end
  467.   if dir.x < 0 then c = Cuboid:new(c[1], coord(c[1].x, c[2].y, c[2].z)); end
  468.   if dir.y < 0 then c = Cuboid:new(c[1], coord(c[2].x, c[1].y, c[2].z)); end
  469.   if dir.z < 0 then c = Cuboid:new(c[1], coord(c[2].x, c[2].y, c[1].z)); end
  470.   return c;
  471. end
  472.  
  473. function Cuboid:cnr(c)
  474.   return self:fac(Coord:new(-1, 0, -1):rot(c or 0));
  475. end
  476.  
  477. function Cuboid:cnriter()
  478.   corners = {};
  479.   for c = 0,3 do
  480.     corners[c] = self:cnr(c);
  481.   end
  482.   return pairs(corners);
  483. end
  484.  
  485. function Cuboid:top()
  486.   return self:fac(DIR.U);
  487. end
  488.  
  489. function Cuboid:bot()
  490.   return self:fac(DIR.D);
  491. end
  492.  
  493. function Cuboid:up(amount)
  494.   return self:off(DIR.U, amount);
  495. end
  496.  
  497. function Cuboid:dwn(amount)
  498.   return self:off(DIR.D, amount);
  499. end
  500.  
  501. function Cuboid:trn(turns, mirAxis, pos)
  502.   return self:rot(turns or 0):mir(mirAxis or coord()):add(pos or coord());
  503. end
  504.  
  505. function Cuboid:dunswe(d, u, n, s, w, e, t)
  506.   t = t or 0;
  507.   return self
  508.     :gro(dirRotate(DIR.D, t), d)
  509.     :gro(dirRotate(DIR.U, t), u)
  510.     :gro(dirRotate(DIR.N, t), n)
  511.     :gro(dirRotate(DIR.S, t), s)
  512.     :gro(dirRotate(DIR.W, t), w)
  513.     :gro(dirRotate(DIR.E, t), e)
  514. end
  515.  
  516. function Cuboid:grohor(amount)
  517.   amount = amount or 1;
  518.   return self:gro(coord(-1, 0, -1), amount):gro(coord(1, 0, 1), amount);
  519. end
  520.  
  521. function Cuboid:shrhor(amount)
  522.   amount = amount or 1;
  523.   return self:grohor(-amount);
  524. end
  525.  
  526. function Cuboid:mid()
  527.   local x = math.floor((self[1].x + self[2].x) / 2);
  528.   local y = math.floor((self[1].y + self[2].y) / 2);
  529.   local z = math.floor((self[1].z + self[2].z) / 2);
  530.   return Cuboid:newAll(x, y, z, x, y, z);
  531. end
  532.  
  533. function Cuboid:pos()
  534.   return self:mid()[1]:cpy();
  535. end
  536.  
  537. function Cuboid:xlen()
  538.   return self[2].x - self[1].x + 1;
  539. end
  540.  
  541. function Cuboid:ylen()
  542.   return self[2].y - self[1].y + 1;
  543. end
  544.  
  545. function Cuboid:zlen()
  546.   return self[2].z - self[1].z + 1;
  547. end
  548.  
  549. function Cuboid:len(axis)
  550.   if axis.x ~= 0 then return self:xlen(); end;
  551.   if axis.y ~= 0 then return self:ylen(); end;
  552.   if axis.z ~= 0 then return self:zlen(); end;
  553. end
  554.  
  555. function Cuboid:vol()
  556.   return self:xlen() * self:ylen() * self:zlen();
  557. end
  558.  
  559. ----------------------------------------------------------------
  560. -- BLOCK SETTERS                                              --
  561. ----------------------------------------------------------------
  562.  
  563. function Coord:putnbt(state, tag)
  564.   commands.setblock(self.x, self.y, self.z, state.block, state.data, "replace", tag);
  565.   return self;
  566. end
  567.  
  568. function Cuboid:fill(state)
  569.   if state == nil then
  570.     print("fill attempt for nil state: " .. tostring(self));
  571.     state = air;
  572.   end
  573.   if erase then state = air; end
  574.  
  575.   if sync then
  576.     com = commands;
  577.   else
  578.     com = commands.async;
  579.     asyncCalled = true;
  580.   end
  581.  
  582.   if self:vol() == 1 then
  583.     com.setblock(self[1].x, self[1].y, self[1].z, state.block, state.data);
  584.   else
  585.     com.fill(self[1].x, self[1].y, self[1].z, self[2].x, self[2].y, self[2].z, state.block, state.data);
  586.   end
  587.  
  588.   return self;
  589. end
  590.  
  591. function Cuboid:dirt()
  592.   return self:fill(dirt);
  593. end
  594.  
  595. function Cuboid:erase()
  596.   return self:fill(air);
  597. end
  598.  
  599. function Cuboid:pillar(pBody, pFoot, pHead)
  600.   self:fill(pBody or colBody);
  601.   self:fac(DIR.D):fill(pFoot or colFoot);
  602.   self:fac(DIR.U):fill(pHead or colHead);
  603.   return self;
  604. end
  605.  
  606. function Cuboid:checker()
  607.   self:face(DIR.D):fill(tileOdd);
  608.   for z = self[1].z, self[2].z do
  609.     for x = self[1].x, self[2].x do
  610.       if( ((x + z) % 2) == 0) then
  611.         Coord:new(x, self[1].y, z):put(tileEven);
  612.       end
  613.     end
  614.   end
  615.   return self;
  616. end
  617.  
  618. function Cuboid:fillcrn(state)
  619.   for _,c in self:cnriter() do c:fill(state); end
  620.   return self;
  621. end
  622.  
  623. function Cuboid:loop(state, corners, sides)
  624.   state = state or stone;
  625.   sides = sides or {DIR.N, DIR.S, DIR.W, DIR.E};
  626.   for _,side in pairs(sides) do
  627.     local k = self:fac(side):fill(state);
  628.     if(corners ~= nil) then k:fillcrn(corners); end
  629.   end
  630.   return self;
  631. end
  632.  
  633. function Cuboid:fence(sides)
  634.   sides = sides or {DIR.N, DIR.S, DIR.W, DIR.E};
  635.   local work = self:bot();
  636.  
  637.   work:loop(stonerailing, stonerailing, sides);
  638.  
  639.   local xlen = work:len(AXIS.X) / 2;
  640.   local zlen = work:len(AXIS.Z) / 2;
  641.   local y = self[1].y + 1;
  642.  
  643.   for _,side in pairs(sides) do
  644.     if(side == DIR.N) then
  645.       for i = 0, xlen, 3 do
  646.         coord(work[1].x + i, y, work[1].z):cub():fill(stonerailing);
  647.         coord(work[2].x - i, y, work[1].z):cub():fill(stonerailing);
  648.       end
  649.     elseif(side == DIR.S) then
  650.       for i = 0, xlen, 3 do
  651.         coord(work[1].x + i, y, work[2].z):cub():fill(stonerailing);
  652.         coord(work[2].x - i, y, work[2].z):cub():fill(stonerailing);
  653.       end
  654.     elseif(side == DIR.W) then
  655.       for i = 0, zlen, 3 do
  656.         coord(work[1].x, y, work[1].z + i):cub():fill(stonerailing);
  657.         coord(work[1].x, y, work[2].z - i):cub():fill(stonerailing);
  658.       end
  659.     elseif(side == DIR.E) then
  660.       for i = 0, zlen, 3 do
  661.         coord(work[2].x, y, work[1].z + i):cub():fill(stonerailing);
  662.         coord(work[2].x, y, work[2].z - i):cub():fill(stonerailing);
  663.       end
  664.     end
  665.   end
  666.  
  667. end
  668.  
  669. function Cuboid:box(pFill, pBase, pCrwn, pBody, pFoot, pHead)
  670.   self:fill(pFill or colFill); --Base Cuboid
  671.   self:bot():loop(pBase or colBase); --Bottom Border
  672.   self:top():loop(pCrwn or colCrwn); --Top Border
  673.   for qturn = 0, 3 do
  674.     self:cnr(qturn):pillar(pBody or colBody, pFoot or colFoot, pHead or colHead);
  675.   end
  676.   return self;
  677. end
  678.  
  679. local rset2 = {
  680.  { 0, 0 }, --1
  681.  { 0, 0 }, --2
  682.  { 0, 0, 1 }, --3
  683.  { 0, 0, 0, 1 }, --4
  684.  { 0, 0, 0, 1 }, --5
  685.  { 0, 0, 0, 1, 1 }, --6
  686.  { 0, 0, 0, 1, 1, 2 }, --7
  687.  { 0, 0, 0, 1, 1, 2, 2 }, --8
  688.  { 0, 0, 0, 0, 1, 1, 2 }, --9
  689.  { 0, 0, 0, 0, 1, 1, 2, 3 }, --10
  690.  { 0, 0, 0, 0, 1, 1, 2, 2, 3 }, --11
  691.  { 0, 0, 0, 0, 1, 1, 2, 2, 3 }, --12
  692.  { 0, 0, 0, 0, 1, 1, 1, 2, 3, 3 }, --13
  693.  { 0, 0, 0, 0, 1, 1, 1, 2, 2, 3, 4 }, --14
  694.  { 0, 0, 0, 0, 1, 1, 1, 2, 2, 3, 4 }, --15
  695.  { 0, 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4 } --16
  696. }
  697.  
  698. function Coord:cylinder(block, r, h, fill)
  699.   h = h - 1;
  700.   local sel = rset2[r];
  701.   if fill then
  702.     for i,d in ipairs(sel) do
  703.       local x = r - d;
  704.       local y = i - 1;
  705.       cuboid(self):off(DIR.N, y):dunswe(0, h, 0, 0, x, x):fill(block);
  706.       cuboid(self):off(DIR.N, x):dunswe(0, h, 0, 0, y, y):fill(block);
  707.       cuboid(self):off(DIR.S, y):dunswe(0, h, 0, 0, x, x):fill(block);
  708.       cuboid(self):off(DIR.S, x):dunswe(0, h, 0, 0, y, y):fill(block);
  709.     end
  710.   else
  711.     for i,d in ipairs(sel) do
  712.       local x = r - d;
  713.       local y = i - 1;
  714.       self:add(coord( x, 0,-y)):cub():gro(DIR.U, h):fill(block);
  715.       self:add(coord(-x, 0,-y)):cub():gro(DIR.U, h):fill(block);
  716.       self:add(coord( x, 0, y)):cub():gro(DIR.U, h):fill(block);
  717.       self:add(coord(-x, 0, y)):cub():gro(DIR.U, h):fill(block);
  718.       self:add(coord( y, 0,-x)):cub():gro(DIR.U, h):fill(block);
  719.       self:add(coord(-y, 0,-x)):cub():gro(DIR.U, h):fill(block);
  720.       self:add(coord( y, 0, x)):cub():gro(DIR.U, h):fill(block);
  721.       self:add(coord(-y, 0, x)):cub():gro(DIR.U, h):fill(block);
  722.     end
  723.   end
  724.   return self;
  725. end
  726.  
  727. function Coord:circle(block, r, fill)
  728.   self:cylinder(block, r, 1, fill);
  729.   return self;
  730. end
  731.  
  732.  
  733. function getStairs(dir, inv, stairsblocks)
  734.   stairsblocks = stairsblocks or stairs;
  735.   inv = inv or false;
  736.   return stairsblocks[dirLetter(dir) .. fif(inv, "i", "")];
  737. end
  738.  
  739. function Cuboid:roof(stairBlocks, sides)
  740.   sides = sides or DIR.HORIZONTALS;
  741.   local xlen = self:len(AXIS.X);
  742.   local zlen = self:len(AXIS.Z);
  743.  
  744.   test = testValues(sides);
  745.  
  746.   if(test[DIR.W] and test[DIR.E]) then xlen = math.floor(xlen / 2); end
  747.   if(test[DIR.N] and test[DIR.S]) then zlen = math.floor(zlen / 2); end
  748.  
  749.   local h = math.min(xlen, zlen);
  750.  
  751.   if(#sides == 1) then
  752.     local lens = {x = xlen, z = zlen};
  753.     local axis = sides[next(sides)].a;
  754.     h = lens[axis];
  755.   end
  756.   local p = self:fac(DIR.D); --get bottom face
  757.  
  758.   for i = 1, h do
  759.     for _,side in pairs(sides) do
  760.       p:fac(side):fill(stairBlocks[dirLetter(dirOpposite(side))]);
  761.       if p:len(side) > 1 then
  762.         p = p:gro(side, -1);
  763.       end
  764.     end
  765.     p = p:up(); --move up one block
  766.   end
  767.  
  768.   return self;
  769. end
  770.  
  771.  
  772. function Cuboid:stairs(stairBlocks, sides, filler)
  773.   sides = sides or DIR.HORIZONTALS;
  774.   filler = filler or stairBlocks.f;
  775.  
  776.   local xlen = self:len(AXIS.X);
  777.   local zlen = self:len(AXIS.Z);
  778.  
  779.   test = testValues(sides);
  780.  
  781.   if(test[DIR.W] and test[DIR.E]) then xlen = math.floor(xlen / 2); end
  782.   if(test[DIR.N] and test[DIR.S]) then zlen = math.floor(zlen / 2); end
  783.  
  784.   local h = math.min(xlen, zlen);
  785.  
  786.   if(#sides == 1) then
  787.     local lens = {x = xlen, z = zlen};
  788.     local axis = sides[next(sides)].a;
  789.     h = lens[axis];
  790.   end
  791.  
  792.   local p = self:fac(DIR.D); --get bottom face
  793.  
  794.   for i = 1, h do
  795.     for _,side in pairs(sides) do
  796.       p:fill(filler);
  797.       p:fac(side):fill(stairBlocks[dirLetter(dirOpposite(side))]);
  798.       if p:len(side) > 1 then
  799.         p = p:gro(side, -1);
  800.       end
  801.     end
  802.     p = p:up(); --move up one block
  803.   end
  804.   return self;
  805. end
  806.  
  807.  
  808. function Cuboid:stairsinv(stairBlocks, sides, filler)
  809.   sides = sides or DIR.HORIZONTALS;
  810.   filler = filler or stairBlocks.f;
  811.  
  812.   local xlen = self:len(AXIS.X);
  813.   local zlen = self:len(AXIS.Z);
  814.  
  815.   test = testValues(sides);
  816.  
  817.   if(test[DIR.W] and test[DIR.E]) then xlen = math.floor(xlen / 2); end
  818.   if(test[DIR.N] and test[DIR.S]) then zlen = math.floor(zlen / 2); end
  819.  
  820.   local h = math.min(xlen, zlen);
  821.  
  822.   if(#sides == 1) then
  823.     local lens = {x = xlen, z = zlen};
  824.     local axis = sides[next(sides)].a;
  825.     h = lens[axis];
  826.   end
  827.  
  828.   local p = self:fac(DIR.U); --get top face
  829.  
  830.   for i = 1, h do
  831.     for _,side in pairs(sides) do
  832.       if filler ~= 0 then
  833.         p:fill(filler);
  834.       end
  835.       p:fac(side):fill(stairBlocks[dirLetter(dirOpposite(side)) .. 'i']);
  836.       if p:len(side) > 1 then
  837.         p = p:gro(side, -1);
  838.       end
  839.     end
  840.     p = p:dwn(); --move down one block
  841.   end
  842.   return self;
  843. end
  844.  
  845. function Coord:lamp(dir)
  846.   return self:cub():fill(blockState("rustic:iron_lantern", "facing=" .. dir.n));
  847. end
  848.  
  849. function Coord:lamppost(h)
  850.   h = h or 3;
  851.   self:cub():gro(DIR.U, h - 1):fill(lattice):top()[1]:lamp(DIR.U);
  852. end
Add Comment
Please, Sign In to add comment