Published using Google Docs
Documentation of TurtleRails
Updated automatically every 5 minutes

Documentation of Turtle-Rails


creator Marco Dittrich

Information

The turtle permanently sends rednet messages and it can be started using a rednet command. The reason I called this program “Turtle-Rails” is because of the colored wool coding it uses(as example: black wool above will make the turtle go 1 step)

The turtle also can Pick Up Items from chests with a preselected quantity)

You Can find a detailed list of Color coding's down below.

Index

        

Information

Index

Code

Explanation

Function CheckItems

Function Refuel

Function  checkFuelLevel

rest

Turtle Inventory Sorting

EXAMPLE

Code        

while true do

local function CheckItems(sInt, slot, tslot)

 while turtle.getItemCount(slot) < sInt do

  if turtle.getItemCount(slot) == 0 then

    turtle.select(slot)

    turtle.suck()

  end

  if turtle.getItemCount(slot) < sInt then

   turtle.select(tslot)

   turtle.suck()

   turtle.select(slot)

   turtle.drop()

   turtle.select(tslot)

   turtle.transferTo(slot)

  end

 end

end

local function refuel()

   if turtle.getFuelLevel() <= 20 then

   turtle.refuel(8)

   end

   rednet.open("right")

   rednet.broadcast("DiamondTurtleCoal")

   rednet.broadcast(tostring(turtle.getItemCount(8)))

end

local function checkFuelLevel()

    rednet.open("right")

    rednet.broadcast("DiamondTurtleFuel")

    rednet.broadcast(tostring(turtle.getFuelLevel()))

end

refuel()

checkFuelLevel()

if turtle.detect() == true then

  turtle.select(3)

  if turtle.compare() == true then

    turtle.down()

    turtle.forward()

  end

  turtle.select(6)

  if turtle.compare() == true then

    turtle.turnLeft()

  end

end

if turtle.detectUp() == true then

  turtle.select(1)

  if turtle.compareUp() == true then

    turtle.forward()

  end

  turtle.select(4)


  if turtle.compareUp() == true then

    turtle.turnRight()

    turtle.forward()

  end

  turtle.select(3)

  if turtle.compareUp() == true then

    turtle.forward()

    while turtle.detectUp() == false do

      turtle.up()

    end

  end

  turtle.select(5)

  if turtle.compareUp() == true then

    turtle.select(15)

    turtle.drop()

    turtle.select(14)

    turtle.drop()

    turtle.select(13)

    turtle.drop()

    turtle.turnRight()

    turtle.turnRight()

    turtle.forward()

  end

  turtle.select(7)

  if turtle.compareUp() == true then

   local senderId, message, distance = rednet.receive()  

     if message == "DTStart" then

      turtle.forward()      

     elseif message == "DTStop" then

       return

     end

  end

  turtle.select(2)

  if turtle.compareUp() == true then

    turtle.select(12)

    turtle.suck()

    turtle.select(9)

    if turtle.compareDown() == true then

      CheckItems(8, 12, 16)

      turtle.select(12)

      turtle.transferTo(13, 8)

    end

    turtle.select(10)

    if turtle.compareDown() == true then

      CheckItems(1, 12, 16)

      turtle.select(12)

      turtle.transferTo(14, 1)

    end

    turtle.select(11)

    if turtle.compareDown() == true then

      CheckItems(64, 12, 16)

      turtle.select(12)

      turtle.transferTo(15, 64)

    end

    turtle.select(12)

    turtle.drop()

    turtle.turnRight()

    turtle.turnRight()

    turtle.forward()

  end

  if turtle.detectUp() == false then

    return

  end

end

sleep(0.1)

end

Explanation

Function CheckItems

local function CheckItems(sInt, slot, tslot)

while turtle.getItemCount(slot) < sInt do

  if turtle.getItemCount(slot) == 0 then

    turtle.select(slot)

    turtle.suck()

  end

  if turtle.getItemCount(slot) < sInt then

   turtle.select(tslot)

   turtle.suck()

   turtle.select(slot)

   turtle.drop()

   turtle.select(tslot)

   turtle.transferTo(slot)

  end

 end

end

# -> If the wanted Items(<sInt>) in slot <slot> are enough the function stops.

# -> If the number of items in slot <slot> equals zero the turtle will suck up another stack

# -> If the number of items in slot <slot> is smaller than the number of required items it will suck up another stack into the temporary slot <tslot> and refill the items from slot <slot> into the chest then the turtle will transfer the items from the temp slot <tslot> into <slot>.

!! In the Current version of the code the turtle would be stuck in front of the chest, to get back into the command line of CraftOS you would need to send the rednet command “DTStop” !!

Function Refuel

 

local function refuel()

   if turtle.getFuelLevel() <= 20 then

   turtle.refuel(8)

   end

   rednet.open("right")

   rednet.broadcast("DiamondTurtleCoal")

   rednet.broadcast(tostring(turtle.getItemCount(8)))

end

# -> Basically the turtle will check if the Fuel Level is below 20 units if so, the turtle trys to refuel itself with 8 coal.

# -> Afterwards the turtle will broadcast a message of the current Coal resources it has.

Function  checkFuelLevel

local function checkFuelLevel()

    rednet.open("right")

    rednet.broadcast("DiamondTurtleFuel")

    rednet.broadcast(tostring(turtle.getFuelLevel()))

end

# -> This is a simple part, the turtle will broadcast a message of her current FuelLevel

rest

HERE COMES THE MESSY CODE!

I Might rewrite this part :) so stay tuned!

refuel()

checkFuelLevel()

if turtle.detect() == true then

  turtle.select(3)

  if turtle.compare() == true then

    turtle.down()

    turtle.forward()

  end

  turtle.select(6)

  if turtle.compare() == true then

    turtle.turnLeft()

  end

end

if turtle.detectUp() == true then

  turtle.select(1)

  if turtle.compareUp() == true then

    turtle.forward()

  end

  turtle.select(4)

  if turtle.compareUp() == true then

    turtle.turnRight()

    turtle.forward()

  end

  turtle.select(3)

  if turtle.compareUp() == true then

    turtle.forward()

    while turtle.detectUp() == false do

      turtle.up()

    end

  end

  turtle.select(5)

  if turtle.compareUp() == true then

    turtle.select(15)

    turtle.drop()

    turtle.select(14)

    turtle.drop()

    turtle.select(13)

    turtle.drop()

    turtle.turnRight()

    turtle.turnRight()

    turtle.forward()

  end

  turtle.select(7)

  if turtle.compareUp() == true then

   local senderId, message, distance = rednet.receive()  

     if message == "DTStart" then

      turtle.forward()      

     elseif message == "DTStop" then

       return

     end

  end

  turtle.select(2)

  if turtle.compareUp() == true then

    turtle.select(12)

    turtle.suck()

    turtle.select(9)

    if turtle.compareDown() == true then

      CheckItems(8, 12, 16)

      turtle.select(12)

      turtle.transferTo(13, 8)

    end

    turtle.select(10)

    if turtle.compareDown() == true then

      CheckItems(1, 12, 16)

      turtle.select(12)

      turtle.transferTo(14, 1)

    end

    turtle.select(11)

    if turtle.compareDown() == true then

      CheckItems(64, 12, 16)

      turtle.select(12)

      turtle.transferTo(15, 64)

    end

    turtle.select(12)

    turtle.drop()

    turtle.turnRight()

    turtle.turnRight()

    turtle.forward()

  end

  if turtle.detectUp() == false then

    return

  end

end

sleep(0.1)

end

# -> Turtle selects a slot

# ->Turtle movement

# ->In this step the turtle will drop all stuff(slot 13,14 and 15[in my example setup this would be coal, flint and obsidian]) out into a chest and turn around to go 1     step forward

# ->while this happens the turtle will move infinitely up until it detects a block (beware of the infinity!)

# ->If the Material above the turtle matches slot 7 it will stop and wait for an rednet message (“DTStart” or “DTStop”)

# ->If the block above the turtle matches slot 2 it checks the block below if it’s slot 9, 10 or 11 it will suck the Items out of the chest [see CheckItems]

# -> No block above?!,will stop the machine.

# -> sleeps for a short time to prevent non yielded while loop

Turtle Inventory Sorting

  __________________________________

 /      #1      /     #2       /                /                /

/________/________/________/________/

 /                /                /                /                /

/________/________/________/________/

 /                /                /                /                /

/________/________/________/________/

 /                /                /                /      #16    /

/________/________/________/________/

The first slot (slot 1) is the one that is marked red and labeled with #1 and the one on the right side is the second slot (slot 2) and the last slot is slot 16 in the down left corner.

Here is the Setup if you didn’t edit the script

Rail Block

[Forward]

OpenChest Block

Block for up down movement

Block for Move right

Drop transported items into a chest

Move left

Stop and wait for command

FUEL

IndicatorBlock 1

used to get specific chest suck amount

IndicatorBlock 2

used to get specific chest suck amount

IndicatorBlock 3

used to get specific chest suck amount

Don’t use this!

This slot will be filled with Items that are linked to the IndicatorBlock 1

This slot will be filled with Items that are linked to the IndicatorBlock 2

This slot will be filled with Items that are linked to the IndicatorBlock 3

Don’t use this!


EXAMPLE


I named the program Startup so it starts at boot also I added this Color Coding to the Turtle