Fern_Silverthorn

Fern Core CC API

Jan 28th, 2015
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.23 KB | None | 0 0
  1. -- Fern Core is the base api of all Fern enterprises.
  2.  
  3. -- Network Funtions
  4.  
  5. function nodelisten(side, channel)
  6.   local modem = peripheral.wrap(side)
  7.   modem.open(channel)
  8.   local event, modemSide, senderChannel, replyChannel, message, senderDistance = os.pullEvent("modem_message")
  9.   return message
  10. end
  11.  
  12. function repeat_node(side, route_ch)
  13.   local modem = peripheral.wrap(side)
  14.   modem.open(route_ch)
  15.   while true do
  16.     local event, modemSide, senderChannel, replyChannel, message, senderDistance = os.pullEvent("modem_message")
  17.     if senderChannel == route_ch then
  18.       local repeat_channel = message
  19.       modem.open(repeatchannel)
  20.       while true do
  21.         local event, modemSide, senderChannel, replyChannel, message, senderDistance = os.pullEvent("modem_message")
  22.         if senderChannel == repeat_channel then
  23.           modem.transmit(repeat_channel, repeat_channel, message)
  24.           modem.close(repeat_channel)
  25.           break
  26.         end
  27.       end
  28.     end
  29.   end
  30. end
  31.  
  32. -- Misc Functions
  33.  
  34. function cls()
  35.   term.clear()
  36.   term.setCursorPos(1,1)
  37. end
  38.  
  39. -- Turtle Functions
  40.  
  41. function walk(direction, distance, endingdir)
  42.   if direction == "forward" or "f" then
  43.     for i = 1,distance,1 do
  44.       if turtle.detect() == false then
  45.         turtle.forward()
  46.       end
  47.     end
  48.     if endingdir == "right" or "r" then
  49.       turtle.turnRight()
  50.     elseif endingdir == "back" or "b" then
  51.       turtle.turnRight()
  52.       turtle.turnRight()
  53.     elseif endingdir == "left" or "l" then
  54.       turtle.turnLeft()
  55.     end  
  56.   elseif direction == "right" or "r" then
  57.     turtle.turnRight()
  58.     for i = 1,distance,1 do
  59.       if turtle.detect() == false then
  60.         turtle.forward()
  61.       end
  62.     end
  63.     if endingdir == "forward" or "f" then
  64.       turtle.turnLeft()
  65.     elseif endingdir == "back" or "b" then
  66.       turtle.turnRight()
  67.     elseif endingdir == "left" or "l" then
  68.       turtle.turnRight()
  69.       turtle.turnRight()
  70.     end  
  71.   elseif direction == "back" or "b" then
  72.     turtle.turnRight()
  73.     turtle.turnRight()
  74.     for i = 1,distance,1 do
  75.       if turtle.detect() == false then
  76.         while true do
  77.           if pcall(turtle.forward()) == true then
  78.             break
  79.           end
  80.         end
  81.       end
  82.     end
  83.     if endingdir == "forward" or "f" then
  84.       turtle.turnRight()
  85.       turtle.turnRight()
  86.     elseif endingdir == "right" or "r" then
  87.       turtle.turnLeft()
  88.     elseif endingdir == "left" or "l" then
  89.       turtle.turnLeft()
  90.       turtle.turnLeft()
  91.     end
  92.   elseif direction == "left"  or "l" then
  93.     turtle.turnLeft()
  94.     for i = 1,distance,1 do
  95.       if turtle.detect() == false then
  96.         turtle.forward()
  97.       end
  98.     end
  99.     if endingdir == "forward" or "f" then
  100.       turtle.turnRight()
  101.     elseif endingdir == "right" or "r" then
  102.       turtle.turnRight()
  103.       turtle.turnRight()
  104.     elseif endingdir == "back" or "b" then
  105.       turtle.turnLeft()
  106.     end
  107.   elseif direction == "up" or "u" then
  108.     for i = 1,distance,1 do
  109.       if turtle.detectUp() == false then
  110.         turtle.up()
  111.       end
  112.     end
  113.     if endingdir == "right" or "r" then
  114.       turtle.turnRight()
  115.     end
  116.   elseif direction == "down" or "d" then
  117.   else
  118.     print("walk pass error")
  119.   end
  120. end
Advertisement
Add Comment
Please, Sign In to add comment