mine.lua: rewrite passes 1-high and 3-high testing

This commit is contained in:
Emerson Rosen-Jones 2025-12-13 00:56:01 -05:00
parent 91a0242ad0
commit b48d836929

View file

@ -56,6 +56,7 @@ local Block = {
self.v1[dim] = point
self.v2[dim] = offset
end
self.v1 = self.v1 + pos
return self
end,
take = function (self, amt, dir)
@ -65,7 +66,7 @@ local Block = {
local block_offset = -1
if self.v2[dir] < 0 then
amt = amt * -1
block_offset = block_offset * -1
block_offset = 1
end
local new, remainder = self:copy(), self
@ -169,7 +170,7 @@ end
-- move to a specific point
function moveAbs (v)
-- print(string.format("Moving to (%d, %d, %d)", v.x, v.y, v.z))
-- print(string.format("Moving to (%s)", v:tostring()))
move(v - getCurrentPos())
end
@ -248,7 +249,9 @@ function mine (block)
-- a. don't move vertically if you don't have to
-- b. set mining mode beforehand
-- 2. move to the ending point
local height = block.v2.y + 1
local offset = 1
if block.v2.y < 0 then offset = -1 end
local height = block.v2.y + offset
if height % 3 == 0 then
mode.mine = { up = true, forward = true, down = true }
elseif height == 2 then
@ -260,17 +263,17 @@ function mine (block)
local end_v = block.v1 + block.v2
if height > 2 then
start_v = start_v + UNIT_Y
end_v = end_v + UNIT_Y
end_v = end_v - UNIT_Y
elseif height < -2 then
start_v = start_v - UNIT_Y
end_v = end_v - UNIT_Y
end_v = end_v + UNIT_Y
end
moveAbs(start_v)
moveAbs(end_v)
end
function canMine (block)
local tooHigh = block.v2.y > 2
local tooHigh = math.abs(block.v2.y) > 2
-- we can only mine in a 1-wide strip at a time
local tooWide = (math.abs(block.v2.x) > 0) and (math.abs(block.v2.z) > 0)
return not (tooHigh or tooWide)
@ -296,8 +299,8 @@ function splitHorizontal (block)
-- TODO split the big block at where the turtle is near
end
-- decide whether to take a slice off of the x or z direction
-- (criteria: take the dimension with the smaller length)
if block.v2.z <= block.v2.x then
-- (criteria: take the dimension that is not too big)
if math.abs(block.v2.z) < BIG_DIM then
return block:take(1, "z")
else
return block:take(1, "x")
@ -306,7 +309,7 @@ end
function split (block)
local tooHigh = function (block)
return block.v2.y > 2
return math.abs(block.v2.y) > 2
end
if tooHigh(block) then
return block:take(3, "y")