Posted 23 November 2014 - 04:46 PM
I made a vertical miner turtle program that works just like I want it to.
But the last time I ran it, it couldn't move down because of a slime directly underneath the turtle, but it thought it had. So it just spun in place forever and ever.
Perhaps I could add a section to the program to look for slimes below it and kill them, before trying to move down?
Here is the current program…
But the last time I ran it, it couldn't move down because of a slime directly underneath the turtle, but it thought it had. So it just spun in place forever and ever.
Perhaps I could add a section to the program to look for slimes below it and kill them, before trying to move down?
Here is the current program…
-- before running program, be sure...
-- coal is in slot 16
-- cobble in slot 15
-- put an actual chest ABOVE the turtle that will be on the mission (empty) (for the loot)
-- put an actual chest BEHIND the turtle that will be on the mission (with more coal in it)
ypos = 0 -- This tracks how far down turtle is from its starting position
facing = 0 -- This tracks direction turtle is facing 0=original-front 1=left 2=right 3=back
mission = 1 -- Current status of mission.
-- 0 means mission completed
-- 1 means operational mission, still running.
-- 2 means that it is time to drop off stuff then return to where u left off
-- 3 means that it is time to refuel
while mission ~= 0 do
FuelLeft = turtle.getFuelLevel() + 1
if FuelLeft < 65 then -- if there is less than 65 fuel in the turtle...
mission = 3
if turtle.getItemCount(16) > 0 then -- if there is at least 1 item in coal-slot 16...
turtle.select(16) -- choose slot 16 on turtle
turtle.refuel(1) -- refuel turtle with 1 item from slot 16
turtle.select(1) -- choose slot 1 on turtle (default?)
mission = 1
else
-- coal slot is empty so go back and get more fuel into slot 16
yrem = ypos -- remember ypos before returning for fuel
facrem = facing -- remember facing before returning for fuel
if ypos == 0 then -- you are back at start
-- get turtle facing the chest (backwards from original direction
if facing == 0 then -- facing forward
turtle.turnLeft() -- turn left
turtle.turnLeft() -- turn left
facing = 3
end
if facing == 1 then -- facing left
turtle.turnLeft() -- turn left
facing = 3
end
if facing == 2 then -- facing right
turtle.turnRight() -- turn right
facing = 3
end
-- see if fuel chest is empty or not and get more fuel
turtle.select(16) -- choose slot 16 on turtle
turtle.suck() -- suck fuel out of chest into slot 16 if possible
turtle.turnRight() -- turning turtle back towards facing the front
facing = 1
turtle.turnRight() -- finishing turning turtle to facing the front
facing = 0
turtle.refuel(1) -- refuel turtle with 1 item from slot 16
turtle.select(1) -- choose slot 1 on turtle (default?)
FuelLeft = turtle.getFuelLevel() + 1
if FuelLeft < 65 then -- still less than 65 fuel after refueling attempt
print "Not enough fuel to continue mission."
else
-- RETURN TO POSITION PRIOR TO NEEDING FUEL IF NECESSARY
while yrem ~= ypos do
turtle.down()
ypos = ypos - 1
end
while facrem ~= facing do
turtle.turnRight()
if facing == 0 then -- 0=original-front 1=left 2=right 3=back
facing = 2
else
if facing == 1 then
facing = 0
else
if facing == 2 then
facing = 3
else
-- facing = 3
facing = 1
end
end
end
end
mission = 1
end
else
-- move back up to start
while ypos<0 and ypos~=0 do
turtle.up()
ypos = ypos + 1
end
end
end
else -- if there is NOT less than 65 fuel in the turtle...
if turtle.down() then -- it was able to move down
ypos = ypos - 1
else -- it cannot move down
-- find out what is below it and act accordingly
local bSuccess, tData = turtle.inspectDown()
if bSuccess and tData.name == "minecraft:chest" then
turtle.suckDown()
turtle.select(15)
turtle.placeDown()
turtle.select(1)
mission = 2 -- drop off all new stuff after grabbing a rare chest
else
if bSuccess and tData.name == "minecraft:bedrock" then -- bottom of the world
mission = 0
while ypos ~= 0 do
turtle.up()
ypos = ypos + 1
-- fill below turtle with cobble IF there is cobble in slot 15
cobcnt = turtle.getItemCount(15)
if cobcnt <1 then
for i = 1, 14 do
sltcnt = turtle.getItemCount(i)
if sltcnt > 0 then
wut = turtle.getItemDetail(i)
if wut.name == "minecraft:cobblestone" then
turtle.select(i)
turtle.transferTo(15)
turtle.select(1)
end
end
end
end
turtle.select(15)
turtle.placeDown()
turtle.select(1)
end
else
turtle.digDown()
turtle.down()
ypos = ypos - 1
end
end
end
if mission~=2 and mission~=0 then
-- seal any holes around this location (main concern: lava)
for i = 1, 4 do
if turtle.detect()=="false" then
-- there is a hole
turtle.select(15)
turtle.place()
turtle.select(1)
turtle.turnLeft()
end
end
-- look around for goodies
flag = 0
for i = 1, 4 do
local bSuccess, tData = turtle.inspect()
if bSuccess and tData.name == "minecraft:stone" then
flag = 1
end
if bSuccess and tData.name == "minecraft:cobblestone" then
flag = 1
end
if bSuccess and tData.name == "minecraft:dirt" then
flag = 1
end
-- if the flag is still zero, it may be valuable
-- and just get rid of gravel
if flag == 0 then
turtle.dig()
turtle.select(15)
turtle.place()
turtle.select(1)
end
turtle.turnLeft()
flag = 0
end
else
-- mission = 2 (or 0)
-- 2 means that it is time to drop off stuff then return to where u left off
-- there is a chest ABOVE the turtle start position for the loot
yrem = ypos -- remember ypos before returning for fuel
while ypos ~= 0 do
turtle.up()
ypos = ypos + 1
end
-- top off slot 15 (cobble) to 64 items - if possible from goodies collected
cobb = turtle.getItemCount(15)
if cobb < 64 then
for i = 1, 14 do
ctslt = turtle.getItemCount(i)
if ctslt ~= 0 then
wut = turtle.getItemDetail(i)
if wut.name == "minecraft:cobblestone" then
turtle.select(i)
turtle.transferTo(15)
end
end
end
end
turtle.select(1)
-- see if there is a chest above the turtle
local bSuccess, tData = turtle.inspectUp()
if bSuccess and tData.name == "minecraft:chest" then
-- dump everything in slots 1-14 in the goodies chest
for i = 1, 14 do
turtle.select(i)
turtle.dropUp()
end
end
turtle.select(1)
while yrem ~= ypos do
turtle.down()
ypos = ypos - 1
end
if mission ~= 0 then -- if mission is not complete
-- mission = 2 -- it just finished dropping and returning
mission = 1
end
end
end
end