Advertisement
Edeldor

Terra2.0

Dec 22nd, 2014
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 11.77 KB | None | 0 0
  1. local x=1
  2. local y=0
  3. local z=1
  4. local d=1
  5. local h=5
  6.  
  7. local dLigne=1
  8.  
  9. local slotTerre = 1
  10. local slotMur = 9
  11. local slotFuel = 16
  12.  
  13. local niveauFuelMini = 200
  14. local niveauStockFuelMini = 5
  15.  
  16. local surface = 0
  17. local action = 0
  18.  
  19. local resultat1,resultat2=0,0
  20.  
  21. function inventaire()
  22.     local success,data=true,{name="",metadata=0}
  23.    
  24.    
  25.     repeat
  26.     print("Pour niveler le terrain, taper 1.")
  27.     print("Pour niveler le terrain et construire un mur d'enceinte, taper 2.")
  28.     action = tonumber(read())
  29.     until action==1 or action==2
  30.     repeat
  31.     print("Sur quel surface de terrain voulez-vous travailler ? (Minimum 5)")
  32.     surface = tonumber(read())
  33.     if surface==tonumber("") then surface=0 end
  34.     until surface>=5
  35.     turtle.turnLeft()
  36.     repeat
  37.     print("Merci de placer un coffre en face de la tortue. Il servira a completer son inventaire avec les materiaux designer ci-apres.")
  38.     print("Lorsque c'est fait, appuye sur une touche.")
  39.     read()
  40.     success,data=turtle.inspect()
  41.     sleep(0.1)
  42.     until data.name=="minecraft:chest"
  43.     turtle.turnLeft()
  44.     repeat
  45.     print("Merci de placer un coffre en face de la tortue. Il servira a recharger la tortue en combustible.")
  46.     print("Lorsque c'est fait, appuye sur une touche.")
  47.     read()
  48.     success,data=turtle.inspect()
  49.     sleep(0.1)
  50.     until data.name=="minecraft:chest"
  51.     turtle.turnLeft()
  52.     if action==2 then
  53.         repeat
  54.         print("Merci de placer un coffre en face de la tortue. Il servira a completer son inventaire avec les materiaux designer ci-apres.")
  55.         print("Lorsque c'est fait, appuye sur une touche.")
  56.         read()
  57.         success,data=turtle.inspect()
  58.         sleep(0.1)
  59.         until data.name=="minecraft:chest"
  60.     end
  61.     turtle.turnLeft()
  62.     resultat1 = 3*surface*surface-10
  63.     repeat
  64.     print("Merci de prevoir dans le coffre a GAUCHE de la tortue "..resultat1.." blocs de terre et 10 blocs dans le slot "..slotTerre..".")
  65.     print("Si necessaire, completer les inventaires et appuyer sur une touche.")
  66.     read()
  67.     until turtle.getItemCount(slotTerre)>=10
  68.     if action==2 then
  69.         resultat2 = ((surface-3)*20)+((surface-1)*4)-10
  70.         repeat
  71.         print("Merci de prevoir dans le coffre a DROITE de la tortue "..resultat2.." blocs d'obsidienne et 10 blocs dans le slot"..slotMur..".")
  72.         print("Si necessaire, completer les inventaires et appuyer sur une touche.")
  73.         read()
  74.         until turtle.getItemCount(slotMur)>=10
  75.     end
  76.     repeat
  77.     print("Merci de preparer 10 combustibles dans l'inventaire de la tortue (Slot 16). Completer egalement le coffre derriere la tortue.")
  78.     print("Lorsque c'est fait, appuye sur une touche.")
  79.     read()
  80.     until turtle.getItemCount(slotFuel)>=10
  81.    
  82.     print("Appuyez sur n'importe quels touches pour commencer le terrassement.")
  83.     read()
  84. end
  85.  
  86. function testZ1()
  87.     local success, data=turtle.inspectDown()
  88.    
  89.     stockTerre()
  90.    
  91.     if success then
  92.         if data.name=="minecraft:dirt" or data.name=="minecraft:grass" then
  93.         else
  94.             turtle.attackDown()
  95.             turtle.digDown()
  96.             turtle.down()
  97.             z=z-1
  98.             refuel()
  99.             turtle.attackDown()
  100.             turtle.digDown()
  101.             turtle.down()
  102.             z=z-1
  103.             refuel()
  104.             turtle.attackDown()
  105.             turtle.digDown()
  106.             turtle.select(slotTerre)
  107.             turtle.placeDown()
  108.             turtle.up()
  109.             z=z+1
  110.             refuel()
  111.             turtle.select(slotTerre)
  112.             turtle.placeDown()
  113.             turtle.up()
  114.             z=z+1
  115.             refuel()
  116.             turtle.select(slotTerre)
  117.             turtle.placeDown()
  118.         end
  119.     else
  120.         turtle.attackDown()
  121.         turtle.digDown()
  122.         turtle.down()
  123.         z=z-1
  124.         refuel()
  125.         turtle.attackDown()
  126.         turtle.digDown()
  127.         turtle.down()
  128.         z=z-1
  129.         refuel()
  130.         turtle.attackDown()
  131.         turtle.digDown()
  132.         turtle.select(slotTerre)
  133.         turtle.placeDown()
  134.         turtle.up()
  135.         z=z+1
  136.         refuel()
  137.         turtle.select(slotTerre)
  138.         turtle.placeDown()
  139.         turtle.up()
  140.         z=z+1
  141.         refuel()
  142.         turtle.select(slotTerre)
  143.         turtle.placeDown()
  144.     end
  145. end
  146.  
  147. function testZ4()
  148.     local testFin=false
  149.     stockMur()
  150.     if testFin==false and x==1 then
  151.         turtle.attackDown()
  152.         turtle.digDown()
  153.         turtle.select(slotMur)
  154.         turtle.placeDown()
  155.         testFin=true
  156.     end
  157.     if testFin==false and x==2 and y>1 and y<surface then
  158.         turtle.attackDown()
  159.         turtle.digDown()
  160.         turtle.select(slotMur)
  161.         turtle.placeDown()
  162.         testFin=true
  163.     end
  164.     if testFin==false and x==surface-1 and y>1 and y<surface then
  165.         turtle.attackDown()
  166.         turtle.digDown()
  167.         turtle.select(slotMur)
  168.         turtle.placeDown()
  169.         testFin=true
  170.     end
  171.     if testFin==false and x==surface then
  172.         turtle.attackDown()
  173.         turtle.digDown()
  174.         turtle.select(slotMur)
  175.         turtle.placeDown()
  176.         testFin=true
  177.     end
  178.     if testFin==false and y==1 then
  179.         turtle.attackDown()
  180.         turtle.digDown()
  181.         turtle.select(slotMur)
  182.         turtle.placeDown()
  183.         testFin=true
  184.     end
  185.     if testFin==false and y==2 and x>1 and x<surface then
  186.         turtle.attackDown()
  187.         turtle.digDown()
  188.         turtle.select(slotMur)
  189.         turtle.placeDown()
  190.         testFin=true
  191.     end
  192.     if testFin==false and y==surface-1 and x>1 and x<surface then
  193.         turtle.attackDown()
  194.         turtle.digDown()
  195.         turtle.select(slotMur)
  196.         turtle.placeDown()
  197.         testFin=true
  198.     end
  199.     if testFin==false and y==surface then
  200.         turtle.attackDown()
  201.         turtle.digDown()
  202.         turtle.select(slotMur)
  203.         turtle.placeDown()
  204.         testFin=true
  205.     end
  206. end
  207.  
  208. function ligne()
  209.     local fin = 1
  210.    
  211.     if d == 1 then
  212.         fin = surface
  213.     else
  214.         fin = 1
  215.     end
  216.    
  217.     while y ~= fin do
  218.         if z == 1 then
  219.             testZ1()
  220.         end
  221.         if z == 2 then
  222.             stockMur()
  223.             if x==2 and y>1 and y<surface then
  224.                 turtle.attackDown()
  225.                 turtle.digDown()
  226.                 turtle.down()
  227.                 z=z-1
  228.                 refuel()
  229.                 turtle.attackDown()
  230.                 turtle.digDown()
  231.                 turtle.down()
  232.                 z=z-1
  233.                 refuel()
  234.                 turtle.attackDown()
  235.                 turtle.digDown()
  236.                 turtle.select(slotMur)
  237.                 turtle.placeDown()
  238.                 turtle.up()
  239.                 z=z+1
  240.                 refuel()
  241.                 turtle.select(slotMur)
  242.                 turtle.placeDown()
  243.                 turtle.up()
  244.                 z=z+1
  245.                 refuel()
  246.                 turtle.select(slotMur)
  247.                 turtle.placeDown()
  248.             end
  249.             if x==surface-1 and y>1 and y<surface then
  250.                 turtle.attackDown()
  251.                 turtle.digDown()
  252.                 turtle.down()
  253.                 z=z-1
  254.                 refuel()
  255.                 turtle.attackDown()
  256.                 turtle.digDown()
  257.                 turtle.down()
  258.                 z=z-1
  259.                 refuel()
  260.                 turtle.attackDown()
  261.                 turtle.digDown()
  262.                 turtle.select(slotMur)
  263.                 turtle.placeDown()
  264.                 turtle.up()
  265.                 z=z+1
  266.                 refuel()
  267.                 turtle.select(slotMur)
  268.                 turtle.placeDown()
  269.                 turtle.up()
  270.                 z=z+1
  271.                 refuel()
  272.                 turtle.select(slotMur)
  273.                 turtle.placeDown()
  274.             end
  275.             if 2<x and x<surface-1 then
  276.                 if y==2 or y==surface-1 then
  277.                     turtle.attackDown()
  278.                     turtle.digDown()
  279.                     turtle.down()
  280.                     z=z-1
  281.                     refuel()
  282.                     turtle.attackDown()
  283.                     turtle.digDown()
  284.                     turtle.down()
  285.                     z=z-1
  286.                     refuel()
  287.                     turtle.attackDown()
  288.                     turtle.digDown()
  289.                     turtle.select(slotMur)
  290.                     turtle.placeDown()
  291.                     turtle.up()
  292.                     z=z+1
  293.                     refuel()
  294.                     turtle.select(slotMur)
  295.                     turtle.placeDown()
  296.                     turtle.up()
  297.                     z=z+1
  298.                     refuel()
  299.                     turtle.select(slotMur)
  300.                     turtle.placeDown()
  301.                 end
  302.             end
  303.         end
  304.         if z == 3 then
  305.             stockMur()
  306.             if x==2 and y>1 and y<surface then
  307.                 turtle.attackDown()
  308.                 turtle.digDown()
  309.                 turtle.select(slotMur)
  310.                 turtle.placeDown()
  311.             end
  312.             if x==surface-1 and y>1 and y<surface then
  313.                 turtle.attackDown()
  314.                 turtle.digDown()
  315.                 turtle.select(slotMur)
  316.                 turtle.placeDown()
  317.             end
  318.             if 2<x and x<surface-1 then
  319.                 if y==2 or y==surface-1 then
  320.                     turtle.attackDown()
  321.                     turtle.digDown()
  322.                     turtle.select(slotMur)
  323.                     turtle.placeDown()
  324.                 end
  325.             end
  326.         end
  327.         if z == 4 then
  328.             testZ4()
  329.         end
  330.         turtle.attack()
  331.         turtle.dig()
  332.         turtle.forward()
  333.         if d == 1 then
  334.             y = y+1
  335.         else
  336.             y = y-1
  337.         end
  338.         refuel()
  339.     end
  340. return true
  341. end
  342.  
  343. function changementLigne()
  344.     local dSave = d
  345.    
  346.     if z==1 then testZ1() end
  347.     if z==4 then testZ4() end
  348.    
  349.     while dSave ~= 2 do
  350.         if d==1 then
  351.             turtle.turnRight()
  352.             dSave = dSave+1
  353.         end
  354.         if d==3 then
  355.             turtle.turnLeft()
  356.             dSave = dSave-1
  357.         end
  358.         if dSave > 4 then
  359.             dSave = 1
  360.         end
  361.     end
  362.    
  363.     turtle.attack()
  364.     turtle.dig()
  365.     turtle.forward()
  366.     x = x+1
  367.     refuel()
  368.    
  369.     if d == 1 then
  370.         d = 3
  371.     else
  372.         d = 1
  373.     end
  374.    
  375.     while dSave ~= d do
  376.         if d==3 then
  377.             turtle.turnRight()
  378.             dSave = dSave+1
  379.         end
  380.         if d==1 then
  381.             turtle.turnLeft()
  382.             dSave = dSave-1
  383.         end
  384.         if dSave > 4 then
  385.             dSave = 1
  386.         end
  387.     end
  388. return true
  389. end
  390.  
  391. function deplacement(dx,dy,dz,dd)
  392.     local td=0
  393.    
  394.     while z~=h do
  395.         turtle.attackUp()
  396.         turtle.digUp()
  397.         turtle.up()
  398.         z = z+1
  399.     end
  400.     if y~=dy then
  401.         if y<dy then td=1 else td=3 end
  402.         while d~=td do
  403.             turtle.turnRight()
  404.             d = d+1
  405.             if d > 4 then
  406.                 d = 1
  407.             end
  408.         end
  409.     end
  410.     while y~=dy do
  411.         turtle.attack()
  412.         turtle.dig()
  413.         turtle.forward()
  414.         if d == 1 then
  415.             y = y+1
  416.         else
  417.             y = y-1
  418.         end
  419.     end
  420.     if x~=dx then
  421.         if x<dx then td=2 else td=4 end
  422.         while d~=td do
  423.             turtle.turnRight()
  424.             d = d+1
  425.             if d > 4 then
  426.                 d = 1
  427.             end
  428.         end
  429.     end
  430.     while x~=dx do
  431.         turtle.attack()
  432.         turtle.dig()
  433.         turtle.forward()
  434.         if d == 2 then
  435.             x = x+1
  436.         else
  437.             x = x-1
  438.         end
  439.     end
  440.     while z~=dz do
  441.         if z<dz then
  442.             turtle.attackUp()
  443.             turtle.digUp()
  444.             turtle.up()
  445.             z=z+1
  446.         end
  447.         if z>dz then
  448.             turtle.attackDown()
  449.             turtle.digDown()
  450.             turtle.down()
  451.             z=z-1
  452.         end
  453.     end
  454.     while d~=dd do
  455.         if d<dd then
  456.             turtle.turnRight()
  457.             d=d+1
  458.         end
  459.         if d>dd then
  460.             turtle.turnLeft()
  461.             d=d-1
  462.         end
  463.     end
  464. end
  465.  
  466. function stockTerre()
  467.     local xSv = x
  468.     local ySv = y
  469.     local zSv = z
  470.     local dSv = d  
  471.     local nb=1
  472.    
  473.     if turtle.getItemCount(slotTerre)<10 then
  474.         slotTerre=slotTerre+1
  475.     end
  476.     if turtle.getItemCount(7)<5 then
  477.         deplacement(1,0,1,4)
  478.         for i=1,7,1 do
  479.             turtle.select(i)
  480.             nb=turtle.getItemSpace()
  481.             turtle.suck(nb)
  482.         end
  483.         deplacement(xSv,ySv,zSv,dSv)
  484.         slotTerre=1
  485.     end
  486. end
  487.  
  488. function stockMur()
  489.     local xSv = x
  490.     local ySv = y
  491.     local zSv = z
  492.     local dSv = d  
  493.     local nb=1
  494.    
  495.     if turtle.getItemCount(slotMur)<10 then
  496.         slotMur=slotMur+1
  497.     end
  498.     if turtle.getItemCount(14)<5 then
  499.         deplacement(1,0,1,2)
  500.         for i=9,14,1 do
  501.             turtle.select(i)
  502.             nb=turtle.getItemSpace()
  503.             turtle.suck(nb)
  504.         end
  505.         deplacement(xSv,ySv,zSv,dSv)
  506.         slotMur=9
  507.     end
  508. end
  509.  
  510. function definitionSlot()
  511.     for i=2,8,1 do
  512.         turtle.select(slotTerre)
  513.         turtle.transferTo(i,1)
  514.     end
  515.     for i=10,15,1 do
  516.         turtle.select(slotMur)
  517.         turtle.transferTo(i,1)
  518.     end
  519. end
  520.  
  521. function refuel()
  522.     while turtle.getFuelLevel() < niveauFuelMini do
  523.         turtle.select(slotFuel)
  524.         turtle.refuel(1)
  525.         if turtle.getItemCount(slotFuel) < niveauStockFuelMini then
  526.             return rechargeFuel()
  527.         end
  528.     end
  529. end
  530.  
  531. function rechargeFuel()
  532.     local xSv = x
  533.     local ySv = y
  534.     local zSv = z
  535.     local dSv = d  
  536.     local nb=1
  537.    
  538.     deplacement(1,0,1,3)
  539.    
  540.     turtle.select(slotFuel)
  541.     nb=64-turtle.getItemCount()
  542.     turtle.suck(nb)
  543.    
  544.     deplacement(xSv,ySv,zSv,dSv)
  545.    
  546.     return true
  547. end
  548.  
  549. function videInventaire()
  550.     local xSv = x
  551.     local ySv = y
  552.     local zSv = z
  553.     local dSv = d  
  554.  
  555.     deplacement(1,0,1,4)
  556.     for i=1,8 do
  557.         turtle.select(i)
  558.         while turtle.getItemCount(i) > 0 do
  559.             turtle.drop(turtle.getItemCount(i))
  560.             sleep(0.2)
  561.         end
  562.     end
  563.     turtle.turnLeft()
  564.     turtle.select(slotFuel)
  565.     while turtle.getItemCount(slotFuel) > 0 do
  566.         turtle.drop(turtle.getItemCount(slotFuel))
  567.         sleep(0.2)
  568.     end
  569.     turtle.turnLeft()
  570.     for i=9,15 do
  571.         turtle.select(i)
  572.         while turtle.getItemCount(i) > 0 do
  573.             turtle.drop(turtle.getItemCount(i))
  574.             sleep(0.2)
  575.         end
  576.     end
  577.     turtle.turnLeft()
  578. end
  579.  
  580. --********************************************--
  581. --********** Programme principal *************--
  582. --********************************************--
  583. local f=0
  584.  
  585. inventaire()
  586.  
  587. print("Terrassement en cours...")
  588.  
  589. definitionSlot()
  590. if action == 1 then
  591.         f = 2
  592.         stockTerre()
  593. else
  594.         f = 5
  595.         stockTerre()
  596.         stockMur()
  597. end
  598.  
  599. refuel()
  600. turtle.forward()
  601. y=y+1
  602.    
  603. while z~=f do
  604.     while x~=surface+1 do
  605.         ligne()
  606.         changementLigne()
  607.     end
  608.     deplacement(1,1,z,1)
  609.     turtle.attackUp()
  610.     turtle.digUp()
  611.     turtle.up()
  612.     z=z+1
  613.     refuel()
  614. end
  615.  
  616. videInventaire()
  617.  
  618. print("Terrassement terminer!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement