Update turtle absolute movement logic (mine only where needed)
This commit is contained in:
@ -152,13 +152,12 @@ function TurtleController:MoveVertical(number_of_blocks, skip_unstocking, skip_r
|
|||||||
self:UnstockIfFull()
|
self:UnstockIfFull()
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Mine
|
-- Mine/Move
|
||||||
if mine_enabled then
|
if mine_enabled then
|
||||||
mine_function()
|
while not move_function() do
|
||||||
end
|
mine_function()
|
||||||
|
end
|
||||||
-- Move
|
elseif not move_function() then
|
||||||
if not move_function() then
|
|
||||||
error("Turtle failed to move vertically!")
|
error("Turtle failed to move vertically!")
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -189,7 +188,15 @@ function TurtleController:MoveToPosition(x, y, z, dir, skip_unstocking, skip_ref
|
|||||||
-- Store the current position on the stack, so we can return using TurtleController:MoveBack()
|
-- Store the current position on the stack, so we can return using TurtleController:MoveBack()
|
||||||
self.last_positions:Push(Position:Copy(self.position))
|
self.last_positions:Push(Position:Copy(self.position))
|
||||||
|
|
||||||
|
-- Store mining config so we can restore it later
|
||||||
|
local mine_forward = self.mine_forward
|
||||||
|
local mine_above = self.mine_above
|
||||||
|
local mine_below = self.mine_below
|
||||||
|
|
||||||
-- EAST/WEST axis (do first to not interfere with chests)
|
-- EAST/WEST axis (do first to not interfere with chests)
|
||||||
|
self:EnableMiningForward()
|
||||||
|
self:DisableMiningAbove()
|
||||||
|
self:DisableMiningBelow()
|
||||||
if self.position.x > x then
|
if self.position.x > x then
|
||||||
self:TurnToDirection(Direction.WEST)
|
self:TurnToDirection(Direction.WEST)
|
||||||
elseif self.position.x < x then
|
elseif self.position.x < x then
|
||||||
@ -206,11 +213,34 @@ function TurtleController:MoveToPosition(x, y, z, dir, skip_unstocking, skip_ref
|
|||||||
self:MoveForward(math.abs(z - self.position.z), skip_unstocking, skip_refueling)
|
self:MoveForward(math.abs(z - self.position.z), skip_unstocking, skip_refueling)
|
||||||
|
|
||||||
-- UP/DOWN axis
|
-- UP/DOWN axis
|
||||||
|
self:DisableMiningForward()
|
||||||
|
if y < self.position.y then
|
||||||
|
self:EnableMiningBelow()
|
||||||
|
elseif y > self.position.y then
|
||||||
|
self:EnableMiningAbove()
|
||||||
|
end
|
||||||
self:MoveVertical(y - self.position.y, skip_unstocking, skip_refueling)
|
self:MoveVertical(y - self.position.y, skip_unstocking, skip_refueling)
|
||||||
|
|
||||||
-- Direction
|
-- Direction
|
||||||
self:TurnToDirection(dir or Direction.NORTH)
|
self:TurnToDirection(dir or Direction.NORTH)
|
||||||
|
|
||||||
|
-- Restore mining config
|
||||||
|
if mine_forward then
|
||||||
|
self:EnableMiningForward()
|
||||||
|
else
|
||||||
|
self:DisableMiningForward()
|
||||||
|
end
|
||||||
|
if mine_above then
|
||||||
|
self:EnableMiningAbove()
|
||||||
|
else
|
||||||
|
self:DisableMiningAbove()
|
||||||
|
end
|
||||||
|
if mine_below then
|
||||||
|
self:EnableMiningBelow()
|
||||||
|
else
|
||||||
|
self:DisableMiningBelow()
|
||||||
|
end
|
||||||
|
|
||||||
-- Sanity check
|
-- Sanity check
|
||||||
if not (self.position.x == x and self.position.y == y and self.position.z == z and self.position.dir == dir) then
|
if not (self.position.x == x and self.position.y == y and self.position.z == z and self.position.dir == dir) then
|
||||||
error("TurtleController:MoveToPosition failed to move to target position!")
|
error("TurtleController:MoveToPosition failed to move to target position!")
|
||||||
@ -258,6 +288,22 @@ function TurtleController:MoveBack(skip_unstocking, skip_refueling)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-----------------------------------------------------------------------------------------------
|
||||||
|
-- Testing Methods
|
||||||
|
-----------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
---@param block_name string
|
||||||
|
---@return boolean
|
||||||
|
function TurtleController:TestForBlock(block_name)
|
||||||
|
local has_block, block_data = turtle.inspect()
|
||||||
|
|
||||||
|
if not has_block then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
return block_data.name == block_name
|
||||||
|
end
|
||||||
|
|
||||||
-----------------------------------------------------------------------------------------------
|
-----------------------------------------------------------------------------------------------
|
||||||
-- Inventory Methods
|
-- Inventory Methods
|
||||||
-----------------------------------------------------------------------------------------------
|
-----------------------------------------------------------------------------------------------
|
||||||
@ -336,6 +382,8 @@ function TurtleController:UnstockIfFull(skip_inventory_check)
|
|||||||
self:DropInventory()
|
self:DropInventory()
|
||||||
self:RefuelIfEmpty()
|
self:RefuelIfEmpty()
|
||||||
|
|
||||||
|
self:TurnToDirection(Direction.NORTH)
|
||||||
|
self:MoveForward(1)
|
||||||
self:MoveBack(true, true)
|
self:MoveBack(true, true)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -379,6 +427,8 @@ function TurtleController:RefuelIfEmpty(skip_fuel_check)
|
|||||||
until turtle.getFuelLevel() >= target_fuel_level
|
until turtle.getFuelLevel() >= target_fuel_level
|
||||||
local after_level = turtle.getFuelLevel()
|
local after_level = turtle.getFuelLevel()
|
||||||
|
|
||||||
|
self:TurnToDirection(Direction.NORTH)
|
||||||
|
self:MoveForward(1)
|
||||||
self:MoveBack(true, true)
|
self:MoveBack(true, true)
|
||||||
|
|
||||||
print(
|
print(
|
||||||
|
|||||||
Reference in New Issue
Block a user