Advertisement
vacnoa

NearEDGE-Functions

Mar 6th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.29 KB | None | 0 0
  1. KnownFallingBlocks =
  2. {
  3.     "minecraft:sand",
  4.     "minecraft:gravel",
  5.     "minecraft:anvil",
  6.     "minecraft:dragon_egg",
  7.     "Natura:heatsand"
  8. }
  9.  
  10. KnownFuelAmounts =
  11. {
  12.     {"Sticks", 5},
  13.     {"Wood Blocks", 15},
  14.     {"Coal", 80},
  15.     {"Blaze Rods", 120},
  16.     {"Lava Buckets", 1000}
  17. }
  18.  
  19. __HaltOnInterruption = true
  20. __DigWhenUnableToMove = true
  21.  
  22.  
  23. function GetRecommendedFuel(cost)
  24.  
  25.     local Fuels = {}
  26.     local MostEff = 1
  27.  
  28.     for i=1,#KnownFuelAmounts do
  29.         local num = math.ceil(cost/(KnownFuelAmounts[i][2]))
  30.         local waste = KnownFuelAmounts[i][2] - (cost%(KnownFuelAmounts[i][2]))
  31.  
  32.         Fuels[i] = {num, waste}
  33.     end
  34.  
  35.     for i=1,#Fuels do
  36.         if(i ~= MostEff) then
  37.  
  38.             if(Fuels[i][1] < Fuels[MostEff][1] and Fuels[i][2] <= (KnownFuelAmounts[i][2]*0.4)) then
  39.                 MostEff = i
  40.             end
  41.         end
  42.     end
  43.  
  44.     return {KnownFuelAmounts[MostEff][1], Fuels[MostEff][1]}
  45. end
  46.  
  47.  
  48. function ConsumeFuel()
  49.  
  50.     DidFuel = false
  51.     for i=1,16 do
  52.         turtle.select(i)
  53.  
  54.         if turtle.refuel(0) then
  55.             turtle.refuel(turtle.getItemCount(i))
  56.             DidFuel = true
  57.         end
  58.     end
  59.  
  60.     return DidFuel
  61. end
  62.  
  63.  
  64.  
  65. function cls()
  66.     term.setBackgroundColor(colours.black)  -- Set the background colour to black.
  67.     term.clear()                            -- Paint the entire display with the current background colour.
  68.     term.setCursorPos(1,1)                  -- Move the cursor to the top left position.
  69. end
  70.  
  71. function BooleanQuery(str)
  72.  
  73.     print(str .. "\n  (Y for Yes, any other for No)\n")
  74.     sinput = io.read()
  75.     sinput = sinput:lower()
  76.  
  77.     output = false
  78.  
  79.     if(sinput:find("y")) then
  80.         output = true
  81.     end
  82.     print("\n")
  83.  
  84.     return output
  85. end
  86.  
  87.  
  88. function ReadNum(str) -- str - String to show user on request.
  89.  
  90.     local fin = false
  91.  
  92.     print(str.."\n\n")
  93.     local tmp = io.read()
  94.     fin = tonumber(tmp)
  95.  
  96.     while not fin do
  97.         print("Error: Input must be a number!")
  98.         sleep(3)
  99.         cls()
  100.         print(str .. "\n\n")
  101.         tmp = io.read()
  102.         fin = tonumber(tmp)
  103.     end
  104.     print("\n")
  105.  
  106.     return tmp
  107. end
  108.  
  109. function BlockCanFall() -- Check if the block in front of the Turtle can fall
  110.  
  111.     local IsBlock, BlockData =  turtle.inspect()
  112.  
  113.     local IsFallingBlock = false
  114.  
  115.     if IsBlock then
  116.         for i=1, #KnownFallingBlocks do
  117.             if(KnownFallingBlocks[i] == BlockData.name) then
  118.                 IsFallingBlock = true
  119.                 break
  120.             end
  121.         end
  122.     end
  123.  
  124.     return IsFallingBlock
  125. end
  126.  
  127.  
  128. function BlockAhead()
  129.     return turtle.detect()
  130. end
  131.  
  132. function BlockAbove()
  133.     return turtle.detectUp()
  134. end
  135.  
  136. function BlockBelow()
  137.     return turtle.detectDown()
  138. end
  139.  
  140.  
  141.  
  142.  
  143. function Dig()
  144.  
  145.     while (BlockAhead()) do
  146.         turtle.dig()
  147.         sleep(1)
  148.     end
  149. end
  150.  
  151. function DigUp()
  152.  
  153.     while (BlockAbove()) do
  154.         turtle.digUp()
  155.         sleep(1)
  156.     end
  157. end
  158.  
  159.  
  160. function DigDown()
  161.  
  162.     while (BlockBelow()) do
  163.         turtle.digDown()
  164.         sleep(1)
  165.     end
  166. end
  167.  
  168.  
  169.  
  170.  
  171.  
  172. function MoveForward()
  173.     local DidMove = turtle.forward()
  174.     local attempts = 0
  175.  
  176.     while (not DidMove) do
  177.         if (attempts == 5) then
  178.             if(__HaltOnInterruption) then
  179.                 break
  180.             end
  181.             if (__DigWhenUnableToMove) then
  182.                 Dig()
  183.             end
  184.         end
  185.  
  186.         attempts = attempts + 1
  187.         DidMove = turtle.forward()
  188.  
  189.     end
  190.  
  191.     return DidMove
  192. end
  193.  
  194. function MoveUp()
  195.     local DidMove = turtle.up()
  196.     local attempts = 0
  197.  
  198.     while (not DidMove) do
  199.         if (attempts == 5) then
  200.             if(__HaltOnInterruption) then
  201.                 break
  202.             end
  203.             if (__DigWhenUnableToMove) then
  204.                 DigUp()
  205.             end
  206.         end
  207.  
  208.         attempts = attempts + 1
  209.         DidMove = turtle.up()
  210.  
  211.     end
  212.  
  213.     return DidMove
  214. end
  215.  
  216. function MoveDown()
  217.     local DidMove = turtle.down()
  218.     local attempts = 0
  219.  
  220.     while (not DidMove) do
  221.         if (attempts == 5) then
  222.             if(__HaltOnInterruption) then
  223.                 break
  224.             end
  225.             if (__DigWhenUnableToMove) then
  226.                 DigDown()
  227.             end
  228.         end
  229.  
  230.         attempts = attempts + 1
  231.         DidMove = turtle.down()
  232.  
  233.     end
  234.  
  235.     return DidMove
  236. end
  237.  
  238.  
  239. function DigMove()
  240.  
  241.     Dig()
  242.  
  243.     local CouldMove = MoveForward()
  244.  
  245.     if(not CouldMove) then
  246.         if(BlockAhead()) then
  247.             Dig()
  248.             CouldMove = MoveForward()
  249.         end
  250.     end
  251.  
  252.     return CouldMove
  253. end
  254.  
  255.  
  256. function DigMoveUp()
  257.  
  258.     DigUp()
  259.  
  260.     local CouldMove = MoveUp()
  261.  
  262.     if(not CouldMove) then
  263.         if(BlockAbove()) then
  264.             DigUp()
  265.             CouldMove = MoveUp()
  266.         end
  267.     end
  268.  
  269.     return CouldMove
  270. end
  271.  
  272.  
  273. function DigMoveDown()
  274.  
  275.     DigDown()
  276.  
  277.     local CouldMove = MoveDown()
  278.  
  279.     if(not CouldMove) then
  280.         if(BlockBelow()) then
  281.             DigDown()
  282.             CouldMove = MoveDown()
  283.         end
  284.     end
  285.  
  286.     return CouldMove
  287. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement