Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local argv = {...}
- local radius = tonumber(argv[1])
- local height = tonumber(argv[2])
- local function check_fuel()
- if turtle.getFuelLevel() < 80 then
- turtle.select(1)
- turtle.refuel(1)
- end
- end
- function distance( x1, y1, x2, y2 )
- return math.sqrt( (x2-x1)^2 + (y2-y1)^2 )
- end
- function round(x)
- local x_m = x % 1.0
- if x_m >= 0.5 then
- return math.ceil(x)
- else
- return math.floor(x)
- end
- end
- local function select_dirt()
- for s=2, 16 do
- turtle.select(s)
- local i_name = turtle.getItemDetail()
- if i_name then
- i_name = i_name.name
- if (i_name == "minecraft:dirt") or (i_name == "minecraft:sand") or (i_name == "minecraft:gravel") then
- break
- end
- end
- end
- end
- local function select_glass()
- for s=2, 16 do
- turtle.select(s)
- local item_detail = turtle.getItemDetail()
- if item_detail and (item_detail.name == "minecraft:glass") then
- break
- end
- end
- end
- local last_layer = false
- local function GenerateLayer(l)
- local final_radius = radius
- if l > height then
- final_radius = radius - (l - height)
- end
- local rtn = {}
- local string_version = ""
- local fill_block_count = 0
- for x=-radius, radius do
- for z=-radius, radius do
- local rtn_id = tostring(x) .. "," .. tostring(z)
- local l_d = distance(0, 0, x, z)
- if round(l_d) == final_radius then
- rtn[rtn_id] = 1
- string_version = string_version .. "#"
- elseif l_d < final_radius then
- rtn[rtn_id] = 2
- string_version = string_version .. "O"
- fill_block_count = fill_block_count + 1
- else
- rtn[rtn_id] = 0
- string_version = string_version .. " "
- end
- end
- if x < radius then
- string_version = string_version .. "\n"
- end
- end
- if fill_block_count == 0 then
- last_layer = true
- end
- print(string_version)
- return rtn
- end
- check_fuel()
- turtle.forward()
- while turtle.down() do
- check_fuel()
- end
- local function attempt_place_down()
- while not turtle.placeDown() do
- print("Something in the way!")
- end
- end
- local current_layer = 0
- local next_dome_layer = nil
- -- place layers
- while true do
- if last_layer then
- break
- end
- current_layer = current_layer + 1
- next_dome_layer = GenerateLayer(current_layer)
- if turtle.detectUp() then
- turtle.digUp()
- end
- check_fuel()
- turtle.up()
- local work_area = (radius * 2) + 1
- local turn_dir = true
- for x=1, work_area do
- for z=1, work_area do
- local cell_id = tostring(x - radius - 1) .. "," .. tostring(z - radius - 1)
- if turtle.detectDown() then
- turtle.digDown()
- end
- if turtle.detect() then
- turtle.dig()
- end
- local target_block = next_dome_layer[cell_id]
- if target_block == 1 then
- select_glass()
- attempt_place_down()
- elseif target_block == 2 then
- select_dirt()
- attempt_place_down()
- end
- check_fuel()
- if z < work_area then
- turtle.forward()
- end
- end
- if x < work_area then
- if turn_dir then
- turtle.turnRight()
- else
- turtle.turnLeft()
- end
- if turtle.detect() then
- turtle.dig()
- end
- check_fuel()
- turtle.forward()
- if turn_dir then
- turtle.turnRight()
- else
- turtle.turnLeft()
- end
- turn_dir = not turn_dir
- end
- end
- if turn_dir then
- turtle.turnLeft()
- for x=2, work_area do
- check_fuel()
- turtle.forward()
- end
- turtle.turnLeft()
- for z=2, work_area do
- check_fuel()
- turtle.forward()
- end
- turtle.turnLeft()
- turtle.turnLeft()
- else
- turtle.turnRight()
- for x=2, work_area do
- check_fuel()
- turtle.forward()
- end
- turtle.turnRight()
- end
- end
- print("FINISHED PRINTING!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement