Marech

Turtle_lines_offline_Marech

Jun 24th, 2015
249
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.43 KB | None | 0 0
  1. --created by Marech
  2. --Turtle program for Minecraft (offline)
  3.  
  4. function clc()
  5.         term.clear()
  6.         term.setCursorPos(1,1)
  7. end
  8.  
  9. function goForward()
  10.     i=0
  11.     while not turtle.forward() and i<30 do
  12.         turtle.attack()
  13.         turtle.dig()
  14.         i=i+1
  15.     end
  16.     turtle.digUp()
  17. end
  18.  
  19. function placeLight()
  20.  
  21.     i = getSlotOf('minecraft:torch')
  22.     if i == 0 then
  23.         display('Plus de torches')
  24.     else
  25.         turtle.select(i)
  26.         turtle.back()
  27.         turtle.turnLeft()
  28.         turtle.placeUp()
  29.         turtle.turnRight()
  30.         goForward()
  31.     end
  32.     turtle.select(1)
  33. end
  34.  
  35. function refuel()
  36.     if turtle.getFuelLevel() ~= "unlimited" and turtle.getFuelLevel() < 1 then
  37.         i = getSlotOf('minecraft:coal')
  38.         if i ~= 0 then
  39.             turtle.select(i)
  40.             turtle.refuel(1)
  41.         else
  42.             turtle.select(1)
  43.             if not turtle.refuel(0) then
  44.                 display('Need fuel in slot 1')
  45.             end
  46.  
  47.             while turtle.refuel(0) == false do
  48.             end
  49.  
  50.             turtle.refuel(1)
  51.         end
  52.  
  53.     end
  54. end
  55.  
  56. function getSlotOf(itemID)
  57.     for i=1,16 do
  58.         turtle.select(i)
  59.         local details = turtle.getItemDetail()
  60.         if details ~= nil then
  61.             if details.name == itemID then
  62.                 return i,details.count
  63.             end
  64.         end
  65.     end
  66.     return 0
  67. end
  68.  
  69. function dropItems()
  70.     i,quantity = getSlotOf('minecraft:cobblestone')
  71.     if i ~= 0 and quantity >= 16 then
  72.         turtle.select(i)
  73.         turtle.drop()
  74.     end
  75.     i,quantity = getSlotOf('minecraft:dirt')
  76.     if i ~= 0 and quantity >= 16 then
  77.         turtle.select(i)
  78.         turtle.drop()
  79.     end
  80.     turtle.select(1)
  81. end
  82.  
  83. function backHome()
  84.     display('Je rentre a la maison')
  85.     turtle.turnRight()
  86.  
  87.     for i=1, lines*3 do
  88.         refuel()
  89.         goForward()        
  90.  
  91.         if i%12 == 0 then
  92.             placeLight()
  93.         end
  94.            
  95.     end
  96. end
  97.  
  98. function display(message)
  99.     print(message)
  100. end
  101.  
  102.  
  103. --Script------
  104.  
  105.  
  106. clc()
  107. print('Hello there !')
  108. print()
  109.  
  110. write('Longueur ?')
  111. print()
  112. length = read()
  113.  
  114. write('Nombre de lignes ? (Nombre pair)')
  115. print()
  116. lines = read()
  117.  
  118. if lines%2 == 1 then
  119.     print('On a dit un nombre pair !')
  120.     print()
  121.     lines = lines+1
  122.     print('On va dire ' .. lines .. ' lignes du coup')
  123. end
  124.  
  125. display('Lets go !')
  126. print()
  127.  
  128. for i=1, lines do
  129.     for j=0,length-1 do
  130.         dropItems()
  131.         refuel()
  132.         goForward()
  133.  
  134.         if j%12 == 0 then
  135.             placeLight()
  136.         end
  137.     end
  138.  
  139.     if i%2 == 1 then
  140.         turtle.turnLeft()
  141.         goForward()
  142.         goForward()
  143.         goForward()
  144.         turtle.turnLeft()
  145.     else
  146.         turtle.turnRight()
  147.         goForward()
  148.         goForward()
  149.         goForward()
  150.         turtle.turnRight()
  151.     end
  152.  
  153.     display('Ligne suivante')
  154. end
  155.  
  156. backHome()
  157.  
  158. display('End')
Advertisement
Add Comment
Please, Sign In to add comment