Advertisement
Guest User

core_mine

a guest
Mar 26th, 2015
254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.90 KB | None | 0 0
  1. local command_arguments= {...}
  2.  
  3. local command_right_meters= tonumber(command_arguments[1])
  4. local command_forward_meters= tonumber(command_arguments[2])
  5.  
  6. function should_keep_block(
  7.   block_name)
  8.  
  9.   local result= true
  10.  
  11.   local blacklist= {
  12.     "BiomesOPlenty:mud",
  13.     "chisel:andesite",
  14.     "chisel:cobblestone",
  15.     "chisel:diorite",
  16.     "chisel:granite",
  17.     "chisel:limestone",
  18.     "minecraft:cobblestone",
  19.     "minecraft:dirt",
  20.     "minecraft:gravel"}
  21.    
  22.   for index= 1,#blacklist do
  23.     if (block_name == blacklist[index]) then
  24.       result= false
  25.       break
  26.     end
  27.   end
  28.  
  29.   return result
  30. end
  31.  
  32. function find_slot_with_block_name(
  33.   block_name)
  34.  
  35.   local result= nil
  36.  
  37.   for index= 1,16 do
  38.     local slot_data= turtle.getItemDetail(index)
  39.  
  40.     if slot_data and (slot_data.name == block_name) then
  41.       result= index
  42.       break
  43.     end
  44.   end      
  45.  
  46.   return result
  47. end
  48.  
  49. function core_drill(
  50.   max_depth)
  51.  
  52.   local depth_stack= {}
  53.  
  54.   -- Dig down to max_depth or bedrock.
  55.   for depth_index= 1,max_depth do
  56.  
  57.     local below_is_filled, below_data= turtle.inspectDown()
  58.    
  59.     if not below_is_filled then
  60.       below_data= {name= "air", metadata= 0}
  61.     end
  62.  
  63.     if (below_data.name == "minecraft:bedrock") then
  64.       print("Found bedrock!")
  65.       break
  66.     end
  67.      
  68.     table.insert(depth_stack, below_data)
  69.    
  70.     turtle.digDown()
  71.     turtle.down()
  72.   end
  73.  
  74.   -- Return to the surface, replacing blocks as we go.
  75.   while (#depth_stack > 0) do
  76.     local popped= table.remove(depth_stack)
  77.  
  78.     turtle.up()
  79.    
  80.     local searched= popped
  81.    
  82.     if (searched.name == "minecraft:grass") then
  83.       searched.name= "minecraft:dirt"
  84.     end
  85.    
  86.     if (searched.name == "minecraft:stone") then
  87.       searched.name= "minecraft:cobblestone"
  88.     end
  89.    
  90.     if not should_keep_block(searched.name) then
  91.      
  92.       local slot_index= find_slot_with_block_name(searched.name)
  93.    
  94.       if slot_index then
  95.         turtle.select(slot_index)
  96.         turtle.placeDown()  
  97.         --print("Restored "..(searched.name))
  98.       end
  99.     else
  100.       print("Kept "..(popped.name))
  101.     end
  102.   end
  103. end
  104.  
  105. function core_mine(
  106.   forward_meters,
  107.   right_meters,
  108.   down_meters)
  109.  
  110.   for right_index= 1,right_meters do
  111.  
  112.     for forward_index= 1,forward_meters do
  113.      
  114.       core_drill(down_meters)
  115.      
  116.       if (forward_index < forward_meters) then
  117.         turtle.dig()
  118.         turtle.forward()
  119.       end
  120.     end
  121.    
  122.     if (right_index < right_meters) then
  123.       if (right_index%2 == 1) then
  124.         turtle.turnRight()
  125.       else
  126.         turtle.turnLeft()
  127.       end
  128.      
  129.       turtle.dig()
  130.       turtle.forward()
  131.      
  132.       if (right_index%2 == 1) then
  133.         turtle.turnRight()
  134.       else
  135.         turtle.turnLeft()
  136.       end
  137.     end
  138.   end
  139. end  
  140.        
  141. core_mine(
  142.   command_forward_meters,
  143.   command_right_meters,
  144.   300)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement