Created
July 7, 2022 16:18
-
-
Save AmariNoa/04c6f4d5937e2064bc0e4f6f6f9281fd to your computer and use it in GitHub Desktop.
Auto felling program for ComputerCraft
This file contains 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 resInspect, blkInfo = turtle.inspect() | |
local blkType = blkInfo.name | |
print(resInspect) | |
print(blkType) | |
if resInspect == false then | |
print("Front block is nil.") | |
return | |
end | |
if string.find(blkType, "log") == nil then | |
print("Target is not log.") | |
return | |
end | |
print("Target is log!") | |
-- Felling | |
local step = 0 | |
repeat | |
-- Get front log | |
local resDig = turtle.dig() | |
-- Can't dig | |
if not resDig then | |
print("DigFront faild.") | |
break | |
end | |
-- Check up | |
local blkUp = turtle.detectUp() | |
if blkUp == true then | |
resDig = turtle.digUp() | |
-- Can't dig | |
if not resDig then | |
print("DigUp failed.") | |
break | |
end | |
end | |
-- Move up | |
local resMove = turtle.up() | |
-- Can't move | |
if not resMove then | |
print("MoveUp faild.") | |
break | |
end | |
-- Increment | |
step = step + 1 | |
-- Inspect front block | |
resInspect, blkInfo = turtle.inspect() | |
-- Update block type name | |
if resInspect == true then | |
blkType = blkInfo.name | |
print("BlockType updated.") | |
end | |
print(blkType) | |
until string.find(blkType, "log") == nil | |
-- End felling | |
local moveDown = 0 | |
local resMove = false | |
while moveDown < step do | |
-- Move down | |
resMove = turtle.down() | |
-- If move success | |
if resMove == true then | |
moveDown = moveDown + 1 | |
end | |
end |
This file contains 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 PRG_DIR = "/dev" | |
local MOVE_FRONT_VAL = 3 | |
local MOVE_DIFF_CNT = 6 | |
local REPEAT_CNT = 4 | |
print("Start program!") | |
local stop = false | |
local moveTargetCnt = MOVE_FRONT_VAL | |
local moveFront = 0 | |
local moveFrontTemp = 0 | |
local resDig = false | |
local resMove = false | |
for i = 1, REPEAT_CNT, 1 do | |
moveFrontTemp = 0 | |
while moveFrontTemp < moveTargetCnt do | |
local frontBlock = turtle.detect() | |
if frontBlock == true then | |
resDig = turtle.dig() | |
if resDig == false then | |
stop = true | |
break | |
end | |
end | |
resMove = turtle.forward() | |
if resMove == true then | |
moveFrontTemp = moveFrontTemp + 1 | |
moveFront = moveFront + 1 | |
end | |
end | |
if stop == true then | |
break | |
end | |
-- TODO Check fail | |
turtle.turnLeft() | |
print("Start felling...") | |
shell.setDir(PRG_DIR) | |
shell.run("AutoFelling.lua") | |
turtle.turnRight() | |
moveTargetCnt = MOVE_DIFF_CNT | |
end | |
print("End felling.") | |
while moveFront > 0 do | |
resMove = turtle.back() | |
if resMove == true then | |
moveFront = moveFront - 1 | |
end | |
end | |
print("Dropping item...") | |
local itemCnt = 0 | |
for i = 1, 16, 1 do | |
turtle.select(i) | |
itemCnt = turtle.getItemCount() | |
if itemCnt > 0 then | |
turtle.dropUp(itemCnt) | |
end | |
end | |
print("End program.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment