Marech

Turtle_tunnel_Marech

Jun 25th, 2015
269
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.46 KB | None | 0 0
  1. --created by Marech
  2.  
  3. function clc()
  4.         term.clear()
  5.         term.setCursorPos(1,1)
  6. end
  7.  
  8. function placeLight()
  9.  
  10.         i = getSlotOf('minecraft:torch')
  11.         if i == 0 then
  12.                 display('Plus de torches')
  13.         else
  14.                 turtle.select(i)       
  15.  
  16.                 left()
  17.         left()
  18.  
  19.                 turtle.place()
  20.  
  21.                 left()
  22.         left()
  23.         end
  24.         turtle.select(1)
  25. end
  26.  
  27. function refuel()
  28.         if turtle.getFuelLevel() ~= "unlimited" and turtle.getFuelLevel() < 1 then
  29.                 i = getSlotOf('minecraft:coal')
  30.                 if i ~= 0 then
  31.                         turtle.select(i)
  32.                         turtle.refuel(1)
  33.                 else
  34.                         turtle.select(1)
  35.                         if not turtle.refuel(0) then
  36.                                 display('Need fuel in slot 1')
  37.                         end
  38.  
  39.                         while turtle.refuel(0) == false do
  40.                         end
  41.  
  42.                         turtle.refuel(1)
  43.                 end
  44.  
  45.         end
  46. end
  47.  
  48. function getSlotOf(itemID)
  49.         for i=1,16 do
  50.                 turtle.select(i)
  51.                 local details = turtle.getItemDetail()
  52.                 if details ~= nil then
  53.                         if details.name == itemID then
  54.                                 return i,details.count
  55.                         end
  56.                 end
  57.         end
  58.         return 0
  59. end
  60.  
  61. function dropItems()
  62.         i,quantity = getSlotOf('minecraft:cobblestone')
  63.         if i ~= 0 and quantity >= 16 then
  64.                 turtle.select(i)
  65.                 turtle.drop()
  66.         end
  67.         i,quantity = getSlotOf('minecraft:dirt')
  68.         if i ~= 0 and quantity >= 16 then
  69.                 turtle.select(i)
  70.                 turtle.drop()
  71.         end
  72.         turtle.select(1)
  73. end
  74.  
  75. function backHome(length)
  76.         display('Je rentre a la maison')
  77.  
  78.         right()
  79.     right()
  80.     up()   
  81.  
  82.         for i=1, length-1 do
  83.                 refuel()
  84.                 goForward()                          
  85.         end
  86.  
  87.     down()
  88. end
  89.  
  90. function display(message)
  91.         print(message)
  92. end
  93.  
  94. function goForward()
  95.         i=0
  96.         while not turtle.forward() and i<30 do
  97.                 turtle.attack()
  98.                 turtle.dig()
  99.                 i=i+1
  100.         end
  101. end
  102.  
  103.  
  104. function forward()
  105. end
  106.  
  107. function left()
  108.     if not turtle.turnLeft() then
  109.         refuel()
  110.         turtle.turnLeft()
  111.     end
  112. end
  113.  
  114. function right()
  115.     if not turtle.turnRight() then
  116.         refuel()
  117.         turtle.turnRight()
  118.     end
  119. end
  120.  
  121. function up()
  122.     if not turtle.up() then
  123.         refuel()
  124.         turtle.up()
  125.     end
  126. end
  127.  
  128. function down()
  129.     if not turtle.down() then
  130.         refuel()
  131.         turtle.down()
  132.     end
  133. end
  134.  
  135. function nextStep()
  136.  
  137.     goForward()
  138.  
  139.     while turtle.digUp() do
  140.     end
  141.    
  142.     --gauche
  143.     left()
  144.  
  145.     while turtle.detect() do
  146.         turtle.dig()
  147.     end
  148.    
  149.     up()
  150.    
  151.     while turtle.detect() do
  152.         turtle.dig()
  153.     end
  154.  
  155.     while turtle.digUp() do
  156.     end
  157.  
  158.     up()
  159.  
  160.     turtle.dig()
  161.    
  162.     right()
  163.  
  164.     --droite
  165.     right()
  166.  
  167.     turtle.dig()
  168.  
  169.     down()
  170.  
  171.     turtle.dig()
  172.  
  173.     down()
  174.  
  175.     while turtle.detect() do
  176.         turtle.dig()
  177.     end
  178.  
  179.     left()
  180. end
  181.  
  182.  
  183.  
  184. --script-------------------------
  185.  
  186. clc()
  187. print('Hello there !')
  188. print()
  189.  
  190. write('Longueur ?')
  191. print()
  192. length = read()
  193.  
  194.  
  195. display('Lets go !')
  196. print()
  197.  
  198. for j=0,length-1 do
  199.     refuel()
  200.     nextStep()
  201.  
  202.     if j%10 == 0 then
  203.         placeLight()
  204.     end
  205.  
  206.     if j%5 == 0 then
  207.         dropItems()
  208.     end
  209. end
  210.  
  211. backHome(length)
  212.  
  213. display('End')
Advertisement
Add Comment
Please, Sign In to add comment