Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local APIS={}
- local inv_slots = 16
- local inv_side = require("sides").left
- local lc = {x=0, y=0, z=0, dr=3}
- local charge_side = require("sides").right
- local battery_side = require("sides").bottom
- function APIS.charge(charge_side)
- comp = require("computer")
- while comp.energy() < (comp.maxEnergy()/2) do
- --local rs = require("component").redstone
- --rs.setOutput(charge_side, 15)
- require("term").clear()
- APIS.use(charge_side)
- print("Зарядка...")
- os.sleep(60)
- --rs.setOutput(charge_side, 0)
- APIS.use(charge_side)
- end
- print("Батарея заряжена")
- return true
- end
- function APIS.charge_tool(s)
- local inv = require("component").inventory_controller
- local r = require("robot")
- if r.durability() < 0.2 then
- r.select(1)
- inv.equip()
- if s == 1 then
- r.dropUp()
- os.sleep(15)
- r.suckUp()
- else
- if s == 2 then
- r.turnAround()
- r.drop()
- os.sleep(15)
- r.suck()
- r.turnAround()
- else
- if s == 3 then
- r.drop()
- os.sleep(15)
- r.suck()
- else
- if s == 4 then
- r.turnRight()
- r.drop()
- os.sleep(15)
- r.suck()
- r.turnLeft()
- else
- if s==5 then
- r.turnLeft()
- r.drop()
- os.sleep(15)
- r.suck()
- r.turnRight()
- else
- r.dropDown()
- os.sleep(15)
- r.suckDown()
- end
- end
- end
- end
- end
- end
- end
- function APIS.use(s)
- local r = require("robot")
- if s == 1 then r.useUp() else
- if s == 2 then
- r.turnAround()
- r.use()
- r.turnAround()
- else
- if s == 3 then r.use() else
- if s == 4 then
- r.turnRight()
- r.use()
- r.turnLeft()
- else
- if s==5 then
- r.turnLeft()
- r.use()
- r.turnRight()
- else
- r.useDown()
- end
- end
- end
- end
- end
- end
- function APIS.drop()
- local r= require("robot")
- for i=1,inv_slots do
- r.select(i)
- r.drop()
- end
- r.select(1)
- end
- function APIS.printState()
- print("Статус:")
- print(lc.x, lc.y, lc.z, lc.dr)
- end
- function turnLeft()
- local r = require("robot")
- r.turnLeft()
- if lc.dr == 3 then
- lc.dr = 5
- elseif lc.dr == 4 then
- lc.dr = 3
- elseif lc.dr == 2 then
- lc.dr = 4
- elseif lc.dr == 5 then
- lc.dr = 2
- end
- end
- function APIS.rot(side)
- local sides = require("sides")
- local r = require("robot")
- while lc.dr ~= side do
- turnLeft()
- end
- --APIS.printState()
- end
- function APIS.mUp()
- local r = require("robot")
- local try = 1
- while not r.up() == true do
- try = try + 1
- event.pull(0.4)
- if try >= 10 then
- APIS.printState()
- return false
- end
- end
- if try < 10 then
- lc.y = lc.y + 1
- APIS.printState()
- return true
- end
- end
- function APIS.mDown()
- local r = require("robot")
- local event = require("event")
- local try = 1
- while not r.down() == true do
- try = try + 1
- event.pull(0.4)
- if try >= 10 then
- APIS.printState()
- return false
- end
- end
- if try < 10 then
- lc.y = lc.y - 1
- return true
- end
- end
- function APIS.mForw(harv)
- local r = require("robot")
- local event = require("event")
- local try = 1
- local sides = require("sides")
- if harv == true then
- --print("Собираем")
- APIS.use(sides.down)
- APIS.use(sides.down)
- end
- while not r.forward() do
- try = try + 1
- event.pull(0.4)
- if try >= 10 then
- return false
- end
- end
- if try < 10 then
- if lc.dr==2 then
- lc.x = lc.x - 1
- elseif lc.dr==3 then
- lc.x = lc.x + 1
- elseif lc.dr==4 then
- lc.z = lc.z + 1
- elseif lc.dr==5 then
- lc.z = lc.z - 1
- end
- APIS.printState()
- return true
- end
- end
- function APIS.mTo(x, y, z, harv)
- local r = require("robot")
- local sides = require("sides")
- while lc.y < y do
- APIS.mUp()
- --print("едем вверх")
- end
- if lc.x > x then
- APIS.rot(sides.back)
- while lc.x > x do
- APIS.mForw(harv)
- end
- end
- if lc.x < x then
- APIS.rot(sides.forward)
- while lc.x < x do
- APIS.mForw(harv)
- end
- end
- if lc.z > z then
- APIS.rot(sides.left)
- while lc.z > z do
- APIS.mForw(harv)
- end
- end
- if lc.z < z then
- APIS.rot(sides.right)
- while lc.z < z do
- APIS.mForw(harv)
- end
- end
- while lc.y > y do
- APIS.mDown()
- print("едем вниз")
- end
- end
- function APIS.plane(x,z,harv)
- local dir = "forward"
- for j=0,z do
- if dir == "forward" then
- for i=0,x do
- APIS.mTo(i,0,j,harv)
- end
- dir = "back"
- else
- for i=x,0,-1 do
- APIS.mTo(i,0,j,harv)
- end
- dir = "forward"
- end
- end
- end
- function APIS.home(harv)
- APIS.mTo(0,0,0, harv)
- APIS.rot(2)
- APIS.drop()
- APIS.rot(3)
- end
- function APIS.field(x,z, time)
- while true do
- APIS.charge(require("sides").top)
- APIS.plane(x,z, true)
- APIS.use(require("sides").down)
- APIS.use(require("sides").down)
- APIS.home()
- print("Ожидание созревания...", time, "минут.")
- os.sleep(60*time)
- end
- end
- function APIS.chop_single()
- local inv = require("component").inventory_controller
- local beam = require("component").tractor_beam
- local r = require("robot")
- while true do
- require("term").clear()
- print("Лесоруб, одиночное дерево. Ожидание роста саженца.")
- local _, wood = r.detect()
- if wood == "solid" then
- print("Рубка дерева.")
- r.swing()
- os.sleep(5)
- for i=1, 5 do
- beam.suck()
- end
- for i=1, inv_slots do
- a=inv.getStackInInternalSlot(i)["name"]
- if a=="minecraft:sapling" then
- r.select(i)
- r.place()
- r.select(1)
- break
- end
- end
- APIS.rot(inv_side)
- APIS.drop()
- APIS.rot(3)
- APIS.charge(charge_side)
- APIS.charge_tool(battery_side)
- end
- os.sleep(10)
- end
- end
- return APIS
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement