Advertisement
Guest User

Untitled

a guest
Dec 1st, 2015
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.49 KB | None | 0 0
  1. -- Minecraft - Turtle - Drill down to bedrock and return to surface
  2. local protocol = "ZigMiningTurtles"
  3.  
  4. -- Check block in front of us against black list of blocks we don't want (dirt, stone)
  5. function blockValuable(name)
  6.   if name == "minecraft:dirt" then return false
  7.   elseif name == "minecraft:stone" then return false
  8.   elseif name == "minecraft:cobblestone" then return false
  9.   elseif name == "minecraft:gravel" then return false
  10.   elseif name == "minecraft:sand" then return false  
  11.   elseif name == "chisel:diorite" then return false
  12.   elseif name == "chisel:andesite" then return false
  13.   elseif name == "chisel:limestone" then return false
  14.   elseif name == "chisel:granite" then return false
  15.   end
  16.   return true
  17. end
  18.  
  19. -- mine block in front of us if it is valuable
  20. function mineValuableBlock()
  21.   local success, data = turtle.inspect()
  22.   if success then
  23.     if blockValuable(data.name) then
  24.       turtle.dig()
  25.     end
  26.   end
  27. end
  28.  
  29. -- Digs down until we reach bed rock
  30. function drillDown()
  31.   local depth = 0
  32.   turtle.digDown()
  33.  
  34.   while turtle.down() do
  35.     depth = depth + 1
  36.     mineValuableBlock()
  37.     turtle.turnRight()
  38.     mineValuableBlock()
  39.     turtle.turnRight()
  40.     mineValuableBlock()
  41.     turtle.turnRight()
  42.     mineValuableBlock()
  43.     turtle.turnRight() -- wasted movement (already checked ore), but this keeps our orientation the same
  44.  
  45.     turtle.digDown()
  46.   end
  47.   print("drilled down " .. depth .. " blocks")
  48.  
  49.   -- Sends the turtle back to (1 block below) the start
  50.   for index = 2,depth do
  51.     turtle.up()
  52.   end --for
  53.  
  54.   -- place "cap" on top of drilled hole using slot
  55.   turtle.select(1)
  56.   turtle.placeDown()
  57.  
  58.   -- go to original position (above ground level)
  59.   turtle.up()
  60.    
  61. end
  62.  
  63. -- Assumes there is an Ender chest in slot 2, which we place in front of us and then dump all of our inventory in it
  64. -- picking up the chest after we are done
  65. function dumpInventoryInChest()
  66.   print("Dumping inventory into Ender Chest (slot 2)")
  67.   turtle.select(2)
  68.   turtle.place() -- assumes the block in front of us is ok
  69.   turtle.select(1)
  70.   turtle.drop()
  71.   for slot=3, 16 do
  72.     turtle.select(slot)
  73.     turtle.drop()
  74.   end
  75.   turtle.select(2)
  76.   turtle.dig()
  77. end
  78.  
  79. -- Move forward 5 blocks, which efficiently covers a space in drill holes without checking any blocks twice
  80. function moveToNextDrillLocation()
  81.   print("Moving to next drill location (5 blocks forward)")
  82.   -- try to move forward, there may be something in front of us however, so dig it out
  83.   local i = 0
  84.   while i<5 do
  85.     turtle.dig()
  86.     local success = turtle.forward()
  87.     if success then
  88.       i = i + 1
  89.       turtle.digUp() -- make high enough for players to pass
  90.     else
  91.       turtle.dig()
  92.     end
  93.   end
  94. end
  95.  
  96. function controlServerOnline()
  97.   rednet.open("right")
  98.   local serverID = rednet.lookup(protocol)
  99.   if serverID then
  100.     local msg = serverID, os.getComputerLabel() .. " reporting in at " .. textutils.formatTime(os.time(), false) .. " FL: " .. turtle.getFuelLevel()
  101.     rednet.send(msg, protocol)
  102.     print(msg)
  103.     return true
  104.   else
  105.     print("Failed to find Turtle Mining Server, shutting down.")
  106.     return false
  107.   end
  108. end
  109.  
  110. -- Main script
  111. while true do
  112.   if not controlServerOnline() then
  113.     return
  114.   end
  115.  
  116.   if turtle.getFuelLevel() < 2800 then
  117.     print("Fuel level must be at least 2800 (drill down 65 blocks and return)")
  118.     return
  119.   end
  120.   print("Drilling down to bedrock.. ")
  121.   drillDown()
  122.   dumpInventoryInChest()
  123.   moveToNextDrillLocation()
  124. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement