A new update is coming soon, maybe this weekend if I have enough time… it will include, at least:
- Menu to control/configue the program, remotely controlable by a computer server program.
- Real time monitorization of the turtle with external screen (maybe support for several turtles simuntaniously). And with password to sync the turtle with new computer from the distance.
- Persistent variables and autostartup: if you close minecraft or the chunk unloads, the program will auto-continue the task in progres exactly where it was before.
- Eaisier to configure, keeping the command arguments to configurate and new option to skip the menu and mine directly.
- Configure it with minecraft world coordinates (needs a small calibration, once)
- Inverting the Y axis: now will be like the minecraft world.
You can give me some feedback or ideas :)/>/>
——————————————————————-
Hi!
I'm new in computercraft, and this is my firs program for computers(and my first program in lua).
What it does: The turtle digs a hole(configurable measures). You can configure it to only collect specific ores, and when cannot carry more ores of that kind, it comes back to the starting point, empty the slots and goes back to mining.
Changelog:
Spoiler
V2:Comming soon…
V1.1
- Two bugs fixed.
- Added input arguments to configure the home and measures of the mining zone.
v1:
- Initial release.
Spoiler
Installation - Copy the script to your turtle. To do it, you can copy&paste line by line directly to the text editor or…Goto "%AppData%Roaming.minecraftsavesworldnamecomputercomputerID" and paste the code in a new text file without extension( for example: "miner"). Do it after switch on your turtle.
You also can put that text fie into "%AppData%Roaming.minecraftmodsComputerCraftluaromprogramsturtle" and it will be available for every turtle in your game.
Usage:
1- Put the turtle somewhere, like the picture(ignore the hole xD). switch it on and copy the script:
Note that the Y axis is has the + below and the - above.
2- Configure the variables editing the file(if you want) and put the ores in the slots.
3- Start the program and wait until the program finishes the hole.
You can use the optional arguments:
help -Show how to use the other arguments.
h X Y Z -specficates the home/dropping position(home# variables)
s X Y Z -specficates the final starting(min# variables)
f X Y Z -specficates the final position(max# variables)
Example:miner h 0 0 -1 s -2 0 0 f 2 4 2
How to configure the hole measures:
The program has 9 variables for measures: homeX,homeY,hameZ to specify the actual position of the turtle. This position will be used to drop the ores and as starting position. The other 6 are the measures of the hole, and are relative to the home variables, to make a hole from minX,minY,minZ to maxX,maxY,maxZ. You can use negative coordinates to dig wherever you want to, but be careful of mining your drop location!
It doesn't uses the GPS api, the place you put the turtle will be the coordinates specified with the home variables.
The image above has been done with the default config, so you can imagine how it works :)/>/>
How to configure the slots for each ore:
It is one array, with 9 values, one for each slot. Yo can group the slots, and when the group is full(full stacks of items) the turtle will go to home coordinates.
This default config has 3 groups of 2 slots: slot1+slot2, slot3+slot4, slot5+slot6, slot7, slot8, slot9:
-- Default config with example of materials:
sums[9]=1 -- Diamond(item)
sums[8]=1 -- Gold ore
sums[7]=1 -- Lapislazulli(Item)
sums[6]=2 -- Redstone dust
sums[5]=1 -- Redstone dust
sums[4]=2 -- Iron ore
sums[3]=1 -- Iron ore
sums[2]=2 -- Coal(item)
sums[1]=1-- Coal(item)
I'm not sure how to explain this, but… the number in the variable determinates the numer of slots below to group, included itself. So, with "sums[2]=2" and "sums[1]=1" your are configuring one group formed with the slots 2 and 1. (You need to put "1" instead of "0" even if that slot is alredy in a group), If you want only one group(useful for mining only one kind of items), you can do:
-- Default config:
sums[9]=9 -- Sand
sums[8]=1 -- Sand
sums[7]=1 -- Sand
sums[6]=1 -- Sand
sums[5]=1 -- Sand
sums[4]=1-- Sand
sums[3]=1 -- Sand
sums[2]=1 -- Sand
sums[1]=1 -- Sand
I almost foreget: you need to put in each slot of each group one item to define the kind of item that the groups will contain. You have an example in the example of the config above.Here is the updated code:
Spoiler
-- Min coords:
minX = 0
minY = 0 -- Must be a number divisible by 2!
minZ = 0
--Max coords:
maxX = 5
maxY = 4 -- Must be a number divisible by 2!
maxZ = 5
-- Start / Cargo drop:
homeX=0
homeY=0
homeZ=-2
-- Slots config
sums = {}
sums[9]=1
sums[8]=1
sums[7]=1
sums[6]=2
sums[5]=1 --
sums[4]=2
sums[3]=1 --
sums[2]=2
sums[1]=1 --
-- Do not change anything below this comment or something could go wrong.
local tArgs = { ... }
term.clear()
term.setCursorPos(1,1)
print(" --- Mining program ---")
sums[0]=0
finaliza = false
help = false
function setInicial()
-- MiddlePass coords
partX = homeX
partY = homeY
partZ = homeZ + 2
if minZ>homeZ then
partZ = minZ
end
-- Current coords:
x = homeX
y = homeY
z = homeZ
lado = 1 -- Starting direction. 0=l 1=f 2=r 3=b
-- last mining coords / mining taring coords:
xw = minX
zw = minZ
yw = minY
if math.fmod(minY,4) ~= 0 then
xw = maxX
zw = maxZ
end
ladow = 1
end
function readAndSetArg(num)
if #tArgs >=num+3 then
if tonumber(tArgs[num+1]) ~= nil and tonumber(tArgs[num+2]) ~= nil and tonumber(tArgs[num+3]) ~= nil then
if tArgs[num] == "h" then
homeX=tonumber(tArgs[num+1])
homeY=tonumber(tArgs[num+2])
homeZ=tonumber(tArgs[num+3])
print("Read home position: x"..homeX.." y"..homeY.." z"..homeZ)
elseif tArgs[num] == "s" then
minX=tonumber(tArgs[num+1])
minY=tonumber(tArgs[num+2])
minZ=tonumber(tArgs[num+3])
print("Read start position: x"..minX.." y"..minY.." z"..minZ)
elseif tArgs[num] == "f" then
maxX=tonumber(tArgs[num+1])
maxY=tonumber(tArgs[num+2])
maxZ=tonumber(tArgs[num+3])
print("Read final position: x"..maxX.." y"..maxY.." z"..maxZ)
end
end
end
end
function readArgs()
-- Reads the arguments
if #tArgs > 0 then
if tArgs[1] == "help" or tArgs[1] == "Help" then
print("Usage: miner [help]")
print("Usage: miner [h X Y Z] [s X Y Z] [f X Y Z]")
print()
print("Where 'h' is the home position, 's' is the start position and 'f' is the finish position. And X Y Z are the coordinates.")
print()
print("Example:")
print(" miner h 0 0 -1 s -2 0 0 f 2 4 2")
help = true
elseif #tArgs >= 4 then
readAndSetArg(1)
readAndSetArg(5)
readAndSetArg(9)
end
end
setInicial()
end
function askStarting()
print()
print("Home position: x"..homeX.." y"..homeY.." z"..homeZ)
print("Start position: x"..minX.." y"..minY.." z"..minZ)
print("Finish position: x"..maxX.." y"..maxY.." z"..maxZ)
print()
print("Are these numbrers correct? [S/Y/N]")
while true do
event, param1 = os.pullEvent()
if event == "char" then
if param1 == "S" or param1 == "s" or param1 == "Y" or param1 == "y" then
print("Ok! Turtle starting...")
return true
elseif param1 == "N" or param1 == "n" then
print("Try again!")
return false
end
elseif event == "key" and param1==28 then
print("Ok! Turtle starting...")
return true
end
end
return false
end
function gira(l)
-- Receive an absolute directon and does the propiate turns
local resta = math.abs(lado -l)
while lado ~= l do
if (resta > 2 and lado < l) or (resta <= 2 and lado > l) then
turtle.turnLeft()
lado = lado-1
else
turtle.turnRight()
lado = lado+1
end
if lado>3 then
lado=0
elseif lado<0 then
lado=3
end
end
end
function movX(tox)
-- Moves the turle to tox in X axix
if x > tox then
gira(0)
elseif x < tox then
gira(2)
end
while x ~= tox do
while turtle.detect() do
turtle.dig()
end
turtle.forward()
if lado == 0 then
x=x-1
else
x=x+1
end
end
end
function movY(toy)
-- Moves the turle to toy in Y axix
while y < toy do
if turtle.detectDown() then
turtle.digDown()
end
turtle.down()
y=y+1;
end
while y > toy do
while turtle.detectUp() do
turtle.digUp()
end
if turtle.up() then
y=y-1;
else
finaliza=true
break;
end
end
end
function movZ(toz)
-- Moves the turle to toz in Z axix
if z > toz then
gira(3)
elseif z < toz then
gira(1)
end
while z ~= toz do
while turtle.detect() do
turtle.dig()
end
turtle.forward()
if lado == 1 then
z=z+1
else
z=z-1
end
end
end
function mueveCords(tox,toy,toz,dir)
-- Moves the turtle to the spcified coords mining everithing in its way.
modY = 0
if dir == "home" then
if y-2 >= toy and y-2 >= minY then
modY=2
movY(y-modY)
end
-- x:
movX(tox)
-- z:
movZ(toz)
-- y:
movY(toy)
else
if y <= toy-2 and toy-2 >= minY then
modY=2;
end
movY(toy-modY)
-- z:
movZ(toz)
-- x:
movX(tox)
-- y:
movY(toy)
end
end
function checkInventario()
-- Checks the slots. If some slot is full, it will go home to drop everihing
local tmp=9
local lleno=false
while tmp >0 do
if turtle.getItemSpace(tmp) == 0 then
turtle.select(tmp)
--if turtle.compare() or turtle.compare() then
lleno=true
tmp=0
--end
end
tmp=tmp-sums[tmp]
end
if lleno then
--rednet.open("Right")
xw=x
yw=y
zw=z
ladow=lado
goHome()
descarga()
goWork()
end
end
function cava()
-- mine forward and up
while (turtle.detect() or turtle.detectUp()) and not finaliza do
cavado=true
if turtle.detect() then
if not turtle.dig() then
finaliza=true
end
end
if turtle.detectUp() then
if not turtle.digUp() then
finaliza=true
end
end
end
end
function workX(num)
-- mine in X axis
gira(num+1)
local fin = false
while not fin and not finaliza do
if (x > minX and num==-1) or (x < maxX and num==1) then
checkInventario()
cava()
if turtle.forward() then
x=x+num
else
finaliza=true
end
else
fin=true
end
end
end
function workZ(num)
-- mine a entire level
local fin = false
while not fin and not finaliza do
if math.fmod(z,2) == 0 then
workX(1*num)
else
workX(-1*num)
end
if (z > minZ and num==-1) or (z < maxZ and num == 1) then
gira(2-num)
cava()
if turtle.forward() then
z = z+num
else
finaliza=true
end
else
fin = true
end
end
end
function goHome()
-- Go to home coords
mueveCords(partX,partY,partZ,"home")
mueveCords(homeX,homeY,homeZ,"home")
end
function descarga()
-- Drops everithing but 1 block
print("Dropping items...")
local tmp2=9
while tmp2 > 0 do
turtle.select(tmp2)
if turtle.getItemCount(tmp2) > 0 then
turtle.drop(turtle.getItemCount(tmp2)-1)
end
tmp2=tmp2-1
end
end
function goWork()
-- Moves the turtle to the last mining coordinates
mueveCords(partX,partY,partZ,"work")
mueveCords(xw,yw,zw,"work")
gira(ladow)
end
function mineria()
-- Starts everithing.
print("Starting from x:"..minX.." y:"..minY.." z:"..minZ)
print("To x:"..maxX.." y:"..maxY.." z:"..maxZ)
goWork()
checkInventario()
while y <= maxY and not finaliza do
if math.fmod(y/2,2) == 0 then
workZ(1)
else
workZ(-1)
end
if y < maxY and not finaliza then
turtle.digUp()
turtle.digDown()
if turtle.down() then
y=y+1
else
finaliza=true
end
turtle.digUp()
turtle.digDown()
if turtle.down() and not finaliza then
y=y+1
else
turtle.digUp()
finaliza=true
end
else
maxY=maxY-1
end
end
end
readArgs()
if not help then
if askStarting() then
mineria()
if finaliza then
print("Something went wrong...(bedrock?player?mob?)")
else
print("Finish!!")
end
goHome()
descarga()
gira(1)
end
end
-- By RODLON
Here is the outdatd code without command arguments and two bugs:
Spoiler
-- Min coords:
minX = 0
minY = 0 -- Must be a number divisible by 4!
minZ = 0
--Max coords:
maxX = 5
maxY = 4 -- Must be a number divisible by 4!
maxZ = 5
-- Start / Cargo drop:
homeX=0
homeY=0
homeZ=-1
-- Slots config
sums = {}
sums[9]=1
sums[8]=1
sums[7]=1
sums[6]=2
sums[5]=1 --
sums[4]=2
sums[3]=1 --
sums[2]=2
sums[1]=1 --
sums[0]=0
-- Do not change anything below this comment or something could go wrong.
-- MiddlePass coords
partX = homeX
partY = homeY
partZ = homeZ + 2
if minZ>homeZ then
partZ = minZ
end
-- Current coords:
x = homeX
y = homeY
z = homeZ
lado = 1 -- Starting direction. 0=l 1=f 2=r 3=b
-- last mining coords / mining taring coords:
xw = minX
yw = minY
zw = minZ
if math.fmod(minY,4) ~= 0 then
xw = maxX
zw = maxZ
end
ladow = 1
finaliza = false
function gira(l)
-- Receive an absolte directon and does the propiate turns
local resta = math.abs(lado -l)
while lado ~= l do
if (resta > 2 and lado < l) or (resta <= 2 and lado > l) then
turtle.turnLeft()
lado = lado-1
else
turtle.turnRight()
lado = lado+1
end
if lado>3 then
lado=0
elseif lado<0 then
lado=3
end
end
end
function movX(tox)
-- Moves the turle to tox in X axix
if x > tox then
gira(0)
elseif x < tox then
gira(2)
end
while x ~= tox do
while turtle.detect() do
turtle.dig()
end
turtle.forward()
if lado == 0 then
x=x-1
else
x=x+1
end
end
end
function movY(toy)
-- Moves the turle to toy in Y axix
while y < toy do
if turtle.detectDown() then
turtle.digDown()
end
turtle.down()
y=y+1;
end
while y > toy do
while turtle.detectUp() do
turtle.digUp()
end
turtle.up()
y=y-1;
end
end
function movZ(toz)
-- Moves the turle to toz in Z axix
if z > toz then
gira(3)
elseif z < toz then
gira(1)
end
while z ~= toz do
while turtle.detect() do
turtle.dig()
end
turtle.forward()
if lado == 1 then
z=z+1
else
z=z-1
end
end
end
function mueveCords(tox,toy,toz,dir)
-- Moves the turtle to the spcified coords mining everithing in its way.
modY = 0
if dir == "home" then
if y-2 >= toy and y-2 <= minY then
modY=2
end
-- x:
movX(tox)
-- z:
movZ(toz)
-- y:
movY(toy)
else
if y <= toy-2 and toy-2 >= minY then
modY=2;
end
movY(toy-modY)
-- z:
movZ(toz)
-- x:
movX(tox)
-- y:
movY(toy)
end
end
function checkInventario()
-- Checks the slots. If some slot is full, it will go home to drop everihing
local tmp=9
local lleno=false
while tmp >0 do
if turtle.getItemSpace(tmp) == 0 then
turtle.select(tmp)
--if turtle.compare() or turtle.compare() then
lleno=true
tmp=0
--end
end
tmp=tmp-sums[tmp]
end
if lleno then
--rednet.open("Right")
xw=x
yw=y
zw=z
ladow=lado
goHome()
descarga()
goWork()
end
end
function cava()
-- mine forward and up
while (turtle.detect() or turtle.detectUp()) and not finaliza do
cavado=true
if turtle.detect() then
if not turtle.dig() then
finaliza=true
end
end
if turtle.detectUp() then
if not turtle.digUp() then
finaliza=true
end
end
end
end
function workX(num)
-- mine in X axis
gira(num+1)
local fin = false
while not fin and not finaliza do
if (x > minX and num==-1) or (x < maxX and num==1) then
checkInventario()
cava()
if turtle.forward() then
x=x+num
else
finaliza=true
end
else
fin=true
end
end
end
function workZ(num)
-- mine a entire level
local fin = false
while not fin and not finaliza do
if math.fmod(z,2) == 0 then
workX(1*num)
else
workX(-1*num)
end
if (z > minZ and num==-1) or (z < maxZ and num == 1) then
gira(2-num)
cava()
if turtle.forward() then
z = z+num
else
finaliza=true
end
else
fin = true
end
end
end
function goHome()
-- Go to home coords
mueveCords(partX,partY,partZ,"home")
mueveCords(homeX,homeY,homeZ,"home")
end
function descarga()
-- Drops everithing but 1 block
print("Dropping items...")
local tmp2=9
while tmp2 > 0 do
turtle.select(tmp2)
if turtle.getItemCount(tmp2) > 0 then
turtle.drop(turtle.getItemCount(tmp2)-1)
end
tmp2=tmp2-1
end
end
function goWork()
-- Moves the turtle to the last mining coordinates
mueveCords(partX,partY,partZ,"work")
mueveCords(xw,yw,zw,"work")
gira(ladow)
end
function mineria()
-- Starts everithing.
goWork()
checkInventario()
while y < maxY and not finaliza do
if math.fmod(y/2,2) == 0 then
workZ(1)
else
workZ(-1)
end
if y < maxY and not finaliza then
turtle.digUp()
turtle.digDown()
if turtle.down() then
y=y+1
else
finaliza=true
end
turtle.digUp()
turtle.digDown()
if turtle.down() and not finaliza then
y=y+1
else
finaliza=true
end
end
end
end
mineria()
if finaliza then
print("Something went wrong...(bedrock?)")
else
print("Finish!!")
end
goHome()
descarga()
gira(1)
-- By RODLON
Maybe my english is bad, but I'm learning :)/>/>