Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local moving={}
- local component = require("component")
- local geo = component.geolyzer
- local robot=require('robot')
- local x=0
- local y=0
- local z=0
- local direct='N'
- function getX()
- return x
- end
- function getY()
- return y
- end
- function getZ()
- return z
- end
- function getCoordinates()
- return x,y,z,direct
- end
- function smartTurnLeft()
- robot.turnLeft()
- if direct=='N' then
- direct='W'
- elseif direct=='W' then
- direct='S'
- elseif direct=='S' then
- direct='E'
- elseif direct=='E' then
- direct='N'
- end
- end
- function smartTurnRight()
- robot.turnRight()
- if direct=='N' then
- direct='E'
- elseif direct=='E' then
- direct='S'
- elseif direct=='S' then
- direct='W'
- elseif direct=='W' then
- direct='N'
- end
- end
- function smartTurnAround()
- robot.turnAround()
- if direct=='N' then
- direct='S'
- elseif direct=='W' then
- direct='E'
- elseif direct=='S' then
- direct='N'
- elseif direct=='E' then
- direct='W'
- end
- end
- function turnNorth()
- if direct=='S' then
- robot.turnAround()
- elseif direct=='W' then
- robot.turnRight()
- elseif direct=='E' then
- robot.turnLeft()
- end
- direct='N'
- end
- function turnWest()
- if direct=='E' then
- robot.turnAround()
- elseif direct=='S' then
- robot.turnRight()
- elseif direct=='N' then
- robot.turnLeft()
- end
- direct='W'
- end
- function turnSouth()
- if direct=='N' then
- robot.turnAround()
- elseif direct=='E' then
- robot.turnRight()
- elseif direct=='W' then
- robot.turnLeft()
- end
- direct='S'
- end
- function turnEast()
- if direct=='W' then
- robot.turnAround()
- elseif direct=='N' then
- robot.turnRight()
- elseif direct=='S' then
- robot.turnLeft()
- end
- direct='E'
- end
- function goNorth()
- if direct=='S' then
- smartTurnAround()
- elseif direct=='W' then
- smartTurnRight()
- elseif direct=='E' then
- smartTurnLeft()
- end
- robot.swing()
- a=robot.forward()
- if a then
- z=z-1
- end
- return a
- end
- function goSouth()
- if direct=='N' then
- smartTurnAround()
- elseif direct=='E' then
- smartTurnRight()
- elseif direct=='W' then
- smartTurnLeft()
- end
- robot.swing()
- a=robot.forward()
- if a then
- z=z+1
- end
- return a
- end
- function goWest()
- if direct=='E' then
- smartTurnAround()
- elseif direct=='S' then
- smartTurnRight()
- elseif direct=='N' then
- smartTurnLeft()
- end
- robot.swing()
- a=robot.forward()
- if a then
- x=x-1
- end
- return a
- end
- function goEast()
- if direct=='W' then
- smartTurnAround()
- elseif direct=='N' then
- smartTurnRight()
- elseif direct=='S' then
- smartTurnLeft()
- end
- robot.swing()
- a=robot.forward()
- if a then
- x=x+1
- end
- return a
- end
- function goUp()
- robot.swingUp()
- a = robot.up()
- if a then
- y=y+1
- end
- return a
- end
- function goDown()
- robot.swingDown()
- a = robot.down()
- if a then
- y=y-1
- end
- return a
- end
- local function analize(f)
- an = geo.analyze(f)
- if an ~= nil and (an.name == "Forestry:beehives" or an.name == "minecraft:bedrock") then
- return true
- else
- return false
- end
- end
- function goZ(go_z)
- if go_z<z then
- while z>go_z do
- if not moving.goNorth() and analize(3) then
- print("Утей, итить его налево!!!... или бедрок...")
- return false
- end
- end
- elseif go_z>z then
- while z<go_z do
- if not moving.goSouth() and analize(3) then
- print("Утей, итить его налево!!!... или бедрок...")
- return false
- end
- end
- end
- return true
- end
- function goY(go_y)
- if go_y<y then
- while y>go_y do
- if not moving.goDown() and analize(0) then
- print("Утей, итить его налево!!!... или бедрок...")
- return false
- end
- end
- elseif go_y>y then
- while y<go_y do
- if not moving.goUp() and analize(1) then
- print("Утей, итить его налево!!!... или бедрок...")
- return false
- end
- end
- end
- return true
- end
- function goX(go_x)
- if go_x<x then
- while x>go_x do
- if not moving.goWest() and analize(3) then
- print("Утей, итить его налево!!!... или бедрок...")
- return false
- end
- end
- elseif go_x>x then
- while x<go_x do
- if not moving.goEast() and analize(3) then
- print("Утей, итить его налево!!!... или бедрок...")
- return false
- end
- end
- end
- return true
- end
- moving['getX']=getX
- moving['getY']=getY
- moving['getZ']=getZ
- moving['smartTurnAround']=smartTurnAround
- moving['smartTurnLeft']=smartTurnLeft
- moving['smartTurnRight']=smartTurnRight
- moving['turnNorth']=turnNorth
- moving['turnEast']=turnEast
- moving['turnSouth']=turnSouth
- moving['turnWest']=turnWest
- moving['goNorth']=goNorth
- moving['goSouth']=goSouth
- moving['goEast']=goEast
- moving['goWest']=goWest
- moving['goUp']=goUp
- moving['goDown']=goDown
- moving['getCoordinates']=getCoordinates
- moving['goX']=goX
- moving['goY']=goY
- moving['goZ']=goZ
- package.loaded['moving']=moving
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement