Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- MiningTurtle = {
- position = {
- x = 0,
- y = 0,
- z = 0
- },
- direction = 0
- }
- -- Check if the Turtle needs to be refueled ( <= refuelLevel )
- -- if yes, try to refuel it taking the contents of the inventory
- -- if this is not possible or not enough, go back to base
- function MiningTurtle:requiredRefuel( refuelLevel, requiredFuelLevel )
- if refuelLevel == nil then
- refuelLevel = 25
- end
- if requiredFuelLevel == nil then
- requiredFuelLevel = 500
- end
- -- should we refuel?
- if turtle.getFuelLevel() <= refuelLevel then
- -- iterate through our inventory
- for slot = 1,16 do
- -- select slot
- turtle.select(slot)
- -- refuel from active slot...
- if turtle.refuel( turtle.getItemCount( slot ) ) then
- end
- -- ...and check again
- if turtle.getFuelLevel() >= requiredFuelLevel then
- return true
- end
- end
- -- check if we did not refueled enough alreay
- if not turtle.getFuelLevel() >= requiredFuelLevel then
- -- if yes, go back to base
- MiningTurtle:toBase()
- -- refuel: to be implemented!!!!
- end
- end
- return false
- end
- -- Go back to the base of the MiningTurtle
- function MiningTurtle:toBase( )
- end
- -- Go to ground
- function MiningTurtle:toGround( )
- while not turtle.detectDown() do
- MiningTurtle:down()
- end
- end
- -- forward
- function MiningTurtle:forward()
- local ret
- ret = turtle.forward()
- if ret then
- if self.direction == 0 then
- self.position.x = self.position.x + 1
- elseif self.direction == 90 then
- self.position.y = self.position.y + 1
- elseif self.direction == 180 then
- self.position.x = self.position.x - 1
- elseif self.direction == 270 then
- self.position.y = self.position.y - 1
- end
- end
- return ret
- end
- -- back
- function MiningTurtle:back()
- local ret
- ret = turtle.back()
- if ret then
- if self.direction == 0 then
- self.position.x = self.position.x - 1
- elseif self.direction == 90 then
- self.position.y = self.position.y - 1
- elseif self.direction == 180 then
- self.position.x = self.position.x + 1
- elseif self.direction == 270 then
- self.position.y = self.position.y + 1
- end
- end
- return ret
- end
- -- up
- function MiningTurtle:up()
- local ret
- ret = turtle.up()
- if ret then
- self.position.z = self.position.z + 1
- end
- return ret
- end
- -- down
- function MiningTurtle:down()
- local ret
- ret = turtle.down()
- if ret then
- self.position.z = self.position.z - 1
- end
- return ret
- end
- -- turn Left
- function MiningTurtle:turnLeft()
- local ret
- ret = turtle.turnLeft()
- if ret then
- self.direction = self.direction + 90
- while self.direction >= 360 do
- self.direction = self.direction - 360
- end
- end
- return ret
- end
- -- turn Right
- function MiningTurtle:turnRight()
- local ret
- ret = turtle.turnRight()
- if ret then
- self.direction = self.direction - 90
- while self.direction < 0 do
- self.direction = self.direction + 360
- end
- end
- return ret
- end
- -- Save forward
- function MiningTurtle:saveForward()
- while not MiningTurtle:forward() do
- turtle.dig()
- end
- end
- -- Save up
- function MiningTurtle:saveUp()
- while not MiningTurtle:up() do
- turtle.digUp()
- end
- end
- -- Save down
- function MiningTurtle:saveDown()
- while not MiningTurtle:down() do
- turtle.digDown()
- end
- end
- -- 180 degree turn
- function MiningTurtle:turn()
- MiningTurtle:turnRight()
- MiningTurtle:turnRight()
- end
- -- Make a tunnel
- function MiningTurtle:tunnel( length, height, width, ret )
- if height == nil then
- height = 2
- end
- if height == nil then
- height = 2
- end
- if ret == nil then
- ret = false
- end
- -- Length loop
- for i = 1,length do
- MiningTurtle:saveForward()
- if i % 2 == 0 then
- -- even
- MiningTurtle:turnLeft()
- for x = 0,width do
- for y = 0,height do
- if x % 2 == 0 then
- MiningTurtle:saveUp()
- else
- MiningTurtle:saveDown()
- end
- end
- if x < width then
- MiningTurtle:saveForward()
- end
- end
- MiningTurtle:turnRight()
- else
- -- odd
- MiningTurtle:turnRight()
- for x = 0,width do
- for y = 0,height do
- if x % 2 == 0 then
- MiningTurtle:saveUp()
- else
- MiningTurtle:saveDown()
- end
- end
- if x < width then
- MiningTurtle:saveForward()
- end
- end
- MiningTurtle:turnLeft()
- end
- end
- if ret then
- MiningTurtle:turn()
- end
- end
- --
- function MiningTurtle:matrix( rows, cols )
- end
- -- main
- while not MiningTurtle:requiredRefuel() do
- print("Waiting for MiningTurtle to have enough fuel")
- end
- MiningTurtle:toGround()
- MiningTurtle:tunnel(10)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement