hashtagPinoy

Cubex

Sep 19th, 2021 (edited)
542
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --For hollowing out a large cube
  2. --Credit to OriginalCEEBS
  3.  
  4. local height = 0
  5. local width = 0
  6. local depth = 0
  7.  
  8. if #arg == 3 then
  9.  
  10.     height = tonumber(arg[1])
  11.     width = tonumber(arg[2])
  12.     depth = tonumber(arg[3])
  13.  
  14.     if (width % 2 == 0 or height  % 2 == 0) then
  15.         print("Please set values for height and width as odd")
  16.         return
  17.     elseif(width == 1 or height ==1) then
  18.         print("Please set values for height and width greater than 1")
  19.         return
  20.     end
  21.    
  22. else
  23.     print("Please enter values for height, width, and depth. You are missing a value")
  24.     return
  25. end
  26.  
  27. local ACCEPTED_FUELS = {
  28.     "minecraft:coal_block",
  29.     "minecraft:coal"
  30. }
  31.  
  32. local INVENTORY_SIZE = 16
  33. local heightMovement = math.floor(height/2)
  34. local widthMovement = math.floor(height/2)
  35.  
  36. function refuel(slot_number)
  37.     print("[TURTLE] Refueling...")
  38.     turtle.select(slot_number)
  39.     turtle.refuel()
  40. end
  41.  
  42.  
  43.  
  44. function checkFuel()
  45.     local minFuelLevel = math.ceil((height*width*depth)+(heightMovement+widthMovement))
  46.     local currentFuel = turtle.getFuelLevel()
  47.  
  48.     if(currentFuel < minFuelLevel) then
  49.         print("Attemping refueling process, stand by")
  50.        
  51.         for i = 1, INVENTORY_SIZE do
  52.             local current_item = turtle.getItemDetail(i)
  53.             if current_item ~= nil then
  54.                 for x = 1, #ACCEPTED_FUELS do
  55.                     if current_item.name == ACCEPTED_FUELS[x] then
  56.                         print("[TURTLE] Acceptable fuel found: " ..ACCEPTED_FUELS[x])
  57.  
  58.                         if currentFuel < minFuelLevel then
  59.                             refuel(i)
  60.                         else
  61.                             return true
  62.                         end
  63.  
  64.                     end
  65.                 end
  66.             end
  67.         end
  68.         print("[TURTLE] Out of fuel, terminating program...")
  69.         return false
  70.     else
  71.          return true
  72.     end
  73. end
  74.  
  75. function digUp()
  76.     while turtle.up() == false do
  77.         turtle.digUp()
  78.     end
  79. end
  80.  
  81. function digForward()
  82.     while turtle.forward() == false do
  83.         turtle.dig()
  84.     end
  85. end
  86.  
  87. function digDown()
  88.     while turtle.down() == false do
  89.         turtle.digDown()
  90.     end
  91. end
  92.  
  93. function moveToStart()
  94.  
  95.     turtle.turnLeft()
  96.     for i = 1, widthMovement do
  97.         digForward()
  98.     end
  99.     turtle.turnRight()
  100.  
  101.     for i = 1, heightMovement do
  102.         digUp()
  103.     end
  104. end
  105.  
  106. function miningSequence()
  107.  
  108.     moveToStart()
  109.  
  110.     for x = 1, depth do
  111.         digForward()
  112.  
  113.         for i = 1, height do
  114.            
  115.             if x % 2 == 0 then
  116.                 turtle.turnLeft()
  117.             else
  118.                 turtle.turnRight()
  119.             end
  120.  
  121.             for y = 1, width - 1 do
  122.                 digForward()
  123.             end
  124.  
  125.             if i ~= height then
  126.                 if x % 2 == 0 then
  127.                     turtle.turnLeft()
  128.                     digUp()
  129.                 else
  130.                     turtle.turnRight()
  131.                     digDown()
  132.                 end
  133.             end
  134.         end
  135.        
  136.         if x % 2 == 0 then
  137.             turtle.turnRight()
  138.         else
  139.             turtle.turnLeft()
  140.         end
  141.  
  142.     end
  143. end
  144.  
  145. if checkFuel() then
  146.     miningSequence()
  147. end
RAW Paste Data