This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
elminister's profile picture

turtle drop inventory in a chest or on the ground ?

Started by elminister, 03 March 2012 - 01:22 PM
elminister #1
Posted 03 March 2012 - 02:22 PM
Hello all,

is it possible that a mining turtle can drop the full inventory on the ground or put it in a chest ?

Thanks for help! :unsure:/>/>
Chub1337 #2
Posted 03 March 2012 - 02:23 PM
You can let it drop the stuff on the ground using turtle.drop(). Not sure about the chest, but i don't think so.

-Chub1337
elminister #3
Posted 03 March 2012 - 02:57 PM
Thanks it works!

i used the excavate program vom build in to setup a autoquarry. the turtle drops the stuff behind him and a obsidianpipe suck it up (buildcraft).

Now i want after he drops the stuff to return to the last dig position and continue to work and after he hit something he can't dig he shoud stop and return. I don't know is it possible ?

Code:
Spoiler

local tArgs = { ... }
if #tArgs ~= 1 then
print( "Usage: excavate <radius>" )
return
end
-- Mine in a quarry pattern until we hit something we can't dig
local size = tonumber( tArgs[1] )
if size < 1 then
print( "Excavate radius must be positive" )
return
end

local depth = 0
local collected = 0
local xPos,zPos = 0,0
local xDir,zDir = 0,1
local function collect()
collected = collected + 1
if math.fmod(collected, 25) == 0 then
  print( "Mined "..collected.." blocks." )
end

for n=1,9 do
  if turtle.getItemCount(n) == 0 then
   return true
  end
end

print( "No empty slots left." )
return false
end
local function tryForwards()
while not turtle.forward() do
  if turtle.dig() then
   if not collect() then
	return false
   end
	 else
   -- give sand a chance to fall
	sleep(0.8)
	  if turtle.dig() then
	   if not collect() then
	 return false
	end
	  else
	   return false
	  end
	 end
end
xPos = xPos + xDir
zPos = zPos + zDir
return true
end
local function tryDown()
if not turtle.down() then
  if turtle.digDown() then
   if not collect() then
	return false
   end
	 end
  if not turtle.down() then
   return false
  end
end
depth = depth + 1
if math.fmod( depth, 10 ) == 0 then
  print( "Descended "..depth.." metres." )
end
return true
end
local function turnLeft()
turtle.turnLeft()
xDir, zDir = -zDir, xDir
end
local function turnRight()
turtle.turnRight()
xDir, zDir = zDir, -xDir
end
print( "Excavating..." )
local reseal = false
if turtle.digDown() then
reseal = true
end
local alternate = 0
local done = false
while not done do
for n=1,size do
  for m=1,size-1 do
   if not tryForwards() then
	done = true
	break
   end
  end
  if done then
   break
  end
  if n<size then
   if math.fmod(n + alternate,2) == 0 then
	turnLeft()
	if not tryForwards() then
	 done = true
	 break
	end
	turnLeft()
   else
	turnRight()
	if not tryForwards() then
	 done = true
	 break
	end
	turnRight()
   end
  end
end
if done then
  break
end

if size > 1 then
  if math.fmod(size,2) == 0 then
   turnRight()
  else
   if alternate == 0 then
	turnLeft()
   else
	turnRight()
   end
   alternate = 1 - alternate
  end
end

if not tryDown() then
  done = true
  break
end
end
print( "Returning to surface..." )
-- Return to where we started
while depth > 0 do
if turtle.up() then
  depth = depth - 1
elseif turtle.digUp() then
  collect()
else
  sleep( 0.5 )
end
end
if xPos > 0 then
while xDir ~= -1 do
  turnLeft()
end
while xPos > 0 do
  if turtle.forward() then
   xPos = xPos - 1
  elseif turtle.dig() then
   collect()
  else
   sleep( 0.5 )
  end
end
end
if zPos > 0 then
while zDir ~= -1 do
  turnLeft()
end
while zPos > 0 do
  if turtle.forward() then
   zPos = zPos - 1
  elseif turtle.dig() then
   collected = collected + 1
  else
   sleep( 0.5 )
  end
end
end
while zDir ~= 1 do
turnLeft()
end
-- Seal the hole
if reseal then
turtle.turnLeft(0)
turtle.turnLeft(0)
sleep( 0.5 )
turtle.drop()
sleep( 1.0)
turtle.placeDown()
end
print( "Mined "..collected.." blocks total." )