Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- term = require("term")
- comp = require("component")
- w = comp.debug.getWorld()
- function quit(msg)
- print(msg)
- os.exit()
- end
- function getNumber(msg)
- while (not value) do
- print("Enter a number: " .. msg)
- value = tonumber(term.read())
- end
- return math.floor(value)
- end
- function getYesNo(msg)
- while (value == nil) do
- print("Yes or no: " .. msg)
- v = string.lower(io.read())
- if (v == "yes" or v == "y" or v == "true" or v == "t" or v == "1") then value = true
- elseif (v == "no" or v == "n" or v == "false" or v == "f" or v == "0") then value = false end
- end
- return value
- end
- -- Find starting coordinate
- sx = getNumber("X-coordinate of grid origin.")
- sy = getNumber("Y-coordinate of grid origin.")
- sz = getNumber("Z-coordinate of grid origin.")
- -- Find grid size
- print("For the following three numbers, enter the number of points, not the number of blocks.")
- print("Use a negative number to go the opposite direction. Use 0 to not extend the grid this way.")
- print("Note that the program will exit if you enter zero for all three numbers.")
- gx = getNumber("Length to extend grid east.")
- gy = getNumber("Length to extend grid up.")
- gz = getNumber("Length to extend grid south.")
- if (gx == 0 and gy == 0 and gz == 0) then os.exit() end
- -- Find blocks and grid lengths
- print("Now enter the block ID *number* and data *byte* to set the blocks at the points to.")
- bld = {id = getNumber("Block ID"), data = getNumber("Block data")}
- blx = {}
- bly = {}
- blz = {}
- dx = 0
- dy = 0
- dz = 0
- if gx ~= 0 then
- print("Now enter the id and data for blocks along lines on the X axis.")
- blx = {id = getNumber("Block ID"), data = getNumber("Block data")}
- print("Now the distance between block centers of two consecutive intersecting points. It can't be 0 or negative.")
- while dx < 1 do dx = getNumber("X distance") end
- end
- if gy ~= 0 then
- print("Now enter the id and data for blocks along lines on the Y axis.")
- bly = {id = getNumber("Block ID"), data = getNumber("Block data")}
- print("Now the distance between block centers of two consecutive intersecting points. It can't be 0 or negative.")
- while dy < 1 do dy = getNumber("Y distance") end
- end
- if gz ~= 0 then
- print("Now enter the id and data for blocks along lines on the Z axis.")
- blz = {id = getNumber("Block ID"), data = getNumber("Block data")}
- print("Now the distance between block centers of two consecutive intersecting points. It can't be 0 or negative.")
- while dz < 1 do dz = getNumber("Z distance") end
- end
- -- Find total grid lengths
- lx = gx * dx
- ly = gy * dy
- lz = gz * dz
- -- Start on the bottom northwest corner regardless of input values
- if (gx < 0) then
- sx = sx + lx
- gx = -gx
- lx = -lx
- end
- if (gy < 0) then
- sy = sy + ly
- gy = -gy
- ly = -ly
- end
- if (gz < 0) then
- sz = sz + lz
- gz = -gz
- lz = -lz
- end
- -- Draw x gridlines
- if (gx ~= 0) then
- for cy = 0, gy do
- y = sy + cy * dy
- for cz = 0, gz do
- z = sz + cz * dz
- for cx = 0, gx-1 do
- for x = sx + cx * dx, sx + (cx + 1) * dx - 1 do
- w.setBlock(x, y, z, blx.id, blx.data)
- end
- end
- end
- end
- end
- -- Draw y gridlines
- if (gy ~= 0) then
- for cx = 0, gx do
- x = sx + cx * dx
- for cz = 0, gz do
- z = sz + cz * dz
- for cy = 0, gy-1 do
- for y = sy + cy * dy, sy + (cy + 1) * dy - 1 do
- w.setBlock(x, y, z, bly.id, bly.data)
- end
- end
- end
- end
- end
- -- Draw z gridlines
- if (gz ~= 0) then
- for cy = 0, gy do
- y = sy + cy * dy
- for cx = 0, gx do
- x = sx + cx * dx
- for cz = 0, gz-1 do
- for z = sz + cz * dz, sz + (cz + 1) * dz - 1 do
- w.setBlock(x, y, z, blz.id, blz.data)
- end
- end
- end
- end
- end
- -- Draw grid intersections
- for cx = 0, gx do
- x = sx + cx * dx
- for cy = 0, gy do
- y = sy + cy * dy
- for cz = 0, gz do
- z = sz + cz * dz
- w.setBlock(x, y, z, bld.id, bld.data)
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement