Advertisement
theTANCO

Raiu API v1.2

Dec 9th, 2019 (edited)
789
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.60 KB | None | 0 0
  1. --v1.2
  2. -- If my vein miner program doesn't exist, it will be automatically downloaded.
  3. if not fs.exists("VeinMiner.lua") then
  4.     shell.run("pastebin","get","0C6LyNES","VeinMiner.lua")
  5. end
  6. require("VeinMiner")
  7.  
  8. function refuel()
  9.     -- Tries to refuel if fuel level is low.
  10.     while turtle.getFuelLevel() == 0 do
  11.         for a = 1, 16 do
  12.             turtle.select(a)
  13.             turtle.refuel(1)
  14.         end
  15.     end
  16. end
  17.  
  18. move = {
  19.     forward = function(x)
  20.         -- Tries to travel forward. May be blocked by entities.
  21.         -- Input x for distance to travel, or nothing to travel 1 only one block.
  22.         if not x then x = 1 end
  23.         for a = 1, x do
  24.             repeat
  25.                 refuel()
  26.                 turtle.dig()
  27.             until turtle.forward()
  28.         end
  29.     end,
  30.  
  31.     back = function(x)
  32.         -- Tries to travel backward. May be blocked by entities or blocks.
  33.         -- Input x for distance to travel, or nothing to travel 1 only one block.
  34.         if not x then x = 1 end
  35.         for a = 1, x do
  36.             repeat
  37.                 refuel()
  38.             until turtle.back()
  39.         end
  40.     end,
  41.  
  42.     up = function(x)
  43.         -- Tries to travel upward. May be blocked by entities.
  44.         -- Input x for distance to travel, or nothing to travel 1 only one block.
  45.         if not x then x = 1 end
  46.         for a = 1, x do
  47.             repeat
  48.                 refuel()
  49.                 turtle.digUp()
  50.             until turtle.up()
  51.         end
  52.     end,
  53.  
  54.     down = function(x)
  55.         -- Tries to travel downward. May be blocked by entities.
  56.         -- Input x for distance to travel, or nothing to travel 1 only one block.
  57.         if not x then x = 1 end
  58.         for a = 1, x do
  59.             repeat
  60.                 refuel()
  61.                 turtle.digDown()
  62.             until turtle.down()
  63.         end
  64.     end,
  65.  
  66.     left = function(x)
  67.         -- Turns left.
  68.         -- Input x for how many times to turn, or nothing to turn once.
  69.         if not x then x = 1 end
  70.         for a = 1, x do
  71.             turtle.turnLeft()
  72.         end
  73.     end,
  74.  
  75.     right = function(x)
  76.         -- Turns right.
  77.         -- Input x for how many times to turn, or nothing to turn once.
  78.         if not x then x = 1 end
  79.         for a = 1, x do
  80.             turtle.turnRight()
  81.         end
  82.     end
  83. }
  84.  
  85. function hallway(y, x, veinMiner)
  86.     -- Creates a 2 or 3 block tall hallway by digging one block above, below, and in front.
  87.     -- Input x for distance to travel, or nothing to travel 1 only one block.
  88.     -- Input y for hallway height. -1 = dig below. 1 = dig above. 0 = dig above and below.
  89.     if not x then x = 1 end
  90.     for a = 1, x do
  91.         move.forward()
  92.         if veinMiner then
  93.             shell.run("VeinMiner.lua")
  94.         end
  95.         if y >= 0 then
  96.             turtle.digUp()
  97.         end
  98.         if y <= 0 then
  99.             turtle.digDown()
  100.         end
  101.     end
  102. end
  103.  
  104. function place(dir, block, damage, sign)
  105.     -- Searches for specified item in inventory and tries to place it in the world.
  106.     -- Input dir for which direction to place the block.
  107.     -- Input block for the item ID. Input damage for the item variant (i.e.: 0 = Stone, 1 = Granite, etc.).
  108.     -- Input sign for the text to display on a sign. Leave blank for no text.
  109.     local placeBlock = 0
  110.  
  111.     if not sign then sign = "" end
  112.     repeat
  113.         for a = 1, 16 do
  114.             local item = turtle.getItemDetail(a)
  115.             if item and item.name == block and item.damage == damage then
  116.                 placeBlock = a
  117.             end
  118.         end
  119.     until placeBlock > 0
  120.     turtle.select(placeBlock)
  121.     if dir == "forward" then
  122.         turtle.dig()
  123.         turtle.place(sign)
  124.     elseif dir == "up" then
  125.         turtle.digUp()
  126.         turtle.placeUp(sign)
  127.     elseif dir == "down" then
  128.         turtle.digDown()
  129.         turtle.placeDown(sign)
  130.     end
  131. end
  132.  
  133. -- 6/20/2022 - v1.2
  134. -- All movement functions are now parts of one object. i.e., use move.forward to run the forward function().
  135. -- VeinMiner.lua is now loaded with require().
  136.  
  137. -- 8/31/2021 - v1.1
  138. -- Fixed refuel function not checking fuel level correctly.
  139. -- Added code to automatically download my Vein Miner program found at: https://pastebin.com/0C6LyNES
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement