lava-collector: add lateral movement
This commit is contained in:
parent
7978cfbe5f
commit
0657c9b336
@ -4,6 +4,11 @@
|
|||||||
-- chest above base needs to contain empty buckets
|
-- chest above base needs to contain empty buckets
|
||||||
-- the filled buckets will be deposited in a chest below the base
|
-- the filled buckets will be deposited in a chest below the base
|
||||||
|
|
||||||
|
FORWARD = 1
|
||||||
|
RIGHT = 2
|
||||||
|
LEFT = 3
|
||||||
|
BACKWARD = 4
|
||||||
|
|
||||||
local function compareItemName(target)
|
local function compareItemName(target)
|
||||||
local itemDetail = turtle.getItemDetail()
|
local itemDetail = turtle.getItemDetail()
|
||||||
if itemDetail == nil then
|
if itemDetail == nil then
|
||||||
@ -31,13 +36,46 @@ local function findFirstLavaBucket()
|
|||||||
return findFirstItem("minecraft:lava_bucket")
|
return findFirstItem("minecraft:lava_bucket")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function goRight()
|
||||||
|
if not turtle.turnRight() then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
local success = turtle.forward()
|
||||||
|
|
||||||
|
turtle.turnLeft()
|
||||||
|
return success
|
||||||
|
end
|
||||||
|
|
||||||
|
local function goLeft()
|
||||||
|
if not turtle.turnLeft() then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
local success = turtle.forward()
|
||||||
|
|
||||||
|
turtle.turnRight()
|
||||||
|
return success
|
||||||
|
end
|
||||||
|
|
||||||
|
local function doReverseMovement(movement)
|
||||||
|
if movement == FORWARD then
|
||||||
|
return turtle.back()
|
||||||
|
elseif movement == RIGHT then
|
||||||
|
return goLeft()
|
||||||
|
elseif movement == LEFT then
|
||||||
|
return goRight()
|
||||||
|
elseif movement == BACKWARD then
|
||||||
|
return turtle.forward()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
local function returnToBase()
|
local function returnToBase()
|
||||||
print('returing to base')
|
print('returing to base')
|
||||||
while ForwardCounter > 0 do
|
for i = #Movements, 1, -1 do
|
||||||
print('ForwardCounter: ' .. ForwardCounter)
|
local movement = Movements[i]
|
||||||
if turtle.back() then
|
print('Movement ' .. i .. ': ' .. movement)
|
||||||
ForwardCounter = ForwardCounter - 1
|
if not doReverseMovement(movement) then
|
||||||
else
|
|
||||||
print('hit a block on the way back, I am stuck!')
|
print('hit a block on the way back, I am stuck!')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -48,6 +86,7 @@ local function despositRefill()
|
|||||||
turtle.select(i)
|
turtle.select(i)
|
||||||
if compareItemName("minecraft:lava_bucket") then
|
if compareItemName("minecraft:lava_bucket") then
|
||||||
while not turtle.dropDown() do
|
while not turtle.dropDown() do
|
||||||
|
---@diagnostic disable-next-line: undefined-field
|
||||||
os.sleep(1)
|
os.sleep(1)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -73,11 +112,11 @@ local function refuel()
|
|||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
ForwardCounter = 0
|
Movements = {}
|
||||||
|
|
||||||
despositRefill()
|
despositRefill()
|
||||||
while true do
|
while true do
|
||||||
if turtle.getFuelLevel() <= ForwardCounter then
|
if turtle.getFuelLevel() <= #Movements then
|
||||||
print('not enough fuel to return. trying to refuel')
|
print('not enough fuel to return. trying to refuel')
|
||||||
if not refuel() then
|
if not refuel() then
|
||||||
print('refulling failed. probably the end of the lava lake. returning to base')
|
print('refulling failed. probably the end of the lava lake. returning to base')
|
||||||
@ -96,9 +135,13 @@ while true do
|
|||||||
turtle.placeDown()
|
turtle.placeDown()
|
||||||
if compareItemName("minecraft:bucket") then
|
if compareItemName("minecraft:bucket") then
|
||||||
if turtle.forward() then
|
if turtle.forward() then
|
||||||
ForwardCounter = ForwardCounter + 1
|
table.insert(Movements, FORWARD)
|
||||||
|
elseif goRight() then
|
||||||
|
table.insert(Movements, RIGHT)
|
||||||
|
elseif goLeft() then
|
||||||
|
table.insert(Movements, LEFT)
|
||||||
else
|
else
|
||||||
print('hit a wall - returning to base')
|
print("can't find a path - returning to base")
|
||||||
returnToBase()
|
returnToBase()
|
||||||
despositRefill()
|
despositRefill()
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user