Created
July 11, 2021 12:52
-
-
Save fokklz/bf880df3bc1479eecea1900dd1ec48be to your computer and use it in GitHub Desktop.
wall programm for mining turtle
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
local width = 0 | |
local height = 0 | |
local locX = 1; | |
local locZ = 1; | |
local locY = 0; | |
local removedTop = false; | |
if #arg == 2 then | |
width = tonumber(arg[1]) - 1 | |
height = tonumber(arg[2]) | |
else | |
print('usage: wall <width> <height>') | |
return | |
end | |
function SelectSlot() | |
for slot = 2, 14 do | |
if turtle.getItemCount(slot) > 0 then | |
turtle.select(slot); | |
return true | |
end | |
end | |
removedTop = false | |
print('waiting for blocks...'); | |
if turtle.getItemCount(16) > 0 then | |
if turtle.detectUp() then | |
turtle.select(15) | |
turtle.digUp() | |
removedTop = true | |
end | |
turtle.select(16) | |
turtle.placeUp() | |
for slot = 2, 14 do | |
if turtle.getItemCount(slot) == 0 then | |
turtle.select(slot); | |
turtle.suckUp() | |
end | |
end | |
turtle.select(16) | |
turtle.digUp() | |
if removedTop then | |
turtle.select(15) | |
turtle.placeUp() | |
end | |
end | |
return false; | |
end | |
function VerifyFuel() | |
if turtle.getFuelLevel() > 10 then return true end | |
if turtle.getItemCount(1) > 1 then | |
turtle.refuel(1) | |
return true | |
else | |
print('waiting for fuel...') | |
return false; | |
end | |
end | |
function Clear() | |
term.clear() | |
term.setCursorPos(1,1) | |
end | |
function ChangeDirection() | |
turtle.turnRight() | |
turtle.forward(); | |
locZ = locZ + 1 | |
end | |
while not VerifyFuel() do sleep(1) Clear() end | |
turtle.forward() | |
if turtle.getItemCount(15) > 0 then | |
turtle.select(15) | |
turtle.drop() | |
turtle.select(1) | |
end | |
while locX <= width do | |
locY = 0; | |
while locY < height do | |
if turtle.detectDown then | |
turtle.select(15) | |
turtle.digDown() | |
turtle.drop() | |
turtle.down() | |
else | |
turtle.down() | |
end | |
locY = locY + 1 | |
end | |
-- fill empty blocks found | |
while locY > 0 do | |
while not SelectSlot() do sleep(1) Clear() end | |
turtle.up() | |
if not turtle.placeDown() then | |
turtle.drop() | |
end | |
locY = locY - 1 | |
end | |
while not VerifyFuel() do sleep(1) Clear() end | |
if locX == width then | |
if locZ == 4 then Clear() print('Successfully complettet wall') return end | |
ChangeDirection() | |
locX = 1 | |
else | |
if turtle.detect() then | |
turtle.select(15) | |
turtle.dig() | |
turtle.drop() | |
end | |
turtle.forward() | |
locX = locX + 1 | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment