Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local fuelSlot = 1
- local floorWireID = "chisel:factory"
- local floorWires = {
- 2;
- 3;
- --not needed
- }
- local floorSideID = "chisel:technicalnew"
- local floorSide = {
- 2;
- 3;
- 4;
- --not needed
- }
- local floorMainID = "chisel:laboratory"
- local floorMain = {
- 2;
- 3;
- 4;
- }
- local wallsID = "chisel:laboratory"
- local walls = {
- 9;
- 10;
- 11;
- 12;
- 13;
- 14;
- 15;
- 16;
- }
- local IECNET = true
- -- end of config
- local args = {...}
- --IECNET setup
- local gpsEnabled = false
- local net = "Turtlenet"
- function iecnetSetup()
- if (IECNET) then
- if (peripheral.isPresent("left")) then
- if (peripheral.getType("left") == "modem") then
- --peripheral is present, starting IECNET
- rednet.open("left")
- if (rednet.lookup(net,"IEC-Host") == nil) then
- print("IECNET does not have a Host or Host is Offline, broadcasts will go unheard.")
- end
- x,y,z = gps.locate()
- if (x == nil) then
- print("GPS not available, will not send Location Data")
- else
- gpsEnabled = true;
- end
- rednet.broadcast("Online",net)
- else
- print("IECNET was enabled, but no modem was found.")
- IECNET = false
- end
- else
- print("IECNET was enabled, but no modem was found.")
- IECNET = false
- end
- end
- end
- function getLocation()
- x,y,z = gps.locate()
- if (x == nil) then
- gpsEnabled = false
- return nil
- else
- if (not gpsEnabled) then
- gpsEnabled = true
- print("GPS now available, sending location data")
- end
- x = math.floor(x+0.5)
- y = math.floor(y+0.5)
- z = math.floor(z+0.5)
- return tostring(x).." "..tostring(y).." "..tostring(z)
- end
- end
- function refuel()
- if(turtle.getFuelLevel() < 5) then
- turtle.select(fuelSlot)
- if(turtle.refuel(1) == false) then
- if (IECNET) then
- if (gpsEnabled) then
- rednet.broadcast("Out of Fuel ".."\n"..location,net)
- else
- rednet.broadcast("Out of Fuel",net)
- end
- end
- error("out of fuel")
- end
- end
- end
- --digs the block infront
- function digForward()
- while(turtle.dig()) do
- end
- end
- --digs the block below
- function digDown()
- while(turtle.digDown()) do
- end
- end
- --digs the block above
- function digUp()
- while(turtle.digUp()) do
- end
- end
- function placeWalls()
- for i=1, #walls do
- turtle.select(walls[i])
- if(turtle.getItemCount() > 0) then
- if(turtle.getItemDetail().name == wallsID) then
- while(not turtle.place()) do
- digForward()
- end
- return true
- end
- end
- end
- return false
- end
- function placeWallsUp()
- for i=1, #walls do
- turtle.select(walls[i])
- if(turtle.getItemCount() > 0) then
- if(turtle.getItemDetail().name == wallsID) then
- while(not turtle.placeUp()) do
- digDown()
- end
- return true
- end
- end
- end
- return false
- end
- function placeFloorWire()
- for i=1, #floorWires do
- turtle.select(floorWires[i])
- if(turtle.getItemCount() > 0) then
- if(turtle.getItemDetail().name == floorWireID) then
- while(not turtle.placeDown()) do
- digDown()
- end
- return true
- end
- end
- end
- return false
- end
- function placeFloorSide()
- for i=1, #floorSide do
- turtle.select(floorSide[i])
- if(turtle.getItemCount() > 0) then
- if(turtle.getItemDetail().name == floorSideID) then
- while(not turtle.placeDown()) do
- digDown()
- end
- return true
- end
- end
- end
- return false
- end
- function placeFloorMain()
- for i=1, #floorMain do
- turtle.select(floorMain[i])
- if(turtle.getItemCount() > 0) then
- if(turtle.getItemDetail().name == floorMainID) then
- while(not turtle.placeDown()) do
- digDown()
- end
- return true
- end
- end
- end
- return false
- end
- function goForward()
- digForward()
- turtle.forward()
- digUp()
- digDown()
- refuel()
- end
- function turn()
- turtle.turnRight()
- turtle.turnRight()
- end
- function move(dist)
- for i=2,dist,1 do
- turtle.forward()
- refuel()
- end
- end
- function tunnel()
- --assumes the turtle is in the middle on the floor
- goForward()
- placeFloorMain()
- turtle.turnRight()
- goForward()
- placeFloorMain()
- placeWalls()
- turtle.up()
- placeWalls()
- turn()
- move(2)
- digForward()
- turtle.forward()
- placeWalls()
- digDown()
- turtle.down()
- placeWalls()
- placeFloorMain()
- turn()
- move(2)
- turtle.turnLeft()
- end
- --begin of program
- local iterations = 1
- if(not(args[1] == nil)) then
- iterations = args[1]
- end
- iecnetSetup()
- print("Starting!")
- for i=1,iterations,1 do
- if (IECNET) then
- location = getLocation()
- if (gpsEnabled) then
- rednet.broadcast("Iteration "..i.."/"..iterations.."\n"..location,net)
- else
- rednet.broadcast("Iteration "..i.."/"..iterations,net)
- end
- end
- tunnel()
- end
- if(IECNET) then
- location = getLocation()
- if (gpsEnabled) then
- rednet.broadcast("Done!".."\n"..location,net)
- else
- rednet.broadcast("Done!",net)
- end
- end
Add Comment
Please, Sign In to add comment