mine: Add zig-zag mode
This commit is contained in:
parent
37eace175d
commit
eed45dac33
49
mine.lua
49
mine.lua
@ -36,6 +36,16 @@ local dirMap = {
|
||||
["1,0"] = 0.25,
|
||||
["-1,0"] = -0.25,
|
||||
}
|
||||
local invDirMap = {
|
||||
[0] = vector.new(0, 0, -1),
|
||||
[0.5] = vector.new(0, 0, 1),
|
||||
[0.25] = vector.new(1, 0, 0),
|
||||
[-0.25] = vector.new(-1, 0, 0),
|
||||
|
||||
[-0.5] = vector.new(0, 0, 1),
|
||||
[-0.75] = vector.new(1, 0, 0),
|
||||
[0.75] = vector.new(-1, 0, 0),
|
||||
}
|
||||
function direction(v)
|
||||
local d = dirMap[v.x..","..v.z]
|
||||
assert(d)
|
||||
@ -295,6 +305,11 @@ settings.define("mine.name", {
|
||||
default = "DiggyBoi",
|
||||
type = "string",
|
||||
})
|
||||
settings.define("mine.stripWidth", {
|
||||
description = "Strip width",
|
||||
default = 16,
|
||||
type = "number",
|
||||
})
|
||||
|
||||
function selectItem(item, nbt)
|
||||
for i = 1, 16 do
|
||||
@ -311,6 +326,7 @@ Miner = {}
|
||||
function Miner.new()
|
||||
local self = setmetatable({}, { __index = Miner })
|
||||
self.name = settings.get("mine.name")
|
||||
self.stripWidth = settings.get("mine.stripWidth")
|
||||
self.equipped = {
|
||||
["left"] = {
|
||||
["last"] = "NONE",
|
||||
@ -522,6 +538,17 @@ function Miner:faceDir(newDir)
|
||||
end
|
||||
end
|
||||
|
||||
function Miner:turnDir(delta)
|
||||
local newDirNum = direction(self.dir) + delta
|
||||
if newDirNum >= 1 then
|
||||
newDirNum = newDirNum - 1
|
||||
elseif newDirNum <= -1 then
|
||||
newDirNum = newDirNum + 1
|
||||
end
|
||||
|
||||
self:faceDir(invDirMap[newDirNum])
|
||||
end
|
||||
|
||||
function Miner:navigateThrough(path, limit)
|
||||
for _, p in ipairs(path) do
|
||||
-- print("move from to", self.pos, p)
|
||||
@ -577,6 +604,8 @@ function Miner:checkRecall()
|
||||
self:sendMessage("recallProgress", { to = msg.to })
|
||||
self:xchgItems()
|
||||
end
|
||||
|
||||
self:xchgItems(true)
|
||||
return true
|
||||
end
|
||||
|
||||
@ -679,8 +708,24 @@ function Miner:mineOres(radius)
|
||||
return true
|
||||
end
|
||||
|
||||
local miner = Miner.new()
|
||||
function Miner:loop()
|
||||
self:turnDir(0.25)
|
||||
|
||||
local shouldRun = true
|
||||
while shouldRun do
|
||||
shouldRun = miner:mineOres(16)
|
||||
local i = self.i - 1
|
||||
if i > 1 and (i % self.stripWidth == 0 or i % self.stripWidth == 1) then
|
||||
local delta = -0.25 -- left
|
||||
if i % (self.stripWidth * 2) == 0 or i % (self.stripWidth * 2) == 1 then
|
||||
delta = 0.25 -- right
|
||||
end
|
||||
|
||||
self:turnDir(delta)
|
||||
end
|
||||
|
||||
shouldRun = self:mineOres(16)
|
||||
end
|
||||
end
|
||||
|
||||
local miner = Miner.new()
|
||||
miner:loop()
|
||||
|
Loading…
Reference in New Issue
Block a user