Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local tArgs = { ... }
- local dis = tonumber(tArgs[1])
- local PylonCount = math.floor(dis/28)
- local y = 0
- local p = 0
- --Slots in Turtle Inventory for Items to be placed
- local cPath = 1 --cPath = SandStone
- local Edge = 5 --Edge = Oak Planks
- local uPath = 9 --uPath = Stone Slabs
- --EnderChest slots containing items for Restocking, one item per chest
- local cPathEnChest = 4 --enderchest with SandStone
- local EdgeEnChest = 8 --enderchest with Oak Planks
- local uPathEnChest = 12 --enderchest with Stone Slabs
- --Variables used to calculate distance traveled for the little guy
- local startmoves = turtle.getFuelLevel()
- local endmoves = 0
- local moves = 0
- --====================================================
- --Rail Way Building Functions
- --====================================================
- local dumpCrap, getItems, CheckslotCount, goingDown, DownPlace, PlaceBlock, placeUnderPath, PlaceSlab, checkHeight, BuildPylon, goingDownSlab, DownPlaceSlab
- --Clear the Turtle inventory of slots not used from above declarations
- --by dumping them into the Enderchest placed in slot 16
- --Slot numbers are hard coded so adjust if needed.
- dumpCrap = function()
- turtle.digUp()
- turtle.select(16)
- turtle.placeUp()
- turtle.select(2)
- turtle.dropUp()
- turtle.select(3)
- turtle.dropUp()
- turtle.select(6)
- turtle.dropUp()
- turtle.select(7)
- turtle.dropUp()
- turtle.select(10)
- turtle.dropUp()
- turtle.select(11)
- turtle.dropUp()
- turtle.select(13)
- turtle.dropUp()
- turtle.select(14)
- turtle.dropUp()
- turtle.select(15)
- turtle.dropUp()
- turtle.select(16)
- turtle.digUp()
- end
- --Restocking Function
- getItems = function(slot,chestslot)
- turtle.select(15)
- turtle.digUp()
- turtle.select(chestslot)
- turtle.placeUp()
- turtle.select(slot)
- turtle.suckUp()
- turtle.select(chestslot)
- turtle.digUp()
- end
- --Check how many items are left and restock if needed
- CheckslotCount = function(slot,chestslot)
- if turtle.getItemCount(slot) < 1 then
- getItems(slot,chestslot)
- end
- end
- --Checks to see how high to build the pathway
- checkHeight = function()
- if turtle.detectDown() then
- for i = 1, 10 do
- turtle.up()
- sleep(0.2)
- end
- else
- turtle.down()
- sleep(0.2)
- checkHeight()
- end
- end
- --==========================================================================
- --Pylon Building Functions
- --==========================================================================
- --Travels down to see how much room there is to place blocks ( Sets variable y )
- goingDown = function(slot,chestslot)
- turtle.down()
- y = y + 1
- DownPlace(slot,chestslot)
- end
- goingDownSlab = function(slot,chestslot)
- turtle.down()
- y = y + 1
- DownPlaceSlab(slot,chestslot)
- end
- --Places blocks in a 1x1 column to a height "y" that was set by the function goingDown()
- PlaceBlock = function(slot,chestslot)
- for i = 1, y do
- CheckslotCount(slot,chestslot)
- turtle.select(slot)
- turtle.placeDown()
- turtle.up()
- end
- end
- --Checks wether to run PlaceBlock when it finds a block below itself, or goingDown if it does not detect a block below itself.
- DownPlace = function(slot,chestslot)
- if turtle.detectDown() then
- PlaceBlock(slot,chestslot)
- else
- goingDown(slot,chestslot)
- end
- end
- DownPlaceSlab = function(slot,chestslot)
- if turtle.detectDown() then
- PlaceSlab(slot,chestslot)
- else
- goingDownSlab(slot,chestslot)
- end
- end
- --This adds the small double slab supports underneath the path
- placeUnderPath = function(slot,chestslot)
- turtle.digDown()
- turtle.down()
- turtle.digDown()
- CheckslotCount(slot,chestslot)
- turtle.select(uPath)
- turtle.placeDown()
- turtle.placeDown()
- turtle.up()
- end
- --Uses the value of y set by the function goingDown to place two slabs in order to fill the whole column.
- PlaceSlab = function(slot,chestslot)
- for i = 1, y-1 do
- CheckslotCount(slot,chestslot)
- turtle.select(slot)
- turtle.placeDown()
- turtle.placeDown()
- turtle.up()
- end
- end
- --======================================================================
- -- Pylon Building Function
- --======================================================================
- BuildPylon = function()
- p = p + 1
- turtle.digDown()
- turtle.up()
- y=0
- DownPlace(Edge,EdgeEnChest)
- turtle.up()
- turtle.dig()
- turtle.forward()
- turtle.down()
- placeUnderPath(uPath,uPathEnChest)
- turtle.select(cPath)
- turtle.placeDown()
- turtle.turnRight()
- turtle.turnRight()
- turtle.dig()
- turtle.forward()
- turtle.dig()
- turtle.forward()
- turtle.digDown()
- placeUnderPath(uPath,uPathEnChest)
- turtle.turnRight()
- turtle.dig()
- turtle.forward()
- y = 0
- DownPlaceSlab(uPath,uPathEnChest)
- turtle.select(Edge)
- turtle.placeDown()
- turtle.turnRight()
- turtle.dig()
- turtle.forward()
- turtle.select(Edge)
- turtle.placeDown()
- turtle.turnLeft()
- turtle.dig()
- turtle.forward()
- turtle.dig()
- turtle.forward()
- turtle.select(Edge)
- turtle.placeDown()
- turtle.turnRight()
- turtle.turnRight()
- turtle.dig()
- turtle.forward()
- turtle.digDown()
- y = 0
- DownPlace(Edge,EdgeEnChest)
- turtle.select(Edge)
- turtle.placeDown()
- turtle.dig()
- turtle.forward()
- turtle.digDown()
- turtle.select(Edge)
- turtle.placeDown()
- turtle.turnLeft()
- turtle.dig()
- turtle.forward()
- turtle.digDown()
- y = 0
- DownPlaceSlab(uPath,uPathEnChest)
- turtle.select(Edge)
- turtle.placeDown()
- turtle.turnRight()
- turtle.dig()
- turtle.forward()
- turtle.dig()
- turtle.forward()
- turtle.digDown()
- y = 0
- DownPlaceSlab(uPath,uPathEnChest)
- turtle.select(Edge)
- turtle.placeDown()
- turtle.turnRight()
- turtle.dig()
- turtle.forward()
- turtle.turnLeft()
- turtle.dig()
- turtle.forward()
- turtle.dig()
- turtle.forward()
- turtle.select(Edge)
- turtle.placeDown()
- turtle.turnRight()
- turtle.turnRight()
- turtle.dig()
- turtle.forward()
- turtle.digDown()
- y = 0
- DownPlace(Edge,EdgeEnChest)
- turtle.select(Edge)
- turtle.placeDown()
- turtle.dig()
- turtle.forward()
- turtle.select(Edge)
- turtle.placeDown()
- turtle.turnLeft()
- turtle.dig()
- turtle.forward()
- turtle.digDown()
- y=0
- DownPlaceSlab(uPath,uPathEnChest)
- turtle.select(Edge)
- turtle.placeDown()
- turtle.turnRight()
- turtle.dig()
- turtle.forward()
- turtle.select(cPath)
- turtle.placeDown()
- turtle.turnRight()
- turtle.dig()
- turtle.forward()
- turtle.select(cPath)
- turtle.placeDown()
- --Clean Up and Restock Inventory
- dumpCrap()
- CheckslotCount(cPath,cPathEnChest)
- CheckslotCount(Edge,EdgeEnChest)
- CheckslotCount(uPath,uPathEnChest)
- end
- --==========================================================================
- -- Main Railway building Script
- --==========================================================================
- for i = 1, dis do
- if i % 28 == 0 then
- BuildPylon()
- turtle.forward()
- turtle.forward()
- --Print out progress
- endmoves = turtle.getFuelLevel()
- moves = startmoves - endmoves
- print( p .. " of " .. PylonCount .. " Pylons built")
- print( turtle.getFuelLevel() .. " = Current Fuel Level")
- print("I've moved " .. moves .. " meters so far.")
- print("===============================")
- end
- checkHeight()
- turtle.digDown()
- turtle.select(uPath)
- turtle.placeDown()
- turtle.turnLeft()
- turtle.dig()
- turtle.select(Edge)
- turtle.place()
- turtle.turnRight()
- turtle.turnRight()
- turtle.dig()
- turtle.select(Edge)
- turtle.place()
- turtle.turnLeft()
- turtle.dig()
- turtle.forward()
- turtle.turnRight()
- turtle.turnRight()
- turtle.select(cPath)
- turtle.place()
- turtle.turnRight()
- turtle.turnRight()
- if i % 4 == 0 then
- dumpCrap()
- end
- CheckslotCount(cPath,cPathEnChest)
- CheckslotCount(Edge,EdgeEnChest)
- CheckslotCount(uPath,uPathEnChest)
- print( i .. " of " .. dis .. " meters of railway built")
- end
Advertisement
Add Comment
Please, Sign In to add comment