Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local State = {INIT = "1",
- WAIT = "2",
- GET_TREE = "3",
- REPLANT = "4"}
- local currentState = State.INIT
- local treeCNT = 0
- disp = peripheral.wrap("bottom")
- function serialize(data, name)
- if not fs.exists('/data') then
- fs.makeDir('/data')
- end
- local f = fs.open('/data/'..name, 'w')
- f.write(textutils.serialize(data))
- f.close()
- end
- function unserialize(name)
- if fs.exists('/data/'..name) then
- local f = fs.open('/data/'..name, 'r')
- data = textutils.unserialize(f.readAll())
- f.close()
- end
- return data
- end
- function getTree()
- turtle.dig()
- turtle.forward()
- while not(turtle.up()) do
- turtle.digUp()
- turtle.up()
- end
- while not (turtle.detectDown()) do
- turtle.down()
- end
- turtle.back()
- treeCNT = treeCNT + 1
- disp.clear()
- disp.setCursorPos(1,1)
- disp.write(tostring(treeCNT).." bomen")
- serialize(treeCNT, "memTreeCount")
- currentState = State.REPLANT
- end
- function replant()
- turtle.select(3)
- if (turtle.getItemCount() < 10) then
- print("Running low on Saplings")
- turtle.suckDown(30)
- end
- turtle.place()
- currentState = State.WAIT
- end
- function waitForGrow()
- local inspectedBlock, data = turtle.inspect()
- if data.name == "minecraft:spruce_log" then
- currentState = State.GET_TREE
- end
- end
- while (1) do
- if currentState == State.INIT then
- treeCNT = unserialize("memTreeCount")
- end
- if currentState == State.WAIT then
- waitForGrow()
- end
- if currentState == State.REPLANT then
- replant()
- end
- if currentState == State.GET_TREE then
- getTree()
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement