Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Start printclr()
- function printclr(...)
- local colors = {
- ["white"] = colors.white,
- ["orange"] = colors.orange,
- ["magenta"] = colors.magenta,
- ["lightBlue"] = colors.lightBlue,
- ["yellow"] = colors.yellow,
- ["lime"] = colors.lime,
- ["pink"] = colors.pink,
- ["gray"] = colors.gray,
- ["lightGray"] = colors.lightGray,
- ["cyan"] = colors.cyan,
- ["purple"] = colors.purple,
- ["blue"] = colors.blue,
- ["brown"] = colors.brown,
- ["green"] = colors.green,
- ["red"] = colors.red,
- ["black"] = colors.black,
- }
- local args = {...}
- for i = 1, #args do
- local arg = args[i]
- if type(arg) == "string" and colors[arg] then
- term.setTextColor(colors[arg])
- else
- write(tostring(arg))
- end
- end
- term.setTextColor(colors.white)
- end
- -- End printclr()
- -- Get the initial location
- startX, startY, startZ = gps.locate()
- function currentLocation()
- currentX, currentY, currentZ = gps.locate()
- end
- -- End Declaring varibles
- -- Start name setting section
- function checkLabel()
- label = os.getComputerLabel()
- if label then
- print("Already has the name : "..label)
- else
- print("Does not have name")
- print("Setting name to CoalMan")
- os.setComputerLabel("CoalMan")
- end
- end
- -- End name setting section
- -- Start Find Item function
- function findItem(name)
- for i=1,16 do
- if turtle.getItemCount(i) > 0 then
- local data = turtle.getItemDetail(i)
- if data and data.name == name then
- return i
- end
- end
- end
- return nil
- end
- -- End Find Item Function
- -- Start Place block function
- function placeBlock(name)
- local slot = findItem(name)
- if slot then
- turtle.select(slot)
- turtle.placeDown()
- printclr("white","Placed a block at ","red", "X: ","yellow",currentX, "red", " Z:","yellow",currentZ,"\n")
- reachedX = false
- reachedZ = false
- else
- print("Error: block not found in inventory.")
- end
- end
- -- End Place block function
- -- Start find facingDirection()
- -- If z plus is south 1
- -- if z minus is north 2
- -- if x minus is west 3
- -- if x plus is east 4
- function facingDirection()
- turtle.forward()
- currentLocation()
- if currentX > startX then
- currentDirection = "east"
- elseif currentX < startX then
- currentDirection = "west"
- elseif currentZ > startZ then
- currentDirection = "south"
- elseif currentZ < startZ then
- currentDirection = "north"
- end
- turtle.back()
- print("Facing: "..currentDirection)
- end
- -- End find facingDirection()
- -- Start turnDirection()
- function turnDirection(directionToFace)
- -- Case east
- if directionToFace == "east" then
- if currentDirection == "north" then
- turtle.turnRight()
- elseif currentDirection == "east" then
- --Do nothing
- elseif currentDirection == "south" then
- turtle.turnLeft()
- elseif currentDirection == "west" then
- turtle.turnRight()
- turtle.turnRight()
- end
- currentDirection = "east"
- end
- --Case east
- --Case west
- if directionToFace == "west" then
- if currentDirection == "north" then
- turtle.turnLeft()
- elseif currentDirection == "east" then
- turtle.turnRight()
- turtle.turnRight()
- elseif currentDirection == "south" then
- turtle.turnRight()
- elseif currentDirection == "west" then
- --Do nothing
- end
- currentDirection = "west"
- end
- --Case west
- --Case north
- if directionToFace == "north" then
- if currentDirection == "north" then
- --Do nothing
- elseif currentDirection == "east" then
- turtle.turnLeft()
- elseif currentDirection == "south" then
- turtle.turnRight()
- turtle.turnRight()
- elseif currentDirection == "west" then
- turtle.turnRight()
- end
- currentDirection = "north"
- end
- --Case north
- --Case south
- if directionToFace == "south" then
- if currentDirection == "north" then
- turtle.turnRight()
- turtle.turnRight()
- elseif currentDirection == "east" then
- turtle.turnRight()
- elseif currentDirection == "south" then
- --Do nothing
- elseif currentDirection == "west" then
- turtle.turnLeft()
- end
- currentDirection = "south"
- end
- --Case south
- end
- -- End turnDirection()
- -- Start moveTo() function
- -- Function to move to the desired location
- function moveTo(goX, goZ)
- -- Calculate the distance from the initial location to the target
- targetX = startX + goX
- targetZ = startZ + goZ
- currentLocation()
- if reachedX ~= true then
- if currentX > targetX then
- print("Should be trying to go west")
- turnDirection("west")
- while currentX ~= targetX do
- print("Moving west")
- print("Current X: "..tostring(currentX))
- print("Target X: "..tostring(targetX))
- turtle.forward()
- currentLocation()
- end
- elseif currentX < targetX then
- print("Should be trying to go east")
- turnDirection("east")
- while currentX ~= targetX do
- print("Moving east")
- print("Current X: "..tostring(currentX))
- print("Target X: "..tostring(targetX))
- turtle.forward()
- currentLocation()
- end
- reachedX = true
- print("Reached X")
- end
- end
- if reachedZ ~= true then
- if currentZ < targetZ then
- print("Should be trying to go south")
- turnDirection("south")
- while currentZ ~= targetZ do
- print("Moving south")
- print("Current Z: "..tostring(currentZ))
- print("Target Z: "..tostring(targetZ))
- turtle.forward()
- currentLocation()
- end
- elseif currentZ > targetZ then
- print("Should be trying to go north")
- turnDirection("north")
- while currentZ ~= targetZ do
- print("Moving north")
- print("Current Z: "..tostring(currentZ))
- print("Target Z: "..tostring(targetZ))
- turtle.forward()
- currentLocation()
- end
- reachedZ = true
- print("Reached Z")
- end
- end
- end
- -- End moveTo() function
- -- Start requests materials for build.
- checkLabel()
- facingDirection()
- -- Start Build code
- turtle.up()
- moveTo(9, 9)
- placeBlock("minecraft:cobblestone")
- moveTo(8, 9)
- placeBlock("minecraft:cobblestone")
- moveTo(7, 9)
- placeBlock("minecraft:cobblestone")
- moveTo(6, 9)
- placeBlock("minecraft:cobblestone")
- moveTo(5, 9)
- placeBlock("minecraft:cobblestone")
- moveTo(5, 8)
- placeBlock("minecraft:cobblestone")
- moveTo(6, 8)
- placeBlock("minecraft:cobblestone")
- moveTo(7, 8)
- placeBlock("minecraft:cobblestone")
- moveTo(8, 8)
- placeBlock("minecraft:cobblestone")
- moveTo(9, 8)
- placeBlock("minecraft:cobblestone")
- moveTo(9, 7)
- redstone.setOutput("bottom", true)
- placeBlock("minecraft:hopper")
- moveTo(8, 7)
- redstone.setOutput("bottom", false)
- placeBlock("minecraft:cobblestone")
- moveTo(7, 7)
- placeBlock("minecraft:cobblestone")
- moveTo(6, 7)
- placeBlock("minecraft:cobblestone")
- moveTo(5, 7)
- placeBlock("minecraft:cobblestone")
- moveTo(5, 6)
- placeBlock("minecraft:cobblestone")
- moveTo(6, 6)
- placeBlock("minecraft:cobblestone")
- moveTo(7, 6)
- placeBlock("minecraft:cobblestone")
- moveTo(8, 6)
- placeBlock("minecraft:cobblestone")
- moveTo(9, 6)
- placeBlock("minecraft:cobblestone")
- moveTo(9, 5)
- placeBlock("minecraft:cobblestone")
- moveTo(8, 5)
- placeBlock("minecraft:cobblestone")
- moveTo(7, 5)
- placeBlock("minecraft:cobblestone")
- moveTo(6, 5)
- placeBlock("minecraft:cobblestone")
- moveTo(5, 5)
- placeBlock("minecraft:cobblestone")
- turtle.up()
- moveTo(4, 5)
- placeBlock("minecraft:cobblestone")
- moveTo(4, 6)
- placeBlock("minecraft:cobblestone")
- moveTo(4, 7)
- placeBlock("minecraft:cobblestone")
- moveTo(4, 8)
- placeBlock("minecraft:cobblestone")
- moveTo(4, 9)
- placeBlock("minecraft:cobblestone")
- moveTo(5, 10)
- placeBlock("minecraft:cobblestone")
- moveTo(6, 10)
- placeBlock("minecraft:cobblestone")
- moveTo(7, 10)
- placeBlock("minecraft:cobblestone")
- moveTo(8, 10)
- placeBlock("minecraft:cobblestone")
- moveTo(9, 10)
- placeBlock("minecraft:cobblestone")
- moveTo(10, 9)
- placeBlock("minecraft:cobblestone")
- moveTo(10, 8)
- placeBlock("minecraft:cobblestone")
- moveTo(10, 7)
- placeBlock("minecraft:cobblestone")
- moveTo(10, 6)
- placeBlock("minecraft:cobblestone")
- moveTo(10, 5)
- placeBlock("minecraft:cobblestone")
- moveTo(9, 4)
- placeBlock("minecraft:cobblestone")
- moveTo(8, 4)
- placeBlock("minecraft:cobblestone")
- moveTo(7, 4)
- placeBlock("minecraft:cobblestone")
- moveTo(6, 4)
- placeBlock("minecraft:cobblestone")
- moveTo(5, 4)
- placeBlock("minecraft:cobblestone")
- turtle.up()
- moveTo(7, 7)
- placeBlock("minecraft:dirt")
- turtle.up()
- placeBlock("minecraft:spruce_sapling")
- -- End build code
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement