chunquarry/code.fnl

56 lines
1.4 KiB
Fennel

(local depth 60)
(local cable-dir :left)
(local outputs {:right 1
:left 2
:up 4
:down 8
:break 16
:rejuv 32
:error 64
:check 128})
(fn pulse-signal [output]
(local id (. outputs output))
(redstone.setBundledOutput cable-dir id)
(os.sleep 1)
(redstone.setBundledOutput cable-dir 0)
(os.sleep 1))
(fn check-gantry []
(print "Checking gantry position")
(redstone.setBundledOutput cable-dir (. outputs :break))
(os.sleep 2)
(when (not (= (redstone.getBundledInput cable-dir)
(+ (. outputs :break) (. outputs :check))))
(error "Incorrect gantry position!")))
(fn run []
(check-gantry)
(print "Moving gantry into chunk")
(for [_ 1 16]
(pulse-signal :right))
(print :Mining)
(for [_ 1 depth]
(pulse-signal :down)
(pulse-signal :break))
;; Wait for items to go into chest
(print "Waiting for items")
(os.sleep 60)
(print "Resetting gantry")
(for [_ 1 depth]
(pulse-signal :up))
(for [_ 1 16]
(pulse-signal :left))
(os.sleep 3)
(check-gantry)
(print "Activating rejuvenator")
(redstone.setBundledOutput cable-dir (. outputs :rejuv))
(os.sleep 20)
(redstone.setBundledOutput cable-dir 0)
nil)
(local (_ err) (pcall run []))
(when err
(print err)
(redstone.setBundledOutput cable-dir (. outputs :error)))