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

[0.0.03] Updated again! Buildcraft Quarry Replacement! Ender Chest and Unlimited fuel Support!

Started by deFENCE_, 30 October 2013 - 07:54 AM
deFENCE_ #1
Posted 30 October 2013 - 08:54 AM
Hi everybody! I started a new survival world and didn't have enough materials to make a BC quarry with engines. However, I had tons of coal and a few diamonds and a house under the ice and a bit of coding knowledge from java :)/>. So I started to script this little quarry.

Usage: quarry <length> <width> <height>

Features:

+Variable size
+Calculates fuel usage (broken)
+Doesn't start if you don't have enough fuel
+Ender Chest Support! They go into slot 16!

Demo Videos:
[media]http://youtu.be/S_bMF1FsrOI[/media]
[media]http://youtu.be/Iwev1y2uiKM[/media]


Version 0.0.0000000001 alpha: http://pastebin.com/C3vLZEdM
Version 0.0.0000000002 alpha: http://pastebin.com/7vQjFQT7
Version 0.0.01 beta: http://pastebin.com/XhfhG8XH
Version 0.0.02 beta: http://pastebin.com/cJBrhLwv
Version 0.0.03 beta: http://pastebin.com/t2CCnSL9


Changelog:

0.0.03:
+Fixed a crash with nil params
+Added unlimited fuel support!
-Removed dungeon loot raiding

0.0.02:
+Added dungeon chest support!
[i][u][b][color=#ff0000]Don't use this if you don't want to get dungeon loot! This is slower than 0.0.01![/color][/b][/u][/i]

0.0.01:
+Added Ender Chest support
+Fixed fuel calculation (hopefully) Nope, still broken :/

Out of alpha stage! Finally!

0.0.0000000002: Fixed last bit of code not being inside the main loop and executing even if there is not enough fuel

0.0.0000000001: Initial release

Current code:


Spoiler

function dumpIntoChest()
  turtle.select(16)
  turtle.placeUp()
  for i = 1, 15 do
	turtle.select(i)
	turtle.dropUp()
  end
  turtle.select(16)
  turtle.digUp()
  turtle.select(1)
end

function digStripe(length)
  for xDec = 1, length - 1 do
	if turtle.getItemCount(15) > 0 then
	  dumpIntoChest()
	end
	turtle.digDown()
	turtle.forward()
  end
  turtle.digDown()
  turtle.turnRight()
  turtle.turnRight()
  for xDec = 1, length - 1 do
	turtle.forward()
  end
  turtle.turnRight()
  turtle.turnRight()
end

function digSquare(length, width)
  for yDec = 1, width -1 do
	digStripe(length)
	turtle.turnRight()
	turtle.forward()
	turtle.turnLeft()
  end
  digStripe(length)
  turtle.turnLeft()
  for yDec = 1, width - 1 do
	turtle.forward()
  end
  turtle.turnRight()
end

function digCube(length, width, height)
  for zDec = 1, height - 1 do
	digSquare(length, width)
	turtle.down()
  end
  digSquare(length, width)
  for zDec = 1, height - 1 do
	turtle.up()
  end
end
local arg = { ... }

if #arg == 3 then
  x = tonumber(arg[1])
  y = tonumber(arg[2])
  z = tonumber(arg[3])

  local fuel = turtle.getFuelLevel()
  if fuel == "unlimited" then
	fuel = 0
	fuelNeeded = -1
  else
	fuelNeeded = ((((x-1)*2)+1) * (y-1) * z + z - 1)
  end
  --print (x..y..z)

  print("Quarrying out area")
  print("Dimensions:")
  print("x: "..x)
  print("y: "..y)
  print("z: "..z)
  print("")
  print("Fuel: "..fuel)
  print("Fuel needed: "..fuelNeeded)
  print("")
  if fuel < fuelNeeded then
	print("Please refuel me! I need a minimum of "..fuelNeeded.." fuel!")
  else
	--Main quarry program

	digCube(x, y, z)
	
	if turtle.getFuelLevel() == "unlimited" then
	  print("Unlimited fuel, fuel calculation disabled!")
	else
	  fuelReallyNeeded = fuel - turtle.getFuelLevel()
	
	  print("Fuel after quarrying: "..turtle.getFuelLevel())
	  print("Fuel needed: "..fuelReallyNeeded)
	
	  if fuelReallyNeeded == fuelNeeded then
		print("Fuel needed equals what I calculated!")
	  else
		print("Aww shit. I calculated the wrong fuel usage! :-[")
		print("Creepers may kill me")
	  end
	end
	dumpIntoChest()
  end
else
  print("Usage: quarry <length> <width> <height>")
  print("[stderr] Wrong parameters.")
end

Please test this out and report bugs back to me!

-deFENCE
Edited on 01 December 2013 - 05:19 AM
deFENCE_ #2
Posted 31 October 2013 - 02:07 AM
Changelog:
0.0.01:
-Added Ender Chest support
-Fixed fuel calculation (hopefully)
-Out of alpha stage! Finally!
deFENCE_ #3
Posted 31 October 2013 - 05:05 AM
Can somebody check out what is wrong with fuel? I can't seem to resolve the issue :/
deFENCE_ #4
Posted 31 October 2013 - 07:02 AM
0.0.02:
Added dungeon chest support!
Don't use this if you don't want to get dungeon loot! This is slower than 0.0.01!
mdutcher #5
Posted 01 November 2013 - 07:31 AM
Seems very cool, might wanna look into a way to keep it going after a server restart or something.
Would be really nice :P/>
deFENCE_ #6
Posted 01 November 2013 - 11:43 PM
Seems very cool, might wanna look into a way to keep it going after a server restart or something.
Would be really nice :P/>
Yea, I thought of that too… But then I would have to rewrite the code… I'll see..
valithor #7
Posted 02 November 2013 - 12:13 AM
Can somebody check out what is wrong with fuel? I can't seem to resolve the issue :/

Just so you know it will be impossible to calculate exactly how much fuel it will use as its inventory might become full forcing it to go back up before you predicted it would. This will cause it to use more fuel than you expect. The only way around this is for it to use a enderchest only if it uses normal chests to store which is a feature that you have it will not work.

(((((x-1)*2)) * z)+((2*z)-2)) * y)+y-1 This right here is the equation required only for digging the area out
x+z+y-3 This is equation for fuel required to get back to home position assuming you use most efficient route to get back
This might fix the calculation for perfect world scenario.

​This calculation was done quickly based on the fact that in a 5 x 5 grid a turtle would have to move 44 times to move the entire area.
(((5-1)*2) * 5)+(4)) = 44
the equation above also includes the fuel required to get back to the home x and z coords but the one i worked out does not

If you wish me to explain this equation i can, but for sake of time i am not going to right now
This equation only will work for the way that the program is set up in the video if the mining pattern has been changed at all this equation will not work
Edited on 01 November 2013 - 11:33 PM
deFENCE_ #8
Posted 02 November 2013 - 12:28 AM
Can somebody check out what is wrong with fuel? I can't seem to resolve the issue :/

Just so you know it will be impossible to calculate exactly how much fuel it will use as its inventory might become full forcing it to go back up before you predicted it would. This will cause it to use more fuel than you expect. The only way around this is for it to use a enderchest only if it uses normal chests to store which is a feature that you have it will not work.
Well, at that time it needs ender chests to work. I will try your method of calculating out, I don't know if it fit the code though. It should work though :)/>
valithor #9
Posted 02 November 2013 - 12:34 AM
Can somebody check out what is wrong with fuel? I can't seem to resolve the issue :/

Just so you know it will be impossible to calculate exactly how much fuel it will use as its inventory might become full forcing it to go back up before you predicted it would. This will cause it to use more fuel than you expect. The only way around this is for it to use a enderchest only if it uses normal chests to store which is a feature that you have it will not work.
Well, at that time it needs ender chests to work. I will try your method of calculating out, I don't know if it fit the code though. It should work though :)/>

make sure to use the most recent i updated it some where around 10 times
also if you wish you could come onto my server and i could help you with it if you need help
http://www.computercraft.info/forums2/index.php?/topic/15793-164no-whitelistcreative-valicraft/ – server information
deFENCE_ #10
Posted 02 November 2013 - 01:13 AM
Can somebody check out what is wrong with fuel? I can't seem to resolve the issue :/

Just so you know it will be impossible to calculate exactly how much fuel it will use as its inventory might become full forcing it to go back up before you predicted it would. This will cause it to use more fuel than you expect. The only way around this is for it to use a enderchest only if it uses normal chests to store which is a feature that you have it will not work.
Well, at that time it needs ender chests to work. I will try your method of calculating out, I don't know if it fit the code though. It should work though :)/>
Fail…
Gives me this

bios:339: [string "quarry"]:64:
unexpected symbol

Current code is:
Spoiler



function dumpIntoChest()
  turtle.select(16)
  turtle.placeUp()
  for i = 1, 15 do
    turtle.select(i)
    turtle.dropUp()
  end
  turtle.select(16)
  turtle.digUp()
  turtle.select(1)
end

function digStripe(length)
  for xDec = 1, length - 1 do
    if turtle.getItemCount(15) > 0 then
      dumpIntoChest()
    end
    turtle.digDown()
    turtle.forward()
  end
  turtle.digDown()
  turtle.turnRight()
  turtle.turnRight()
  for xDec = 1, length - 1 do
    turtle.forward()
  end
  turtle.turnRight()
  turtle.turnRight()
end

function digSquare(length, width)
  for yDec = 1, width -1 do
    digStripe(length)
    turtle.turnRight()
    turtle.forward()
    turtle.turnLeft()
  end
  digStripe(length)
  turtle.turnLeft()
  for yDec = 1, width - 1 do
    turtle.forward()
  end
  turtle.turnRight()
end

function digCube(length, width, height)
  for zDec = 1, height - 1 do
    digSquare(length, width)
    turtle.down()
  end
  digSquare(length, width)
  for zDec = 1, height - 1 do
    turtle.up()
  end
end
local arg = { ... }

x = tonumber(arg[1])
y = tonumber(arg[2])
z = tonumber(arg[3])

local fuel = turtle.getFuelLevel()

local fuelNeeded = ((((x-1)*2))*z)+(2*z-2))*y

print("Quarrying out area")
print("Dimensions:")
print("x: "..x)
print("y: "..y)
print("z: "..z)
print("")
print("Fuel: "..fuel)
print("Fuel needed: "..fuelNeeded)
print("")
if fuel < fuelNeeded then
  print("Please refuel me! I need a minimum of "..fuelNeeded.." fuel!")
else
  --Main quarry program

  digCube(x, y, z)

  fuelReallyNeeded = fuel - turtle.getFuelLevel()

  print("Fuel after quarrying: "..turtle.getFuelLevel())
  print("Fuel needed: "..fuelReallyNeeded)

  if fuelReallyNeeded == fuelNeeded then
    print("Fuel needed equals what I calculated!")
  else
    print("Aww shit. I calculated the wrong fuel usage! :-[")
    print("Creepers may kill me")
  end
  dumpIntoChest()
end

Can somebody check out what is wrong with fuel? I can't seem to resolve the issue :/

Just so you know it will be impossible to calculate exactly how much fuel it will use as its inventory might become full forcing it to go back up before you predicted it would. This will cause it to use more fuel than you expect. The only way around this is for it to use a enderchest only if it uses normal chests to store which is a feature that you have it will not work.
Well, at that time it needs ender chests to work. I will try your method of calculating out, I don't know if it fit the code though. It should work though :)/>

make sure to use the most recent i updated it some where around 10 times
also if you wish you could come onto my server and i could help you with it if you need help
http://www.computerc...tive-valicraft/ – server information
Sure I can come on your server :D/>
I'll be happy to :)/>
kelm #11
Posted 02 November 2013 - 12:11 PM
Can somebody check out what is wrong with fuel? I can't seem to resolve the issue :/

The movement makes the calculation harder. If at the end of a row, instead of having the turtle come back to the starting place and then moving over, it just moved over and dug on its way back, the fuel would be (height * width * length). You've made it traverse every block twice, basically, so it is (height * width * length * 2).
deFENCE_ #12
Posted 02 November 2013 - 11:55 PM
Can somebody check out what is wrong with fuel? I can't seem to resolve the issue :/

The movement makes the calculation harder. If at the end of a row, instead of having the turtle come back to the starting place and then moving over, it just moved over and dug on its way back, the fuel would be (height * width * length). You've made it traverse every block twice, basically, so it is (height * width * length * 2).
The problem is, it isn't height*2, it is (height-1)*2 because if it is 5 long, it goes 4 blocks forward. Then it goes 4 blocks backward. I have thought of ((height-1) * width * length * 2) too, but that didn't work sadly.
deFENCE_ #13
Posted 01 December 2013 - 05:49 AM
I'm adding unlimited fuel support right now…
deFENCE_ #14
Posted 01 December 2013 - 06:08 AM
Update released!
0.0.03:
+Fixed a crash with nil params
+Added unlimited fuel support!
-Removed dungeon loot raiding
deFENCE_ #15
Posted 03 December 2013 - 09:04 AM
Save movement coming soon!
apemanzilla #16
Posted 03 December 2013 - 09:32 AM
Could you just use the edit button next time?
deFENCE_ #17
Posted 05 December 2013 - 06:46 AM
Could you just use the edit button next time?
What? I'm using the edit button actually…