Advertisement
EditorRUS

Беспощадный код Эдитора

Apr 11th, 2013
386
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.16 KB | None | 0 0
  1. function Torch(param)
  2.             if math.fmod(param, 7) == 0 then
  3.                 if turtle.getItemCount(UsedSlot) > 0 then
  4.                     if UsedSlot <= TorchSlots then
  5.                         turtle.placeUp()
  6.                     end
  7.                 else
  8.                     UsedSlot = UsedSlot + 1
  9.                     if UsedSlot <= TorchSlots then
  10.                         turtle.select(UsedSlot)
  11.                         turtle.placeUp()
  12.                     else
  13.                         print("Reached max slot, no more lighting")
  14.                     end
  15.                 end
  16.             end
  17. end
  18.  
  19. tArgs = { ... }
  20. if #tArgs ~= 4 then
  21.     local tHelp
  22.     tHelp = "Usage: shaft [length of shaft] [length of nodes] [distance of 1 and 2 nodes] [slots for torchs] \nThis program will dig up shaft. Every node in that shaft that's twice splitting, which length defines in arguments \nWell, when it digged up it, it return to the centre, where node are started, and dig so much so you define in third argument \nProgram almost automaticly, but it require some special conditions \nFirst - turtle don't collect a ore, you should dig or gather it yourself \nSecond - slots for torchs means that number, which show how much stacks of torches have your turtle. You must fill turtle with torch from first slot, and futher. Very good if every slot would contain 64 torchs \nTurtle should put up a torchs every 7 blocks because torch have seven level of lighting \nLast slot MUST be contain some gravel otherwise when turtle meets gravel, than it wouldn't works normally \nby EditorRUS"
  23.     textutils.pagedPrint(tHelp)
  24.     return 0
  25. end
  26.  
  27. ShaftLength = math.abs(tonumber(tArgs[1]))
  28. NodeLength = math.abs(tonumber(tArgs[2]))
  29. Distance = math.abs(tonumber(tArgs[3]))
  30. TorchSlots = math.abs(tonumber(tArgs[4]))
  31. UsedSlot = 1
  32. if TorchSlots > 15 then
  33.     print("Too much slots for torchs")
  34.     return 0
  35. end
  36.  
  37. NeededTorchs = (NodeLength / 7 * 2) + (Distance * ShaftLength / 7)
  38. NeededFuel = (NodeLength * 2 + Distance) * ShaftLength
  39.  
  40. if NeededFuel > turtle.getFuelLevel() then
  41.     print("Not enough fuel, now value is ", tostring(turtle.getFuelLevel()), ", needed more or equal " , tostring(NeededFuel))
  42.     return 0
  43. end
  44.  
  45. local RNofTorches = 0
  46. for i=1, TorchSlots do
  47.     RNofTorches = RNofTorches + turtle.getItemCount(i)
  48. end
  49.  
  50. if RNofTorches < NeededTorchs then
  51.     print("That count of torch not enough for fully lighting a shaft.")
  52.     local answer = "n"
  53.     while 1 do
  54.         print("Do you want continue? Y/N")
  55.         answer = read()
  56.         if answer == "N" then return 0 end
  57.         if answer == "Y" then break end
  58.     end
  59. end
  60.  
  61. for i = 1, ShaftLength do
  62.     for j = 1, 2 do
  63.         if j == 1 then
  64.             turtle.turnLeft()
  65.         else
  66.             turtle.turnRight()
  67.         end
  68.         for k=1, NodeLength do
  69.             local old = UsedSlot
  70.             turtle.select(16)
  71.             while turtle.compare() do
  72.                 turtle.dig()
  73.             end
  74.             if turtle.detect() then
  75.                 turtle.dig()
  76.             end
  77.             turtle.forward()
  78.             if turtle.detectUp() then
  79.                 turtle.digUp()
  80.             end
  81.             turtle.select(old)
  82.             Torch(k)
  83.             if k == NodeLength then
  84.                 turtle.turnRight()
  85.                 turtle.turnRight()
  86.                 for a=1, NodeLength do
  87.                     turtle.forward()
  88.                 end
  89.                 if j == 1 then
  90.                     turtle.turnLeft()
  91.                 else
  92.                     turtle.turnRight()
  93.                 end    
  94.             end
  95.         end
  96.     end
  97.    
  98.     for a=1, Distance do
  99.         if turtle.detect() then
  100.             turtle.dig()
  101.         end
  102.         turtle.forward()
  103.         if turtle.detectUp() then
  104.             turtle.digUp()
  105.         end
  106.         Torch(a)
  107.     end
  108. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement