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