Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Lays lights for a horizontal 5-grid plane
- -- place on an existing light, facing the new area
- -- storage: lamp ender chest = slot 1, structural material chest = slot 2
- -- lamps = slot 3, structural material = slot 4
- -- mode 2: build window arrays - lamp chest = slot 1, structural chest = slot 2, window chest = slot 3
- -- lamps = slot 4, structural = slot 5, window = slot 6
- lamp_chest_slot = 1
- structure_chest_slot = 2
- window_chest_slot = 0
- lamp_slot = 3
- structural_slot = 4
- window_slot = 0
- function go_forward()
- while(turtle.forward() == false) do
- turtle.dig()
- turtle.attack()
- end
- end
- function refill_lamps()
- turtle.select(lamp_chest_slot)
- while(turtle.placeUp() == false) do
- turtle.attackUp()
- turtle.digUp()
- end
- -- if we broke or killed something, we need to drop it
- turtle.select(lamp_slot)
- turtle.drop()
- turtle.select(lamp_chest_slot)
- turtle.drop()
- turtle.suckUp()
- turtle.transferTo(lamp_slot)
- turtle.digUp()
- end
- function refill_structural()
- turtle.select(structure_chest_slot)
- while(turtle.placeUp() == false) do
- turtle.attackUp()
- turtle.digUp()
- end
- -- if we broke or killed something, we need to drop it
- turtle.select(structural_slot)
- turtle.drop()
- turtle.select(structure_chest_slot)
- turtle.drop()
- turtle.suckUp()
- turtle.transferTo(structural_slot)
- turtle.digUp()
- end
- function refill_window()
- turtle.select(window_chest_slot)
- while(turtle.placeUp() == false) do
- turtle.attackUp()
- turtle.digUp()
- end
- -- if we broke or killed something, we need to drop it
- turtle.select(window_slot)
- turtle.drop()
- turtle.select(window_chest_slot)
- turtle.drop()
- turtle.suckUp()
- turtle.transferTo(window_slot)
- turtle.digUp()
- end
- function place_lamp()
- while(turtle.getItemCount(lamp_slot) == 0) do
- refill_lamps()
- end
- turtle.select(lamp_slot)
- while(turtle.placeDown() == false) do
- turtle.digDown()
- turtle.attackDown()
- end
- while(turtle.getItemCount(lamp_slot) == 0) do
- refill_lamps()
- end
- end
- function place_structural()
- while(turtle.getItemCount(structural_slot) == 0) do
- refill_structural()
- end
- turtle.select(structural_slot)
- while(turtle.placeDown() == false) do
- turtle.digDown()
- turtle.attackDown()
- end
- while(turtle.getItemCount(structural_slot) == 0) do
- refill_structural()
- end
- end
- function place_window()
- while(turtle.getItemCount(window_slot) == 0) do
- refill_window()
- end
- turtle.select(window_slot)
- while(turtle.placeDown() == false) do
- turtle.digDown()
- turtle.attackDown()
- end
- while(turtle.getItemCount(window_slot) == 0) do
- refill_window()
- end
- end
- function build_lamp_row(num)
- -- for each number, move forward 3 times while placing structural blocks underneath
- -- then move forward once more and place a lamp block underneath
- for i = 1, num do
- for j = 1, 3 do
- go_forward()
- place_structural()
- end
- go_forward()
- place_lamp()
- end
- end
- function build_structural_row(num)
- -- for each number, move forward 4 times while placing structural blocks underneath
- for i = 1, num do
- for j = 1, 4 do
- go_forward()
- place_structural()
- end
- end
- end
- function build_window_row(num)
- -- for each number, move forward 3 times while placing window blocks underneath
- -- then move forward once more and place a structural block underneath
- for i = 1, num do
- for j = 1, 3 do
- go_forward()
- place_window()
- end
- go_forward()
- place_structural()
- end
- end
- function turn_turtle(is_lamp)
- if(previous == "right") then
- turtle.turnLeft()
- go_forward()
- turtle.turnLeft()
- if(is_lamp) then
- place_lamp()
- else
- place_structural()
- end
- previous = "left"
- elseif(previous == "left") then
- turtle.turnRight()
- go_forward()
- turtle.turnRight()
- if(is_lamp) then
- place_lamp()
- else
- place_structural()
- end
- previous = "right"
- elseif(previous == "up") then
- while(turtle.up() == false) do
- turtle.digUp()
- turtle.attackUp()
- end
- turtle.turnRight()
- turtle.turnRight()
- if(is_lamp) then
- place_lamp()
- else
- place_structural()
- end
- previous = "up"
- end
- end
- print("Initialising 5-grid construction program.")
- print("This program will construct a horizontal or vertical 5-grid plane using items from ender chests. Place on an existing lamp facing towards the new area. It must be pre-loaded with fuel (use an electric charging station).")
- print("The turtle will lay lamps and structure blocks in a rectangle ahead and to the left, right or above of its current position.")
- print("Enter l for left, r for right or v for vertical:\n")
- direction=io.read(io.stdin)
- while (direction ~= "l" and direction ~= "r" and direction ~= "v") do
- print("Error: direction must be \"l\", \"r\" or \"v\"..")
- direction = io.read(io.stdin)
- end
- print("Enter mode (a for wall, b for window):\n")
- mode=io.read(io.stdin)
- while (mode ~= "a" and mode ~= "b") do
- print("Error: mode must be \"a\" (wall) or \"b\" (window).")
- mode = io.read(io.stdin)
- end
- if(mode == "b") then
- window_chest_slot = 3
- lamp_slot = 4
- structural_slot = 5
- window_slot = 6
- end
- print("Place the lamp ender chest in the first slot, the material ender chest in the second slot and (if applicable) the window ender chest in the third slot.")
- tempvar = io.read(io.stdin)
- print("Enter number of grid units to build forward:")
- numforward = tonumber(io.read(io.stdin))
- while(numforward <= 0) do
- print("Error: must build more than 1 ahead. Enter number of grid units to build forward.")
- numforward = tonumber(io.read(io.stdin))
- end
- print("Enter number of grid units built to the side:")
- numside = tonumber(io.read(io.stdin))
- while(numside < 0) do
- print("Error: cannot build negative grids. Ender number of grid units to build to the side.")
- numside = tonumber(io.read(io.stdin))
- end
- fuelcost = (numside + 1) * numforward * 4 + numside * 4
- if(fuelcost > turtle.getFuelLevel()) then
- print("Error: do not have enough fuel for this operation. Requires ", fuelcount, ", have ", turtle.getFuelLevel(), ".")
- return
- else
- print("Fuel cost: ", fuelcost, ", current fuel level is ", turtle.getFuelLevel(), ".")
- end
- refill_lamps()
- refill_structural()
- if(mode == "b") then
- refill_window()
- end
- previous = "blankety"
- if(direction == "l") then
- previous = "right"
- elseif(direction == "r") then
- previous = "left"
- else
- previous = "up"
- end
- build_lamp_row(numforward)
- -- the first line will always be lamp/structural
- -- the next three will either be pure structural or structural/window, depending on the mode
- while(numside > 0) do
- for i = 1, 3 do
- turn_turtle(false)
- if(mode == "a") then
- build_structural_row(numforward)
- elseif(mode == "b") then
- build_window_row(numforward)
- end
- end
- turn_turtle(true)
- build_lamp_row(numforward)
- numside = numside - 1
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement