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

Excavate Replacement

Started by kelm, 03 November 2013 - 11:17 AM
kelm #1
Posted 03 November 2013 - 12:17 PM
This works like excavate, but allows you specify all dimensions (including height), and doesn't waste fuel coming up to origin by using ender chests (from the ender storage mod) or a tesseract instead.

Usage: dig [length] [width] [height] [-f]
Put an ender chest in the first slot.

It will check to see if you have enough fuel and reject your attempts to start it if you don't have enough. If you think it is wrong or want it go start anyway, append '-f' to the command.

It's inspired by deFENCE_'s rendition, but uses about half the fuel, and half the time (doesn't re-traverse each row), and won't be offset by gravel.

Video
[media]http://youtu.be/MusAJVBRShE[/media]

Code - http://pastebin.com/urvJWGnu
Spoiler

-- Build Tools
-- dig v1

local args = { ... }

if args[1] == nil or args[2] == nil or args[3] == nil or turtle.getItemCount(1) < 1 or args[1] == "help" then
  print ("Usage: dig [forward length] [right length] [depth]")
  print ("Put an ender chest in the first slot")
  return
end

local tilt = 0
local flength = tonumber(args[1])
local rlength = tonumber(args[2])
local depth = tonumber(args[3])
local blocks = rlength * flength * depth

if turtle.getFuelLevel() < blocks + rlength + flength + depth and args[4] ~= "-f" then
  print ("You do not have enough fuel. This job needs ", fuelreq, " fuel.")
  print ("Add more fuel, or append -f to dig anyway.")
  return
end

function step()
  while not turtle.forward() do
	turtle.dig()
  end
end

function stepUp()
  while not turtle.up() do
	turtle.digUp()
  end
end

function stepDown()
  while not turtle.down() do
	turtle.digDown()
  end
end

function placeUp()
  while not turtle.placeUp() do
	turtle.digUp()
  end
end

function rotateRight()
  turtle.turnRight()
  if vertical then
	stepUp()
  else
	step()
  end
  turtle.turnRight()
end

function rotateLeft()
  turtle.turnLeft()
  if vertical then
	stepUp()
  else
	step()
  end
  turtle.turnLeft()
end

-- Dump inventory into ender chest.
function dump()
  turtle.select(1)
  placeUp()
  for m = 2, 16, 1 do
	turtle.select(m)
	turtle.dropUp()
  end
  turtle.select(1)
  turtle.digUp()
end

-- Dig em up.
for i = 1, depth, 1 do
  for j = 1, rlength, 1 do
	for k = 1, flength, 1 do
	  if turtle.getItemCount(16) > 1 then
		dump()
	  end
	  turtle.digDown()
	  if k < flength then
		step()
	  end
	end
	if j < rlength then
	  if (j + tilt) % 2 ~= 0 then
		rotateRight()
	  else
		rotateLeft()
	  end
	end
  end
  if rlength % 2 == 0 and i % 2 ~= 0 then
	tilt = 1
  else
	tilt = 0
  end
  turtle.turnRight()
  turtle.turnRight()
  stepDown()
end

-- Raise to initial height.
for i = 1, depth, 1 do
  stepUp()
end

-- Return to origin.
if depth % 2 ~= 0 then
  if rlength % 2 == 0 then
	turtle.turnLeft()
	for i = 1, rlength - 1, 1 do
	  step()
	end
  else
	turtle.turnRight()
	for i = 1, rlength - 1, 1 do
	  step()
	end
	turtle.turnLeft()
	for i = 1, flength - 1, 1 do
	  step()
	end
  end
end

Download
pastebin get urvJWGnu dig
sens #2
Posted 03 November 2013 - 12:42 PM
Neat idea, does it also work in multi-player? Which user's "ender space" would the turtle access in that case?
kelm #3
Posted 03 November 2013 - 12:55 PM
Neat idea, does it also work in multi-player? Which user's "ender space" would the turtle access in that case?

It works in multiplayer, and it will just use the chest space of the colors of the wool. So it could be publicly accessible. It also works with Tesseracts though, if you'd rather just put one of those in the first slot. Be sure to right click it with shiny dust after configuring it so that it retains the settings when the turtle places it and digs it up.
Wojbie #4
Posted 03 November 2013 - 12:56 PM
Sad to inform you but minecraft enderchests are inaccessible by turtles.

Author of this program meant enderchests from enderStorage mod
kelm #5
Posted 03 November 2013 - 05:03 PM
Sad to inform you but minecraft enderchests are inaccessible by turtles.

Author of this program meant enderchests from enderStorage mod

I've actually never played vanilla, so I didn't know the difference. Sorry for being unclear.
dngrzone #6
Posted 25 January 2014 - 07:51 PM
I set up 16 turtles with this script. Some quick and dirty rednet implementation.

This thing tears through a chunk faster than a quarry.

Some of the turtles get confused when it's time to dump the items into an ender chest though.