Advertisement
Quae_pumilio

TurtleGo

Jan 21st, 2017
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.38 KB | None | 0 0
  1. compass=peripheral.find('compass')
  2. modem=peripheral.find('modem')
  3. local card={north=1,east=2,south=3,west=4}
  4. homeBlock="EnderStorage:enderChest"
  5.  
  6.  
  7. local programName="TurtleGo"
  8. local potentialConfig={{nom="sens d'avance",choices=true, possibilities={"north","south","east","west"}},{nom="couleur",choices=true,possibilities={"cyan","orange"}}}
  9. if not(fs.exists('InstallCraft')) then
  10.     os.run('pastebin get Byfqqd4S InstallCraft')
  11. end
  12. os.loadAPI('InstallCraft')
  13. local config=InstallCraft.config(programName,potentialConfig)
  14.  
  15. for k,v in pairs(card) do                           --On calcule les directions qui nous manque
  16.     if math.abs(v-card[config["sens d'avance"]])==2 then
  17.         dirRecule=k
  18.     end
  19. end
  20.  
  21. function rotateToDirection(dir)                     --Tourne, tourne, Turtle
  22.     if (card[compass.getFacing()]-card[dir])%4==1 then
  23.         turtle.turnLeft()
  24.     elseif (card[compass.getFacing()]-card[dir])%4==2 then
  25.         turtle.turnLeft()
  26.         turtle.turnLeft()
  27.     elseif (card[compass.getFacing()]-card[dir])%4==3 then
  28.         turtle.turnRight()
  29.     end
  30. end
  31.  
  32. function goHome()
  33.     rotateToDirection(dirRecule)
  34.     bool,block=turtle.inspectDown()
  35.     while not(block.name==homeBlock) do
  36.         turtle.forward()
  37.         bool,block=turtle.inspectDown()
  38.     end
  39.     rotateToDirection(config["sens d'avance"])
  40.     while (turtle.getFuelLimit()-turtle.getFuelLevel())>80 do
  41.         turtle.suckDown(math.min(math.floor((turtle.getFuelLimit()-turtle.getFuelLevel()/80)),64))
  42.         turtle.refuel()
  43.     end
  44. end
  45.  
  46. function waitForAnything()
  47.     modem.open(colors[config.couleur])
  48.     ev,side,freq,repFreq,mess,dis=os.pullEvent('modem_message')
  49. end
  50.  
  51. function dance()
  52.     while true do
  53.         turtle.turnLeft()
  54.     end
  55. end
  56.  
  57. function waitForDANCE()
  58.     modem.open(colors[config.couleur])
  59.     while true do
  60.         ev,side,freq,repFreq,mess,dis=os.pullEvent('modem_message')
  61.         if mess==-2 then
  62.             turtle.forward()
  63.             turtle.forward()
  64.             turtle.forward()
  65.             parallel.waitForAny(dance,waitForAnything)
  66.         end
  67.     end
  68. end
  69.  
  70. function waitForModem()
  71.     modem.open(colors[config.couleur])
  72.     rotateToDirection(config["sens d'avance"])
  73.     while true do
  74.         ev,side,freq,repFreq,mess,dis=os.pullEvent('modem_message')
  75.         if mess==-1 then
  76.             os.sleep(0.5)
  77.             goHome()
  78.             modem.transmit(repFreq, freq, "Retour a la base, Over")
  79.         elseif mess>0 then
  80.             for i=1,mess do
  81.                 turtle.forward()
  82.             end
  83.             modem.transmit(repFreq, freq, "Move done, Over")
  84.         end
  85.     end
  86. end
  87.  
  88. while true do
  89.     parallel.waitForAny(waitForModem,waitForDANCE)
  90. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement