Jump to content

How to program turtle to mine place for quarry?


Kotja

Recommended Posts

Here's a miningprogramm for a turtle. 

You have to do the first layer by hand and the turtle needs to be at the bottom left block. 

hoch = 0                  -- Höhe des Tunnels
hoch2 = 0                 -- Hilfsvariable für die Fackeln
breit = 0                 -- Breite des Tunnels
lang = 0                  -- Länge des Tunnels
arbeit = 0                -- Anzahl der Felder die abgebaut werden
weg = 0                   -- Zurückgelegte Strecke
fackel = 0                -- Abstand der Fackeln
kiste = 0                 -- Prüft ob Platz im Inventar ist
kiste2 = 0                -- Hilfsvariable für Kiste
position = "unten"        -- Standort des Turtle
ausrichtung = "rechts"    -- Gräbt er nach links oder rechts

function Titel()
term.clear()
term.setCursorPos(1,1)
print("~~~~~~~~~~~~ReduceTheBlock~~~~~~~~~~~~")
print("{                                    }")
print("{           Tunnel graben            }")
print("{       Kohle in Slot 16 legen       }")
print("{       Fackeln in Slot 15 legen     }")
print("{       Kiste in Slot 14 legen       }")
print("{                                    }")
print("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
print()
end

function Ausrichtung()
if ausrichtung == "links" then
turtle.turnLeft()
Warten()
Tanken()
turtle.forward()
turtle.turnRight()
else if ausrichtung == "rechts" then
turtle.turnRight()
Warten()
Tanken()
turtle.forward()
turtle.turnLeft()
end
end
end

function Wechsel()
if ausrichtung == "links" then
ausrichtung = "rechts"
else if ausrichtung == "rechts" then
ausrichtung = "links"
end
end
end

function Graben()
if position == "unten" then
Hoch()
else if position == "oben" then
Runter()
end
end
end

function Tanken()
tank = turtle.getFuelLevel()
if tank == 0 then
turtle.select(16)
turtle.refuel(1)
turtle.select(1)
end
end

function Warten()
while turtle.detect() do
turtle.dig()
sleep(0.6)
end
end

function Hoch()
if not turtle.detectDown() then
turtle.select(1)
turtle.placeDown()
end
hoch1 = hoch-1
while hoch1 > 0 do
turtle.dig()
Warten()
arbeit = arbeit-1
Kiste()
Titel()
print("    "..arbeit.." Felder werden ausgegraben")
Warten()
Tanken()
turtle.up()
turtle.dig()
Warten()
hoch1 = hoch1-1
Kiste()
position = "oben"
end
if not turtle.detectUp() then
turtle.select(1)
turtle.placeUp()
end
arbeit = arbeit-1
Titel()
print("    "..arbeit.." Felder werden ausgegraben")
hoch1 = hoch
end

function Runter()
if not turtle.detectUp() then
turtle.select(1)
turtle.placeUp()
end
runter = hoch-1
while runter > 0 do
turtle.dig()
Warten()
turtle.digDown()
arbeit = arbeit-1
Kiste()
Titel()
print("    "..arbeit.." Felder werden ausgegraben")
Warten()
Tanken()
turtle.down()
turtle.dig()
turtle.digDown()
Warten()
runter = runter-1
Kiste()
position = "unten"
end
if not turtle.detectDown() then
turtle.select(1)
turtle.placeDown()
end
arbeit = arbeit-1
Titel()
print("    "..arbeit.." Felder werden ausgegraben")
runter = hoch
end

function Fackel()
if weg == fackel then
turtle.select(15)
turtle.turnRight()
turtle.turnRight()


if ausrichtung =="rechts" then

  if position == "unten" then
  turtle.place()
  end
  if position == "oben" then
    while hoch2 > 1 do
	turtle.down()
	hoch2 = hoch2-1
	end
	hoch2 = hoch
	turtle.place()
	while hoch2 > 1 do 
	turtle.up()
	hoch2 = hoch2-1
	end
	hoch2 = hoch
    --turtle.place()
  end

end
if ausrichtung =="links" then

  if position == "unten" then
  turtle.place()
  end
  if position == "oben" then
    while hoch2 > 1 do
	turtle.down()
	hoch2 = hoch2-1
	end
	hoch2 = hoch
	turtle.place()
	while hoch2 > 1 do 
	turtle.up()
	hoch2 = hoch2-1
	end
	hoch2 = hoch
    --turtle.place()
  end

end

turtle.turnLeft()
turtle.turnLeft()
turtle.select(1)
weg = 0
end
end

function Kiste()
kiste = tonumber(turtle.getItemCount(13))
if kiste > 0 then

 while not turtle.detectDown() do
 turtle.down()
 kiste2 = kiste2+1
 end
 
turtle.select(14)
turtle.turnLeft()
turtle.turnLeft()
turtle.dig()
turtle.place()
for i = 1,13,1 do
turtle.select(i)
turtle.drop()
end
turtle.turnRight()
turtle.turnRight()
  while kiste2 > 0 do
  turtle.up()
  kiste2 = kiste2-1
  end
end
turtle.select(1)
end




Titel()
print("Wie hoch soll Dein Tunnel sein?")
write("Höhe : ")
hoch = tonumber(io.read())
hoch2 = hoch              -- Hilfsvariable für die Fackeln
Titel()
print("Wie breit soll Dein Tunnel sein?")
write("Breite : ")
breit = tonumber(io.read())
Titel()
print("Wie lang soll Dein Tunnel sein?")
write("Länge : ")
lang = tonumber(io.read())
Titel()
print("In welchem Abstand sollen die Fackeln sein?")
write("Abstand : ")
fackel = tonumber(io.read())
arbeit = hoch*breit*lang
Titel()
print("    "..arbeit.." Felder werden ausgegraben")
sleep(1)

breit1 = breit

while lang > 0 do

while breit1 >= 1 do
Graben()
breit1 = breit1-1
if breit1 > 0 then
Ausrichtung()
end

end
breit1 = breit
Wechsel()
turtle.dig()
Warten()
turtle.forward()
lang = lang-1
weg = weg+1
Fackel()
end

Its in german but it sould be easy to understand :)

 

Coal to power the Turtle goes to slot 16

Torches to slot 15

and an Enderchest to slot 14

 

Place another Enderchest somewhere else so you can empty the Chest right into your base

 

 

If you dont understand the programm tell me and i try to translate the most important parts :)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...