Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- DESIGNATED_BLOCK = "minecraft:stone"
- DESIGNATED_FUEL = "minecraft:coal"
- INVENTORY_SIZE = 16
- local function log(message)
- print(">-- "..message)
- end
- local function get_slot_with_item_in_inventory(item)
- for i = 1, INVENTORY_SIZE, 1 do
- if turtle.getItemDetail(i) then
- if turtle.getItemDetail().name == item then
- return i
- end
- end
- end
- log("Couldn't find item with name: "..item)
- return nil
- end
- local function wait_for_item_in_inventory_and_get_slot(item)
- while true do
- for i = 1, INVENTORY_SIZE, 1 do
- if turtle.getItemDetail(i) then
- if turtle.getItemDetail().name == item then
- return i
- end
- end
- end
- os.sleep(0.5)
- log("Cannot find item with name: "..item)
- end
- end
- local function placeBlock()
- if turtle.getItemDetail() then
- if turtle.getItemDetail().name ~= DESIGNATED_BLOCK then
- turtle.select(wait_for_item_in_inventory_and_get_slot(DESIGNATED_BLOCK))
- end
- else
- turtle.select(wait_for_item_in_inventory_and_get_slot(DESIGNATED_BLOCK))
- end
- if not turtle.compareDown() then
- turtle.digDown()
- turtle.placeDown()
- end
- end
- local function proceedForward()
- if turtle.detect() then
- turtle.dig()
- end
- turtle.forward()
- end
- local function proceedLeft()
- placeBlock()
- turtle.turnLeft()
- if turtle.detect() then
- turtle.dig()
- end
- turtle.forward()
- turtle.turnLeft()
- end
- local function proceedRight()
- placeBlock()
- turtle.turnRight()
- if turtle.detect() then
- turtle.dig()
- end
- turtle.forward()
- turtle.turnRight()
- end
- local function refuel(wait)
- repeat
- for i = 1, INVENTORY_SIZE, 1 do
- turtle.select(i)
- if turtle.refuel() then
- log("Succesfully refueled")
- return
- end
- end
- if wait then
- log("Could find fuel, waiting for fuel in inventory")
- os.sleep(0.5)
- else
- log("Could find fuel, proceeding...")
- end
- until not wait
- end
- --Main
- local function main()
- term.write("Width: ")
- local target_width = io.read()
- term.write("Height: ")
- local target_height = io.read()
- print(target_width, target_height)
- for width = 1, target_width, 1 do
- for height = 1, target_height - 1, 1 do
- if turtle.getFuelLevel() < 100 then
- log("Low on fuel")
- refuel(false)
- elseif turtle.getFuelLevel() < 10 then
- log("Fuel level critical, waiting for fuel")
- refuel(true)
- end
- placeBlock()
- proceedForward()
- log(width.." "..height)
- end
- if width % 2 == 1 then
- proceedRight()
- else
- proceedLeft()
- end
- end
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment