Advertisement
Aranyalma2

advancedTunnel v.honnantudjam

Jun 10th, 2020
1,055
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 8.65 KB | None | 0 0
  1. magas = 10
  2. szeles = 100
  3. hosszu = 300
  4.  
  5. jobbOldal = true
  6. fent = false
  7.  
  8. tCoordx_int = 0
  9. tCoordy_int = 0
  10. tCoordz_int = 0
  11.  
  12. chestX = 0
  13. chestY = 0
  14. chestZ = 0
  15.  
  16. fChest = false
  17. fChestX = 0
  18. fChestY = 0
  19. fChestZ = 0
  20.  
  21. lavaRefuel_bln = true
  22. coalRefuel_bln = false
  23. doDumping_bln = true
  24.  
  25. orientation_int = 1 --north 1, east 2, south3, west 4
  26.  
  27. ------------------------------------------------------
  28.  
  29.  --function definialas
  30.  
  31. orientations = {"north","east","south","west"}
  32.  
  33. zDiff = {-1,0,1,0}
  34. xDiff = {0,1,0,-1}
  35.  
  36. -------------------------------------------
  37.  
  38. function dumping_fcn()
  39.     workX = tCoordx_int
  40.     workY = tCoordy_int
  41.     workZ = tCoordz_int
  42.     workLook = orientation_int
  43.    
  44.     goTo_fcn(chestX, chestY, chestZ)
  45.     for i = 1,numberOfUseableSlots do
  46.         turtle.select(i)
  47.         turtle.dropDown()
  48.     end
  49.     goTo_fcn(workX, workY, workZ)
  50.     look_fcn(1)
  51. end
  52.  
  53. function checkInventory_fcn()
  54.     j = 1
  55.     IsThereEmptySlot_bln = false
  56.    
  57.     while j <= numberOfUseableSlots and not(IsThereEmptySlot_bln) do
  58.         if turtle.getItemCount(j) == 0 then
  59.             IsThereEmptySlot_bln = true
  60.         end
  61.         if j == numberOfUseableSlots and IsThereEmptySlot_bln == false and coalRefuel_bln then
  62.             for j1 = 1,numberOfUseableSlots do
  63.                 turtle.select(j1)
  64.                 if turtle.refuel(turtle.getItemCount(j1)) then
  65.                     IsThereEmptySlot_bln = true
  66.                     print("fl+:"..turtle.getFuelLevel())
  67.                     print("wl:"..workLevel.."%")
  68.                 end
  69.             end
  70.         end
  71.         j = j + 1
  72.     end
  73.    
  74.     if false == IsThereEmptySlot_bln then
  75.         dumping_fcn()
  76.     end
  77. end
  78.  
  79. function checkFuel()
  80.     if fChest then
  81.         fworkX = tCoordx_int
  82.         fworkY = tCoordy_int
  83.         fworkZ = tCoordz_int
  84.         fworkLook = orientation_int
  85.        
  86.         pillUt = math.abs(tCoordx_int - chestX) + math.abs(tCoordy_int - chestY) + math.abs(tCoordz_int - chestZ) + math.abs(chestX - fChestX) + math.abs(chestY - fChestY) + math.abs(chestZ - fChestZ) + 2
  87.         if turtle.getFuelLevel() < pillUt then
  88.             goTo_fcn(chestX, chestY, chestZ)
  89.             dumping_fcn()
  90.             goTo_fcn(fChestX, fChestY, fChestZ)
  91.            
  92.             doneBefore = false
  93.             chestEmpty = false
  94.            
  95.             while turtle.getFuelLevel() < pillUt + 10000 or chestEmpty == false do
  96.                 for i = 1,numberOfUseableSlots do
  97.                     turtle.select(i)
  98.                     if turtle.suckDown() then
  99.                         turtle.refuel(turtle.getItemCount(i))
  100.                     else
  101.                         chestEmpty = true
  102.                     end
  103.                 end
  104.                
  105.                 print("fl: "..turtle.getFuelLevel())
  106.                
  107.                 if chestEmpty then
  108.                     doneBefore = true
  109.                 end
  110.                
  111.                 for i = 1,numberOfUseableSlots do
  112.                     if turtle.getItemCount(i) ~= 0 then
  113.                         dumping_fcn()
  114.                         break
  115.                     end
  116.                 end
  117.                
  118.                 if doneBefore and chestEmpty then
  119.                     print("uzemanyagra varok")
  120.                     os.sleep(60)
  121.                     chestEmpty = false
  122.                 end
  123.             end
  124.            
  125.             print("ujra toltve")
  126.             print("wl: "..workLevel)
  127.             goTo_fcn(fworkX, fworkY, fworkZ)
  128.             look_fcn(fworkLook)
  129.         end
  130.     end
  131. end
  132. ---------------------------
  133. function dig_fcn()
  134.     if lavaRefuel_bln then
  135.         if false == turtle.dig() then
  136.             turtle.select(16)
  137.             if turtle.place() then
  138.                 if turtle.refuel() == false then
  139.                     turtle.place()
  140.                 else
  141.                     print("fl+:"..turtle.getFuelLevel())
  142.                     print("wl:"..workLevel.."%")
  143.                 end
  144.             end
  145.             turtle.select(1)
  146.         end
  147.     else
  148.         turtle.dig()
  149.     end
  150.     if doDumping_bln then
  151.         checkInventory_fcn()
  152.     end
  153. end
  154.  
  155. function digUp_fcn()
  156.     turtle.digUp()
  157.     checkInventory_fcn()
  158. end
  159.  
  160. function digDown_fcn()
  161.     turtle.digDown()
  162.     checkInventory_fcn()
  163. end
  164. ---------------------------
  165.  
  166. function moveForward_fcn()
  167.     moveF_bln = false
  168.     while not(moveF_bln) do
  169.         turtle.dig()
  170.         turtle.attack()
  171.         moveF_bln = turtle.forward()
  172.     end
  173.    
  174.     tCoordx_int = tCoordx_int + xDiff[orientation_int]
  175.     tCoordz_int = tCoordz_int + zDiff[orientation_int]
  176. end
  177.  
  178. function moveDown_fcn()
  179.     moveD_bln = false
  180.     while not(moveD_bln) do
  181.         turtle.digDown()
  182.         turtle.attackDown()
  183.         moveD_bln = turtle.down()
  184.     end
  185.    
  186.     tCoordy_int = tCoordy_int - 1
  187. end
  188.  
  189. function moveUp_fcn()
  190.     moveU_bln = false
  191.     while not(moveU_bln) do
  192.         turtle.digUp()
  193.         turtle.attackUp()
  194.         moveU_bln = turtle.up()
  195.     end
  196.    
  197.     tCoordy_int = tCoordy_int + 1
  198. end
  199.  
  200. -------------------------------------
  201.  
  202. function turnRight_fcn()
  203.     orientation_int = orientation_int - 1
  204.     orientation_int = (orientation_int + 1) % 4
  205.     orientation_int = orientation_int + 1
  206.    
  207.     turtle.turnRight()
  208. end
  209.  
  210. function turnLeft_fcn()
  211.     orientation_int = orientation_int - 1
  212.     orientation_int = (orientation_int - 1) % 4
  213.     orientation_int = orientation_int + 1
  214.    
  215.     turtle.turnLeft()
  216. end
  217.    
  218.  
  219. function look_fcn( direction )
  220.     if direction > orientation_int then
  221.         if direction == 4 and orientation_int == 1 then
  222.             turnLeft_fcn()
  223.         else
  224.             while direction > orientation_int do
  225.                 turnRight_fcn()
  226.             end
  227.         end
  228.     elseif direction < orientation_int then
  229.         if direction == 1 and orientation_int == 4 then
  230.             turnRight_fcn()
  231.         else
  232.             while direction < orientation_int do
  233.                 turnLeft_fcn()
  234.             end
  235.         end
  236.     end
  237. end
  238.  
  239. function goTo_fcn( xTarget, yTarget, zTarget )
  240.    
  241.     if xTarget > tCoordx_int then
  242.         look_fcn( 2 )
  243.         while xTarget > tCoordx_int do
  244.             moveForward_fcn()
  245.         end
  246.     elseif xTarget < tCoordx_int then
  247.         look_fcn( 4 )
  248.         while xTarget < tCoordx_int do
  249.             moveForward_fcn()
  250.         end
  251.     end
  252.    
  253.     if zTarget > tCoordz_int then
  254.         look_fcn( 3 )
  255.         while zTarget > tCoordz_int do
  256.             moveForward_fcn()
  257.         end
  258.     elseif zTarget < tCoordz_int then
  259.         look_fcn( 1 )
  260.         while zTarget < tCoordz_int do
  261.             moveForward_fcn()
  262.         end
  263.     end
  264.    
  265.     if yTarget > tCoordy_int then
  266.         while yTarget > tCoordy_int do
  267.             moveUp_fcn()
  268.         end
  269.     elseif yTarget < tCoordy_int then
  270.         while yTarget < tCoordy_int do
  271.             moveDown_fcn()
  272.         end
  273.     end
  274.    
  275. end
  276.  
  277. function felas_fcn ()
  278.     for i = 1,magas do
  279.         dig_fcn()
  280.         if not(i==magas) then
  281.             checkFuel()
  282.             moveUp_fcn()
  283.         end
  284.     end
  285.     fent = true
  286. end
  287.  
  288. function leas_fcn()
  289.     for i1 = 1,magas do
  290.         dig_fcn()
  291.         if not(i1==magas) then
  292.             checkFuel()
  293.             moveDown_fcn()
  294.         end
  295.     end
  296.     fent = false
  297. end
  298.  
  299. function left_fcn()
  300.     turnLeft_fcn()
  301.     checkFuel()
  302.     moveForward_fcn()
  303.     turnRight_fcn()
  304. end
  305.  
  306. function right_fcn()
  307.     turnRight_fcn()
  308.     checkFuel()
  309.     moveForward_fcn()
  310.     turnLeft_fcn()
  311. end
  312.  
  313. function ellenorzes_fcn() --ellenorzi hogy minden meg van e a feladathoz
  314.     eredmeny = true
  315.     fuel = turtle.getFuelLevel()
  316.     ut = magas*szeles*hosszu
  317.    
  318.     print("uzemanyag szint: "..fuel)
  319.    
  320.     if doDumping_bln then
  321.         print("nem tudom mennyi uzemanyag kell o.0")
  322.        
  323.         if lavaRefuel_bln or coalRefuel_bln then
  324.             print("nem tudom mennyi uzemanyag marad o.0")
  325.             eredmeny = true
  326.         else
  327.             print("min. kell: "..ut)
  328.             if ut > fuel then
  329.                 eredmeny = false
  330.                 print("tul keves az uzemanyag")
  331.             end
  332.         end
  333.     else
  334.         print("ennyi uzemanyag kell: "..ut)
  335.        
  336.         if lavaRefuel_bln or coalRefuel_bln then
  337.             print("nem tudom mennyi uzemanyag marad o.0")
  338.             eredmeny = true
  339.         else
  340.             if ut > fuel then
  341.                 eredmeny = false
  342.                 print("tul keves az uzemanyag")
  343.             else
  344.                 eredmeny = true
  345.                 print("ennyi uzemanyag marad: "..fuel-ut)
  346.             end
  347.         end
  348.     end
  349.    
  350.     if fChest then
  351.         if not( fChestX == chestX and fChestY == chestY and fChestZ == chestZ) then
  352.             eredmeny = true
  353.             print("van fChest ujra tudok tolteni!")
  354.         else
  355.             eredmeny = false
  356.             print("a ket chest koordinataja nem lehet ugyan az!")
  357.         end
  358.     end
  359.    
  360.     if lavaRefuel_bln then
  361.         turtle.select(16)
  362.        
  363.         data = turtle.getItemDetail()
  364.        
  365.         if turtle.getItemCount() == 1 then
  366.             if data.name == "minecraft:bucket" then
  367.                 eredmeny = true
  368.             else
  369.                 eredmeny = false
  370.                 print("az utolso (16.) slot-ba kell EGY vodor!")
  371.             end
  372.         else
  373.             eredmeny = false
  374.             print("az utolso (16.) slot-ba kell EGY vodor!")
  375.         end
  376.     end
  377.    
  378.     --wl worklevel es fl fuel level
  379.     return eredmeny
  380. end
  381.  
  382. function jobbLayer_fcn()
  383.     for i2=1,szeles do
  384.         if fent then
  385.             leas_fcn()
  386.         else
  387.             felas_fcn()
  388.         end
  389.         if not(i2==szeles) then
  390.             left_fcn()
  391.         end
  392.     end
  393.     jobbOldal = false
  394. end
  395.  
  396. function balLayer_fcn()
  397.     for i3=1,szeles do
  398.         if fent then
  399.             leas_fcn()
  400.         else
  401.             felas_fcn()
  402.         end
  403.         if not(i3==szeles) then
  404.             right_fcn()
  405.         end
  406.     end
  407.     jobbOldal = true
  408. end
  409.  
  410.  --main
  411. workLevel = 0
  412.  if lavaRefuel_bln then
  413.         numberOfUseableSlots = 15
  414.     else
  415.         numberOfUseableSlots = 16
  416. end
  417.  
  418.  if ellenorzes_fcn() then
  419.     for i2 = 1,hosszu do
  420.         if jobbOldal then
  421.             jobbLayer_fcn()
  422.         else
  423.             balLayer_fcn()
  424.         end
  425.         checkFuel()
  426.         moveForward_fcn()
  427.         print("fl:"..turtle.getFuelLevel())
  428.         workLevel = i2/(hosszu*0.01)
  429.         print("wl:"..workLevel.."%")
  430.     end
  431.     goTo_fcn(chestX, chestY, chestZ)
  432.     dumping_fcn()
  433. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement