Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Start Declaring varibles
- 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()
- return true
- else
- print("Error: block not found in inventory.")
- return false
- 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"
- end
- if currentX < startX then
- currentDirection = "west"
- end
- if currentZ > startZ then
- currentDirection = "north"
- end
- if currentZ < startZ then
- currentDirection = "south"
- end
- 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.turnRight()
- turtle.turnRight()
- elseif currentDirection == "west" then
- turtle.turnLeft()
- end
- 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.turnLeft()
- elseif currentDirection == "west" then
- --Do nothing
- end
- end
- --Case west
- --Case north
- if directionToFace == "north" then
- if currentDirection == "north" then
- --Do nothing
- elseif currentDirection == "east" then
- turtle.turnRight()
- elseif currentDirection == "south" then
- turtle.turnRight()
- turtle.turnRight()
- elseif currentDirection == "west" then
- turtle.turnLeft()
- end
- end
- --Case north
- --Case south
- if directionToFace == "south" then
- if currentDirection == "north" then
- turtle.turnRight()
- turtle.turnRight()
- elseif currentDirection == "east" then
- turtle.turnLeft()
- elseif currentDirection == "south" then
- --Do nothing
- elseif currentDirection == "west" then
- turtle.turnRight()
- end
- end
- --Case south
- end
- -- End turnDirection()
- -- Start moveTo() function
- -- Get the initial location
- startX, startY, startZ = gps.locate()
- -- Function to move to the target coordinates
- function moveTo(goX, goZ)
- -- Calculate the distance from the initial location to the target
- targetX = startX + goX
- targetZ = startZ + goZ
- currentLocation()
- -- If z plus is south 1
- -- if z minus is north 2
- -- if x minus is west 3
- -- if x plus is east 4
- if currentX > targetX then
- turnDirection("west")
- while currentX ~= targetX do
- print("Moving west")
- print(tostring(currentX))
- turtle.forward()
- currentLocation()
- end
- print("Reached X")
- end
- if currentX < targetX then
- turnDirection("east")
- while currentX ~= targetX do
- print("Moving east")
- print(tostring(currentX))
- turtle.forward()
- currentLocation()
- end
- print("Reached X")
- end
- if currentZ > targetZ then
- turnDirection("south")
- while currentX ~= targetX do
- print("Moving south")
- print(tostring(currentZ))
- turtle.forward()
- currentLocation()
- end
- print("Reached X")
- end
- if currentZ < targetZ then
- turnDirection("north")
- while currentX ~= targetX do
- print("Moving north")
- print(tostring(currentZ))
- turtle.forward()
- currentLocation()
- end
- print("Reached X")
- 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