0x0049 icon

Light Placer

0x0049 | PRO | 07/10/15 01:27:31 AM UTC | 0 ⭐ | 412 👁️ | Never ⏰ | []
Lua |

2.35 KB

|

None

|

0 👍

/

0 👎

--[[
    Light placer v1.0
    Places a light block every x blocks in a flat grid-like
    configuration.
 
    Turtle starts in the lower left corner, where the _first light block_ should go.
--]]
 
length = 115 -- How many "columns". Make sure it's in increments of nth.
depth = 115 -- How long a column is. Make sure it's in increments of nth.
direction = 0 -- So we know which way to turn at the end of a column.
nth = 5 -- We will place blocks every nth block.
 
-- Select first slot.
slot = 1
turtle.select(slot)
 
--[[
    The plan is to move up the first column (0), placing blocks every X blocks.
    After reaching the end we turn, move X blocks, turn, then repeat.
--]]
 
-- Move foward after removing any obstacles.
function move()
    -- Loop and sleep in case of falling blocks.
    while turtle.detect() do
        turtle.dig()
        sleep(1)
    end
    turtle.forward()
end
 
-- Move to the next column
function nextColumn()
    if direction == 0 then
        turtle.turnRight()
    else
        turtle.turnLeft()
    end
 
    for i = 1, nth, 1 do
        move()
    end
 
    if direction == 0 then
        turtle.turnRight()
        direction = 1
    else
        turtle.turnLeft()
        direction = 0
    end
end
 
-- Place light block down, removing anything in the way.
-- Checks inventory and will wait for refills.
function placeLight()
    if turtle.detectDown() then
        turtle.digDown()
    end
 
    -- Leave at least one block so it won't get filled by something else and then the turtle places that something else.
    while turtle.getItemCount() <= 1 do
        if slot == 16 then
            slot = 1
            print "Need more building materials"
            sleep(5)
        else
            slot = slot + 1
        end
        turtle.select(slot)
    end
 
    turtle.placeDown()
end
 
for i = 0, length, nth do
    for j = 0, depth, 1 do
        -- Place light on every nth spot.
        if (i % nth == 0 and j % nth == 0) then
            placeLight()
        end
 
    -- Only move if we aren't at the end of the column.
    if j ~= depth then
            move()
    end
    end
    -- Once we've reached the end, turn, move X blocks, then turn again. Then we're ready for another go.
    -- But don't bother if this is the last column.
    if i ~= length then
        nextColumn()
    end
end

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎