Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Erstellt 27.11.2023
- --Version 1.0
- --Zuletzt geändert 04.12.2023
- --Wandbau Programm für eine CCraft Turtle
- --0.1 - Abbau der Wand (Player in the Way) Turtle fährt nicht bis zum schluss
- --0.2 - Test Fix des "PitW" Fehlers; Anfang des Wandbau-Modus
- --0.3 - Abbau Modus fertig, Bau Modus tests
- --0.4 - Bau Modus Fix
- --
- --Info
- --
- term.clear()
- term.setCursorPos(1,1)
- print("The turtle must face the wall to be built with its front and right side.")
- print("The room size is given in WxDxH from the turtle's perspective, not the wall size.")
- print("A crate behind the turtle.") --2 Modi: Blöcke im weg=vorher Dig ; im Freien, direkter Bau
- --
- --Variables
- --
- term.write("Width: ")
- local breit = tonumber(read())
- term.write("Depth: ")
- local tief = tonumber(read())
- term.write("Height : ")
- local hoch = tonumber(read())
- local hochv = hoch --veränderbar
- local hochgereist = 0 --wenn einmal rum, nach unten zu fahren und das Inv zu leeren in eine Kiste
- local slot = 1
- local q = 0 -- Anzahl der Blöcke
- term.write("is the path blocked?? y/n: ")
- local mode = string.lower(read()) --Modus für im Freien bauen oder wenn Blöcke im Weg sind
- local bt = breit --wechsel zwischen breit und tief
- local four = 0 --4x für 4 Wände
- --
- --functions
- --
- function checkInv()
- q = 0
- for i = 1, 16 do
- q = q + turtle.getItemCount(i)
- end
- if q < 1 then
- print("Inventory empty! Give me some Blocks!")
- print("Press ENTER to continue.")
- repeat
- sleep(0.2)
- local event, key = os.pullEvent( "key" )
- until key == keys.enter
- end
- end
- function check()
- repeat
- slotSelect()
- if turtle.getItemCount(slot) < 1 then
- checkInv()
- else
- break
- end
- until q >= 1
- end
- function slotSelect() --für den Bau-Modus
- for i = 1, 16 do
- if turtle.getItemCount(i) > 0 then
- turtle.select(i)
- slot = i
- break
- end
- end
- end
- function dig()
- if hochv >= 3 then
- dig3()
- elseif hochv == 2 then
- dig2()
- elseif hochv == 1 then
- dig1()
- end
- end
- function dig1()
- turtle.dig()
- end
- function dig2()
- turtle.dig()
- turtle.digDown()
- end
- function dig3()
- turtle.dig()
- turtle.digDown()
- turtle.digUp()
- end
- function place()
- if hochv >= 3 then
- place3()
- elseif hochv == 2 then
- place2()
- elseif hochv == 1 then
- place1()
- end
- end
- function place1()
- check()
- turtle.place()
- end
- function place2()
- check()
- turtle.placeDown()
- check()
- turtle.place()
- end
- function place3()
- check()
- turtle.placeDown()
- check()
- turtle.placeUp()
- check()
- turtle.place()
- end
- function placefirst()
- if hochv >= 3 then
- placefirst3()
- elseif hochv == 2 then
- placefirst2()
- elseif hochv == 1 then
- placefirst1()
- end
- end
- function placefirst1()
- if hochgereist >=3 then
- -- turtle.place()
- else
- sleep(0.1)
- end
- end
- function placefirst2()
- if hochgereist >=3 then
- check()
- turtle.placeDown()
- -- turtle.place()
- else
- sleep(0.1)
- end
- end
- function placefirst3()
- if hochgereist >=3 then
- check()
- turtle.placeDown()
- check()
- turtle.placeUp()
- -- turtle.place()
- else
- check()
- turtle.placeUp()
- end
- end
- function placelast()
- check()
- turtle.place()
- sleep(0.1) -- Temporär? (für immer)
- end
- function placefirstone()
- sleep(0.1)
- end
- function starta() -- Start Abbau-Modus -- MUSS AUCH REDUNDAND WERDEN SIEHE "PitW" Fehler
- turtle.dig()
- turtle.forward()
- turtle.turnRight()
- turtle.dig()
- turtle.forward()
- around()
- if hoch > 1 then
- turtle.digUp()
- up()
- end
- end
- function startb() -- Start Bau-Modus -- MUSS AUCH REDUNDAND WERDEN SIEHE "PitW" Fehler
- turtle.forward()
- turtle.turnRight()
- turtle.forward()
- if hoch > 1 then
- up()
- end
- end
- function around()
- turtle.turnRight()
- turtle.turnRight()
- end
- function up() -- MUSS AUCH REDUNDAND WERDEN SIEHE "PitW" Fehler
- turtle.digUp()
- turtle.up()
- hochgereist = hochgereist + 1
- end
- function down() -- MUSS AUCH REDUNDAND WERDEN SIEHE "PitW" Fehler
- turtle.down()
- hochgereist = hochgereist - 1
- end
- function home() --return to Home Position -- MUSS AUCH REDUNDAND WERDEN SIEHE "PitW" Fehler
- if hochgereist >= 1 then
- repeat
- down()
- until hochgereist == 0
- end
- turtle.forward()
- turtle.turnLeft()
- turtle.forward()
- around()
- end
- function home2()
- turtle.back()
- check()
- turtle.place()
- turtle.turnLeft()
- turtle.back()
- check()
- turtle.place()
- end
- function ecke()
- if hochgereist >= 1 then
- if hochgereist + 1 < hoch then
- check()
- turtle.placeUp()
- end
- repeat
- down()
- check()
- turtle.placeUp()
- until hochgereist == 0
- end
- end
- --
- --Main Code
- --
- -- ABBAU MODUS
- if mode == "y" then -- IF01START--abbau Modus
- starta() -- start Abbau-Modus
- while hochv >= 1 do -- WHILE01START -- Muss vielleicht angeasst werden
- repeat -- REPEAT01START --4x für 4 Wände
- local a = 0
- local a = -1 --hier muss geschaut werden ob es 3,4 oder 5 "Wände" insgesamt sind
- repeat --REPEAT02START --Wand abbauen
- dig()
- local count = 0
- while not turtle.forward() do -- WHILE02START
- dig()
- sleep(0.2)
- turtle.attack()
- sleep(0.2)
- end -- WHILE02END
- a = a + 1
- until a >= bt -- REPEAT02END --Wand abbauen
- if bt == breit then -- IF03START --wechsel zwischen breit und tief
- bt = tief
- else
- bt = breit
- end -- IF03END
- turtle.turnLeft()
- sleep(0.1)
- four = four + 1
- until four >= 4 -- REPEAT01END --4x für 4 Wände
- four = 0
- if hochv <= 0 then -- IF04START
- print("hochv <0")
- break
- elseif hochv == 1 then
- hochv = hochv - 1
- elseif hochv == 2 then
- hochv = hochv - 2
- elseif hochv >= 3 then
- hochv = hochv - 3
- end -- IF04END
- if hochv >= 2 then -- IF05START
- up()
- up()
- up()
- elseif hochv == 1 then
- up()
- up()
- elseif hochv <= 0 then
- break
- end -- IF05END
- end -- WHILE01END
- home()
- print("")
- bt = breit -- neu-indexierung --wechsel zwischen breit und tief
- hochv = hoch --veränderbar
- four = 0 --4x für 4 Wände
- hochgereist = 0
- term.write("In den Bau Modus wechseln? y: ")
- local xy = string.lower(read())
- if xy == "y" then
- mode = "n"
- print("Jetzt brauche ich die Bau-Blöcke")
- print("")
- else
- print("")
- term.write("Do you want to Exit? y: ")
- xy = string.lower(read())
- if xy == "y" then
- mode = "false"
- else
- print("")
- term.write("In den Bau Modus wechseln? y: ")
- local xy = string.lower(read())
- if xy == "y" then
- mode = "n"
- print("Jetzt brauche ich die Bau-Blöcke")
- print("")
- else
- mode = "false"
- end
- end
- end
- end -- IF01END
- -- BAU MODUS
- if mode == "n" then --bau Modus
- startb()
- while hochv >= 1 do -- WHILE01START -- Muss vielleicht angeasst werden
- local first = 0 --damit der Block freigelassen word für home()
- repeat -- REPEAT01START --4x für 4 Wände
- local a = 0
- local a = -1 --hier muss geschaut werden ob es 3,4 oder 5 "Wände" insgesamt sind
- repeat --REPEAT02START --Wand abbauen
- local count = 0
- while not turtle.back() do -- WHILE02START
- sleep(0.2)
- count = count + 1
- if count >= 10 then -- IF02START
- around()
- turtle.attack()
- around()
- count = 0
- end -- IF02END
- end -- WHILE02END
- if (first == 1) and (hochv == 1) and (hoch == 1) then -- IF11START
- placefirstone()
- first = 2
- elseif first == 0 then
- placefirst()
- first = 1
- elseif (four == 3) and (a >= bt - 1) then
- placelast()
- else
- place()
- end -- IF11END
- a = a + 1
- until a >= bt -- REPEAT02END --Wand abbauen
- if bt == breit then -- IF03START --wechsel zwischen breit und tief
- bt = tief
- else
- bt = breit
- end -- IF03END
- turtle.turnLeft()
- four = four + 1
- until four >= 4 -- REPEAT01END --4x für 4 Wände
- four = 0
- if hochv <= 0 then -- IF04START
- print("hochv <0")
- break
- elseif hochv == 1 then
- hochv = hochv - 1
- elseif hochv == 2 then
- hochv = hochv - 2
- elseif hochv >= 3 then
- hochv = hochv - 3
- end -- IF04END
- if hochv >= 2 then -- IF05START
- up()
- up()
- up()
- elseif hochv == 1 then
- up()
- up()
- elseif hochv <= 0 then
- break
- end -- IF05END
- end -- WHILE01END
- ecke()
- home2()
- else
- print("End")
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement