Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local INTERPRETER = 18
- local has_fuel = true
- local busy = false
- local ready = false
- local current_time = 0
- local current_task = nil
- local screen = peripheral.wrap("front")
- local function update_screen()
- screen.clear()
- screen.setTextScale(1.5)
- screen.setCursorPos(1,1)
- screen.write("State:")
- screen.setCursorPos(1,2)
- if not ready then
- screen.write("Initting")
- elseif not has_fuel then
- screen.write("NO FUEL")
- elseif busy then
- if current_task == "bake_bread" then
- screen.write("Baking bread")
- else
- screen.write("Planting crops")
- end
- else
- screen.write("Growing")
- end
- screen.setCursorPos(1,4)
- screen.write("Time until harvest:")
- screen.setCursorPos(1,5)
- screen.write(40 - current_time .. "m")
- screen.setCursorPos(1,7)
- screen.write("[")
- -- Can fit 15 |'s in a single line
- local lines = (current_time / 40) * 15
- for c = 0, lines do
- screen.write("|")
- end
- for c = 0, 15 - lines do
- screen.write(" ")
- end
- screen.write("]")
- end
- local function handleMessage(msg)
- print("Got message ", msg)
- if msg == "has_fuel" then
- has_fuel = true
- elseif msg == "has_no_fuel" then
- has_fuel = false
- elseif msg == "performing_task" then
- busy = true
- elseif msg == "done_task" then
- busy = false
- elseif msg == "ready" then
- ready = true
- end
- update_screen()
- end
- local function check_state()
- local id, msg = rednet.receive(1)
- if not id then
- return
- end
- if id == INTERPRETER then
- handleMessage(msg)
- end
- end
- local function freeze_while_waiting()
- print("Freezing")
- while not has_fuel or busy or not ready do
- check_state()
- end
- print("Not freezing anymore")
- end
- local function start_farm()
- redstone.setOutput("back", true)
- sleep(60)
- redstone.setOutput("back", false)
- sleep(30)
- redstone.setOutput("left", true)
- sleep(10)
- redstone.setOutput("left", false)
- rednet.send(INTERPRETER, "farm")
- end
- local function iterate()
- while true do
- update_screen()
- freeze_while_waiting()
- print("Starting time")
- -- 40 minutes, time to fully grow a crop
- for t = 0, 8 do
- -- 5 minutes
- for f = 0, 5 do
- -- 1 minute
- print("mins")
- for s = 0, 60 do
- check_state()
- end
- print("mine")
- current_time = current_time + 1
- update_screen()
- end
- freeze_while_waiting()
- -- Make bread
- rednet.send(INTERPRETER, "bake_bread")
- current_task = "bake_bread"
- busy = true
- freeze_while_waiting()
- end
- current_time = 0
- update_screen()
- freeze_while_waiting()
- -- Trigger flood and then replant crops
- start_farm()
- current_task = "farm"
- busy = true
- freeze_while_waiting()
- end
- end
- local function init()
- rednet.open("top")
- iterate()
- end
- init()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement