Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local nowKey
- local function keyCheck()
- while true do
- local event, key, isHeld = os.pullEvent("key")
- nowKey = keys.getName(key)
- end
- end
- local function keyMap(kvalue)
- if(kvalue == "w") then
- turtle.forward()
- elseif (kvalue == "s") then
- turtle.back()
- elseif (kvalue == "a") then
- turtle.turnLeft()
- elseif (kvalue == "d") then
- turtle.turnRight()
- elseif (kvalue == "leftShift") then
- turtle.down()
- elseif (kvalue == "space") then
- turtle.up()
- end
- end
- local function moveloop()
- while 1 do
- if(nowKey ~= nil) then
- keyMap(nowKey)
- nowKey = nil
- end
- os.sleep(1)
- end
- end
- if(arg[1] == nil) then
- parallel.waitForAll(moveloop,keyCheck)
- return
- end
- print("start work!")
- local emptyFlag =false
- local bkslot = 2
- local function turtleSelfCheck()
- -- check fuel
- if(turtle.getFuelLevel() < 100) then
- turtle.select(1)
- turtle.refuel(1)
- end
- -- check space
- turtle.select(bkslot)
- if(emptyFlag == false) then
- while (turtle.getItemCount() == 0) do
- bkslot = bkslot + 1
- if(turtle.getItemCount(2) ~= 0) then
- bkslot = 2
- break
- end
- if(bkslot > 16) then
- os.shutdown()
- end
- turtle.select(bkslot)
- end
- end
- end
- local count = tonumber(arg[1])
- local orient = arg[2]
- while (count > 0) do
- turtleSelfCheck()
- -- place
- if(orient == "u") then
- turtle.up()
- turtle.forward()
- turtle.placeDown()
- elseif (orient == "d") then
- turtle.forward()
- turtle.down()
- turtle.placeDown()
- else
- break
- end
- count = count - 1
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement