Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local function sync()
- -- print("sync")
- local init_slot = turtle.getSelectedSlot() -- 退避
- local found_slot = 0
- for i = 1, 16 do
- -- print("sync:: slot:"..i.." found slot:"..found_slot)
- local info = turtle.getItemDetail(i)
- if info then
- if info.name == "minecraft:concrete" then
- turtle.select(i)
- turtle.dropUp()
- elseif (found_slot == 0) and (info.name == "minecraft:concrete_powder") then
- found_slot = i
- -- print("sync:: found")
- end
- end
- end
- turtle.select(init_slot)
- return found_slot
- end
- local function place_and_dig_impl()
- -- print("place_and_dig_impl")
- turtle.dig()
- while 0 < turtle.getItemCount() do
- local info = turtle.getItemDetail(i)
- if (not info) or (info.name ~= "minecraft:concrete_powder") then break end
- local re, message = turtle.place()
- if not re then return re, message end
- os.sleep(0.2)
- while true do
- local re, info = turtle.inspect()
- if re and info ~= nil and info.name == "minecraft:concrete" then
- break
- end
- os.sleep(0.1)
- end
- re, message = turtle.dig()
- if not re then return re, message end
- end
- return true
- end
- ---@param slot integer
- local function place_and_dig(slot)
- local init_slot = turtle.getSelectedSlot() -- 退避
- turtle.select(slot)
- local re, message = place_and_dig_impl()
- turtle.select(init_slot)
- return re, message
- end
- local function main()
- while true do
- local slot = sync()
- if slot ~= 0 then
- local re, message = place_and_dig(slot)
- if not re then return re, message end
- else
- os.sleep(2)
- end
- end
- return true
- end
- local re, message = main()
- if not re then print(message) end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement