Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local distance
- local defaultBlockUnderneith
- -- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- --------
- function refuel()
- -- This beast is designed to run on coal
- if turtle.getFuelLevel() <= 20 then
- turtle.select(1)
- return turtle.refuel(1)
- end
- return true
- end
- -- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- --------
- function findBlockOrWait(name)
- local b=0
- local warn=true
- while ( b == 0 ) do
- b = findBlockOrWaitOrFail(name)
- if (b>0) then
- return b
- end
- if warn then
- print("Could not find " .. name .. "! Please insert to continue.")
- warn = false
- end
- sleep(2)
- end
- end
- -- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- --------
- function findBlockOrWaitOrFail(name)
- local s = 1
- repeat
- local d = turtle.getItemDetail(s)
- if ( d ) then
- if (d.name == name) then
- return s
- end
- end
- s = s + 1
- until s > 16
- return 0
- end
- -- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- --------
- function placeBlockDownSafely(item)
- local invSlot = findBlockOrWait(item)
- turtle.select(invSlot)
- local placedOk = turtle.placeDown()
- --print("Placed ok : " .. tostring(placedOk) .. " : " .. item)
- if not placedOk then
- -- If we didn't place a block, try to stick a "default" block underneith where we are
- turtle.down()
- local repSlot = findBlockOrWait(defaultBlockUnderneith.name)
- turtle.select(repSlot)
- turtle.placeDown()
- turtle.up()
- -- Try to place again.
- turtle.select(invSlot)
- placedOk = turtle.placeDown(invSlot)
- --print("Second try Placed ok : " .. tostring(placedOk) .. " : " .. item)
- end
- return placedOk
- end
- -- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- --------
- function placeBlockMoveForward(item,number)
- local a=number
- while a>0 and distance > 1 do
- a = a - 1
- placeBlockDownSafely(item)
- turtle.forward()
- distance = distance - 1
- print ("Distance remaining : " .. distance)
- end
- end
- -- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- --------
- function placeRedstoneTorch()
- turtle.down()
- turtle.digDown()
- turtle.down()
- turtle.digDown()
- placeBlockDownSafely("minecraft:redstone_torch")
- turtle.up()
- placeBlockDownSafely(defaultBlockUnderneith.name)
- turtle.up()
- end
- -- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- --------
- function beginPlacingTrack()
- repeat
- placeRedstoneTorch()
- placeBlockMoveForward("minecraft:golden_rail",1)
- placeBlockMoveForward("minecraft:rail",6)
- turtle.up()
- placeBlockDownSafely(defaultBlockUnderneith.name)
- turtle.up()
- end
- -- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- --------
- function beginPlacingTrack()
- repeat
- placeRedstoneTorch()
- placeBlockMoveForward("minecraft:golden_rail",1)
- placeBlockMoveForward("minecraft:rail",6)
- refuel()
- until distance <= 1
- turtle.down()
- end
- -- -------- -------- -------- -------- -------- -------- -------- -------- -------- -------- --------
- local tArgs = { ... }
- if #tArgs ~= 1 then
- print( "Usage: track <distance>" )
- return
- end
- distance = tonumber( tArgs[1] )
- print("Posi's Trackbuilder ... Use CTRL+T to terminate.")
- refuel()
- -- Find what block we're sitting on, that's our default for any supports/etc/
- local success
- local d
- success,defaultBlockUnderneith = turtle.inspectDown()
- if (not success) then
- print "Must be placed on a block to start."
- return
- end
- -- We need to be one block up in the air to place track
- while (success) do
- turtle.up()
- success,d = turtle.inspectDown()
- end
- beginPlacingTrack()
- -- Done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement