daily pastebin goal
64%
SHARE
TWEET

Sandai's NeoMiner 0.1

a guest Mar 23rd, 2019 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ---------------------------------------
  2. -- Sandai's NeoMiner                 --
  3. -- "It's not a bug, it's a feature!" --
  4. ---------------------------------------
  5.  
  6.  
  7. local program_version = "0.1"
  8. local min_torch_distance = 6
  9.  
  10. local whitelisted_items_fuel = {
  11.     -- Fuel items
  12.     "minecraft:coal",
  13.     "minecraft:blaze_rod",
  14.     "minecraft:lava_bucket",
  15. }
  16.  
  17. local whitelisted_items_misc = {
  18.     -- misc items
  19.     "minecraft:torch",
  20.     "minecraft:chest"
  21. }
  22.  
  23.  
  24. function is_fuel_item_whitelisted(item_id) -- returns true if the item given is in the whitelisted list
  25.     for current_item in whitelisted_items_fuel do
  26.         if item_id == current_item then
  27.             return true
  28.        
  29.         else
  30.             return false
  31.         end
  32.     end
  33. end
  34.  
  35.  
  36. function is_misc_item_whitelisted(item_id) -- returns true if the item given is in the whitelisted list
  37.     for current_item in whitelisted_items_misc do
  38.         if item_id == current_item then
  39.             return true
  40.        
  41.         else
  42.             return false
  43.         end
  44.     end
  45. end
  46.  
  47.  
  48. function refuel_turtle()
  49.     for i = 1, 16 do -- For slot 1 to 16...
  50.         turtle.select(i) -- Select slot
  51.  
  52.         if turtle.getItemCount() > 0 then -- if there is an item there...
  53.  
  54.                 if is_item_whitelisted(turtle.getItemDetail(i).name) == true then -- If the item is whitelisted...
  55.                     turtle.refuel()
  56.                     print("[INFO]: The turtle has been refueled!")
  57.            
  58.                     break
  59.                 end
  60.  
  61.         elseif i == 16 then
  62.                 print("[WARN]: No fuel found !")
  63.                 break
  64.         end
  65.     end
  66. end
  67.  
  68.  
  69.  
  70. function break_3x3()
  71.     -- breaks a 3x3 area of blocks in front of it,
  72.     -- We're assuming that the turtle is in the middle-ground block
  73.  
  74.     turtle.dig()
  75.     turtle.forward()
  76.  
  77.     for i=1,3 do -- Each iteration is 1x3 blocks
  78.    
  79.         turtle.turnLeft()
  80.         turtle.dig()
  81.  
  82.         turtle.turnRight()
  83.         turtle.turnRight()
  84.         turtle.dig()
  85.  
  86.         turtle.turnLeft()
  87.         turtle.up()
  88.    
  89.     end
  90.  
  91.     turtle.down()
  92.     turtle.down() -- The turtle is now on the ground. (middle-ground block)
  93.  
  94. end
  95.  
  96. function check_if_turtle_full()
  97.     -- Scans the inventory, if it's full, then it will place a chest
  98.     -- Then dump all of it's items in it
  99.  
  100.     if turtle.getItemCount(15) > 0 then -- If the slot 15 has an item, then...
  101.         -- We scan the inventory for chests
  102.         for i=1,16 do
  103.  
  104.             if turtle.getItemDetail(i).name == "minecraft:chest" then -- If a chest was detected...
  105.                 turtle.turnLeft()
  106.                 turtle.turnLeft()
  107.                 turtle.forward()
  108.                 turtle.turnRight()
  109.                 turtle.turnRight()
  110.  
  111.                 turtle.up()
  112.                 turtle.select(i)
  113.                 turtle.placeDown() -- Place the chest down
  114.  
  115.                 for item=1,16 do -- Drop all items without whitelisted ones
  116.                     turtle.select(item)
  117.  
  118.                     if is_fuel_item_whitelisted(turtle.getItemDetail(item).name) == true then
  119.                         -- If the current item is whitelisted, do nothing
  120.                    
  121.  
  122.                     elseif is_misc_item_whitelisted(turtle.getItemDetail(item).name) == true then
  123.                         -- If the current item is whitelisted, do nothing
  124.  
  125.                     else
  126.                         -- The item is not whitelisted
  127.                         turtle.dropDown()
  128.                     end
  129.                
  130.                 turtle.forward()
  131.                 turtle.down()
  132.                
  133.                 end
  134.            
  135.             else
  136.                 print("==> There is no chests in the inventory!")
  137.             end
  138.         end
  139.     end
  140. end
  141.  
  142.  
  143. function drop_all_cobblestone()
  144.     for i=1,16 do
  145.         if turtle.getItemDetail(i).name == "minecraft:cobblestone" then -- If the item is cobblestone, then...
  146.             turtle.select(i)
  147.             turtle.dropDown()
  148.         end
  149.     end
  150. end
  151.                
  152. function place_torch() -- The turtle will place a torch in the upper-right block (wall side)
  153.     -- Here we're assuming that the turtle is on the middle-ground block.
  154.     turtle.up()
  155.     turtle.turnRight()
  156.    
  157.     for item=1,16 do -- Loops through the inventory to search for torches.
  158.         if turtle.getItemDetail(item).name == "minecraft:torch" then -- If the item is a torch
  159.             turtle.select(item)
  160.             turtle.place() -- Place the torch on the wall
  161.         end
  162.     end
  163.  
  164.     turtle.turnLeft()
  165.     turtle.down()
  166. end
  167.  
  168. function main()
  169.     -- Starting point of the program
  170.     print("Sandai's NeoMiner [v"..program_version.."]")
  171.     print("Number of blocks to mine : ")
  172.     local blocks_to_mine = read().tonumber() -- cast the user's input to int
  173.     local actual_torch_distance = 0 -- The actual distance to the nearest torch
  174.  
  175.     print("[INSTRUCTIONS] :")
  176.     print("==> Items to have : chest, torches, coal/charcoal")
  177.     print("==> Items MUST be in the first slots of the turtle!")
  178.     print("Press [ENTER] to start mining...")
  179.     read()
  180.  
  181.     for mining_status=1,blocks_to_mine do
  182.         term.setCursorPos(1,1)
  183.         term.clear()
  184.  
  185.         print("[STATUS] : Mining...")
  186.         print("[MINING_STATUS]: ["..mining_status.."/"..blocks_to_mine.."] blocks")
  187.  
  188.         break_3x3() -- breaks a 3x3 area of blocks, then return at the middle-ground block.
  189.  
  190.         if turtle.getFuelLevel() <= 100 then -- if fuel level is behind 100 then refuel the turtle.
  191.             refuel_turtle()
  192.        
  193.         end
  194.  
  195.         drop_all_cobblestone()
  196.         check_if_turtle_full()
  197.         refuel_turtle()
  198.  
  199.         if actual_torch_distance >= min_torch_distance then -- If we need to place a torch...
  200.             place_torch()
  201.             actual_torch_distance = 0
  202.         end
  203.        
  204.         actual_torch_distance = actual_torch_distance + 1
  205.     end
  206.     print("Done!")
  207. end
  208.  
  209. main()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top